2014-09-22 19:11:00 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
const { Cc, Cu, Ci } = require("chrome");
|
|
|
|
const { FileUtils } = Cu.import("resource://gre/modules/FileUtils.jsm", {});
|
2016-02-27 15:51:10 +03:00
|
|
|
const Services = require("Services");
|
2015-11-05 00:35:53 +03:00
|
|
|
const Strings = Services.strings.createBundle("chrome://devtools/locale/webide.properties");
|
2014-09-22 19:11:00 +04:00
|
|
|
|
2016-05-17 21:25:54 +03:00
|
|
|
function doesFileExist(location) {
|
2014-09-22 19:11:00 +04:00
|
|
|
let file = new FileUtils.File(location);
|
|
|
|
return file.exists();
|
|
|
|
}
|
|
|
|
exports.doesFileExist = doesFileExist;
|
|
|
|
|
2016-05-17 21:25:54 +03:00
|
|
|
function _getFile(location, ...pickerParams) {
|
2015-04-08 21:43:00 +03:00
|
|
|
if (location) {
|
2017-03-03 11:42:27 +03:00
|
|
|
return Promise.resolve(new FileUtils.File(location));
|
2014-09-22 19:11:00 +04:00
|
|
|
}
|
2015-04-08 21:43:00 +03:00
|
|
|
let fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
|
|
|
|
fp.init(...pickerParams);
|
2017-03-03 11:42:27 +03:00
|
|
|
|
|
|
|
return new Promise(resolve => {
|
|
|
|
fp.open(res => {
|
|
|
|
if (res == Ci.nsIFilePicker.returnCancel) {
|
|
|
|
resolve(null);
|
|
|
|
} else {
|
|
|
|
resolve(fp.file);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2015-04-08 21:43:00 +03:00
|
|
|
}
|
|
|
|
|
2016-05-17 21:25:54 +03:00
|
|
|
function getCustomBinary(window, location) {
|
2015-04-08 21:43:00 +03:00
|
|
|
return _getFile(location, window, Strings.GetStringFromName("selectCustomBinary_title"), Ci.nsIFilePicker.modeOpen);
|
|
|
|
}
|
|
|
|
exports.getCustomBinary = getCustomBinary;
|
|
|
|
|
2016-05-17 21:25:54 +03:00
|
|
|
function getCustomProfile(window, location) {
|
2015-04-08 21:43:00 +03:00
|
|
|
return _getFile(location, window, Strings.GetStringFromName("selectCustomProfile_title"), Ci.nsIFilePicker.modeGetFolder);
|
|
|
|
}
|
|
|
|
exports.getCustomProfile = getCustomProfile;
|
|
|
|
|
2016-05-17 21:25:54 +03:00
|
|
|
function getPackagedDirectory(window, location) {
|
2015-04-08 21:43:00 +03:00
|
|
|
return _getFile(location, window, Strings.GetStringFromName("importPackagedApp_title"), Ci.nsIFilePicker.modeGetFolder);
|
2014-09-22 19:11:00 +04:00
|
|
|
}
|
|
|
|
exports.getPackagedDirectory = getPackagedDirectory;
|
|
|
|
|
2016-05-17 21:25:54 +03:00
|
|
|
function getHostedURL(window, location) {
|
2014-09-22 19:11:00 +04:00
|
|
|
let ret = { value: null };
|
|
|
|
|
|
|
|
if (!location) {
|
|
|
|
Services.prompt.prompt(window,
|
|
|
|
Strings.GetStringFromName("importHostedApp_title"),
|
|
|
|
Strings.GetStringFromName("importHostedApp_header"),
|
|
|
|
ret, null, {});
|
|
|
|
location = ret.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!location) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clean location string and add "http://" if missing
|
|
|
|
location = location.trim();
|
|
|
|
try { // Will fail if no scheme
|
|
|
|
Services.io.extractScheme(location);
|
2016-05-17 21:25:54 +03:00
|
|
|
} catch (e) {
|
2014-09-22 19:11:00 +04:00
|
|
|
location = "http://" + location;
|
|
|
|
}
|
|
|
|
return location;
|
|
|
|
}
|
|
|
|
exports.getHostedURL = getHostedURL;
|