function OnInit(initData) {
initData.name = 'EverythingFolderSize';
initData.version = '2024-04-30';
initData.url = 'https://resource.dopus.com/t/everythingfoldersize-use-everything-to-calculate-folder-sizes/44281';
initData.desc = 'Use Everything to display folder sizes';
initData.default_enable = true;
initData.min_version = '12.0';
initData.config_desc = DOpus.Create().Map();
initData.config_groups = DOpus.Create().Map();
initData.config_desc('exeES') = 'Enter full path to es.exe';
initData.config_groups('exeES') = '1 - Paths';
initData.config.exeES = '/programfiles\\Everything\\es.exe';
// initData.config.exeES = '/programfiles\\Everything 1.5a\\es.exe';
// Everything 1.4: Check "Index folder size" in Tools-Options-Indexes
// Everything 1.5: Everything-1.5a.ini needs to contain this line: alpha_instance=0
initData.config_desc('colType') = 'Set column type';
initData.config_groups('colType') = '2 - Columns';
initData.config.colType = DOpus.Create.Vector(0,
'size',
'number');
initData.config_desc('logLevel') = 'Set level of logging';
initData.config_groups('logLevel') = '3 - Logging';
initData.config.logLevel = DOpus.Create.Vector(0,
'none',
'standard',
'max');
}
function OnAddColumns(addColData) {
var col = addColData.AddColumn();
col.name = 'EverythingFolderSize';
col.header = 'EFS';
col.method = 'OnColumn';
col.justify = 'right';
col.type = Script.config.colType ? 'number' : 'size';
col.autorefresh = 2;
var exeES = fsu.Resolve(Script.config.exeES);
if (fsu.Exists(exeES)) {
Log(1, 'exeES: ' + exeES);
} else {
Log(1, 'exeES: ' + exeES);
Log(1, ' File not found!');
}
if (!fsu.Exists(exeES.pathpart + '\\Everything.exe') &&
!fsu.Exists(exeES.pathpart + '\\Everything64.exe')) {
Log(1, ' Everything.exe/Everything64.exe not found!');
}
Log(1, 'logLevel: ' + Script.config.logLevel);
Log(1, 'colType: ' + Script.config.colType);
}
function OnColumn(scriptColData) {
var item = scriptColData.item;
if (item.is_dir) {
if (item.path.drive == 0) return;
var dirVar = 'EFS"' + item + '"';
if (!DOpus.vars.Exists(dirVar)) return;
scriptColData.value = DOpus.vars.Get(dirVar);
} else {
scriptColData.value = item.size;
}
}
function OnOpenTab(openTabData) {
if (!openTabData.tab) {
Log(1, 'OnOpenTab: !openTabData.tab is true');
return;
}
if (openTabData.tab == undefined) {
Log(1, 'OnOpenTab: openTabData.tab == undefined');
return;
}
cmd.SetSourceTab(openTabData.tab);
if (!cmd.IsSet('Set COLUMNSTOGGLE=scp:EverythingFolderSize/EverythingFolderSize')) {
Log(1, 'OnOpenTab: No column "EverythingFolderSize" in this file display... nothing to do!');
return;
}
if (!openTabData.tab.path) {
Log(1, 'OnOpenTab: !openTabData.tab.path is true');
return;
}
if (openTabData.tab.path == undefined) {
Log(1, 'OnOpenTab: openTabData.tab.path == undefined');
return;
}
if (!String(openTabData.tab.path)) {
Log(1, 'OnOpenTab: Empty path!');
return;
}
Log(1, 'OnOpenTab: Calling QueryEverything...');
QueryEverything(openTabData.tab.path);
Log(1, 'OnOpenTab: ... done!');
}
function OnBeforeFolderChange(beforeFolderChangeData) {
if (!beforeFolderChangeData.tab) {
Log(1, 'OnBeforeFolderChange: no beforeFolderChangeData.tab');
return;
}
cmd.SetSourceTab(beforeFolderChangeData.tab);
if (!cmd.IsSet('Set COLUMNSTOGGLE=scp:EverythingFolderSize/EverythingFolderSize')) {
Log(1, 'OnBeforeFolderChange: No column "EverythingFolderSize" in this file display... nothing to do!');
return;
}
if (!beforeFolderChangeData.path) {
Log(1, 'OnBeforeFolderChange: no beforeFolderChangeData.path');
return;
}
if (beforeFolderChangeData.path.drive == 0) {
Log(1, 'OnBeforeFolderChange: beforeFolderChangeData.path.drive == 0');
return;
}
if (!String(beforeFolderChangeData.path)) {
Log(1, 'OnBeforeFolderChange: Empty path!');
return;
}
Log(1, 'OnBeforeFolderChange: Calling QueryEverything...');
QueryEverything(beforeFolderChangeData.path);
}
function QueryEverything(path) {
var exeES = fsu.Resolve(Script.config.exeES);
if (!fsu.Exists(exeES)) {
Log(1, 'exeES: ' + exeES);
Log(1, ' File not found!');
return;
}
var expPath = fsu.GetTempFilePath();
var cmdLine = '"' + exeES + '"' +
' -size' +
' -no-header' +
' -export-csv "' + expPath + '"' +
' -parent "' + path + '"' +
' /ad';
Log(1, cmdLine);
wsh.Run(cmdLine, 0, true);
var expFile = fsu.GetItem(expPath).Open();
var arr = stt.Decode(expFile.Read(), 'utf8').split('\r\n');
expFile.Close();
var re = /(\d+),(.*)/;
for (var i = 0; i < arr.length; i++) {
var line = arr[i].match(re);
if (!line) continue;
if (line.length != 3) continue;
var size = line[1];
var dirVar = 'EFS' + line[2];
DOpus.vars.Set(dirVar, size);
Log(2, dirVar + '\t' + size);
}
if (!Script.config.logLevel) {
cmd.RunCommand('Delete' +
' FILE="' + expPath + '"' +
' QUIET' +
' NORECYCLE');
// DOpus.Output('Deleted: ' + expPath);
}
}
function Log(level, str, time) {
var logLevel = Script.config ? Script.config.logLevel : 2;
if (!logLevel) return;
if (!level) return;
if (level > logLevel) return;
if (time) {
var currTime = DOpus.Create().Date();
str = padTime(currTime + currTime.ms - time - time.ms) + ' ' + str;
}
DOpus.Output(str);
}
var cmd = DOpus.Create().Command();
var stt = DOpus.Create().StringTools();
var fsu = DOpus.FSUtil();
var wsh = new ActiveXObject('WScript.Shell');