Adding files to an extension's uninstallationFrom MozillaZine Knowledge BaseThe uninstall logWhen an extension is installed, the Extension Manager creates a log of the files which comprise that extension. This log is used by the Extension Manager to cleanly uninstall an extension when requested by the user. Here's a real log created when the PasswordMaker extension is installed on a Windows OS: add C:\Documents and Settings\Eric Jung\Application Data\Mozilla\Firefox\Profiles\ifk9k760.dev9\extensions\ {5872365e-67d1-4afd-9480-fd293bebd20d}\install.rdf add C:\Documents and Settings\Eric Jung\Application Data\Mozilla\Firefox\Profiles\ifk9k760.dev9\extensions\ {5872365e-67d1-4afd-9480-fd293bebd20d}\defaults\passwordmakerdialog.ico add C:\Documents and Settings\Eric Jung\Application Data\Mozilla\Firefox\Profiles\ifk9k760.dev9\extensions\ {5872365e-67d1-4afd-9480-fd293bebd20d}\defaults\passwordmakerdialog.xpm add C:\Documents and Settings\Eric Jung\Application Data\Mozilla\Firefox\Profiles\ifk9k760.dev9\extensions\ {5872365e-67d1-4afd-9480-fd293bebd20d}\install.js add C:\Documents and Settings\Eric Jung\Application Data\Mozilla\Firefox\Profiles\ifk9k760.dev9\extensions\ {5872365e-67d1-4afd-9480-fd293bebd20d}\chrome\passwdmaker.jar register profile package passwdmaker register profile skin classic/1.0 An extension's log is written to the file "Add" entriesEach add\tpath\filename\n where When an extension is uninstalled, the Extension Manager reads the extension's log and subsequently deletes each file that has an Adding entries to the uninstall logIf an extension creates file(s) during its lifetime, and the extension developer would like those file(s) automatically deleted when the extension is uninstalled, /** * Adds an "add" entry to this extension's Uninstall log. * The file argument can be created by DirIO.get() or FileIO.get() * in io.js. See usage example below. */ function addToUninstallList(file) { // make sure the new file is in the extension uninstall list var uninstallFile = DirIO.get("ProfD"); // %Profile% dir uninstallFile.append("extensions"); uninstallFile.append("{5872365E-67D1-4AFD-9480-FD293BEBD20D}"); uninstallFile.append("uninstall"); uninstallFile.append("Uninstall"); var data = FileIO.read(uninstallFile); var r = new RegEx("^add\s.*" + file.path", "m"); if (!data || r.test(data)) { // Uninstall file doesn't exist or filename is // already listed in it. return; } // Add new file to the Uninstall list. // Note we're not using the FileIO.path() function // because it returns an URL-encoded path (e.g., a space equals %20) var newLine = "add\t" + file.path + "\n"; FileIO.write(uninstallFile, newLine, "a"); } Sample use of the function: // Write a file. If successful, update the Uninstall log // so the file is automatically deleted when our extension // is uninstalled by the user. var myfile = DirIO.get("ProfD"); // %Profile% dir myfile.append("extensions"); myfile.append("{5872365E-67D1-4AFD-9480-FD293BEBD20D}"); myfile.append("myfile.xml"); if (FileIO.write(myfile, "<hello-world/>", "w")) { // Make sure the new file is in the extension uninstall list addToUninstallList(myfile); } |