const exec = require('child_process').exec,
    readline = require('readline');

module.exports = function() {
    return new Promise(function(resolve, reject) {
        exec('Wmic logicaldisk', (error, stdout, stderr) => {
            if (error) {
                reject(`exec error: ${error}`);
                return;
            }
            let disk_infos = {};
            let stdouts = stdout.toString().split('\n');
            stdouts.forEach(v => {
            	
                let info_ary = v.replace(/[\s]+/g, '-').split('-');
                //["0", "E:", "FALSE", "Win32_LogicalDisk", "���ع̶�����", "E:", "3", "NTFS", "190674534400", "255", "12", "E:",
                // "TRUE", "FALSE", "FALSE", "214748360704", "TRUE", "TRUE", "Win32_ComputerSystem", "DESKTOP", "5BI41SA", "FALSE", "��Ŀ", "0007824F", ""]

                let disk_info = {
                    id: info_ary[1], //盘符
                    size: +info_ary[15], //b  大小
                    free_space: +info_ary[8], //剩余空间
                    format: info_ary[7] //格式  fat32  ntfs
                };
                disk_infos[disk_info.id] = disk_info;
            })
            resolve(disk_infos);
        });
    });
};
