diff --git a/exec/freqit.js b/exec/freqit.js index 1ec23944bd5b1090e6532f6424fca29c3b5fca98..8e018dfdfd964f3f09fbcb1322139601a2cf3530 100644 --- a/exec/freqit.js +++ b/exec/freqit.js @@ -7,55 +7,6 @@ load("filebase.js"); load("fidocfg.js"); -function FREQITCfg() -{ - var f=new File(system.ctrl_dir+'freqit.ini'); - var val; - - if (!f.open('r')) { - log(LOG_ERROR, "Unable to open '"+f.name+"'"); - return; - } - // TODO: Support requiring passwords for specific files/dirs - this.dirs = []; - this.securedirs = []; - this.magic = {}; - val = f.iniGetValue(null, 'Dirs'); - if (val != undefined) - this.dirs = val.toLowerCase().split(/,/); - val = f.iniGetValue(null, 'SecureDirs'); - if (val != undefined) - this.securedirs = val.toLowerCase().split(/,/); - this.maxfiles=f.iniGetValue(null, 'MaxFiles', 10); - f.iniGetSections().forEach(function(key) { - var dir = f.iniGetValue(key, 'Dir'); - - if (dir == undefined) { - log(LOG_ERROR, "Magic value '"+key+"' without a dir configured"); - return; - } - if (this.magic === undefined) - this.magic = {}; - this.magic[key] = {}; - this.magic[key].dir=dir; - this.magic[key].match=f.iniGetValue(key, 'Match', '*'); - this.magic[key].secure=f.iniGetValue(key, 'Secure', 'No'); - switch(this.magic[key].secure.toUpperCase()) { - case 'TRUE': - case 'YES': - case 'ON': - this.magic[key].secure = true; - break; - default: - if (parseInt(this.magic[key].secure, 10)) { - this.magic[key].secure = true; - break; - } - this.magic[key].secure = false; - } - }); - f.close(); -} var cfg = new FREQITCfg(); diff --git a/exec/freqitcfg.js b/exec/freqitcfg.js new file mode 100644 index 0000000000000000000000000000000000000000..c2f290c8d70cc77c73eddc57c85862cfa7680441 --- /dev/null +++ b/exec/freqitcfg.js @@ -0,0 +1,95 @@ +load("uifcdefs.js"); +load("fidocfg.js"); + +var cfg=new FREQITCfg(); + +var dctx = {}; +var gctx = new uifc.list.CTX(); +function pick_dir() +{ + var cmd = 0; + var libs = Object.keys(file_area.lib); + + function do_pick_dir(grp) { + var dirs; + var dircodes; + var dir; + var ret; + + dir = 0; + while (dir >= 0) { + if (dctx[grp] === undefined) + dctx[grp] = new uifc.list.CTX(); + + dircodes = file_area.lib[libs[cmd]].dir_list.map(function(v){return v.code;}); + dirs = dircodes.map(function(v){return file_area.dir[v].name;}); + dir = uifc.list(WIN_BOT|WIN_SAV|WIN_ACT, "Select Dir", dirs, dctx[grp]); + if (dir >= 0) + return dircodes[dir]; + } + return undefined; + } + + while (cmd >= 0) { + cmd = uifc.list(WIN_RHT|WIN_SAV|WIN_ACT, "Select Group" , libs, gctx); + if (cmd >= 0) { + file = do_pick_dir(libs[cmd]); + if (file !== undefined) + return file; + } + } + return undefined; +} + +var dirctx = new uifc.list.CTX(); +function edit_dirs(list) +{ + var dir=0; + var dirs; + + while(dir >= 0) { + dirs = list.map(function(v){return file_area.dir[v].name;}); + dir = uifc.list(WIN_INS|WIN_INSACT|WIN_DEL|WIN_XTR|WIN_SAV, "Directories", dirs, dirctx); + if (dir == -1) + return undefined; + if (dir == dirs.length-1 || dir & MSK_INS) { + dir &= MSK_OFF; + var newdir=pick_dir(); + if (newdir) + list.splice(dir, 0, newdir); + } + else if (dir & MSK_DEL) { + dir &= MSK_OFF; + list.splice(dir, 1); + } + } + return undefined; +} + +function main() +{ + var cmd=0; + var ctx = new uifc.list.CTX(); + var opts; + + uifc.init("FREQIT Config"); + while (cmd >= 0) { + opts = ["Dirs...", "Secure Dirs...", format("Max Files (%d)", cfg.maxfiles), "Magic Names..."]; + cmd = uifc.list(WIN_ACT|WIN_ORG|WIN_MID, "FREQIT Options", opts, ctx); + switch(cmd) { + case 0: // Dirs + edit_dirs(cfg.dirs); + break; + case 1: // Secure Dirs + edit_dirs(cfg.securedirs); + break; + case 2: // Max Files + case 3: // Magic Names + case -1: // Done + // TODO: Save. + uifc.bail(); + } + } +} + +main(); diff --git a/exec/load/fidocfg.js b/exec/load/fidocfg.js index 8e6541102bc58930d24cdccdbcfaa81b5ed1f7ba..5a97e32a1da22e8092a9981be089b889ed4c8977 100644 --- a/exec/load/fidocfg.js +++ b/exec/load/fidocfg.js @@ -205,3 +205,53 @@ TickITCfg.prototype.save = function() tcfg.iniRemoveSection(sects[i]); tcfg.close(); } + +function FREQITCfg() +{ + var f=new File(system.ctrl_dir+'freqit.ini'); + var val; + + if (!f.open('r')) { + log(LOG_ERROR, "Unable to open '"+f.name+"'"); + return; + } + // TODO: Support requiring passwords for specific files/dirs + this.dirs = []; + this.securedirs = []; + this.magic = {}; + val = f.iniGetValue(null, 'Dirs'); + if (val != undefined) + this.dirs = val.toLowerCase().split(/,/); + val = f.iniGetValue(null, 'SecureDirs'); + if (val != undefined) + this.securedirs = val.toLowerCase().split(/,/); + this.maxfiles=f.iniGetValue(null, 'MaxFiles', 10); + f.iniGetSections().forEach(function(key) { + var dir = f.iniGetValue(key, 'Dir'); + + if (dir == undefined) { + log(LOG_ERROR, "Magic value '"+key+"' without a dir configured"); + return; + } + if (this.magic === undefined) + this.magic = {}; + this.magic[key] = {}; + this.magic[key].dir=dir; + this.magic[key].match=f.iniGetValue(key, 'Match', '*'); + this.magic[key].secure=f.iniGetValue(key, 'Secure', 'No'); + switch(this.magic[key].secure.toUpperCase()) { + case 'TRUE': + case 'YES': + case 'ON': + this.magic[key].secure = true; + break; + default: + if (parseInt(this.magic[key].secure, 10)) { + this.magic[key].secure = true; + break; + } + this.magic[key].secure = false; + } + }); + f.close(); +}