2024-10-13 19:38:18 +00:00
|
|
|
// app.js
|
|
|
|
// Bootstrap code for running a javascript app in windows. Run as:
|
|
|
|
// cscript.js app.js <appname> <app arguments> ...
|
|
|
|
//
|
|
|
|
// Author: Namhyeon Go <abuse@catswords.net>
|
|
|
|
// Repository: https://github.com/gnh1201/welsonjs
|
|
|
|
// Report abuse: abuse@catswords.net
|
|
|
|
// Latest news: [ActivityPub @catswords_oss@catswords.social](https://catswords.social/@catswords_oss)
|
|
|
|
// Join our team: https://teams.live.com/l/community/FEACHncAhq8ldnojAI
|
|
|
|
//
|
2024-07-22 07:12:45 +00:00
|
|
|
"use strict";
|
|
|
|
|
2020-07-23 02:41:33 +00:00
|
|
|
var exit = function(status) {
|
2022-11-04 06:43:22 +00:00
|
|
|
console.error("Exit", status, "caused");
|
2021-04-28 07:28:43 +00:00
|
|
|
|
2022-11-04 06:43:22 +00:00
|
|
|
if (typeof WScript !== "undefined") {
|
2024-01-08 06:42:54 +00:00
|
|
|
WScript.Quit(status);
|
2024-07-22 15:22:01 +00:00
|
|
|
return;
|
2022-11-04 06:43:22 +00:00
|
|
|
} else if (typeof window !== "undefined") {
|
2021-04-28 07:32:17 +00:00
|
|
|
window.close();
|
2024-07-22 15:22:01 +00:00
|
|
|
return;
|
2021-04-28 07:32:17 +00:00
|
|
|
}
|
2024-07-22 15:22:01 +00:00
|
|
|
|
|
|
|
// to exit completely
|
|
|
|
throw new Error("Exit " + status + " caused");
|
2020-07-23 02:41:33 +00:00
|
|
|
};
|
2020-07-03 09:15:23 +00:00
|
|
|
|
2020-06-28 14:22:57 +00:00
|
|
|
var console = {
|
2021-04-29 07:49:36 +00:00
|
|
|
_timers: {},
|
2021-04-29 08:05:53 +00:00
|
|
|
_counters: {},
|
2020-11-04 07:41:56 +00:00
|
|
|
_messages: [],
|
2020-11-25 03:16:42 +00:00
|
|
|
_join: function(args, sep) {
|
|
|
|
args = args || [];
|
|
|
|
sep = sep || ' ';
|
|
|
|
var res = '';
|
|
|
|
for (var i = args.length - 1; i > -1; i--) {
|
|
|
|
res = (i ? sep : '') + args[i] + res;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
},
|
2024-07-21 09:37:54 +00:00
|
|
|
_echoDefault: function(message) {
|
2022-11-04 06:43:22 +00:00
|
|
|
if (typeof WScript !== "undefined") {
|
2024-01-08 06:42:54 +00:00
|
|
|
WScript.Echo("[*] " + message)
|
2022-11-04 06:43:22 +00:00
|
|
|
}
|
|
|
|
},
|
2024-07-21 09:37:54 +00:00
|
|
|
_echoCallback: null,
|
2020-11-18 04:13:38 +00:00
|
|
|
_echo: function(args, type) {
|
2024-11-14 18:48:19 +00:00
|
|
|
var messages = [];
|
2022-02-09 10:09:33 +00:00
|
|
|
var params = {
|
|
|
|
type: type,
|
2024-07-21 09:37:54 +00:00
|
|
|
scope: [],
|
2022-11-28 17:49:58 +00:00
|
|
|
message: '',
|
2022-05-03 04:25:29 +00:00
|
|
|
datetime: new Date().toISOString()
|
2022-02-09 10:09:33 +00:00
|
|
|
};
|
|
|
|
|
2024-11-14 18:48:19 +00:00
|
|
|
var argl = args.length;
|
|
|
|
for (var i = 0; i < argl; i++) {
|
|
|
|
switch (typeof args[i]) {
|
|
|
|
case "string":
|
|
|
|
messages.push(args[i]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "number":
|
|
|
|
case "boolean":
|
|
|
|
messages.push(String(args[i]));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "object":
|
|
|
|
if ("message" in args[i]) {
|
|
|
|
messages.push(args[i].message);
|
|
|
|
for (var k in args[i]) {
|
|
|
|
params[k] = args[i][k];
|
|
|
|
}
|
2022-05-03 04:24:33 +00:00
|
|
|
} else {
|
2024-11-14 18:48:19 +00:00
|
|
|
messages.push("[object Object]");
|
2022-05-03 04:24:33 +00:00
|
|
|
}
|
2024-11-14 18:48:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "unknown":
|
|
|
|
messages.push("[unknown]");
|
|
|
|
break;
|
2022-02-09 10:09:33 +00:00
|
|
|
}
|
2020-07-03 11:14:20 +00:00
|
|
|
}
|
2024-11-14 18:48:19 +00:00
|
|
|
|
|
|
|
var message = messages.join(' ');
|
|
|
|
this._echoDefault(message);
|
|
|
|
this._messages.push(message);
|
2022-01-27 01:34:48 +00:00
|
|
|
|
2024-07-21 09:37:54 +00:00
|
|
|
if (params.scope.length > 0 && this._echoCallback != null) {
|
2022-02-25 07:17:29 +00:00
|
|
|
try {
|
2022-05-03 04:24:33 +00:00
|
|
|
this._echoCallback(params, type);
|
2022-02-25 07:17:29 +00:00
|
|
|
} catch (e) {
|
2024-07-21 09:37:54 +00:00
|
|
|
this._echoDefault("Exception:" + e.message);
|
2022-02-25 07:17:29 +00:00
|
|
|
}
|
2022-01-27 01:34:48 +00:00
|
|
|
}
|
2020-07-07 15:55:50 +00:00
|
|
|
},
|
2021-04-28 07:45:56 +00:00
|
|
|
assert: function(assertion) {
|
|
|
|
if (arguments.length > 1 && assertion === arguments[0]) {
|
|
|
|
if(!assertion) {
|
2024-07-21 09:37:54 +00:00
|
|
|
this.error("Assertion failed:", this._join(arguments.slice(1)));
|
2021-04-28 07:45:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2021-04-28 07:28:43 +00:00
|
|
|
clear: function() {
|
|
|
|
this._messages = [];
|
|
|
|
},
|
2020-11-18 04:13:38 +00:00
|
|
|
log: function() {
|
|
|
|
this._echo(arguments);
|
2020-07-23 02:41:33 +00:00
|
|
|
},
|
2020-11-18 04:13:38 +00:00
|
|
|
error: function() {
|
|
|
|
this._echo(arguments, "error");
|
2020-07-07 17:06:38 +00:00
|
|
|
},
|
2020-11-18 04:13:38 +00:00
|
|
|
info: function() {
|
|
|
|
this._echo(arguments, "info");
|
2020-07-07 17:06:38 +00:00
|
|
|
},
|
2020-11-18 04:13:38 +00:00
|
|
|
warn: function() {
|
|
|
|
this._echo(arguments, "warn");
|
2020-07-23 02:47:17 +00:00
|
|
|
},
|
2020-11-18 04:13:38 +00:00
|
|
|
debug: function() {
|
|
|
|
this._echo(arguments, "debug");
|
2021-04-29 07:49:36 +00:00
|
|
|
},
|
|
|
|
time: function(label) {
|
2021-04-29 08:05:53 +00:00
|
|
|
label = label || "default";
|
|
|
|
if (!(label in this._timers)) {
|
|
|
|
this._timers[label] = new Date();
|
|
|
|
}
|
2021-04-29 07:49:36 +00:00
|
|
|
},
|
|
|
|
timeLog: function(label, end) {
|
2021-04-29 08:05:53 +00:00
|
|
|
label = label || "default";
|
2021-04-29 07:49:36 +00:00
|
|
|
if (label in this._timers) {
|
2021-08-10 08:48:47 +00:00
|
|
|
console.debug(label + ":", ((new Date()).getTime() - this._timers[label].getTime()) + "ms", (end ? " - timer ended" : ""));
|
2021-04-29 07:49:36 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
timeEnd: function(label) {
|
2021-04-29 08:05:53 +00:00
|
|
|
label = label || "default";
|
2021-04-29 07:49:36 +00:00
|
|
|
if (label in this._timers) {
|
|
|
|
this.timeLog();
|
|
|
|
delete this._timers[label];
|
|
|
|
}
|
2021-04-29 08:05:53 +00:00
|
|
|
},
|
|
|
|
count: function(label) {
|
|
|
|
label = label || "default";
|
|
|
|
if (!(label in this._counters)) {
|
|
|
|
this._counters[label] = 1;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
countReset: function(label) {
|
|
|
|
label = label || "default";
|
|
|
|
if (label in this._counters) {
|
|
|
|
this.timeLog();
|
|
|
|
delete this._counters[label];
|
|
|
|
}
|
2020-07-07 17:06:38 +00:00
|
|
|
}
|
2020-06-28 14:22:57 +00:00
|
|
|
};
|
|
|
|
|
2022-11-04 06:43:22 +00:00
|
|
|
if (typeof CreateObject === "undefined") {
|
2020-11-10 09:13:41 +00:00
|
|
|
var CreateObject = function(progId, serverName, callback) {
|
2021-08-10 06:27:47 +00:00
|
|
|
var progIds = (progId instanceof Array ? progId : [progId]);
|
2020-10-20 05:18:00 +00:00
|
|
|
|
|
|
|
for (var i = 0; i < progIds.length; i++) {
|
|
|
|
try {
|
2023-09-04 18:27:00 +00:00
|
|
|
var obj = CreateObject.make(progIds[i], serverName);
|
2022-11-04 06:43:22 +00:00
|
|
|
if (typeof callback === "function") {
|
2020-11-10 09:13:41 +00:00
|
|
|
callback(obj, progIds[i]);
|
|
|
|
}
|
|
|
|
return obj;
|
2020-11-04 07:30:52 +00:00
|
|
|
} catch (e) {
|
|
|
|
console.error(e.message);
|
|
|
|
};
|
2020-10-20 05:18:00 +00:00
|
|
|
}
|
2020-07-23 10:39:24 +00:00
|
|
|
};
|
2023-09-04 18:27:00 +00:00
|
|
|
CreateObject.make = function(p, s) {
|
|
|
|
if (typeof WScript !== "undefined") {
|
2024-01-08 06:42:54 +00:00
|
|
|
if ("CreateObject" in WScript) {
|
|
|
|
return WScript.CreateObject(p, s);
|
|
|
|
} else {
|
|
|
|
console.warn("(Chakra) The standalone engine does not supported. Please use the built-in engine.");
|
|
|
|
console.warn("(Chakra) hint:", "cscript //NoLogo //E:{1b7cd997-e5ff-4932-a7a6-2a9e636da385} app.js <filename> <...arguments>");
|
2024-06-09 21:23:35 +00:00
|
|
|
throw new Error("Could not find a loader");
|
2024-01-08 06:42:54 +00:00
|
|
|
}
|
2023-09-04 18:27:00 +00:00
|
|
|
} else if (typeof ActiveXObject !== "undefined") {
|
|
|
|
return new ActiveXObject(p);
|
2024-06-09 21:23:35 +00:00
|
|
|
} else {
|
|
|
|
throw new Error("Could not find a loader");
|
2023-09-04 18:27:00 +00:00
|
|
|
}
|
|
|
|
};
|
2020-07-23 10:35:53 +00:00
|
|
|
}
|
|
|
|
|
2021-04-24 20:32:31 +00:00
|
|
|
/**
|
|
|
|
* @FN {string} The name of the file.
|
|
|
|
*/
|
2024-08-14 05:25:55 +00:00
|
|
|
function __evalFile__(FN) {
|
|
|
|
try {
|
|
|
|
return eval(require._load(FN));
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e.message);
|
|
|
|
}
|
2021-08-10 06:27:47 +00:00
|
|
|
}
|
2021-06-20 18:17:58 +00:00
|
|
|
|
2021-08-10 06:27:47 +00:00
|
|
|
/**
|
|
|
|
* @FN {string} The name of the file.
|
|
|
|
*/
|
2024-01-26 09:27:11 +00:00
|
|
|
function require(pathname) {
|
2024-07-21 09:57:57 +00:00
|
|
|
var cache = require._cache = require._cache || {};
|
2024-01-26 09:27:11 +00:00
|
|
|
var suffix = (function(pos, s) {
|
2024-07-22 15:22:01 +00:00
|
|
|
return pos < 0 ? '.' : s.substring(pos);
|
2024-01-26 09:27:11 +00:00
|
|
|
})(pathname.lastIndexOf('.'), pathname);
|
|
|
|
var FN = pathname;
|
2021-08-10 06:32:32 +00:00
|
|
|
|
2024-01-26 07:58:27 +00:00
|
|
|
if ('.js$.jse$.coffee$.ls$.ts$.re$.res$.enc$'.indexOf(suffix + '$') < 0) FN += ".js";
|
2020-06-28 14:22:57 +00:00
|
|
|
if (cache[FN]) return cache[FN];
|
2022-11-28 08:32:21 +00:00
|
|
|
|
2024-07-21 15:56:55 +00:00
|
|
|
var T = null;
|
|
|
|
var pos = FN.indexOf('://');
|
2024-10-13 19:38:18 +00:00
|
|
|
if (pos > -1) {
|
|
|
|
// load script from a remote server
|
2024-07-21 15:56:55 +00:00
|
|
|
if (["http", "https"].indexOf(FN.substring(0, pos)) > -1) {
|
|
|
|
require._addScriptProvider(function(url) {
|
|
|
|
try {
|
|
|
|
return require("lib/http").get(url);
|
|
|
|
} catch (e) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (require._scriptProviders.length > 0) {
|
|
|
|
var i = 0;
|
|
|
|
while (T == null && i < require._scriptProviders.length) {
|
|
|
|
try {
|
|
|
|
T = require._scriptProviders[i](FN) || null;
|
|
|
|
break;
|
|
|
|
} catch (e) {
|
|
|
|
T = null;
|
|
|
|
}
|
|
|
|
i++;
|
2024-07-21 10:23:38 +00:00
|
|
|
}
|
2023-12-11 03:10:54 +00:00
|
|
|
}
|
2024-10-13 19:38:18 +00:00
|
|
|
} else {
|
|
|
|
// load script from a local server
|
2024-07-21 10:23:38 +00:00
|
|
|
var _filename = (function(fs, path) {
|
|
|
|
var filepaths = [
|
|
|
|
FN, // default
|
|
|
|
path.join(pathname, "index.js"), // default
|
|
|
|
path.join(FN + '.enc'), // default (encrypted)
|
|
|
|
path.join(pathname, 'index.js.enc'), // default (encrypted)
|
|
|
|
path.join("Scripts", FN), // NuGet
|
|
|
|
path.join("Scripts", pathname, "index.js"), // NuGet
|
|
|
|
path.join("bower_components", FN), // Bower
|
|
|
|
path.join("bower_components", pathname, "index.js"), // Bower
|
|
|
|
path.join("node_modules", FN), // NPM
|
|
|
|
path.join("node_modules", pathname, "index.js"), // NPM
|
|
|
|
];
|
|
|
|
var filename = filepaths[0];
|
|
|
|
|
2024-07-21 15:56:55 +00:00
|
|
|
var i = 0;
|
2024-07-21 10:23:38 +00:00
|
|
|
while (!fs.existsSync(filename) && i < filepaths.length) {
|
|
|
|
filename = filepaths[i];
|
|
|
|
i++;
|
|
|
|
}
|
2023-12-11 03:10:54 +00:00
|
|
|
|
2024-07-21 10:23:38 +00:00
|
|
|
return filename;
|
|
|
|
})({
|
|
|
|
existsSync: function(filename) {
|
|
|
|
return CreateObject("Scripting.FileSystemObject").FileExists(filename);
|
2023-12-11 03:10:54 +00:00
|
|
|
}
|
2024-07-21 10:23:38 +00:00
|
|
|
}, {
|
|
|
|
join: function() {
|
|
|
|
var result = arguments[0];
|
|
|
|
for (var i = 1; i < arguments.length; i++) {
|
|
|
|
result += "\\" + arguments[i];
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
var _dirname = (function(dirname) {
|
|
|
|
var currentScriptDirectory = require._getCurrentScriptDirectory();
|
|
|
|
return dirname.length > 0 ? currentScriptDirectory + "\\" + dirname : currentScriptDirectory;
|
|
|
|
})(require._getDirName(_filename));
|
|
|
|
T = require._load(_filename);
|
|
|
|
|
|
|
|
// check the suffix again
|
|
|
|
suffix = (function(pos, s) {
|
2024-07-22 15:22:01 +00:00
|
|
|
return pos < 0 ? '.' : s.substring(pos);
|
2024-07-21 10:23:38 +00:00
|
|
|
})(_filename.lastIndexOf('.'), _filename);
|
|
|
|
}
|
2020-07-19 21:19:33 +00:00
|
|
|
|
2023-08-02 06:59:05 +00:00
|
|
|
// transpile
|
2022-11-29 05:22:58 +00:00
|
|
|
switch (suffix) {
|
|
|
|
case '.coffee': // CoffeeScript 2
|
2024-07-21 09:57:57 +00:00
|
|
|
T = require._msie9("app/assets/js/coffeescript-legacy-2.7.0.min", [T], function(p, w, d, l) {
|
2022-11-29 05:22:58 +00:00
|
|
|
return w.CoffeeScript.compile(p[0], {
|
|
|
|
"header": true,
|
|
|
|
"sourceMap": false,
|
|
|
|
"bare": true
|
|
|
|
});
|
2022-11-28 14:32:21 +00:00
|
|
|
});
|
2022-11-29 05:22:58 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ".ls": // LiveScript
|
2024-07-21 09:57:57 +00:00
|
|
|
T = require._msie9("app/assets/js/livescript-1.6.1.min", [T, "app/assets/ls/prelude.ls"], function(p, w, d, l) {
|
|
|
|
return w.require("livescript").compile(require._load(p[1]) + "\n\n" + p[0], {
|
2022-11-29 05:22:58 +00:00
|
|
|
"header": true,
|
2022-11-29 08:12:19 +00:00
|
|
|
"bare": true
|
2022-11-29 05:22:58 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
break;
|
2022-12-22 06:30:39 +00:00
|
|
|
|
2022-12-22 06:55:00 +00:00
|
|
|
case ".ts": // TypeScript
|
2024-07-21 09:57:57 +00:00
|
|
|
T = require._modernie("app/assets/js/typescript-4.9.4", [T], function(p, w, d, l) {
|
2022-12-22 06:30:39 +00:00
|
|
|
return w.ts.transpile(p[0]);
|
|
|
|
});
|
|
|
|
break;
|
2023-08-02 06:59:05 +00:00
|
|
|
|
|
|
|
case ".re": // Rescript (aka. BuckleScript, ReasonML)
|
2023-12-11 06:35:33 +00:00
|
|
|
case ".res":
|
2024-07-21 09:57:57 +00:00
|
|
|
T = require._modernie("app/assets/js/rescript-compiler-10.1.2", [T], function(p, w, d, l) {
|
2023-08-02 06:59:05 +00:00
|
|
|
var compiler = w.rescript_compiler.make();
|
|
|
|
var result = compiler.rescript.compile(p[0]);
|
|
|
|
return result.js_code;
|
|
|
|
});
|
|
|
|
break;
|
2024-01-26 07:55:49 +00:00
|
|
|
|
2024-11-05 11:01:34 +00:00
|
|
|
case ".enc": // encrypted script (require WelsonJS.Toolkit)
|
2024-07-21 09:57:57 +00:00
|
|
|
T = (function(data, o) {
|
2024-01-26 07:57:53 +00:00
|
|
|
try {
|
2024-07-21 09:57:57 +00:00
|
|
|
var s = '', i = 0, k = 6;
|
|
|
|
while (i < k && (s.length == 0 || s.length > 16)) {
|
|
|
|
if (i > 0) {
|
2024-01-27 05:12:40 +00:00
|
|
|
console.error("Invalid key length");
|
|
|
|
}
|
2024-07-21 09:57:57 +00:00
|
|
|
s = o.Prompt("This file has been encrypted. Please enter the password:");
|
|
|
|
i++;
|
2024-01-26 07:57:53 +00:00
|
|
|
}
|
2024-07-21 09:57:57 +00:00
|
|
|
if (i == k) return '';
|
2024-11-05 11:01:34 +00:00
|
|
|
return o.DecryptString(s, data);
|
2024-01-26 07:57:53 +00:00
|
|
|
} catch (e) {
|
|
|
|
console.error("Failed to load the encrypted data:", e.message);
|
|
|
|
return '';
|
2024-01-26 07:55:49 +00:00
|
|
|
}
|
2024-01-26 15:50:07 +00:00
|
|
|
})(T, CreateObject("WelsonJS.Toolkit"));
|
2024-01-26 07:55:49 +00:00
|
|
|
break;
|
2022-11-28 08:32:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// compile
|
2024-07-21 09:57:57 +00:00
|
|
|
T = "(function(global){var module=new require.__Module__();return(function(exports,require,module,__filename,__dirname){"
|
2021-04-29 12:17:15 +00:00
|
|
|
+ '"use strict";'
|
|
|
|
+ T
|
2024-07-21 09:57:57 +00:00
|
|
|
+ "\n\nreturn module.exports})(module.exports,global.require,module,_filename,_dirname)})(require._global);\n\n////@ sourceURL="
|
2021-08-10 06:27:47 +00:00
|
|
|
+ FN
|
2021-08-10 06:33:57 +00:00
|
|
|
;
|
2021-04-24 20:32:31 +00:00
|
|
|
|
2021-08-10 06:32:32 +00:00
|
|
|
// execute
|
2021-08-10 06:33:57 +00:00
|
|
|
try {
|
|
|
|
cache[FN] = eval(T);
|
|
|
|
} catch (e) {
|
2021-08-10 07:41:25 +00:00
|
|
|
console.error("PARSE ERROR!", e.number + ",", e.description + ",", "FN=" + FN);
|
2021-08-10 06:33:57 +00:00
|
|
|
}
|
2020-06-28 14:22:57 +00:00
|
|
|
|
2022-09-27 08:54:47 +00:00
|
|
|
// print VERSIONINFO and AUTHOR
|
2022-11-04 06:43:22 +00:00
|
|
|
if (typeof cache[FN] === "object") {
|
2022-09-27 08:54:47 +00:00
|
|
|
if ("VERSIONINFO" in cache[FN]) {
|
|
|
|
if ("AUTHOR" in cache[FN]) {
|
|
|
|
console.log(cache[FN].VERSIONINFO + " by " + cache[FN].AUTHOR);
|
|
|
|
} else {
|
|
|
|
console.log(cache[FN].VERSIONINFO);
|
|
|
|
}
|
|
|
|
}
|
2020-07-07 23:03:02 +00:00
|
|
|
}
|
2020-07-19 21:19:33 +00:00
|
|
|
|
|
|
|
return cache[FN];
|
2020-07-07 23:03:02 +00:00
|
|
|
}
|
2024-07-21 09:57:57 +00:00
|
|
|
require.__Module__ = function() {
|
2021-08-10 06:27:47 +00:00
|
|
|
this.exports = {};
|
|
|
|
};
|
2024-07-21 09:57:57 +00:00
|
|
|
require._global = this;
|
|
|
|
require._getDirName = function(path) {
|
2023-12-11 02:40:31 +00:00
|
|
|
var pos = Math.max.apply(null, [path.lastIndexOf("\\"), path.lastIndexOf("/")]);
|
2021-08-10 06:33:57 +00:00
|
|
|
return (pos > -1 ? path.substring(0, pos) : "");
|
2021-08-10 06:27:47 +00:00
|
|
|
};
|
2024-07-21 09:57:57 +00:00
|
|
|
require._getCurrentScriptDirectory = function() {
|
2024-07-22 15:22:01 +00:00
|
|
|
try {
|
|
|
|
if (typeof WScript !== "undefined") {
|
|
|
|
if ("ScriptFullName" in WScript) {
|
|
|
|
return require._getDirName(WScript.ScriptFullName);
|
|
|
|
} else {
|
|
|
|
throw new Error("No detected an absolute path.");
|
|
|
|
}
|
|
|
|
} else if (typeof document !== "undefined") {
|
|
|
|
return require._getDirName(document.location.pathname);
|
2024-01-08 06:42:54 +00:00
|
|
|
} else {
|
2024-07-22 15:22:01 +00:00
|
|
|
throw new Error("No detected an absolute path.");
|
2024-01-08 06:42:54 +00:00
|
|
|
}
|
2024-07-22 15:22:01 +00:00
|
|
|
} catch (e) {
|
|
|
|
console.warn(e.message, "Use the relative path.");
|
2021-08-10 06:33:57 +00:00
|
|
|
}
|
2024-07-22 15:22:01 +00:00
|
|
|
|
|
|
|
return ".";
|
2021-08-10 06:27:47 +00:00
|
|
|
};
|
2024-07-21 09:57:57 +00:00
|
|
|
require._load = function(FN) {
|
2023-08-02 06:59:05 +00:00
|
|
|
// if empty
|
|
|
|
if (FN == '') return '';
|
|
|
|
|
2021-08-10 06:33:57 +00:00
|
|
|
// get filename
|
2024-07-21 09:57:57 +00:00
|
|
|
var _filename = require._getCurrentScriptDirectory() + "\\" + FN;
|
2021-08-10 06:33:57 +00:00
|
|
|
|
|
|
|
// load script file
|
2022-11-28 16:56:58 +00:00
|
|
|
// use ADODB.Stream instead of Scripting.FileSystemObject, because of supporting UTF-8 (Unicode)
|
2021-08-10 06:33:57 +00:00
|
|
|
var objStream = CreateObject("ADODB.Stream");
|
|
|
|
var T = null;
|
|
|
|
try {
|
|
|
|
objStream.charSet = "utf-8";
|
|
|
|
objStream.open();
|
2024-07-21 09:57:57 +00:00
|
|
|
objStream.loadFromFile(_filename);
|
2021-08-10 06:33:57 +00:00
|
|
|
T = objStream.readText();
|
|
|
|
objStream.close();
|
|
|
|
} catch (e) {
|
2021-08-10 07:41:25 +00:00
|
|
|
console.error("LOAD ERROR!", e.number + ",", e.description + ",", "FN=" + FN);
|
2021-08-10 06:33:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return T;
|
2021-08-10 06:27:47 +00:00
|
|
|
};
|
2024-07-21 09:57:57 +00:00
|
|
|
require._msie9 = function(FN, params, callback) {
|
2023-08-02 06:59:05 +00:00
|
|
|
if (typeof FN !== "string" || FN == null) FN = '';
|
2024-07-22 07:12:45 +00:00
|
|
|
else if (FN.substring(FN.length - 3) !== '.js') FN += ".js";
|
2022-11-28 14:32:21 +00:00
|
|
|
|
|
|
|
var exports = null;
|
2022-11-28 16:56:58 +00:00
|
|
|
try {
|
2024-07-21 09:57:57 +00:00
|
|
|
var T = require._load("app/assets/js/core-js-3.26.1.minified.js")
|
|
|
|
+ "\n\n" + require._load("app/assets/js/html5shiv-printshiv-3.7.3.min.js")
|
|
|
|
+ "\n\n" + require._load("app/assets/js/modernizr-2.8.3.min.js")
|
|
|
|
+ "\n\n" + require._load(FN);
|
2022-11-28 16:56:58 +00:00
|
|
|
var htmlfile = CreateObject("htmlfile");
|
|
|
|
htmlfile.write('<meta http-equiv="X-UA-Compatible" content="IE=9">');
|
|
|
|
htmlfile.write('<script type="text/javascript">//<!--<![CDATA[\n' + T + '\n//]]>--></script>');
|
2022-11-29 09:49:03 +00:00
|
|
|
if (typeof callback === "function") {
|
2023-07-26 16:38:32 +00:00
|
|
|
var loadScript = function(FN) {
|
|
|
|
if (FN.indexOf('://') > -1) {
|
|
|
|
htmlfile.write('<script type="text/javascript" src="' + FN + '"></script>');
|
|
|
|
} else {
|
2024-07-21 09:57:57 +00:00
|
|
|
htmlfile.write('<script type="text/javascript">//<!--<![CDATA[\n' + require._load(FN) + '\n//]]>--></script>');
|
2023-07-26 16:38:32 +00:00
|
|
|
}
|
|
|
|
};
|
2022-11-29 09:49:03 +00:00
|
|
|
//console.log(htmlfile.parentWindow.navigator.userAgent);
|
2023-07-26 16:38:32 +00:00
|
|
|
exports = callback(params, htmlfile.parentWindow, htmlfile.parentWindow.document, loadScript);
|
2022-11-29 09:49:03 +00:00
|
|
|
}
|
|
|
|
htmlfile.close();
|
|
|
|
} catch (e) {
|
|
|
|
console.error("LOAD ERROR!", e.number + ",", e.description + ",", "FN=" + FN);
|
|
|
|
}
|
|
|
|
|
|
|
|
return exports;
|
|
|
|
};
|
2024-07-21 09:57:57 +00:00
|
|
|
require._modernie = function(FN, params, callback) {
|
2023-08-02 06:59:05 +00:00
|
|
|
if (typeof FN !== "string" || FN == null) FN = '';
|
2024-07-22 15:22:01 +00:00
|
|
|
else if (FN.substring(FN.length - 3) !== '.js') FN += ".js";
|
2022-11-29 09:49:03 +00:00
|
|
|
|
|
|
|
var exports = null;
|
|
|
|
try {
|
2022-12-22 06:55:00 +00:00
|
|
|
var ua = '', T = '', htmlfile = CreateObject("htmlfile");
|
2022-12-22 06:30:39 +00:00
|
|
|
|
2022-11-29 09:49:03 +00:00
|
|
|
htmlfile.write('<meta http-equiv="X-UA-Compatible" content="IE=edge">');
|
2024-07-21 09:57:57 +00:00
|
|
|
htmlfile.write('<script type="text/javascript">//<!--<![CDATA[\n\nfunction __getUserAgent(){return window.navigator.userAgent}\n\n//]]>--></script>');
|
|
|
|
ua = htmlfile.parentWindow.__getUserAgent();
|
2022-12-22 06:30:39 +00:00
|
|
|
|
2022-12-22 06:55:00 +00:00
|
|
|
if (ua.indexOf('Trident/ ')) {
|
2024-07-21 09:57:57 +00:00
|
|
|
T = require._load("app/assets/js/core-js-3.26.1.minified.js")
|
|
|
|
+ "\n\n" + require._load("app/assets/js/modernizr-2.8.3.min.js")
|
|
|
|
+ "\n\n" + require._load("app/assets/js/babel-standalone-7.20.6.min.js")
|
|
|
|
+ "\n\n" + require._load(FN);
|
2022-12-22 06:30:39 +00:00
|
|
|
} else {
|
2024-07-21 09:57:57 +00:00
|
|
|
T = require._load("app/assets/js/core-js-3.26.1.minified.js")
|
|
|
|
+ "\n\n" + require._load("app/assets/js/html5shiv-printshiv-3.7.3.min.js")
|
|
|
|
+ "\n\n" + require._load("app/assets/js/modernizr-2.8.3.min.js")
|
|
|
|
+ "\n\n" + require._load(FN);
|
2022-12-22 06:30:39 +00:00
|
|
|
}
|
2022-11-29 09:49:03 +00:00
|
|
|
htmlfile.write('<script type="text/javascript">//<!--<![CDATA[\n' + T + '\n//]]>--></script>');
|
2022-12-22 06:30:39 +00:00
|
|
|
|
2022-11-28 16:56:58 +00:00
|
|
|
if (typeof callback === "function") {
|
2023-08-02 06:59:05 +00:00
|
|
|
var loadScript = function(src) {
|
|
|
|
if (src.indexOf('://') > -1) {
|
|
|
|
htmlfile.write('<script type="text/javascript" src="' + src + '"></script>');
|
2023-07-26 16:38:32 +00:00
|
|
|
} else {
|
2024-07-21 09:57:57 +00:00
|
|
|
htmlfile.write('<script type="text/javascript">//<!--<![CDATA[\n' + require._load(src) + '\n//]]>--></script>');
|
2023-07-26 16:38:32 +00:00
|
|
|
}
|
|
|
|
};
|
2022-11-28 16:56:58 +00:00
|
|
|
//console.log(htmlfile.parentWindow.navigator.userAgent);
|
2023-07-26 16:38:32 +00:00
|
|
|
exports = callback(params, htmlfile.parentWindow, htmlfile.parentWindow.document, loadScript);
|
2022-11-28 16:56:58 +00:00
|
|
|
}
|
|
|
|
htmlfile.close();
|
|
|
|
} catch (e) {
|
|
|
|
console.error("LOAD ERROR!", e.number + ",", e.description + ",", "FN=" + FN);
|
2022-11-28 14:32:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return exports;
|
|
|
|
};
|
2024-07-21 10:23:38 +00:00
|
|
|
require._scriptProviders = [];
|
|
|
|
require._addScriptProvider = function(f) {
|
|
|
|
if (typeof f === "function") {
|
|
|
|
require._scriptProviders.push(f);
|
|
|
|
} else {
|
|
|
|
console.error("This is not an function");
|
|
|
|
}
|
|
|
|
};
|
2021-04-24 20:32:31 +00:00
|
|
|
|
2020-06-28 14:22:57 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Load script, and call app.main()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2021-08-10 06:27:47 +00:00
|
|
|
function initializeConsole() {
|
2022-11-04 06:43:22 +00:00
|
|
|
if (typeof WScript === "undefined") {
|
2024-07-22 15:22:01 +00:00
|
|
|
console.error("This is not a console application");
|
|
|
|
return;
|
2020-07-19 21:19:33 +00:00
|
|
|
}
|
|
|
|
|
2020-07-27 02:31:52 +00:00
|
|
|
var argl = WScript.arguments.length;
|
|
|
|
if (argl > 0) {
|
2020-06-28 14:22:57 +00:00
|
|
|
var args = [];
|
2020-07-27 02:31:52 +00:00
|
|
|
for (var i = 0; i < argl; i++) {
|
2020-06-28 14:22:57 +00:00
|
|
|
args.push(WScript.arguments(i));
|
|
|
|
}
|
|
|
|
var name = args.shift();
|
|
|
|
var app = require(name);
|
|
|
|
if (app) {
|
|
|
|
if (app.main) {
|
2024-06-09 21:23:35 +00:00
|
|
|
var status = app.main.call(this, args);
|
|
|
|
if (typeof status !== "undefined") {
|
|
|
|
exit(status);
|
2020-06-28 14:22:57 +00:00
|
|
|
}
|
|
|
|
} else {
|
2022-11-28 08:32:21 +00:00
|
|
|
console.error("Error, missing main entry point in", name);
|
2020-06-28 14:22:57 +00:00
|
|
|
}
|
|
|
|
} else {
|
2022-11-29 08:09:06 +00:00
|
|
|
console.error("Error, cannot find", name);
|
2020-06-28 14:22:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-10 06:27:47 +00:00
|
|
|
function initializeWindow(name, args, w, h) {
|
2022-11-04 06:43:22 +00:00
|
|
|
if (typeof window === "undefined") {
|
2024-07-21 10:04:39 +00:00
|
|
|
console.error("This is not a GUI application");
|
2024-07-22 15:22:01 +00:00
|
|
|
return;
|
2020-07-19 21:19:33 +00:00
|
|
|
}
|
2020-06-28 14:22:57 +00:00
|
|
|
var app = require(name);
|
2020-07-03 09:15:23 +00:00
|
|
|
|
2024-07-22 07:04:40 +00:00
|
|
|
// set default size of window
|
2022-11-04 06:43:22 +00:00
|
|
|
if (typeof w !== "undefined" && typeof h !== "undefined") {
|
2020-07-03 09:15:23 +00:00
|
|
|
window.resizeTo(w, h);
|
|
|
|
}
|
|
|
|
|
2024-07-22 07:04:40 +00:00
|
|
|
// load the application
|
2020-06-28 14:22:57 +00:00
|
|
|
if (app) {
|
|
|
|
if (app.main) {
|
2024-07-22 07:04:40 +00:00
|
|
|
var status = app.main.call(app, args);
|
2024-07-22 19:26:38 +00:00
|
|
|
if (status > 0) {
|
2024-07-22 07:04:40 +00:00
|
|
|
exit(status);
|
2020-07-04 12:49:30 +00:00
|
|
|
}
|
2020-06-28 14:22:57 +00:00
|
|
|
} else {
|
2024-06-09 21:23:35 +00:00
|
|
|
console.error("Missing main entry point in", name + ".js");
|
2024-07-22 15:22:01 +00:00
|
|
|
return;
|
2020-06-28 14:22:57 +00:00
|
|
|
}
|
|
|
|
} else {
|
2024-06-09 21:23:35 +00:00
|
|
|
console.error("Could not find", name + ".js");
|
2024-07-22 15:22:01 +00:00
|
|
|
return;
|
2020-06-28 14:22:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-25 06:28:03 +00:00
|
|
|
function dispatchServiceEvent(name, eventType, w_args, argl) {
|
2024-07-22 07:04:40 +00:00
|
|
|
var app = require(name);
|
2024-08-25 06:28:03 +00:00
|
|
|
var args = [];
|
|
|
|
|
|
|
|
// convert the arguments to Array
|
|
|
|
for (var i = 0; i < argl; i++) {
|
|
|
|
args.push(w_args(i));
|
|
|
|
}
|
2024-07-22 07:04:40 +00:00
|
|
|
|
|
|
|
// load the service
|
|
|
|
if (app) {
|
2024-08-12 03:47:19 +00:00
|
|
|
var bind = function(eventType) {
|
|
|
|
var event_callback_name = "on" + eventType;
|
|
|
|
|
|
|
|
if (event_callback_name in app && typeof app[event_callback_name] === "function")
|
|
|
|
return app[event_callback_name];
|
|
|
|
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
2024-07-22 15:22:01 +00:00
|
|
|
return (function(action) {
|
2024-07-22 07:04:40 +00:00
|
|
|
if (eventType in action) {
|
|
|
|
try {
|
2024-07-29 12:43:14 +00:00
|
|
|
return (function(f) {
|
2024-08-25 06:28:03 +00:00
|
|
|
return (typeof f !== "function" ? null : f(args));
|
2024-07-29 12:43:14 +00:00
|
|
|
})(action[eventType]);
|
2024-07-22 07:04:40 +00:00
|
|
|
} catch (e) {
|
|
|
|
console.error("Exception:", e.message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})({
|
2024-08-12 03:47:19 +00:00
|
|
|
start: bind("ServiceStart"),
|
|
|
|
stop: bind("ServiceStop"),
|
|
|
|
elapsedTime: bind("ServiceElapsedTime"),
|
2024-09-20 07:53:50 +00:00
|
|
|
screenNextTemplate: bind("ScreenNextTemplate"),
|
|
|
|
screenTemplateMatched: bind("ScreenTemplateMatched"),
|
2024-08-25 14:21:58 +00:00
|
|
|
fileCreated: bind("FileCreated"),
|
2024-09-09 08:09:31 +00:00
|
|
|
networkConnected: bind("NetworkConnected"),
|
2024-09-14 17:54:18 +00:00
|
|
|
registryModified: bind("RegistryModified"),
|
|
|
|
avScanResult: bind("AvScanResult")
|
2024-07-22 07:04:40 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
console.error("Could not find", name + ".js");
|
2024-07-22 15:22:01 +00:00
|
|
|
return;
|
2024-07-22 07:04:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-22 15:22:01 +00:00
|
|
|
// Date.prototype.toISOString() polyfill for MSScriptControl.ScriptControl
|
|
|
|
if (!Date.prototype.toISOString) {
|
|
|
|
Date.prototype.toISOString = function() {
|
|
|
|
var pad = function(number) {
|
|
|
|
return number < 10 ? ('0' + number) : number;
|
|
|
|
};
|
|
|
|
return this.getUTCFullYear() +
|
|
|
|
'-' + pad(this.getUTCMonth() + 1) +
|
|
|
|
'-' + pad(this.getUTCDate()) +
|
|
|
|
'T' + pad(this.getUTCHours()) +
|
|
|
|
':' + pad(this.getUTCMinutes()) +
|
|
|
|
':' + pad(this.getUTCSeconds()) +
|
|
|
|
'.' + (this.getUTCMilliseconds() / 1000).toFixed(3).slice(2, 5) +
|
|
|
|
'Z';
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-04-24 20:32:31 +00:00
|
|
|
// JSON 2
|
2024-01-08 06:42:54 +00:00
|
|
|
if (typeof JSON === "undefined") {
|
2024-08-14 05:25:55 +00:00
|
|
|
__evalFile__("app/assets/js/json2.js");
|
2024-01-08 06:42:54 +00:00
|
|
|
}
|
2021-04-24 20:32:31 +00:00
|
|
|
|
2024-08-14 05:31:32 +00:00
|
|
|
// core-js (formerly, babel-polyfill)
|
|
|
|
require("app/assets/js/core-js-3.38.0.minified");
|
2021-04-24 20:32:31 +00:00
|
|
|
|
2021-04-29 11:30:08 +00:00
|
|
|
// Squel.js SQL query string builder for Javascript
|
2024-11-14 19:05:06 +00:00
|
|
|
var squel = require("app/assets/js/squel-basic-5.13.0-afa1cb5.wsh");
|
2020-11-14 14:32:30 +00:00
|
|
|
|
2022-02-08 02:47:07 +00:00
|
|
|
// JavaScript YAML parser and dumper.
|
|
|
|
var yaml = require("app/assets/js/js-yaml-4.1.0.wsh");
|
|
|
|
|
2022-05-03 04:24:33 +00:00
|
|
|
// is.js Micro check library
|
|
|
|
var is = require("app/assets/js/is-0.9.0.min");
|
|
|
|
|
2023-07-27 09:09:20 +00:00
|
|
|
// Intl (ECMA-402) polyfill
|
|
|
|
//var Intl = require("app/assets/js/Intl-1.2.5-e93b114.min");
|
|
|
|
//console.log(new Intl.NumberFormat().format(1234567890.123456));
|
|
|
|
|
2024-11-14 17:40:58 +00:00
|
|
|
// numbers.js - Advanced Mathematics Library for Node.js and JavaScript
|
2024-11-14 18:48:19 +00:00
|
|
|
var numbers = require("app/assets/js/numbers-0.7.0.wsh");
|
2024-11-14 17:40:58 +00:00
|
|
|
|
2024-04-06 06:17:59 +00:00
|
|
|
// linq.js - LINQ for JavaScript
|
2024-08-29 10:06:19 +00:00
|
|
|
var Enumerable = require("app/assets/js/linq-4.0.2.wsh")._default;
|
|
|
|
|
|
|
|
// PEG.js: Parser generator for JavaScript
|
|
|
|
var PEG = require("app/assets/js/peg-0.10.0");
|
2024-04-06 06:17:59 +00:00
|
|
|
|
2021-04-24 20:32:31 +00:00
|
|
|
// Dive into entrypoint
|
2021-08-10 06:27:47 +00:00
|
|
|
function __main__() {
|
2023-12-28 02:46:33 +00:00
|
|
|
console.log("");
|
|
|
|
console.log(" __ __ _ _ ____ ");
|
|
|
|
console.log(" \\ \\ / /__| |___ ___ _ __ | / ___| ");
|
|
|
|
console.log(" \\ \\ /\\ / / _ \\ / __|/ _ \\| '_ \\ _ | \\___ \\ ");
|
|
|
|
console.log(" \\ V V / __/ \\__ \\ (_) | | | | |_| |___) |");
|
|
|
|
console.log(" \\_/\\_/ \\___|_|___/\\___/|_| |_|\\___/|____/ ");
|
|
|
|
console.log("");
|
2024-11-06 07:31:37 +00:00
|
|
|
console.log(" WelsonJS - Build a Windows app on the Windows built-in JavaScript engine");
|
|
|
|
console.log(" C-2021-000237 (cros.or.kr), 10.5281/zenodo.11382385 (doi.org), 2023-A0562 (oss.kr), Codename Macadamia");
|
|
|
|
console.log(" This software is distributed as open source under the GPL 3.0 or MS-RL licenses.");
|
|
|
|
console.log(" Please support this project: https://gnh1201.link");
|
|
|
|
console.log(" Source code available: https://github.com/gnh1201/welsonjs");
|
2023-12-28 02:46:33 +00:00
|
|
|
console.log("");
|
|
|
|
|
2022-11-04 06:43:22 +00:00
|
|
|
if (typeof window === "undefined") {
|
2021-08-10 06:27:47 +00:00
|
|
|
initializeConsole();
|
2020-06-28 14:22:57 +00:00
|
|
|
} else {
|
|
|
|
console.log("welcome");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-10 06:27:47 +00:00
|
|
|
__main__();
|