📄 nspostupdatewin.js
字号:
// since we are not running with elevated privs, we can't write out // the log file (at least, not on Vista). So, write the output to // temp, and then later, we'll pass the file (gCopiedLog) to // the post update clean up process, which can copy it to // the desired location (because it will have elevated privs) gCopiedLog = getFile(KEY_TMPDIR); gCopiedLog.append("uninstall"); gCopiedLog.createUnique(gCopiedLog.DIRECTORY_TYPE, PERMS_DIR); if (uninstallLog) uninstallLog.copyTo(gCopiedLog, "uninstall.log"); gCopiedLog.append("uninstall.log"); LOG("uninstallLog = " + uninstallLog.path); LOG("copiedLog = " + gCopiedLog.path); if (!gCopiedLog.exists()) gCopiedLog.create(Components.interfaces.nsILocalFile.NORMAL_FILE_TYPE, PERMS_FILE); this._outputStream = openFileOutputStream(gCopiedLog, PR_WRONLY | PR_APPEND); // The NSIS uninstaller deletes all directories where the installer has // added a file if the directory is empty after the files have been removed // so there is no need to log directories. for (var relPath in newEntries) this._writeLine(PREFIX_FILE + relPath); }, end: function() { if (!this._outputStream) return; this._outputStream.close(); this._outputStream = null; }};var installLogWriter;var gCopiedLog;//-----------------------------------------------------------------------------/** * A thin wrapper around nsIWindowsRegKey * note, only the "read" methods are exposed. If you want to write * to the registry on Vista, you need to be a priveleged app. * We've moved that code into the uninstaller. */function RegKey() { // Internally, we may pass parameters to this constructor. if (arguments.length == 3) { this._key = arguments[0]; this._root = arguments[1]; this._path = arguments[2]; } else { this._key = Components.classes["@mozilla.org/windows-registry-key;1"]. createInstance(nsIWindowsRegKey); }}RegKey.prototype = { _key: null, _root: null, _path: null, ACCESS_READ: nsIWindowsRegKey.ACCESS_READ, ROOT_KEY_CURRENT_USER: nsIWindowsRegKey.ROOT_KEY_CURRENT_USER, ROOT_KEY_LOCAL_MACHINE: nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE, ROOT_KEY_CLASSES_ROOT: nsIWindowsRegKey.ROOT_KEY_CLASSES_ROOT, close: function() { this._key.close(); this._root = null; this._path = null; }, open: function(rootKey, path, mode) { this._key.open(rootKey, path, mode); this._root = rootKey; this._path = path; }, openChild: function(path, mode) { var child = this._key.openChild(path, mode); return new RegKey(child, this._root, this._path + "\\" + path); }, readStringValue: function(name) { return this._key.readStringValue(name); }, hasValue: function(name) { return this._key.hasValue(name); }, hasChild: function(name) { return this._key.hasChild(name); }, get childCount() { return this._key.childCount; }, getChildName: function(index) { return this._key.getChildName(index); }, toString: function() { var root; switch (this._root) { case this.ROOT_KEY_CLASSES_ROOT: root = "HKEY_KEY_CLASSES_ROOT"; break; case this.ROOT_KEY_LOCAL_MACHINE: root = "HKEY_LOCAL_MACHINE"; break; case this.ROOT_KEY_CURRENT_USER: root = "HKEY_CURRENT_USER"; break; default: LOG("unknown root key"); return ""; } return root + "\\" + this._path; }};/** * This method walks the registry looking for the registry keys of * the previous version of the application. */function haveOldInstall(key, brandFullName, version) { var ourInstallDir = getFile(KEY_APPDIR); var result = false; var childKey, productKey, mainKey; try { for (var i = 0; i < key.childCount; ++i) { var childName = key.getChildName(i); childKey = key.openChild(childName, key.ACCESS_READ); if (childKey.hasValue("CurrentVersion")) { for (var j = 0; j < childKey.childCount; ++j) { var productVer = childKey.getChildName(j); productKey = childKey.openChild(productVer, key.ACCESS_READ); if (productKey.hasChild("Main")) { mainKey = productKey.openChild("Main", key.ACCESS_READ); var installDir = mainKey.readStringValue("Install Directory"); mainKey.close(); LOG("old install? " + installDir + " vs " + ourInstallDir.path); LOG("old install? " + childName + " vs " + brandFullName); LOG("old install? " + productVer.split(" ")[0] + " vs " + version); if (newFile(installDir).equals(ourInstallDir) && (childName != brandFullName || productVer.split(" ")[0] != version)) { result = true; } } productKey.close(); if (result) break; } } childKey.close(); if (result) break; } } catch (e) { result = false; if (childKey) childKey.close(); if (productKey) productKey.close(); if (mainKey) mainKey.close(); } return result;}function checkRegistry(){ // XXX todo // this is firefox specific // figure out what to do about tbird and sunbird, etc LOG("checkRegistry"); var result = false; try { var key = new RegKey(); key.open(RegKey.prototype.ROOT_KEY_CLASSES_ROOT, "FirefoxHTML\\shell\\open\\command", key.ACCESS_READ); var commandKey = key.readStringValue(""); LOG("commandKey = " + commandKey); // if "-requestPending" is not found, we need to do the cleanup result = (commandKey.indexOf("-requestPending") == -1); } catch (e) { LOG("failed to open command key for FirefoxHTML: " + e); } key.close(); return result;}function checkOldInstall(rootKey, vendorShortName, brandFullName, version){ var key = new RegKey(); var result = false; try { key.open(rootKey, "SOFTWARE\\" + vendorShortName, key.ACCESS_READ); LOG("checkOldInstall: " + key + " " + brandFullName + " " + version); result = haveOldInstall(key, brandFullName, version); } catch (e) { LOG("failed trying to find old install: " + e); } key.close(); return result;}//-----------------------------------------------------------------------------function nsPostUpdateWin() { gConsole = Components.classes["@mozilla.org/consoleservice;1"] .getService(Components.interfaces.nsIConsoleService); var prefs = Components.classes["@mozilla.org/preferences-service;1"]. getService(Components.interfaces.nsIPrefBranch); try { gAppUpdateLogPostUpdate = prefs.getBoolPref("app.update.log.all"); } catch (ex) { } try { if (!gAppUpdateLogPostUpdate) gAppUpdateLogPostUpdate = prefs.getBoolPref("app.update.log.PostUpdate"); } catch (ex) { }}nsPostUpdateWin.prototype = { QueryInterface: function(iid) { if (iid.equals(Components.interfaces.nsIRunnable) || iid.equals(Components.interfaces.nsISupports)) return this; throw Components.results.NS_ERROR_NO_INTERFACE; }, run: function() { try { installLogWriter = new InstallLogWriter(); try { installLogWriter.begin(); } finally { installLogWriter.end(); installLogWriter = null; } } catch (e) { LOG(e); } var app = Components.classes["@mozilla.org/xre/app-info;1"]. getService(Components.interfaces.nsIXULAppInfo). QueryInterface(Components.interfaces.nsIXULRuntime); var sbs = Components.classes["@mozilla.org/intl/stringbundle;1"]. getService(Components.interfaces.nsIStringBundleService); var brandBundle = sbs.createBundle(URI_BRAND_PROPERTIES); var vendorShortName; try { // The Thunderbird vendorShortName is "Mozilla Thunderbird", but we // just want "Thunderbird", so allow it to be overridden in prefs. var prefs = Components.classes["@mozilla.org/preferences-service;1"]. getService(Components.interfaces.nsIPrefBranch); vendorShortName = prefs.getCharPref("app.update.vendorName.override"); } catch (e) { vendorShortName = brandBundle.GetStringFromName("vendorShortName"); } var brandFullName = brandBundle.GetStringFromName("brandFullName"); if (!gCopiedLog && !checkRegistry() && !checkOldInstall(RegKey.prototype.ROOT_KEY_LOCAL_MACHINE, vendorShortName, brandFullName, app.version) && !checkOldInstall(RegKey.prototype.ROOT_KEY_CURRENT_USER, vendorShortName, brandFullName, app.version)) { LOG("nothing to do, so don't launch the helper"); return; } try { var winAppHelper = app.QueryInterface(Components.interfaces.nsIWinAppHelper); // note, gCopiedLog could be null if (gCopiedLog) LOG("calling postUpdate with: " + gCopiedLog.path); else LOG("calling postUpdate without a log"); winAppHelper.postUpdate(gCopiedLog); } catch (e) { LOG("failed to launch the helper to do the post update cleanup: " + e); } }};//-----------------------------------------------------------------------------var gModule = { registerSelf: function(compMgr, fileSpec, location, type) { compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar); for (var key in this._objects) { var obj = this._objects[key]; compMgr.registerFactoryLocation(obj.CID, obj.className, obj.contractID, fileSpec, location, type); } }, getClassObject: function(compMgr, cid, iid) { if (!iid.equals(Components.interfaces.nsIFactory)) throw Components.results.NS_ERROR_NOT_IMPLEMENTED; for (var key in this._objects) { if (cid.equals(this._objects[key].CID)) return this._objects[key].factory; } throw Components.results.NS_ERROR_NO_INTERFACE; }, _makeFactory: #1= function(ctor) { function ci(outer, iid) { if (outer != null) throw Components.results.NS_ERROR_NO_AGGREGATION; return (new ctor()).QueryInterface(iid); } return { createInstance: ci }; }, _objects: { manager: { CID : Components.ID("{d15b970b-5472-40df-97e8-eb03a04baa82}"), contractID : "@mozilla.org/updates/post-update;1", className : "nsPostUpdateWin", factory : #1#(nsPostUpdateWin) }, }, canUnload: function(compMgr) { return true; }};function NSGetModule(compMgr, fileSpec) { return gModule;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -