Commits (2)
......@@ -2,7 +2,7 @@
// This script parses a .ini file (default filename is install-xtrn.ini)
// and installs the external programs defined within into the Synchronet BBS
// configuration file: ctrl/xtrn.cnf. The programs defined within this file
// configuration file: ctrl/xtrn.ini. The programs defined within this file
// can by online programs (a.k.a. Doors), editors, or events.
//
// This script is intended for use by sysops using JSexec, for example:
......@@ -96,7 +96,7 @@
"use strict";
const REVISION = "3.18c";
const REVISION = "3.20a";
const ini_fname = "install-xtrn.ini";
load("sbbsdefs.js");
......@@ -114,7 +114,7 @@ function aborted()
return false;
}
function install_xtrn_item(cnf, type, name, desc, item, cats)
function install_xtrn_item(cfg, type, name, desc, item, cats)
{
if (!item.code)
return false;
......@@ -137,14 +137,14 @@ function install_xtrn_item(cnf, type, name, desc, item, cats)
return -1;
}
if(find_code(cnf[type], item.code) >= 0) {
if(find_code(cfg[type], item.code) >= 0) {
if(options.auto
|| deny(desc + " (" + item.code + ") already exists, continue"))
return false;
}
while (!item.code && !aborted()
|| (find_code(cnf[type], item.code) >= 0
|| (find_code(cfg[type], item.code) >= 0
&& print(desc + " Internal Code (" + item.code + ") already exists!")))
item.code = js.global.prompt(desc + " Internal code");
......@@ -166,7 +166,7 @@ function install_xtrn_item(cnf, type, name, desc, item, cats)
return false;
}
if (type == "xtrn") {
if (type == "prog") {
if (!xtrn_area.sec_list.length)
return "No external program sections have been created";
......@@ -207,9 +207,9 @@ function install_xtrn_item(cnf, type, name, desc, item, cats)
} catch(e) {
return e;
}
cnf[type].push(item);
cfg[type].push(item);
if (options.debug)
print(JSON.stringify(cnf[type], null, 4));
print(JSON.stringify(cfg[type], null, 4));
print(desc + " (" + item.name + ") installed successfully");
return true;
......@@ -321,10 +321,10 @@ function install(ini_fname)
if(subs.length)
print("Sub-categories: " + subs.join(", "));
var cnflib = load({}, "cnflib.js");
var xtrn_cnf = cnflib.read(system.ctrl_dir + "xtrn.cnf");
if (!xtrn_cnf)
return "Failed to read " + system.ctrl_dir + "xtrn.cnf";
var cfglib = load({}, "cfglib.js");
var xtrn_cfg = cfglib.read(system.ctrl_dir + "xtrn.ini");
if (!xtrn_cfg)
return "Failed to read " + system.ctrl_dir + "xtrn.ini";
var startup_dir = ini_fname.substr(0, Math.max(ini_fname.lastIndexOf("/"), ini_fname.lastIndexOf("\\"), 0));
startup_dir = relpath.get(system.ctrl_dir, startup_dir);
......@@ -338,9 +338,9 @@ function install(ini_fname)
return result;
const types = {
prog: { desc: "External Program", struct: "xtrn" },
prog: { desc: "External Program", struct: "prog" },
event: { desc: "External Timed Event", struct: "event" },
editor: { desc: "External Editor", struct: "xedit" }
editor: { desc: "External Editor", struct: "editor" }
};
var done = false;
......@@ -350,7 +350,7 @@ function install(ini_fname)
var item = list[i];
if (item.startup_dir === undefined)
item.startup_dir = startup_dir;
var result = install_xtrn_item(xtrn_cnf, types[t].struct, name, types[t].desc, item, cats);
var result = install_xtrn_item(xtrn_cfg, types[t].struct, name, types[t].desc, item, cats);
if (typeof result !== 'boolean')
return result;
if (result === true)
......@@ -459,8 +459,8 @@ function install(ini_fname)
}
if (installed) {
if (!options.debug && !cnflib.write(system.ctrl_dir + "xtrn.cnf", undefined, xtrn_cnf))
return "Failed to write " + system.ctrl_dir + "xtrn.cnf";
if (!options.debug && !cfglib.write(system.ctrl_dir + "xtrn.ini", undefined, xtrn_cfg))
return "Failed to write " + system.ctrl_dir + "xtrn.ini";
print("Installed " + installed + " items from " + ini_fname + " successfully");
}
......
// Helper load-library for configuration (ctrl/????.ini) files
// Replacement for cnflib.js use in SBBS v3.20+
const backup_level = 10;
function read_sections(f, prefix)
{
return f.iniGetAllObjects("code", prefix, /* lowercase: */false, /* blanks: */true);
}
function read_main_ini(filename)
{
}
function read_msgs_ini(filename)
{
}
function read_file_ini(filename)
{
}
function find_xtrn_sec(obj, code)
{
for(var i = 0; i < obj.sec.length; i++) {
if(obj.sec[i].code == code)
return i;
}
return -1;
}
function read_xtrn_ini(filename)
{
var f = new File(filename);
if(!f.open("r"))
throw "Error " + f.error + " opening " + f.name;
var obj = {};
obj.event = read_sections(f, "event:");
obj.editor = read_sections(f, "editor:");
obj.sec = read_sections(f, "sec:");
obj.prog = read_sections(f, "prog:");
obj.native = read_sections(f, "native:");
for(var i in obj.prog) {
var item = obj.prog[i];
var i = item.code.indexOf(':');
if(i >= 0) {
var seccode = item.code.substring(0, i);
var secnum = find_xtrn_sec(obj, seccode);
if(secnum < 0)
throw "Invalid xtrn prog sec name: " + seccode;
item.sec = secnum;
item.code = item.code.substring(i + 1);
}
}
return obj;
}
function write_sections(f, arr, prefix)
{
if(!arr)
return;
f.iniRemoveSections(prefix);
for(var i = 0; arr && i < arr.length; i++) {
var item = arr[i];
f.iniSetObject(prefix + item.code, item);
}
}
function write_xtrn_ini(filename, obj)
{
file_backup(filename, backup_level);
var f = new File(filename);
if(!f.open(f.exists ? 'r+' : 'w+'))
throw "Error " + f.error + " opening/creating " + f.name;
for(var i = 0; obj.prog && i < obj.prog.length; i++) {
var item = obj.prog[i];
if(obj.sec[item.sec] === undefined)
throw "Invalid section number: " + item.sec;
item.code = obj.sec[item.sec].code + ":" + item.code;
}
write_sections(f, obj.event, "event:");
write_sections(f, obj.editor, "editor:");
write_sections(f, obj.sec, "sec:");
write_sections(f, obj.prog, "prog:");
write_sections(f, obj.native, "native:");
return true;
}
function read_chat_ini(filename)
{
}
function read(filename, struct)
{
if(struct)
throw "struct argument not supported";
switch(file_getname(filename)) {
case "main.ini":
return read_main_ini(filename);
case "msgs.ini":
return read_msgs_ini(filename);
case "file.ini":
return read_file_ini(filename);
case "xtrn.ini":
return read_xtrn_ini(filename);
case "chat.ini":
return read_chat_ini(filename);
}
throw "unsupported filename: " + filename;
}
function write(filename, struct, obj)
{
if(struct)
throw "struct argument not supported";
switch(file_getname(filename)) {
case "main.ini":
return write_main_ini(filename, obj);
case "msgs.ini":
return write_msgs_ini(filename, obj);
case "file.ini":
return write_file_ini(filename, obj);
case "xtrn.ini":
return write_xtrn_ini(filename, obj);
case "chat.ini":
return write_chat_ini(filename, obj);
}
throw "unsupported filename: " + filename;
}
this;