Skip to content
Snippets Groups Projects
Commit 1de4be85 authored by deuce's avatar deuce
Browse files

Add FREQITCfg object to fidocfg.js

Start of a FREQIT config script.
parent 319bdfab
No related branches found
No related tags found
No related merge requests found
......@@ -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();
......
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();
......@@ -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();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment