From d461d20df08ec76e73a0ce5335dd4665ec024fbd Mon Sep 17 00:00:00 2001
From: Unknown
Date: Mon, 2 Apr 2018 20:25:28 +0100
Subject: add get and rm
---
README.md | 10 ++-
main-repo/helloworld/package.json | 1 -
main-repo/pkg93/package.json | 5 --
main-repo/pkg93/pkg93.js | 1 -
main-repo/wget93/package.json | 4 +-
pkg93.js | 179 +++++++++++++++++++++++++++++++++-----
6 files changed, 164 insertions(+), 36 deletions(-)
delete mode 100644 main-repo/pkg93/package.json
delete mode 120000 main-repo/pkg93/pkg93.js
diff --git a/README.md b/README.md
index 89a9d76..1062e9b 100644
--- a/README.md
+++ b/README.md
@@ -7,6 +7,10 @@ Unfinished!
Firstly, make sure that [CORS is enabled on your webserver](https://enable-cors.org/server.html).
If it isn't on, your users will be unable to download packages!
Secondly you need to create a repo.json in the folder where you want your repository to be in.
+In it, there should be 4 keys.
+- `name` This is your repo's name.
+- `msg` This is your repo's message to all visitors.
+- `packages` This is an array containing all the names of packages.
Here's an example:
```json
{
@@ -40,16 +44,14 @@ Firstly, you want to make a new folder called the name of the package.
Then, you want to make a file called package.json in the folder.
In it, there should be 4 keys.
- `"name"`: **Must be the same as the folder name and command name!**
-- `"version"`: An array of 3 numbers, 1st number is major, 2nd number is minor, 3rd number is patch.
- `"inject"`: It should be the name of the injection script.
- `"uninstall"`: Optional, It should be the name of the uninstaller script, if it doesn't exist pkg93 will simply delete the command for you.
Here's a example:
```json
{
"name": "examplepkg",
- "version": [1, 3, 7],
"inject": "installer.js",
- "uninstall": "mypointlessuninstaller.js"
+ "uninstall": "optionaluninstaller.js"
}
```
And the directory structure:
@@ -57,5 +59,5 @@ And the directory structure:
examplepkg
├── package.json
├── installer.js
-└── mypointlessuninstaller.js
+└── optionaluninstaller.js
```
diff --git a/main-repo/helloworld/package.json b/main-repo/helloworld/package.json
index f5c7625..10d8523 100644
--- a/main-repo/helloworld/package.json
+++ b/main-repo/helloworld/package.json
@@ -1,5 +1,4 @@
{
"name": "helloworld",
- "version": [1, 0, 0],
"inject": "helloworld.js"
}
diff --git a/main-repo/pkg93/package.json b/main-repo/pkg93/package.json
deleted file mode 100644
index dbe1030..0000000
--- a/main-repo/pkg93/package.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
- "name": "pkg93",
- "version": [0, 1, 0],
- "inject": "pkg93.js"
-}
diff --git a/main-repo/pkg93/pkg93.js b/main-repo/pkg93/pkg93.js
deleted file mode 120000
index 58d2fb8..0000000
--- a/main-repo/pkg93/pkg93.js
+++ /dev/null
@@ -1 +0,0 @@
-../../pkg93.js
\ No newline at end of file
diff --git a/main-repo/wget93/package.json b/main-repo/wget93/package.json
index d96a422..e3677ec 100644
--- a/main-repo/wget93/package.json
+++ b/main-repo/wget93/package.json
@@ -1,6 +1,4 @@
{
"name": "wget93",
- "version": [0, 1, 0],
- "inject": "wget93.js",
- "uninstall": "unwget93.js"
+ "inject": "wget93.js"
}
diff --git a/pkg93.js b/pkg93.js
index fd94a0e..b7e3fd2 100644
--- a/pkg93.js
+++ b/pkg93.js
@@ -1,37 +1,172 @@
+/***************************
+ * 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;
+}
+
+console.group("[pkg93]");
+var failed = false;
+console.log("[pkg93] Injecting packages...");
+try {
+ var config = JSON.parse(localStorage[".pkg93/config.json"]);
+} catch (err) {
+ console.error("[pkg93] Couldn't load package information.");
+ failed = true;
+}
+if (!failed) {
+ console.log("[pkg93] Not implemented.")
+}
+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 = "v0.1.0";
- if (localStorage[".config/pkg93.json"] == undefined) {
- localStorage[".config/pkg93.json"] = '{"sources": [], "pkgs": [], "cache": []}';
+ if (localStorage[".pkg93/config.json"] === undefined) {
+ localStorage[".pkg93/config.json"] = '{"sources": ["http://codinggamerhd.com/main-repo"], "installed": [], "pkglist": []}';
+ }
+ if (localStorage[".pkg93/downloaded/"] === undefined) {
+ localStorage[".pkg93/downloaded/"] = "";
}
- if (args.length == 0) {
- $log.info(`pkg93 ${version} help`);
- $log(`Usage: pkg93 [command]
-Command can be one of the below:
-update 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
+ 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(`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.
-help Gets help for a command
+Color meanings
+Executing OK Error Warning
-Examples:
-pkg93 get gud
-pkg93 rm kebab
-pkg93 help ivefallenandicantgetup`);
- } else {
- if (args[0] == "update") {
- var config = JSON.parse(localStorage[".config/pkg93.json"]);
- config.sources.forEach((value) => {
+Examples
+pkg93 get gud
+pkg93 rm kebab
+WARN Not all packages are safe. Treat packages like EXE files.`);
+ } else if (args[0] == "pull") {
+ var pkgs = [];
+ config.pkglist = [];
+ config.sources.forEach(function (source) {
+ $log("GET " + source);
+ request.open('GET', source + "/repo.json", false);
+ try {
+ request.send(null);
+ var json = JSON.parse(request.responseText);
+ json.packages.forEach(function(item) {
+ $log("OK " + item + "@" + source);
+ pkgs.push(item + "@" + source);
+ });
+ config.pkglist = config.pkglist.concat(pkgs);
+ } catch (err) {
+ $log("ERR " + err.message);
+ }
+ });
+ } 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);
+ request.open('GET', pkgsource + "/" + pkgname + "/" + json.inject, false);
+ request.send(null);
+ localStorage[".pkg93/downloaded/" + pkgname + ".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/downloaded/un" + args[1] + ".js"]) {
+ eval(localStorage[".pkg93/downloaded/un" + args[1] + ".js"]); // Typing eval makes me feel dirty.
+ } 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;
+ $log("OK Removed!");
+ }
+ } catch (err) {
+ $log("ERR " + err.message);
+ }
+ }
+ }
+ } 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
-}
+};
--
cgit v1.2.3