** authored by rue and Wladimir, with code adapted from the optimoz project
*/
/* global vars for uninstall-status */
var removalCheckArray = new Array(); // the array of our deinstall "checks"
var reportN; // the total value of our deinstall "checks"
var syncComplete = false; // if true, all synchronous operations have completed
var quitTimer; // repeatedly checks if asynchronous disk-operations have completed
var quitTimerMonitor; // monitors the quitTimer -- stops it after 120 seconds
var isProfileInstalled = false; // if true, component-removal will be unnecessary -- set by deleteJar()
// confirm and begin the uninstall
function uninstallAdblock() {
var confirmUninstall = confirm("Do you really want to deinstall Adblock?-\n..the proceedure may take up to two-minutes, and the browser will have to quit immediately afterwards." );
// user choose to cancel
if (!confirmUninstall)
return; // do nothing further
document.getElementById("deinstall-menuitem").setAttribute("disabled", true); // disable the "DeInstall" menuitem
alert("Adblock was unable to shutdown the browser. \n\nYou are strongly advised to close all windows and shutdown the app.");
}
// alerts the user to "deinstall-failure" -- the timer doesn't like string-literals
function failureNotify() {
alert("DeInstallation failed. \n\n\ " + removalCheckArray[0] + removalCheckArray[1] + removalCheckArray[2] + removalCheckArray[3] + removalCheckArray[4] + removalCheckArray[5] + "\n\nPlease post this error-code, along with the browser-name, build date, and any other information you think might be relevant, to:\n\n adblock.mozdev.org/forum.html/no_wrap\n\n Thank You. \n--The Adblock Team");
}
// removes entries from the rdf-overlays in user-chrome and app-chrome and corresponding entries in chrome.rdf
installedChromeArray[n].remove(true); // remove the file so we can replace it
installedChromeArray[n].create(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0666); // create a new, blank file -- there's no way to empty an existing one
adblockJar.append("adblock.jar"); // "appends" the file-string to our dir file-obj
// move jar-file to temp-dir
try {
if (adblockJar.exists()) {
if (dirArray[i] == "UChrm") isProfileInstalled = true; // component-removal will be unnecessary
adblockJar.moveTo(tempDir, "adblock-jar-"+dirArray[i]+"-uninstalled"); // move the jar to the temp-dir, renaming
if (!removalCheckArray[2]) removalCheckArray[2]++; // don't increment twice (..if adblock was double-installed)
}
} catch(ei) {
// rename jar-file -- if move fails
try {
if (adblockJar.exists()) {
var newNameMain = "adblock-uninstalled";
var newName = newNameMain;
var adblockJarRenamed = chromeDir.clone();
var n = 1;
adblockJarRenamed.append(newName);
if (adblockJarRenamed.exists())
while(adblockJarRenamed.exists()) {
newName = new String(newNameMain + n); // + nameEnd); // find a unique-name for our "move-to" destination
adblockJarRenamed = chromeDir.clone();
adblockJarRenamed.append(newName);
n++;
}
adblockJar.moveTo(null, newName); // rename the jar to the "unique name"
if (!removalCheckArray[2]) removalCheckArray[2]++; // don't increment twice (..if adblock was double-installed)
}
} catch(eii) { /*alert("Unable to remove adblock.jar from:\n\n"+adblockJar.path+"\n\n..you'll have to quit the browser and remove it by hand.");*/ }
}
}
}
// deletes the xul cache-file
function deleteXULCache() {
var dirService = Components.classes['@mozilla.org/file/directory_service;1'].getService(Components.interfaces.nsIProperties);
var profileDir = dirService.get("ProfD", Components.interfaces.nsIFile);
var profileChromeDir = dirService.get("UChrm", Components.interfaces.nsIFile);
var tempDir = profileChromeDir.clone();
var cacheArray = [];
var found = false, xulCacheFile;
tempDir.append("adblock-temp");
cacheArray[0] = "XUL FastLoad File"; // -- mac classic
cacheArray[1] = "XUL.mfast"; // -- mac osX
cacheArray[2] = "XUL.mfasl"; // -- linux
cacheArray[3] = "XUL.mfl"; // -- windows + other
for (var n = 0 ; n < cacheArray.length &! found ; n++) {
xulCacheFile = profileDir.clone();
xulCacheFile.append(cacheArray[n]);
found = xulCacheFile.exists(); }
if (!found) {
removalCheckArray[3]++; // if there's no cache-file, we're done
return; }
// if the temp-dir doesn't exist yet, create it
try {
if (!tempDir.exists()) tempDir.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0666);
} catch(e) {}
try {
xulCacheFile.moveTo(tempDir, xulCacheFile.leafName + "-uninstalled"); // move the jar to the temp-dir, renaming
removalCheckArray[3]++;
} catch(e) { alert("Unable to remove the XUL Cache File: " + xulCacheFile.leafName + " \n..you'll have to quit the browser and remove it by hand.");}
}
// deletes the adblock-component
function deleteComponent() {
/*
if (isProfileInstalled) {
removalCheckArray[4]++;
return; } // component-removal was unnecessary
*/
var dirService = Components.classes['@mozilla.org/file/directory_service;1'].getService(Components.interfaces.nsIProperties);
var profileChromeDir = dirService.get("UChrm", Components.interfaces.nsIFile);
var tempDir = profileChromeDir.clone();
var component = dirService.get("ComsD", Components.interfaces.nsIFile); // http://lxr.mozilla.org/seamonkey/source/xpcom/io/nsDirectoryServiceDefs.h
tempDir.append("adblock-temp");
component.append("nsAdblock.js");
// remove component, if it exists
try {
if (component.exists()) component.moveTo(tempDir, component.leafName + "-uninstalled"); // move the jar to the temp-dir, renaming
removalCheckArray[4]++;
} catch(e) {alert("Unable to remove Adblock's Component File:\n\n" + component.path + "\n\n..you'll have to quit the browser and remove it by hand.");}
}
// removes all entries from compreg.dat
function removeCompregDat() {
/*
if (isProfileInstalled) {
removalCheckArray[5]++;
return; } // component-removal was unnecessary
*/
var dirService = Components.classes['@mozilla.org/file/directory_service;1'].getService(Components.interfaces.nsIProperties);
var compRegistry = dirService.get("ComRegF", Components.interfaces.nsIFile); // http://lxr.mozilla.org/seamonkey/source/xpcom/io/nsDirectoryServiceDefs.h
var streamIn = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream);
var streamOut = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream);
var wrappedIn = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance(Components.interfaces.nsIScriptableInputStream);
else alert("Your browser's Component Registry was not restored.\n\nThe registry file could not be written: \n\n" + compRegistry.path + "\n\nPlease verify that \'"+compRegistry.leafName+"\' has the necessary permissions and restart your browser.");
}
else alert("Your browser's Component Registry was not restored.\n\nThe registry file could not be read: \n\n" + compRegistry.path + "\n\nPlease verify that \'"+compRegistry.leafName+"\' has the necessary permissions and restart your browser.");