Remove temp directory on shutdown

This commit is contained in:
Dan Stillman 2008-11-14 13:43:01 +00:00
parent 6f9033d206
commit c6ae811dde

View file

@ -36,13 +36,11 @@ var Zotero = new function(){
// Privileged (public) methods // Privileged (public) methods
this.init = init; this.init = init;
this.stateCheck = stateCheck; this.stateCheck = stateCheck;
//this.shutdown = shutdown;
this.getProfileDirectory = getProfileDirectory; this.getProfileDirectory = getProfileDirectory;
this.getInstallDirectory = getInstallDirectory; this.getInstallDirectory = getInstallDirectory;
this.getZoteroDirectory = getZoteroDirectory; this.getZoteroDirectory = getZoteroDirectory;
this.getStorageDirectory = getStorageDirectory; this.getStorageDirectory = getStorageDirectory;
this.getZoteroDatabase = getZoteroDatabase; this.getZoteroDatabase = getZoteroDatabase;
this.getTempDirectory = getTempDirectory;
this.chooseZoteroDirectory = chooseZoteroDirectory; this.chooseZoteroDirectory = chooseZoteroDirectory;
this.debug = debug; this.debug = debug;
this.log = log; this.log = log;
@ -85,7 +83,6 @@ var Zotero = new function(){
var _debugLevel; var _debugLevel;
var _debugTime; var _debugTime;
var _debugLastTime; var _debugLastTime;
//var _shutdown = false;
var _localizedStringBundle; var _localizedStringBundle;
@ -100,15 +97,11 @@ var Zotero = new function(){
var start = (new Date()).getTime() var start = (new Date()).getTime()
// Register shutdown handler to call Zotero.shutdown() // Register shutdown handler to call Zotero.shutdown()
/*
var observerService = Components.classes["@mozilla.org/observer-service;1"] var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService); .getService(Components.interfaces.nsIObserverService);
observerService.addObserver({ observerService.addObserver({
observe: function(subject, topic, data){ observe: Zotero.shutdown
Zotero.shutdown(subject, topic, data) }, "quit-application", false);
}
}, "xpcom-shutdown", false);
*/
// Load in the preferences branch for the extension // Load in the preferences branch for the extension
Zotero.Prefs.init(); Zotero.Prefs.init();
@ -307,15 +300,11 @@ var Zotero = new function(){
} }
/* this.shutdown = function (subject, topic, data) {
function shutdown(subject, topic, data){ Zotero.debug("Shutting down Zotero");
// Called twice otherwise, for some reason Zotero.removeTempDirectory();
if (_shutdown){
return false;
}
return true; return true;
} }
*/
function getProfileDirectory(){ function getProfileDirectory(){
@ -389,7 +378,7 @@ var Zotero = new function(){
/** /**
* @return {nsIFile} * @return {nsIFile}
*/ */
function getTempDirectory() { this.getTempDirectory = function () {
var tmp = this.getZoteroDirectory(); var tmp = this.getZoteroDirectory();
tmp.append('tmp'); tmp.append('tmp');
Zotero.File.createDirectoryIfMissing(tmp); Zotero.File.createDirectoryIfMissing(tmp);
@ -397,6 +386,18 @@ var Zotero = new function(){
} }
this.removeTempDirectory = function () {
var tmp = this.getZoteroDirectory();
tmp.append('tmp');
if (tmp.exists()) {
try {
tmp.remove(true);
}
catch (e) {}
}
}
this.getStylesDirectory = function () { this.getStylesDirectory = function () {
var dir = this.getZoteroDirectory(); var dir = this.getZoteroDirectory();
dir.append('styles'); dir.append('styles');