[Slashhack-cvs] slashhack/resources/js/jslib/install autoupdate.js,NONE,1.1 install.js,NONE,1.1 unin
Brought to you by:
fletch
|
From: Dave F. <fl...@us...> - 2004-10-21 03:49:23
|
Update of /cvsroot/slashhack/slashhack/resources/js/jslib/install In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4907/install Added Files: autoupdate.js install.js uninstall.js uninstall.xul Log Message: Task #106454 - include jslib. --- NEW FILE: autoupdate.js --- /*** -*- Mode: Javascript; tab-width: 2; The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is jslib team code. The Initial Developer of the Original Code is jslib team. Portions created by jslib team are Copyright (C) 2000 jslib team. All Rights Reserved. Original Author: Pete Collins <pe...@mo...> Contributor(s): ***/ if (typeof(JS_LIB_LOADED)=='boolean') { const JS_AUTOUPDATE_LOADED = true; const JS_AUTOUPDATE_FILE = 'autoupdate.js'; // Constructor function AutoUpdate (aRemoteFile, aPackageName, aContent, aCallback) { // jslibTurnDumpOn(); // pull in dependent libs include (jslib_remotefile); include (jslib_dir); include (jslib_file); include (jslib_dirutils); include (jslib_prefs); if (!(aRemoteFile && aPackageName)) throw "Missing: aRemoteFile or aPackageName"; var ext = aRemoteFile.substring(aRemoteFile.lastIndexOf(".")+1, aRemoteFile.length); switch (ext) { case "xpi": case "jar": case "rdf": break; default: jslibDebug("Bad Remote File"); throw "Invalid Mozilla package file"; } this.mPackageExt = ext; this.mRemoteFile = aRemoteFile; this.mPackageName = aPackageName; this.mContent = aContent; this.mCallback = aCallback; } AutoUpdate.prototype = { mRemoteFile:null, mPackageName:null, mPackageExt:null, mRemoteVersion:null, mLocalVersion:null, mRemoteURL:null, mContent:null, mDataSource:null, mCallback:null, CHROME_NS:"http://www.mozilla.org/rdf/chrome#", // main API use to check for updates checkForUpdate : function () { var rv; switch (this.mPackageExt) { case "xpi": rv = this.checkByTimeStamp(); break; case "rdf": rv = this.checkByRDF(); break; } return rv; }, // checking by time stamp is one way to do it // not necessarily the best checkByTimeStamp : function () { var rf = new RemoteFile (this.mRemoteFile); if (!rf.exists()) throw this.mRemoteFile + " wasn't found"; // get the remote xpi time stamp var lastModified = new Date(rf.lastModified); // check and see what and where the package file is var pkgTS = this.packageTimeStamp(); var remoteTS = lastModified.getTime(); var localTS = pkgTS.getTime() + 200000; // fuzz add two hours // local and server clocks // are never exact so we ballpark jslibDebug("Remote Package Time Stamp: "+remoteTS); jslibDebug("Local Package Time Stamp: "+localTS); var rv = (remoteTS > localTS); return rv; }, packageTimeStamp : function () { var du = new DirUtils(); var fTest = du.getChromeDir()+"/"+this.mPackageName; var d = new Dir(fTest); var dateModified; // check global chrome first if (d.isDir()) { dateModified = d.dateModified; } else { fTest += ".jar"; var f = new File(fTest); if (f.exists()) dateModified = f.dateModified; } // check user chrome if (!dateModified) { fTest = du.getUserChromeDir()+"/"+this.mPackageName+".jar"; f = new File(fTest); if (f.exists()) dateModified = f.dateModified; jslibDebug(dateModified); jslibDebug(f.path); } return dateModified; }, checkByRDF : function () { var RDF = this.RDF; var observer = { onBeginLoad : function (sink) {}, onInterrupt : function (sink) {}, onResume : function (sink) {}, onError : function (sink,status,msg) {}, onEndLoad : function (sink) { var RDF = this.o.RDF; var packres = RDF.GetResource("urn:mozilla:package:" + this.o.mPackageName); var packageVersionPred = RDF.GetResource(this.o.CHROME_NS + "packageVersion") var version = this.o.mDataSource.GetTarget(packres, packageVersionPred, true); var packageURLPred = RDF.GetResource(this.o.CHROME_NS + "packageURL") var url = this.o.mDataSource.GetTarget(packres, packageURLPred, true); if (version instanceof jslibI.nsIRDFLiteral) var packageVersion = version.Value; this.o.mRemoteVersion = packageVersion; if (url instanceof jslibI.nsIRDFLiteral) var packageURL = url.Value; this.o.mRemoteURL = packageURL; // callback function if (typeof(this.o.mCallback)=="function") this.o.mCallback(); this.o.verifyVersions(); sink.removeXMLSinkObserver(this); jslibQI(sink, "nsIRDFDataSource"); } }; var ds = RDF.GetDataSource(this.mRemoteFile); this.mDataSource = ds; jslibQI(ds, "nsIRDFXMLSink"); ds.addXMLSinkObserver(observer); // add autoupdate object as property to observer observer.o = this; }, verifyVersions : function () { this.mLocalVersion = this.getLocalVersion(); // strip out any version dots. // rv = remote version, lv = local version var rv = parseInt(this.mRemoteVersion.replace(/\./g, ""), 10); var lv = parseInt(this.mLocalVersion.replace(/\./g, ""), 10); if (rv > lv) { var message = this.mPackageName + " version: " + this.mRemoteVersion + " is now available for download" + "\nWould you like to update now?"; var ps = jslibGetService("@mozilla.org/embedcomp/prompt-service;1", "nsIPromptService"); // check to see if Ignore Updates is set var prefs = new Prefs(); const pref = "jslib.autoupdate.checkForUpdates"; var prefValue; if (prefs.getType(pref) == 0) prefValue = true; else prefValue = prefs.getBool(pref); jslibPrint("type: "+prefValue); jslibPrint("check: "+prefs.getBool(pref)); // if no pref value we bolt if (!prefValue) return; var checkValue = { value:prefValue }; try { // XXX yes, I know these strings need localizaton // Brian, you are good at that! :) var conf = ps.confirmCheck(this.mContent, "AutoUpdate", message, "Always Check for New Updates", checkValue); } catch(e) { jslibDebug(e); } jslibPrint("checkValue: "+checkValue.value); // XXX if checkbox is set let's set the pref prefs.setBool(pref, checkValue.value); prefs.save(); jslibPrint("confirm: "+conf); if (checkValue.value && conf) this.autoupdate(); else jslibDebug("No Update Made"); } else { jslibDebug("Local Version: "+this.mLocalVersion); jslibDebug("Remote Version: "+this.mRemoteVersion); jslibDebug("No Update Necessary"); } }, // returns the installed local package version from chrome/chrome.rdf getLocalVersion : function () { var rv; var du = new DirUtils(); var f = "file://"+du.getChromeDir()+"/chrome.rdf"; var RDF = this.RDF; var ds = RDF.GetDataSourceBlocking(f); var packres = RDF.GetResource("urn:mozilla:package:" + this.mPackageName); var packageVersionPred = RDF.GetResource(this.CHROME_NS + "packageVersion") var version = ds.GetTarget(packres, packageVersionPred, true); if (version instanceof jslibI.nsIRDFLiteral) rv = version.Value; return rv; }, get RDF () { return jslibGetService("@mozilla.org/rdf/rdf-service;1", "nsIRDFService"); }, get datasource () { return this.mDataSource; }, autoupdate : function () { this.mContent.location = this.mRemoteURL; } } } // END BLOCK JS_LOADED CHECK // If jslib base library is not loaded, dump this error. else { dump("JS_AUTOUPDATE library not loaded:\n" + " \tTo load use: chrome://slashhack/content/resources/js/jslib/jslib.js\n" + " \tThen: include (jslib_autoupdate);\n\n"); } --- NEW FILE: uninstall.xul --- <?xml version="1.0"?> <!-- The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is Mozdev Group, Inc. code. The Initial Developer of the Original Code is Mozdev Group, Inc. Portions created by Mozdev Group, Inc. are Copyright (C) 2003 Mozdev Group, Inc. All Rights Reserved. Original Author: Pete Collins <pe...@mo...> Contributor(s): --> <!-- ***************** STYLE SHEET ****************** --> <?xml-stylesheet href="chrome://global/skin/" type="text/css"?> <?xml-stylesheet href="chrome://slashhack/content/resources/js/jslib/install/uninstall.css" type="text/css"?> <!-- ***************** STYLE SHEET ****************** --> <!DOCTYPE wizard> <wizard id="uninstallWizard" title="Uninstall Wizard" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" onwizardcancel="// return onCancel();" onwizardfinish="finish();" onload="initWizard();"> <script type="application/x-javascript" src="chrome://slashhack/content/resources/js/jslib/jslib.js" /> <script> <![CDATA[ include (jslib_routines); include (jslib_uninstall); var gPackageName = window.arguments[0]; var gInstallCallback = window.arguments[1]; var gUninstall = new Uninstall(gPackageName, gInstallCallback); function initWizard() { document.documentElement.pageIndex = 0; gUninstall.generateUninstallInfo(); const msg1 = "The package "; const msg2 = " will be removed."; var text = document.createTextNode(msg1 + gUninstall.packageDisplayName + msg2); document.getElementById("uninstallText").appendChild(text); } function uninstallPackage () { jslibDebug("uninstallPackage"); gUninstall.closeOpenWindows(); var wizard = document.getElementById("uninstallWizard"); wizard.canRewind = false; wizard.canAdvance = false; var pmeter = document.getElementById("uninstallProgress"); gUninstall.uninstallPackage(); } function finish () { gUninstall.finish(); } function displayFilesToDelete() { document.getElementById("showFilesButton").hidden = true; document.getElementById("filesBlock").hidden = false; var listbox = document.getElementById("filesList"); var files = gUninstall.filesToDelete; for (var t=0; t<files.length; t++){ try { var filename = files[t].leafName; listbox.appendItem(filename,filename); } catch (ex){ jslibDebug(ex); } } } ]]> </script> <wizardpage pageid="page1" next="page2" label="Uninstall"> <description id="uninstallText" class="text"/> <separator/> <description id="uninstallText2" class="text"> All open windows will be closed before the package is removed. </description> <separator/> <hbox> <button id="showFilesButton" label="Show files to be deleted" oncommand="displayFilesToDelete();" /> </hbox> <vbox id="filesBlock" hidden="true" flex="1"> <label value="Files to be deleted:"/> <listbox id="filesList" flex="1"/> </vbox> </wizardpage> <wizardpage pageid="page2" label="Uninstall" onpageshow="uninstallPackage();"> <label id="progressText" class="text" value="Uninstalling general data" /> <progressmeter id="uninstallProgress" value="0" /> </wizardpage> </wizard> --- NEW FILE: uninstall.js --- /*** -*- Mode: Javascript; tab-width: 2; The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is jslib team code. The Initial Developer of the Original Code is jslib team. Portions created by jslib team are Copyright (C) 2003 jslib team. All Rights Reserved. Original Author: Pete Collins <pe...@mo...> Contributor(s): Neil Deakin <ne...@mo...> ***/ // STATUS: WORK IN PROGRESS // Make sure jslib.js is loaded if (typeof(JS_LIB_LOADED) == 'boolean') { // Ensure we are in a DOM window environment if (typeof(window) == 'undefined') { jslibDebug("Error: This library can only be used in a dom window environment"); } else { // Load dependency lib files include(jslib_file); include(jslib_dirutils); include(jslib_dir); include(jslib_fileutils); include(jslib_window); // GLOBALS const JS_LIB_UNINSTALL_LOADED = true; const JS_LIB_UNINSTALL_FILE = 'uninstall.js'; // CONSTRUCTOR function Uninstall(aPackageName, installCallback) { if (!aPackageName) { throw - jslibRes.NS_ERROR_XPC_NOT_ENOUGH_ARGS; } else { if (typeof(aPackageName) == "string"){ this.mNames = [aPackageName]; } else { this.mNames = aPackageName; } } this.mInstallCallback = installCallback; this.gRDF = jslibGetService("@mozilla.org/rdf/rdf-service;1", "nsIRDFService"); this.gDirService = jslibGetService("@mozilla.org/file/directory_service;1", "nsIProperties"); } /*********** UNINSTALL ***************/ Uninstall.prototype = { // set ACTIVE_MODE to false for debugging, and changes will only be simulated. ACTIVE_MODE : true, gRDF : null, gDirService : null, CHRM_REG_CID : "@mozilla.org/chrome/chrome-registry;1", CHROME_NS : "http://www.mozilla.org/rdf/chrome#", mNames : null, mLastURL : "about:blank", mLastChromeURL : null, mUninstallInfoGenerated : false, mInstallCallback : null, filesToDelete : [], filesToDeleteHash : {}, overlaysToDelete : [], baseURIs : {}, packageDisplayName : "", closeOpenWindows : function () { if (!this.ACTIVE_MODE) return; jslibDebug(opener.location); // jslibDebug(opener._content.location); this.mLastChomeURL = opener.location.toString(); try { this.mLastURL = opener._content.location.toString(); } catch (e) {} var win = new CommonWindow(); var openWindows = win.openWindows; for (var i=0; i<openWindows.length; i++) { if (/chrome:\/\/jslib\/content\/install\/uninstall.xul/.test(openWindows[i].location)) { jslibPrint("Skipping: "+openWindows[i].location); continue; } openWindows[i].close(); } return; }, launchLastWindow : function () { if (!this.mLastChomeURL) return; window.openDialog(this.mLastChomeURL, "_blank", "chrome,all,dialog=no", this.mLastURL); }, finish : function () { this.launchLastWindow(); }, generateUninstallInfo : function () { if (!this.mUninstallInfoGenerated){ this.mUninstallInfoGenerated = true; this.filesToDelete = []; this.filesToDeleteHash = {}; this.overlaysToDelete = []; this.baseURIs = {}; this.doUninstall(false); } }, uninstallPackage : function () { this.generateUninstallInfo(); this.doUninstall(true); }, /** * Iterates over the items in an RDF Container */ iterateContainer : function(ds, resource, callback) { try { var container = jslibCreateInstance("@mozilla.org/rdf/container;1", "nsIRDFContainer"); container.Init(ds, resource); } catch (ex){ return; } var elements = container.GetElements(); while (elements.hasMoreElements()){ var element = elements.getNext(); callback(resource, element, this); } }, /** * Get all of the currently installed packages. This function is not currently used. */ getAllPackagesInfo : function(chromeDS) { var allPackages = {}; var handlePackages = function(container, packres, uninstallObj) { var childPred = uninstallObj.gRDF.GetResource(uninstallObj.CHROME_NS + "name") var childName = chromeDS.GetTarget(packres, childPred, true); var displayPred = uninstallObj.gRDF.GetResource(uninstallObj.CHROME_NS + "displayName") var displayName = chromeDS.GetTarget(packres, displayPred, true); if (childName instanceof jslibI.nsIRDFLiteral){ if (displayName instanceof jslibI.nsIRDFLiteral){ displayName = displayName.Value; } else { displayName = childName.Value; } allPackages[childName.Value] = displayName; } } var rootseq = this.gRDF.GetResource("urn:mozilla:package:root"); this.iterateContainer(chromeDS, rootseq, handlePackages); }, /** * Do the uninstallation. This function will be called twice. Once to generate * the list of files and overlays to delete, and the second to do the deletions. */ doUninstall : function(makeChanges) { var ioService = jslibGetService("@mozilla.org/network/io-service;1", "nsIIOService"); // scan through chrome.rdf and find all references to the package and remove them. var appChromeDir = this.gDirService.get("AChrom", jslibI.nsIFile); var chromeRdfFile = appChromeDir.clone(); chromeRdfFile.append("chrome.rdf"); var chromeUrl = ioService.newFileURI(chromeRdfFile).spec; var appChromeDS = this.gRDF.GetDataSourceBlocking(chromeUrl); for (var pt = 0; pt < this.mNames.length; pt++){ this.handleChromeRDF(this.mNames[pt], appChromeDir, appChromeDS, makeChanges); } // scan through chrome.rdf and find all references to the package and remove them. var userChromeDir = this.gDirService.get("UChrm", jslibI.nsIFile); chromeRdfFile = userChromeDir.clone(); chromeRdfFile.append("chrome.rdf"); chromeUrl = ioService.newFileURI(chromeRdfFile).spec; var userChromeDS = this.gRDF.GetDataSourceBlocking(chromeUrl); for (var pt = 0; pt < this.mNames.length; pt++){ this.handleChromeRDF(this.mNames[pt], userChromeDir, userChromeDS, makeChanges); } if (makeChanges){ if (this.ACTIVE_MODE){ if (appChromeDS instanceof jslibI.nsIRDFRemoteDataSource) appChromeDS.Flush(); if (userChromeDS instanceof jslibI.nsIRDFRemoteDataSource) userChromeDS.Flush(); } if (this.mInstallCallback) this.mInstallCallback(this.filesToDelete,true); for (t=0; t<this.overlaysToDelete.length; t++){ this.removeOverlay(this.overlaysToDelete[t]); } this.removeFromInstalledChrome(appChromeDir); var uninstallObj = this; var callback = function() { uninstallObj.doNextUninstallStep(uninstallObj,0); } setTimeout(callback,50); } else { if (this.mInstallCallback) this.mInstallCallback(this.filesToDelete,false); } }, doNextUninstallStep : function(uninstallObj,step) { jslibPrint("doNextUninstallStep"); var pmeter = document.getElementById("uninstallProgress"); if (step >= uninstallObj.filesToDelete.length){ pmeter.value = 100; document.getElementById("progressText").value = "Uninstall Complete"; var wizard = document.getElementById("uninstallWizard"); wizard.canAdvance = true; return; } var adj = Math.round(100 / uninstallObj.filesToDelete.length); if (adj < 5){ if (step % Math.round(uninstallObj.filesToDelete.length / 20)) adj = 5; else adj = 0; } pmeter.value = parseInt(pmeter.value) + adj; // ignore errors since it doesn't matter if a file could not be found, and // non-empty directories should not be deleted. try { var file = uninstallObj.filesToDelete[step]; var path = file.path; document.getElementById("progressText").value = "Uninstalling " + file.leafName; var ext = path.substring(path.lastIndexOf(".")+1, path.length); // close the jar filehandle so we can unlock it and delete it on // OS's like Windows that like to lock their open files if (ext == "jar") { var IOService = jslibGetService("@mozilla.org/network/io-service;1", "nsIIOService"); var handler = IOService.getProtocolHandler("jar"); if (handler instanceof jslibI.nsIJARProtocolHandler) { var zrc = handler.JARCache; var nsIZipReader = zrc.getZip(file); nsIZipReader.close(); } } jslibDebug("Uninstall ---- Delete " + file.path + "\n"); if (this.ACTIVE_MODE && file.exists()) file.remove(false); } catch (ex){ jslibDebug(ex); } var callback = function() { uninstallObj.doNextUninstallStep(uninstallObj,step + 1); } setTimeout(callback,50); }, /** * Gather information about the package from a chrome.rdf file and remove it. */ handleChromeRDF :function(packagename, chromeDir, chromeDS, makeChanges) { // remove package from content var rootseq = this.gRDF.GetResource("urn:mozilla:package:root"); var packres = this.gRDF.GetResource("urn:mozilla:package:" + packagename); if (makeChanges){ this.removeFromChrome(chromeDS, rootseq, packres); } else { this.generateUninstallData(chromeDS, rootseq, packres, chromeDir); if (!this.packageDisplayName){ var displayNamePred = this.gRDF.GetResource(this.CHROME_NS + "displayName") var displayName = chromeDS.GetTarget(packres, displayNamePred, true); if (displayName instanceof Components.interfaces.nsIRDFLiteral){ this.packageDisplayName = displayName.Value; } else { this.packageDisplayName = packagename; } } } // remove package from skin var provider = "skin"; var handleSkinLocaleList = function(container, skinLocale, uninstallObj) { var rootseq = chromeDS.GetTarget(skinLocale, uninstallObj.gRDF.GetResource(uninstallObj.CHROME_NS + "packages"),true); rootseq.QueryInterface(jslibI.nsIRDFResource); var skinLocaleName = chromeDS.GetTarget(skinLocale, uninstallObj.gRDF.GetResource(uninstallObj.CHROME_NS + "name"),true); if (skinLocaleName instanceof jslibI.nsIRDFLiteral){ var skinLocaleRes = uninstallObj.gRDF.GetResource("urn:mozilla:" + provider + ":" + skinLocaleName.Value + ":" + packagename); if (makeChanges) uninstallObj.removeFromChrome(chromeDS, rootseq, skinLocaleRes); else uninstallObj.generateUninstallData(chromeDS, rootseq, skinLocaleRes, chromeDir); } }; var packreslist = this.gRDF.GetResource("urn:mozilla:skin:root"); this.iterateContainer(chromeDS, packreslist, handleSkinLocaleList); // remove package from locale provider = "locale"; packreslist = this.gRDF.GetResource("urn:mozilla:locale:root"); this.iterateContainer(chromeDS, packreslist, handleSkinLocaleList); }, /** * Perform an uninstallation given a contents.rdf datasource. * aChromeDS - chrome.rdf datasource * rootseq - root sequence * packres - packagename as a resource */ generateUninstallData : function(chromeDS, rootseq, packres, chromeDir) { var baseUrlPred = this.gRDF.GetResource(this.CHROME_NS + "baseURL") var baseUrl = chromeDS.GetTarget(packres, baseUrlPred, true); if (baseUrl instanceof jslibI.nsIRDFLiteral){ var ds; try { ds = this.gRDF.GetDataSourceBlocking(baseUrl.Value + "contents.rdf"); } catch (ex){ jslibDebug(ex); return; } this.markJarForDeletion(baseUrl.Value); this.generateFilesToDelete(ds, packres); this.generateOverlaysToDelete(ds, chromeDir, "overlays"); this.generateOverlaysToDelete(ds, chromeDir, "stylesheets"); } }, /** * Generate the files to delete, which are listed in the uninstallInfo section * of the contents.rdf */ generateFilesToDelete : function(aDS, node) { var pred = this.gRDF.GetResource(this.CHROME_NS + "uninstallInfo"); var uninstallInfo = aDS.GetTarget(node,pred,true); if (uninstallInfo){ this.iterateContainer(aDS, uninstallInfo, this.makeFileForDeletion); } }, /** * Mark a file for deletion. */ makeFileForDeletion : function(container, filename, uninstallObj) { if (!(filename instanceof jslibI.nsIRDFLiteral)) return; filename = filename.Value; var filekey; var colonIdx = filename.indexOf(":"); if (colonIdx >= 0){ filekey = filename.substring(0,colonIdx); filename = filename.substring(colonIdx + 1); } else { filekey = "CurProcD"; } var file; try { file = uninstallObj.gDirService.get(filekey, jslibI.nsIFile); } catch (ex) { return; } var fileparts = filename.split("/"); for (var t=0; t<fileparts.length; t++){ file.append(fileparts[t]); } if (!uninstallObj.filesToDeleteHash[file.path]){ uninstallObj.filesToDeleteHash[file.path] = file; uninstallObj.filesToDelete.push(file); } }, /** * Given a baseURI reference, determine the JAR file to delete. */ markJarForDeletion : function(url) { this.baseURIs[url] = url; if (url.indexOf("jar:")) return; var jarfile; url = url.substring(4); var expos = url.indexOf("!"); if (expos > 0){ url = url.substring(0,expos); if (url.indexOf("resource:/") == 0){ url = url.substring(10); jarfile = this.gDirService.get("CurProcD", jslibI.nsIFile); var fileparts = url.split("/"); for (var t=0; t<fileparts.length; t++){ jarfile.append(fileparts[t]); } } else if (url.indexOf("file://") == 0){ var ioService = jslibGetService("@mozilla.org/network/io-service;1", "nsIIOService"); var fileuri = ioService.newURI(url,"",null); if (fileuri instanceof jslibI.nsIFileURL){ jarfile = fileuri.file; } } } if (!this.filesToDeleteHash[jarfile.path]){ this.filesToDeleteHash[jarfile.path] = jarfile; this.filesToDelete.push(jarfile); } }, /** * Generate the list of overlays referenced in a contents.rdf file. */ generateOverlaysToDelete : function(aDS, chromeDir, overlayType) { var iterateOverlays = function(container, overlayFile, uninstallObj) { if ((container instanceof jslibI.nsIRDFResource) && (overlayFile instanceof jslibI.nsIRDFLiteral)){ uninstallObj.overlaysToDelete.push( { overlaidFile: container, overlayFile: overlayFile, chromeDir : chromeDir, type: overlayType }); } } var iterateOverlaids = function(container, overlaidFile, uninstallObj) { uninstallObj.iterateContainer(aDS, overlaidFile, iterateOverlays); } var oroot = this.gRDF.GetResource("urn:mozilla:" + overlayType); this.iterateContainer(aDS, oroot, iterateOverlaids); }, /** * Remove an overlay from the overlayinfo. */ removeOverlay : function(overlay) { jslibPrint("removeOverlay"); var overlayItems = this.splitURL(overlay.overlaidFile.Value); var overlayRdfFile = overlay.chromeDir.clone(); overlayRdfFile.append("overlayinfo"); overlayRdfFile.append(overlayItems.packagename); overlayRdfFile.append(overlayItems.provider); overlayRdfFile.append(overlay.type + ".rdf"); var ioService = jslibGetService("@mozilla.org/network/io-service;1", "nsIIOService"); var overlayRdfUrl = ioService.newFileURI(overlayRdfFile).spec; var dsource = this.gRDF.GetDataSourceBlocking(overlayRdfUrl); try { jslibDebug("Uninstall ---- Uncontain Overlay " + this.RDFGetValue(overlay.overlayFile) + " from " + this.RDFGetValue(overlay.overlaidFile) + "\n"); var container = jslibCreateInstance("@mozilla.org/rdf/container;1", "nsIRDFContainer"); container.Init(dsource, overlay.overlaidFile); if (this.ACTIVE_MODE) container.RemoveElement(overlay.overlayFile, true); } catch (ex) { jslibDebug(ex); } if (this.ACTIVE_MODE && dsource instanceof jslibI.nsIRDFRemoteDataSource) dsource.Flush(); }, /** * split a chrome URL into component parts. * * The algorithm was taken from mozilla/rdf/chrome/src/nsChromeRegistry.cpp */ splitURL : function(url) { if (url.indexOf("chrome://")) return null; var packagename = url.substring(9); var slashidx = packagename.indexOf("/"); if (slashidx == -1) return null; var provider = packagename.substring(slashidx + 1); packagename = packagename.substring(0,slashidx); slashidx = provider.indexOf("/"); if (slashidx >= 0){ provider = provider.substring(0,slashidx); } return { packagename: packagename, provider: provider }; }, /** * Useful debugging function to convert an nsIRDFNode into a string. */ RDFGetValue : function(node) { return ((node instanceof jslibI.nsIRDFResource) ? node.Value : ((node instanceof jslibI.nsIRDFLiteral) ? node.Value : "")); }, /** * Remove references to a package from chrome.rdf. */ removeFromChrome : function (dsource, rootseq, packres) { jslibPrint("removeFromChrome"); var packresnode = packres.QueryInterface(jslibI.nsIRDFNode); try { jslibDebug("Uninstall ---- Uncontain " + packres.Value + " from " + rootseq.Value + "\n"); var container = jslibCreateInstance("@mozilla.org/rdf/container;1", "nsIRDFContainer"); container.Init(dsource, rootseq); if (this.ACTIVE_MODE) container.RemoveElement(packresnode, true); } catch (ex) { jslibDebug(ex); } var arcs = dsource.ArcLabelsOut(packres); while(arcs.hasMoreElements()) { var arc = arcs.getNext(); var prop = arc.QueryInterface(jslibI.nsIRDFResource); var targets = dsource.GetTargets(packres, prop, true); while (targets.hasMoreElements()) { var target = targets.getNext(); var targetNode = target.QueryInterface(jslibI.nsIRDFNode); jslibDebug("Uninstall ---- Unassert [" + packres.Value + " , " + prop.Value + " , " + this.RDFGetValue(target) + "]\n"); if (this.ACTIVE_MODE) dsource.Unassert(packres, prop, targetNode); } } }, removeFromInstalledChrome : function(chromeDir) { jslibPrint("removeFromInstalledChrome"); chromeDir.append("installed-chrome.txt"); var ifile = new File(chromeDir.path); ifile.open("r"); var changeNeeded = false; try { var content = ""; while (!ifile.EOF){ var found = false; var ln = ifile.readline(); for (uri in this.baseURIs){ var idx = ln.indexOf(uri); if ((idx > 0) && (idx == ln.length - uri.length)){ jslibDebug("Uninstall ---- Removing from installed-chrome.txt : " + ln + "\n"); found = true; changeNeeded = true; } } if (!found) content += ln + "\n"; } } finally { ifile.close(); } if (this.ACTIVE_MODE && changeNeeded){ ifile.open("w",0664); try { ifile.write(content); } finally { ifile.close(); } } } } // END CLASS jslibDebug('*** load: '+JS_LIB_UNINSTALL_FILE+' OK'); } // END BLOCK DOM WINDOW CHECK // END BLOCK JS_LIB_LOADED CHECK // If jslib base library is not loaded, dump this error. } else { const JS_LIB_UNINSTALL_LOAD_MSG = "JS_LIB_UNISTALL library not loaded:\n" + " \tTo load use: chrome://slashhack/content/resources/js/jslib/jslib.js\n" + " \tThen: include(jslib_uninstall);\n\n"; dump(JS_LIB_UNINSTALL_LOAD_MSG); } --- NEW FILE: install.js --- /* The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is jslib team code. The Initial Developer of the Original Code is jslib team. Portions created by jslib team are Copyright (C) 2000 jslib team. All Rights Reserved. Original Author: Pete Collins <pe...@mo...> Contributor(s): */ //Prefs var htmlresults = false; var installName = "Beonex Communicator 0.6"; var installPage = "http://www.beonex.com/communicator/version/0.6/install"; //Other global vars // for exclusive const anymozilla = 0; // any Mozilla const sameversion = 1; // this Mozilla release only, e.g. Mozilla 0.6/Netscape 6.0/Beonex Comm. 0.6 const samevendorrelease = 2; // this vendor release only, e.g. Beonex Comm. 0.6 var newline; if (htmlresults) newline = "<br>"; else newline = "\n"; var numstatus = 0; var numxpi = 0; var gxpi; function statusCallback(url, status) { for (i in gxpi) { if ( url.indexOf(gxpi[i]) != -1 ) { gxpi[i] = status; numstatus++; break; } } // if we've gotten all results then display them if (numstatus == numxpi) { var restart = false; var textResults = ""; var textInstructions = ""; for (i in gxpi) { textResults += i + ": "; switch (status) { case 999: restart = true; // fall-through case 0: textResults += "Successful"; restart = true; //XXX break; case -210: textResults += "Cancelled"; break; default: textResults += "Error encountered -- "+status; break; } textResults += newline; } if (restart) { textInstructions += "Please restart Communicator."; if (isWindows()) textInstructions += " If you are using Win9x (incl. Windows ME), restart your computer."; } if (htmlresults) { dlg = window.open("","resultWindow"); //open(,, "width=400,height=300,scrollbars=yes,resizable=yes"); XXX dlg.document.write("<he" + "ad>" + "<tit" + "le>" + "XPInstall Results" + "</tit" + "le>" + "</he" + "ad>"); dlg.document.write("<bo" + "dy>" + "<h1>Installation Results</h1>"); dlg.document.write(textResults); if (textInstructions != "") { dlg.document.write("<h1>Instructions</h1>"); dlg.document.write(textInstructions); } dlg.document.write("<p><center><f" + "orm name=\"okclose\">" + "<i" + "nput type=button " + "on" + "Click=\"window.close();\" " + "on" + "Command=\"window.close();\" " + "value=\"OK\">" + "</center></f" + "orm>"); dlg.document.write("</bo" + "dy>"); dlg.document.close(); } else { alert(textResults + newline + textInstructions); } } } function isWindows() { return (navigator.platform.indexOf("Win") == 0); } function isLinux() { return (navigator.platform.indexOf("Linux") == 0); } function isMac() { return (navigator.platform.indexOf("Mac") != -1); } function badPlatform() { alert("Platform not recognized"); } function gotoInstallPage() { document.location.href = installPage; } // exclusive: anymozilla, sameversion or samevendorrelease function browserOK(exclusive) { if (exclusive == anymozilla) { if (typeof InstallTrigger == "object") return true; else { if(window.confirm("This package is intended only for Beonex Communicator, Netscape 6 or Mozilla.\nWould you like to download " + installName + "?")) gotoInstallPage(); return false; } } else if (exclusive == sameversion) { var start = navigator.userAgent.indexOf("Gecko/") + 6; var build = parseInt(navigator.userAgent.substring(start, start + 8)); if (typeof InstallTrigger == "object" && build >= 20001100) return true; else { if(window.confirm("This package is intended only for Beonex Communicator 0.6, Netscape 6.0 or Mozilla 0.6.\nWould you like to download " + installName + "?")) gotoInstallPage(); return false; } } else if (exclusive == samevendorrelease) { if (typeof InstallTrigger == "object" && navigator.vendor && navigator.vendor == "Beonex" && navigator.vendorSub && navigator.vendorSub.substr(0,3) == "0.6") return true; else { if(window.confirm("This package is intended for Beonex Communicator 0.6 only.\nWould you like to download " + installName + "?")) gotoInstallPage(); return false; } } else { alert("Fatal error: Bug on Website"); return false; } } // xpi = Array for InstallTrigger // exclusive = see above function startInstall(xpi, exclusive) { if (!browserOK(exclusive)) return; gxpi = xpi; for (i in xpi) { numxpi++; } InstallTrigger.install(xpi,statusCallback); } // genLaunch - Generic Launcher: picks up package URLs and names from document. // idClass = Class of package to be installed. // Use empty string to install all packages. // exclusive = see above // // Example: // <a class="dlLinux,java" name="Java RE" href="http://foo/bar-ix.xpi">bla</a> // <a class="dlLinux,psm" name="PSM" href="http://foo/baz-ix.xpi">bla bla</a> // <a class="dlWin32,java" name="Java RE" href="http://foo/bar-win.xpi">bla</a> // <a class="dlWin32,psm" name="PSM" href="http://foo/baz-win.xpi">bla bla</a> // <div onclick="genLaunch('java',1)>button 1</div> // <div onclick="genLaunch('',1)>button 2</div> // If you click on button 1, the Java package for your platform // will be installed. // If you click on button 2, both the Java and PSM package for your platform // will be installed. function genLaunch(idClass, exclusive) { if (!browserOK(exclusive)) // make sure, older browsers don't fail below return; var platformClass; if (isWindows()) platformClass = "dlWin32"; else if (isLinux()) platformClass = "dlLinux"; else if (isMac()) platformClass = "dlMac"; else { badPlatform(); return; } // "dlAll" is OK, too. var xpi = new Array(); var found = false; var elems = document.getElementsByTagName("A"); for (var i = 0; i < elems.length; i++) { var elem = elems.item(i); var attrs = elem.attributes; if (attrs) { var classes = attrs.getNamedItem("class"); if (classes && ( classes.value.indexOf(platformClass) != -1 || classes.value.indexOf("dlAll") != -1 )) { if (classes && classes.value.indexOf(idClass) != -1) { uri = attrs.getNamedItem("href").value; name = attrs.getNamedItem("name").value; //alert("name " + name + "\nuri " + uri); xpi[name] = uri; found = true; } } } } if (!found) alert("No appropriate packages available"); else startInstall(xpi,exclusive); } |