diff --git a/chrome/content/zotero/rtfScan.js b/chrome/content/zotero/rtfScan.js index d6530b6480..18fc2c1856 100644 --- a/chrome/content/zotero/rtfScan.js +++ b/chrome/content/zotero/rtfScan.js @@ -51,13 +51,11 @@ var Zotero_RTFScan = new function() { this.introPageShowing = function() { var path = Zotero.Prefs.get("rtfScan.lastInputFile"); if(path) { - inputFile = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); - inputFile.initWithPath(path); + inputFile = Zotero.File.pathToFile(path); } var path = Zotero.Prefs.get("rtfScan.lastOutputFile"); if(path) { - outputFile = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); - outputFile.initWithPath(path); + outputFile = Zotero.File.pathToFile(path); } _updatePath(); document.getElementById("choose-input-file").focus(); diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index c22ef38b7f..8e29308c84 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -2239,7 +2239,7 @@ Zotero.Item.prototype.getFilePath = function () { } let file = Components.classes["@mozilla.org/file/local;1"] - .createInstance(Components.interfaces.nsILocalFile); + .createInstance(Components.interfaces.nsIFile); try { file.persistentDescriptor = path; } @@ -2345,7 +2345,7 @@ Zotero.Item.prototype.getFilePathAsync = Zotero.Promise.coroutine(function* () { // the file couldn't be found if (Zotero.isMac && path.startsWith('AAAA')) { let file = Components.classes["@mozilla.org/file/local;1"] - .createInstance(Components.interfaces.nsILocalFile); + .createInstance(Components.interfaces.nsIFile); try { file.persistentDescriptor = path; } diff --git a/chrome/content/zotero/xpcom/dataDirectory.js b/chrome/content/zotero/xpcom/dataDirectory.js index ca8e6663cb..397d573989 100644 --- a/chrome/content/zotero/xpcom/dataDirectory.js +++ b/chrome/content/zotero/xpcom/dataDirectory.js @@ -100,7 +100,7 @@ Zotero.DataDirectory = { let nsIFile; try { nsIFile = Components.classes["@mozilla.org/file/local;1"] - .createInstance(Components.interfaces.nsILocalFile); + .createInstance(Components.interfaces.nsIFile); nsIFile.persistentDescriptor = prefVal; } catch (e) { @@ -265,7 +265,7 @@ Zotero.DataDirectory = { let nsIFile; try { nsIFile = Components.classes["@mozilla.org/file/local;1"] - .createInstance(Components.interfaces.nsILocalFile); + .createInstance(Components.interfaces.nsIFile); nsIFile.persistentDescriptor = prefs['extensions.zotero.dataDir']; } catch (e) { diff --git a/chrome/content/zotero/xpcom/file.js b/chrome/content/zotero/xpcom/file.js index ddb4842dd9..2a42ab8696 100644 --- a/chrome/content/zotero/xpcom/file.js +++ b/chrome/content/zotero/xpcom/file.js @@ -1319,7 +1319,6 @@ Zotero.File = new function(){ dialogButtonText: Zotero.getString('file.accessError.showParentDir'), dialogButtonCallback: function () { try { - file.parent.QueryInterface(Components.interfaces.nsILocalFile); file.parent.reveal(); } // Unsupported on some platforms @@ -1353,13 +1352,12 @@ Zotero.File = new function(){ Zotero.debug("Revealing " + file); var nsIFile = this.pathToFile(file); - nsIFile.QueryInterface(Components.interfaces.nsILocalFile); try { nsIFile.reveal(); } catch (e) { Zotero.logError(e); - // On platforms that don't support nsILocalFile.reveal() (e.g. Linux), + // On platforms that don't support nsIFile.reveal() (e.g. Linux), // launch the directory let zp = Zotero.getActiveZoteroPane(); if (zp) { diff --git a/chrome/content/zotero/xpcom/itemTreeView.js b/chrome/content/zotero/xpcom/itemTreeView.js index 42ed281fa5..8bf19c8489 100644 --- a/chrome/content/zotero/xpcom/itemTreeView.js +++ b/chrome/content/zotero/xpcom/itemTreeView.js @@ -2847,7 +2847,7 @@ Zotero.ItemTreeView.fileDragDataProvider.prototype = { var dirPrimitive = {}; var dataSize = {}; transferable.getTransferData("application/x-moz-file-promise-dir", dirPrimitive, dataSize); - var destDir = dirPrimitive.value.QueryInterface(Components.interfaces.nsILocalFile); + var destDir = dirPrimitive.value.QueryInterface(Components.interfaces.nsIFile); var draggedItems = Zotero.Items.get(this._itemIDs); var items = []; @@ -2901,7 +2901,7 @@ Zotero.ItemTreeView.fileDragDataProvider.prototype = { var numFiles = 0; while (files.hasMoreElements()) { var f = files.getNext(); - f.QueryInterface(Components.interfaces.nsILocalFile); + f.QueryInterface(Components.interfaces.nsIFile); if (f.leafName.indexOf('.') != 0) { numFiles++; } diff --git a/chrome/content/zotero/xpcom/schema.js b/chrome/content/zotero/xpcom/schema.js index 2182f7b134..e9f4dad46c 100644 --- a/chrome/content/zotero/xpcom/schema.js +++ b/chrome/content/zotero/xpcom/schema.js @@ -2588,7 +2588,7 @@ Zotero.Schema = new function(){ } else { let file = Components.classes["@mozilla.org/file/local;1"] - .createInstance(Components.interfaces.nsILocalFile); + .createInstance(Components.interfaces.nsIFile); try { file.persistentDescriptor = path; } diff --git a/chrome/content/zotero/xpcom/translation/translate_item.js b/chrome/content/zotero/xpcom/translation/translate_item.js index b78af7518f..ad30d33950 100644 --- a/chrome/content/zotero/xpcom/translation/translate_item.js +++ b/chrome/content/zotero/xpcom/translation/translate_item.js @@ -681,11 +681,11 @@ Zotero.Translate.ItemSaver.prototype = { }, "_parseAbsolutePath":function(path) { - var file = Components.classes["@mozilla.org/file/local;1"]. - createInstance(Components.interfaces.nsILocalFile); + var file; try { - file.initWithPath(path); - } catch(e) { + file = Zotero.File.pathToFile(path); + } + catch (e) { Zotero.debug("Translate: Invalid absolute path: " + path); return false; } @@ -994,9 +994,7 @@ Zotero.Translate.ItemGetter.prototype = { "exportFiles":function(dir, extension) { // generate directory - this._exportFileDirectory = Components.classes["@mozilla.org/file/local;1"]. - createInstance(Components.interfaces.nsILocalFile); - this._exportFileDirectory.initWithFile(dir.parent); + this._exportFileDirectory = dir.parent.clone(); // delete this file if it exists if(dir.exists()) { @@ -1012,9 +1010,7 @@ Zotero.Translate.ItemGetter.prototype = { // generate a new location for the exported file, with the appropriate // extension - var location = Components.classes["@mozilla.org/file/local;1"]. - createInstance(Components.interfaces.nsILocalFile); - location.initWithFile(this._exportFileDirectory); + var location = this._exportFileDirectory.clone(); location.append(name+"."+extension); return location; @@ -1075,9 +1071,7 @@ Zotero.Translate.ItemGetter.prototype = { // Separate the path into a list of subdirectories and the attachment filename, // and initialize the required file objects - var targetFile = Components.classes["@mozilla.org/file/local;1"]. - createInstance(Components.interfaces.nsILocalFile); - targetFile.initWithFile(exportDir); + var targetFile = exportDir.clone(); for (let dir of attachPath.split("/")) targetFile.append(dir); // First, check that we have not gone lower than exportDir in the hierarchy diff --git a/chrome/content/zotero/xpcom/utilities_internal.js b/chrome/content/zotero/xpcom/utilities_internal.js index daccf48a7f..08d838f0eb 100644 --- a/chrome/content/zotero/xpcom/utilities_internal.js +++ b/chrome/content/zotero/xpcom/utilities_internal.js @@ -1717,9 +1717,7 @@ Zotero.Utilities.Internal.executeAppleScript = new function() { return function(script, block) { if(_osascriptFile === undefined) { - _osascriptFile = Components.classes["@mozilla.org/file/local;1"]. - createInstance(Components.interfaces.nsILocalFile); - _osascriptFile.initWithPath("/usr/bin/osascript"); + _osascriptFile = Zotero.File.pathToFile('/usr/bin/osascript'); if(!_osascriptFile.exists()) _osascriptFile = false; } if(_osascriptFile) { diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index f8d8ccb3d1..7202bcc016 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -1010,7 +1010,7 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js"); Zotero.debug(e); Zotero.debug("Launching via executable failed -- passing to loadUrl()"); - // If nsILocalFile.launch() isn't available and the fallback + // If nsIFile.launch() isn't available and the fallback // executable doesn't exist, we just let the Firefox external // helper app window handle it var nsIFPH = Components.classes["@mozilla.org/network/protocol;1?name=file"] @@ -1080,9 +1080,7 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js"); } var path = Zotero.Prefs.get(pref); - var exec = Components.classes["@mozilla.org/file/local;1"] - .createInstance(Components.interfaces.nsILocalFile); - exec.initWithPath(path); + let exec = Zotero.File.pathToFile(path); if (!exec.exists()) { throw ("Fallback executable not found -- check extensions.zotero." + pref + " in about:config"); } diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index a045d6641b..6f86492ccc 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -4214,10 +4214,9 @@ var ZoteroPane = new function() file.reveal(); } catch (e) { - // On platforms that don't support nsILocalFile.reveal() (e.g. Linux), + // On platforms that don't support nsIFile.reveal() (e.g. Linux), // launch the parent directory - var parent = file.parent.QueryInterface(Components.interfaces.nsILocalFile); - Zotero.launchFile(parent); + Zotero.launchFile(file.parent); } Zotero.Notifier.trigger('open', 'file', attachment.id); }; diff --git a/components/zotero-service.js b/components/zotero-service.js index eb20e9b290..4c0241889e 100644 --- a/components/zotero-service.js +++ b/components/zotero-service.js @@ -612,9 +612,7 @@ ZoteroCommandLineHandler.prototype = { // Wait to handle things that require the UI until after it's loaded Zotero.uiReadyPromise .then(function () { - var file = Components.classes["@mozilla.org/file/local;1"]. - createInstance(Components.interfaces.nsILocalFile); - file.initWithPath(param); + var file = Zotero.File.pathToFile(param); if(file.leafName.substr(-4).toLowerCase() === ".csl" || file.leafName.substr(-8).toLowerCase() === ".csl.txt") { diff --git a/test/resource/httpd.js b/test/resource/httpd.js index c72e47f50b..8fba7f6290 100644 --- a/test/resource/httpd.js +++ b/test/resource/httpd.js @@ -2284,7 +2284,7 @@ function ServerHandler(server) this._server = server; /** - * A FileMap object containing the set of path->nsILocalFile mappings for + * A FileMap object containing the set of path->nsIFile mappings for * all directory mappings set in the server (e.g., "/" for /var/www/html/, * "/foo/bar/" for /local/path/, and "/foo/bar/baz/" for /local/path2). * @@ -2717,7 +2717,7 @@ ServerHandler.prototype = * * @param metadata : Request * the Request for which a response is being generated - * @param file : nsILocalFile + * @param file : nsIFile * the file which is to be sent in the response * @param response : Response * the response to which the file should be written @@ -3057,7 +3057,7 @@ ServerHandler.prototype = }, /** - * Returns the nsILocalFile which corresponds to the path, as determined using + * Returns the nsIFile which corresponds to the path, as determined using * all registered path->directory mappings and any paths which are explicitly * overridden. * @@ -3067,7 +3067,7 @@ ServerHandler.prototype = * when the correct action is the corresponding HTTP error (i.e., because no * mapping was found for a directory in path, the referenced file doesn't * exist, etc.) - * @returns nsILocalFile + * @returns nsIFile * the file to be sent as the response to a request for the path */ _getFileForPath: function(path) @@ -3432,11 +3432,11 @@ ServerHandler.prototype = /** - * Maps absolute paths to files on the local file system (as nsILocalFiles). + * Maps absolute paths to files on the local file system (as nsIFiles). */ function FileMap() { - /** Hash which will map paths to nsILocalFiles. */ + /** Hash which will map paths to nsIFiles. */ this._map = {}; } FileMap.prototype = @@ -3444,12 +3444,12 @@ FileMap.prototype = // PUBLIC API /** - * Maps key to a clone of the nsILocalFile value if value is non-null; + * Maps key to a clone of the nsIFile value if value is non-null; * otherwise, removes any extant mapping for key. * * @param key : string * string to which a clone of value is mapped - * @param value : nsILocalFile + * @param value : nsIFile * the file to map to key, or null to remove a mapping */ put: function(key, value) @@ -3461,12 +3461,12 @@ FileMap.prototype = }, /** - * Returns a clone of the nsILocalFile mapped to key, or null if no such + * Returns a clone of the nsIFile mapped to key, or null if no such * mapping exists. * * @param key : string * key to which the returned file maps - * @returns nsILocalFile + * @returns nsIFile * a clone of the mapped file, or null if no mapping exists */ get: function(key) @@ -5330,7 +5330,7 @@ function server(port, basePath) if (basePath) { var lp = Cc["@mozilla.org/file/local;1"] - .createInstance(Ci.nsILocalFile); + .createInstance(Ci.nsIFile); lp.initWithPath(basePath); } diff --git a/test/tests/translateTest.js b/test/tests/translateTest.js index 53c48040a5..d7bf416033 100644 --- a/test/tests/translateTest.js +++ b/test/tests/translateTest.js @@ -1882,9 +1882,7 @@ describe("Zotero.Translate.ItemGetter", function() { getter._itemsLeft = items.slice(); let exportDir = yield getTempDirectory(); - getter._exportFileDirectory = Components.classes["@mozilla.org/file/local;1"] - .createInstance(Components.interfaces.nsILocalFile); - getter._exportFileDirectory.initWithPath(exportDir); + getter._exportFileDirectory = Zotero.File.pathToFile(exportDir); let legacy = getter.legacy = legacyMode[i]; let suffix = legacy ? ' in legacy mode' : ''; @@ -1988,9 +1986,7 @@ describe("Zotero.Translate.ItemGetter", function() { if (!linkToURL) { // localPath assert.isString(attachment.localPath, prefix + 'localPath is set' + suffix); - let attachmentFile = Components.classes["@mozilla.org/file/local;1"] - .createInstance(Components.interfaces.nsILocalFile); - attachmentFile.initWithPath(attachment.localPath); + let attachmentFile = Zotero.File.pathToFile(attachment.localPath); assert.isTrue(attachmentFile.exists(), prefix + 'localPath points to a file' + suffix); assert.isTrue(attachmentFile.equals(attachments[j].getFile()), prefix + 'localPath points to the correct file' + suffix);