/***************************
* This code was created *
* by 1024x2, and is *
* licensed under the MIT *
* License, which means *
* you can do whatever you *
* want on it as long as *
* you keep this copyright *
* notice included with *
* this software. Please *
* respect that by not *
* deleting 'LICENSE' or *
* this notice. Thank you! *
* ~1024x2 *
***************************/
// Thanks, Draco!
function loadJS (source, onready){
var sc = document.createElement("script");
sc.src = source;
sc.type = "text/javascript";
if (onready) sc.addEventListener("load", onready);
document.head.appendChild(sc);
return sc;
}
// Taken from https://github.com/substack/semver-compare, thanks substack!
function cmp (a, b) {
var pa = a.split('.');
var pb = b.split('.');
for (var i = 0; i < 3; i++) {
var na = Number(pa[i]);
var nb = Number(pb[i]);
if (na > nb) return 1;
if (nb > na) return -1;
if (!isNaN(na) && isNaN(nb)) return 1;
if (isNaN(na) && !isNaN(nb)) return -1;
}
return 0;
}
var pkg93 = {debug: false};
console.group("[pkg93]");
var failed = false;
console.log("[pkg93] Injecting packages...");
try {
var config = JSON.parse(localStorage[".pkg93/config.json"]);
config.installed.forEach(function (pkg) {
eval(localStorage[".pkg93/packages/" + pkg + ".js"]);
});
} catch (err) {
console.error("[pkg93] Couldn't load package information.");
failed = true;
}
console.log("[pkg93] Done!");
console.groupEnd();
le._apps.pkg93 = {
exec: function() {
const protected = ["3d","acid","acidbox","ansi","anthology","arena93","bananamp","base64","bytebeat","calc","castlegafa","catex","cd","clear","clearhist","clippy","code","contact","crazy","defrag","dmg","do a barrel roll","doctor","download","find","font","format","fullscreen","fx","gameoflife","glitch","global thermonuclear war","gravity","hampster","hello","help","hexed","history","hl3","hydra","ie6","iframe","img","info","js","key","killall","layer","lenna","lisa","ls","manifesto","marburg","messenger","mines","necronomicoin","pd","piskel","pkg93","pony","potato","progressquest","pwd","reboot","robby","rotate","shutdown","skifree","solitude","speech","starwars","superplayer","takethis","terminal","textarea","tree","trollbox","vega","virtualpc","vm","wat","whatif","whois","win","zkype"];
const args = this.arg.arguments;
const version = "v1.0.1";
const help = `pkg93 ${version}
Usage: pkg93 [command]
List of Commands
pull Updates package listing
get [package] Installs a package
rm [package] Uninstalls a package
add-repo [url] Adds a repository
rm-repo [id] Removes a repository
ls [pkgs|installed|repos] Lists all packages, installed
packages or repositories.
Color meanings
Executing OK Error Warning
Examples
pkg93 get gud
pkg93 rm kebab`;
if (localStorage[".pkg93/config.json"] === undefined) {
localStorage[".pkg93/config.json"] = '{"repos": ["http://codinggamerhd.com/main-repo"], "installed": [], "pkglist": []}';
}
if (localStorage[".pkg93/packages/"] === undefined) {
localStorage[".pkg93/packages/"] = "";
}
localStorage[".pkg93/README.txt"] = "WARNING!\nThis folder contains important data about pkg93. Do not edit anything in here unless you want pkg93 to not work!\n\n~1024x2";
var config = JSON.parse(localStorage[".pkg93/config.json"]);
var request = new XMLHttpRequest();
if (args.length === 0) {
$log(help);
} else if (args[0] == "pull") {
$log("WARN Windows93 may lag while getting packages.\n This is a normal thing.");
var pkgs = [];
config.pkglist = [];
config.repos.forEach(function (source) {
$log("GET " + source);
request.open('GET', source + "/repo.json", false);
try {
request.send(null);
var json = JSON.parse(request.responseText);
$log("NAME " + json.name);
$log("MOTD \"" + json.motd + "\"");
json.packages.forEach(function(item) {
try {
$log("OK " + item + "@" + source);
pkgs.push(item + "@" + source);
} catch (err) {
$log("ERR " + err.message);
}
});
config.pkglist = config.pkglist.concat(pkgs);
} catch (err) {
$log("ERR " + err.message);
$log(request.responseText);
}
});
} else if (args[0] == "get") {
if (args.length < 2) {
$log("ERR No package specified.");
} else if (protected.includes(args[1])) {
$log("ERR You're trying to modify a pre-installed Windows93 app.\n Don't do that!");
} else {
$log("SRCH " + args[1]);
var index = config.pkglist.findIndex(function(string) {
return string.split("@")[0] == args[1];
});
if (index < 0) {
$log("ERR Not found.");
} else {
$log("OK Found!");
var pkgname = config.pkglist[index].split("@")[0];
var pkgsource = config.pkglist[index].split("@")[1];
request.open('GET', pkgsource + "/" + pkgname + "/package.json", false);
try {
request.send(null);
var json = JSON.parse(request.responseText);
localStorage[".pkg93/packages/" + pkgname + ".json"] = request.responseText;
request.open('GET', pkgsource + "/" + pkgname + "/" + json.inject, false);
request.send(null);
localStorage[".pkg93/packages/" + pkgname + ".js"] = request.responseText;
if (!!json.uninstall) {
request.open('GET', pkgsource + "/" + pkgname + "/" + json.inject, false);
request.send(null);
localStorage[".pkg93/packages/" + pkgname + ".rm.js"] = request.responseText;
}
eval(request.responseText);
$log("OK Injected package!");
config.installed.push(pkgname);
} catch (err) {
$log("ERR " + err.message);
}
}
}
} else if (args[0] == "rm") {
if (args.length < 2) {
$log("ERR No package specified.");
} else if (protected.includes(args[1])) {
$log("ERR You're trying to modify a pre-installed Windows93 app.\n Don't do that!");
} else if (!!localStorage[".pkg93/packages/" + args[1] + ".rm.js"]) {
eval(localStorage[".pkg93/packages/" + args[1] + ".rm.js"]); // Typing eval makes me feel dirty.
localStorage[".pkg93/packages/" + args[1] + ".rm.js"] = null;
localStorage[".pkg93/packages/" + args[1] + ".js"] = null;
localStorage[".pkg93/packages/" + args[1] + ".json"] = null;
} else {
var index = config.installed.indexOf(args[1]);
if (index < 0) {
$log("ERR Not found.");
} else {
try {
if (le._apps[config.installed[index]] === null) {
$log("ERR Already removed.");
} else {
le._apps[config.installed[index]] = null;
console.log("no u");
localStorage[".pkg93/packages/" + config.installed[index] + ".js"] = null;
localStorage[".pkg93/packages/" + config.installed[index] + ".json"] = null;
config.installed.splice(index, 1);
$log("OK Removed!");
}
} catch (err) {
$log("ERR " + err.message);
}
}
}
} else if (args[0] == "add-repo") {
try {
config.repos.push(args[1]); // well, that was easy
$log("OK Done!\n Run \"pkg93 pull\" to update the package listing.");
} catch (err) {
$log("ERR " + err.message);
}
} else if (args[0] == "rm-repo") {
try {
config.repos.splice(parseInt(args[1]), 1);
localStorage[".pkg93/config.json"] = JSON.stringify(config);
$log("OK Done!\n Run \"pkg93 pull\" to update the package listing.");
} catch (err) {
$log("ERR " + err.message);
}
} else if (args[0] == "ls") {
if (args[1] == "pkgs") {
$log(config.pkglist.join("\n"));
} else if (args[1] == "installed") {
$log(config.installed.join("\n"));
} else if (args[1] == "repos") {
lerepos = "";
config.repos.forEach(function (repo, index) {
lerepos += "[" + index + "] " + repo;
});
$log(lerepos);
} else {
$log("ERR You must select either pkgs, installed, or repos.");
}
} else if (args[0] == "help") {
$log(help);
} else {
$log("ERR Invalid command. Type \"pkg93\" without any arguments for help.");
}
localStorage[".pkg93/config.json"] = JSON.stringify(config);
},
icon: "/c/sys/skins/w93/install.png",
terminal: true,
hascli: true,
categories: "Network;"
};