Fx60: Remove instances of nsILocalFile

nsILocalFile was merged into nsIFile, so either replace it with that or
switch to Zotero.File.pathToFile().
This commit is contained in:
Dan Stillman 2019-08-25 06:51:11 -04:00
parent 6f965251ed
commit 433794916a
13 changed files with 36 additions and 57 deletions

View file

@ -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();

View file

@ -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;
}

View file

@ -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) {

View file

@ -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) {

View file

@ -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++;
}

View file

@ -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;
}

View file

@ -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

View file

@ -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) {

View file

@ -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");
}

View file

@ -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);
};

View file

@ -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") {

View file

@ -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);
}

View file

@ -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);