1 /* coded by Ketmar // Invisible Vector (psyc://ketmar.no-ip.org/~Ketmar)
2 * Understanding is not required. Only obedience.
4 * This program is free software. It comes without any warranty, to
5 * the extent permitted by applicable law. You can redistribute it
6 * and/or modify it under the terms of the Do What The Fuck You Want
7 * To Public License, Version 2, as published by Sam Hocevar. See
8 * http://www.wtfpl.net/txt/copying/ for more details.
10 ////////////////////////////////////////////////////////////////////////////////
12 let lastUpdateCount = 0;
13 let pkgList = {lmod:-1};
16 ////////////////////////////////////////////////////////////////////////////////
17 exports.getPackageList = function () {
18 if (lastUpdateCount != pkgList.lmod) {
19 let list = pkgDB.getActivePackages();
20 pkgList.lmod = lastUpdateCount;
27 ////////////////////////////////////////////////////////////////////////////////
31 let queue = new Array();
34 ////////////////////////////////////////////////////////////////////////////////
35 exports.__defineGetter__("inProgress", function () (dldr && dldr.running));
38 ////////////////////////////////////////////////////////////////////////////////
39 exports.cancel = function () {
41 if (dldr.running) dldr.cancel();
48 ////////////////////////////////////////////////////////////////////////////////
49 function pingQueue () {
50 if (dldr) return; // in progress
51 let qo; // queue object
53 if (queue.length == 0) return; // nothing to do
56 queue.splice(0, 1); // remove first element
58 // no url: update request; find package
59 let pi = pkgDB.getActivePackageByName(qo.name);
60 if (pi) { qo.url = pi.downurl; break; }
61 logError("can't update unknown package '"+qo.name+"'");
67 dldr = new PkgDownloader(qo.url);
69 dldr.onError = function () { ++lastUpdateCount; pingQueue(); };
70 dldr.onCancel = function () { ++lastUpdateCount; pingQueue(); };
71 dldr.onComplete = function () {
72 let upd = pkgDB.checkAndUpdate(qo.name, this.pkg);
73 conlog((upd ? "" : "NOT "), "UPDATED: '", qo.name, "'");
76 dldr.onMainReceived = function () pkgDB.checkAndUpdate(qo.name, this.pkg, {checkOnly:true});
81 ////////////////////////////////////////////////////////////////////////////////
82 exports.install = function (name, url) {
83 if (typeof(name) !== "string" || !name) throw new Error("invalid package name");
84 if (typeof(url) !== "string" || !(/https?:/.test(url))) throw new Error("invalid package url");
87 for (let qo of queue) {
88 if (qo.name == name) {
89 if (qo.url != url) throw new Error("conflicting URLs for package '"+name+"'");
94 if (!found) queue.push({name:name, url:url});
99 ////////////////////////////////////////////////////////////////////////////////
100 exports.update = function (name) {
101 if (typeof(name) !== "string" || !name) throw new Error("invalid package name");
104 for (let qo of queue) {
105 if (qo.name == name) {
110 if (!found) queue.push({name:name, url:null});
115 ////////////////////////////////////////////////////////////////////////////////
116 exports.remove = function (name) {
117 if (typeof(name) !== "string" || !name) throw new Error("invalid package name");
118 if (dldr && dldr.running) throw new Error("package manager is busy");
119 pkgDB.removePackage(name);