2012-04-17 07:17:23 -07: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/. */
|
|
|
|
|
2012-10-31 09:13:28 -07:00
|
|
|
this.EXPORTED_SYMBOLS = ["WebappsInstaller"];
|
2012-04-17 07:17:23 -07:00
|
|
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cu = Components.utils;
|
2012-07-05 15:02:17 -07:00
|
|
|
const Cr = Components.results;
|
2012-04-17 07:17:23 -07:00
|
|
|
|
2012-04-22 14:27:05 -07:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
Cu.import("resource://gre/modules/FileUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/NetUtil.jsm");
|
2013-02-25 23:48:35 -08:00
|
|
|
Cu.import("resource://gre/modules/osfile.jsm");
|
2013-08-01 17:00:22 -07:00
|
|
|
Cu.import("resource://gre/modules/WebappOSUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/AppsUtils.jsm");
|
2013-08-08 10:31:58 -07:00
|
|
|
Cu.import("resource://gre/modules/Task.jsm");
|
2013-08-26 12:04:33 -07:00
|
|
|
Cu.import("resource://gre/modules/Promise.jsm");
|
2012-04-17 07:17:23 -07:00
|
|
|
|
2013-10-04 10:00:13 -07:00
|
|
|
// 0755
|
|
|
|
const PERMS_DIRECTORY = OS.Constants.libc.S_IRWXU |
|
|
|
|
OS.Constants.libc.S_IRGRP | OS.Constants.libc.S_IXGRP |
|
|
|
|
OS.Constants.libc.S_IROTH | OS.Constants.libc.S_IXOTH;
|
|
|
|
|
|
|
|
// 0644
|
|
|
|
const PERMS_FILE = OS.Constants.libc.S_IRUSR | OS.Constants.libc.S_IWUSR |
|
|
|
|
OS.Constants.libc.S_IRGRP |
|
|
|
|
OS.Constants.libc.S_IROTH;
|
|
|
|
|
|
|
|
const DESKTOP_DIR = OS.Constants.Path.desktopDir;
|
|
|
|
const HOME_DIR = OS.Constants.Path.homeDir;
|
|
|
|
const TMP_DIR = OS.Constants.Path.tmpDir;
|
|
|
|
|
2012-10-31 09:13:28 -07:00
|
|
|
this.WebappsInstaller = {
|
2013-08-01 17:00:39 -07:00
|
|
|
shell: null,
|
|
|
|
|
2013-08-01 17:00:39 -07:00
|
|
|
/**
|
2013-08-01 17:00:39 -07:00
|
|
|
* Initializes the app object that takes care of the installation
|
|
|
|
* and creates the profile directory for an application
|
2013-08-01 17:00:39 -07:00
|
|
|
*
|
2013-08-01 17:00:39 -07:00
|
|
|
* @param aData the data provided to the install function
|
2013-08-01 17:00:39 -07:00
|
|
|
*
|
2013-08-01 17:00:39 -07:00
|
|
|
* @returns NativeApp on success, null on error
|
2013-08-01 17:00:39 -07:00
|
|
|
*/
|
2013-08-01 17:00:39 -07:00
|
|
|
init: function(aData) {
|
|
|
|
#ifdef XP_WIN
|
|
|
|
this.shell = new WinNativeApp(aData);
|
|
|
|
#elifdef XP_MACOSX
|
|
|
|
this.shell = new MacNativeApp(aData);
|
|
|
|
#elifdef XP_UNIX
|
|
|
|
this.shell = new LinuxNativeApp(aData);
|
|
|
|
#else
|
|
|
|
return null;
|
|
|
|
#endif
|
2013-08-01 18:51:12 -07:00
|
|
|
|
2013-08-01 17:00:39 -07:00
|
|
|
try {
|
|
|
|
if (Services.prefs.getBoolPref("browser.mozApps.installer.dry_run")) {
|
|
|
|
return this.shell;
|
|
|
|
}
|
|
|
|
} catch (ex) {}
|
|
|
|
|
|
|
|
try {
|
|
|
|
this.shell.createAppProfile();
|
|
|
|
} catch (ex) {
|
|
|
|
Cu.reportError("Error installing app: " + ex);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.shell;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a native installation of the web app in the OS
|
|
|
|
*
|
|
|
|
* @param aData the data provided to the install function
|
|
|
|
* @param aManifest the manifest data provided by the web app
|
2013-09-13 05:32:47 -07:00
|
|
|
* @param aZipPath path to the zip file for packaged apps (undefined for
|
|
|
|
* hosted apps)
|
2013-08-01 17:00:39 -07:00
|
|
|
*/
|
2013-09-13 05:32:47 -07:00
|
|
|
install: function(aData, aManifest, aZipPath) {
|
2012-04-19 18:47:52 -07:00
|
|
|
try {
|
|
|
|
if (Services.prefs.getBoolPref("browser.mozApps.installer.dry_run")) {
|
2013-08-26 12:04:33 -07:00
|
|
|
return Promise.resolve();
|
2012-04-19 18:47:52 -07:00
|
|
|
}
|
|
|
|
} catch (ex) {}
|
|
|
|
|
2013-08-01 17:00:39 -07:00
|
|
|
this.shell.init(aData, aManifest);
|
2012-04-17 07:17:23 -07:00
|
|
|
|
2013-09-13 05:32:47 -07:00
|
|
|
return this.shell.install(aZipPath).then(() => {
|
2013-08-26 12:04:33 -07:00
|
|
|
let data = {
|
2013-10-04 10:00:13 -07:00
|
|
|
"installDir": this.shell.installDir,
|
2013-08-26 12:04:33 -07:00
|
|
|
"app": {
|
|
|
|
"manifest": aManifest,
|
|
|
|
"origin": aData.app.origin
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Services.obs.notifyObservers(null, "webapp-installed", JSON.stringify(data));
|
|
|
|
});
|
2012-04-17 07:17:23 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-06-03 18:57:41 -07:00
|
|
|
* This function implements the common constructor for
|
2013-08-01 17:00:39 -07:00
|
|
|
* the Windows, Mac and Linux native app shells. It sets
|
|
|
|
* the app unique name. It's meant to be called as
|
|
|
|
* NativeApp.call(this, aData) from the platform-specific
|
|
|
|
* constructor.
|
2012-04-17 07:17:23 -07:00
|
|
|
*
|
2013-08-01 17:00:39 -07:00
|
|
|
* @param aData the data object provided to the install function
|
2012-04-17 07:17:23 -07:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
function NativeApp(aData) {
|
2013-08-01 17:00:39 -07:00
|
|
|
let jsonManifest = aData.isPackage ? aData.app.updateManifest : aData.app.manifest;
|
|
|
|
let manifest = new ManifestHelper(jsonManifest, aData.app.origin);
|
2012-04-17 07:17:23 -07:00
|
|
|
|
2013-09-13 05:32:47 -07:00
|
|
|
aData.app.name = manifest.name;
|
|
|
|
this.uniqueName = WebappOSUtils.getUniqueName(aData.app);
|
|
|
|
|
2013-08-01 17:00:39 -07:00
|
|
|
this.appName = sanitize(manifest.name);
|
|
|
|
this.appNameAsFilename = stripStringForFilename(this.appName);
|
|
|
|
}
|
2012-04-17 07:17:23 -07:00
|
|
|
|
2013-08-01 17:00:39 -07:00
|
|
|
NativeApp.prototype = {
|
|
|
|
uniqueName: null,
|
|
|
|
appName: null,
|
|
|
|
appNameAsFilename: null,
|
|
|
|
iconURI: null,
|
|
|
|
developerName: null,
|
|
|
|
shortDescription: null,
|
|
|
|
categories: null,
|
|
|
|
webappJson: null,
|
|
|
|
runtimeFolder: null,
|
2013-08-26 12:04:50 -07:00
|
|
|
manifest: null,
|
2013-08-01 17:00:39 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This function reads and parses the data from the app
|
|
|
|
* manifest and stores it in the NativeApp object.
|
|
|
|
*
|
|
|
|
* @param aData the data object provided to the install function
|
|
|
|
* @param aManifest the manifest data provided by the web app
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
init: function(aData, aManifest) {
|
2013-10-04 10:00:13 -07:00
|
|
|
let app = this.app = aData.app;
|
2013-08-26 12:04:50 -07:00
|
|
|
let manifest = this.manifest = new ManifestHelper(aManifest,
|
2013-09-13 05:32:46 -07:00
|
|
|
app.origin);
|
2013-08-01 17:00:39 -07:00
|
|
|
|
2013-09-13 05:32:46 -07:00
|
|
|
let origin = Services.io.newURI(app.origin, null, null);
|
2013-08-01 17:00:39 -07:00
|
|
|
|
|
|
|
let biggestIcon = getBiggestIconURL(manifest.icons);
|
2012-04-17 07:17:23 -07:00
|
|
|
try {
|
2013-08-01 17:00:39 -07:00
|
|
|
let iconURI = Services.io.newURI(biggestIcon, null, null);
|
|
|
|
if (iconURI.scheme == "data") {
|
|
|
|
this.iconURI = iconURI;
|
|
|
|
}
|
|
|
|
} catch (ex) {}
|
|
|
|
|
|
|
|
if (!this.iconURI) {
|
|
|
|
try {
|
|
|
|
this.iconURI = Services.io.newURI(origin.resolve(biggestIcon), null, null);
|
|
|
|
}
|
|
|
|
catch (ex) {}
|
2012-04-17 07:17:23 -07:00
|
|
|
}
|
|
|
|
|
2013-08-26 12:04:50 -07:00
|
|
|
if (manifest.developer) {
|
|
|
|
if (manifest.developer.name) {
|
|
|
|
let devName = sanitize(manifest.developer.name.substr(0, 128));
|
|
|
|
if (devName) {
|
|
|
|
this.developerName = devName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (manifest.developer.url) {
|
|
|
|
this.developerUrl = manifest.developer.url;
|
2013-08-01 17:00:39 -07:00
|
|
|
}
|
|
|
|
}
|
2012-04-17 07:17:23 -07:00
|
|
|
|
2013-08-01 17:00:39 -07:00
|
|
|
if (manifest.description) {
|
|
|
|
let firstLine = manifest.description.split("\n")[0];
|
|
|
|
let shortDesc = firstLine.length <= 256
|
|
|
|
? firstLine
|
|
|
|
: firstLine.substr(0, 253) + "…";
|
|
|
|
this.shortDescription = sanitize(shortDesc);
|
|
|
|
} else {
|
|
|
|
this.shortDescription = this.appName;
|
2012-04-17 07:17:23 -07:00
|
|
|
}
|
|
|
|
|
2013-09-13 05:32:46 -07:00
|
|
|
this.categories = app.categories.slice(0);
|
2012-04-17 07:17:23 -07:00
|
|
|
|
2013-08-01 17:00:39 -07:00
|
|
|
this.webappJson = {
|
2013-10-04 10:00:13 -07:00
|
|
|
// The app registry is the Firefox profile from which the app
|
|
|
|
// was installed.
|
|
|
|
"registryDir": OS.Constants.Path.profileDir,
|
2013-08-01 17:00:39 -07:00
|
|
|
"app": {
|
|
|
|
"manifest": aManifest,
|
2013-09-13 05:32:46 -07:00
|
|
|
"origin": app.origin,
|
|
|
|
"manifestURL": app.manifestURL,
|
|
|
|
"installOrigin": app.installOrigin,
|
|
|
|
"categories": app.categories,
|
|
|
|
"receipts": app.receipts,
|
|
|
|
"installTime": app.installTime,
|
2013-08-01 17:00:39 -07:00
|
|
|
}
|
|
|
|
};
|
2012-06-03 18:57:41 -07:00
|
|
|
|
2013-09-13 05:32:46 -07:00
|
|
|
if (app.etag) {
|
|
|
|
this.webappJson.app.etag = app.etag;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (app.packageEtag) {
|
|
|
|
this.webappJson.app.packageEtag = app.packageEtag;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (app.updateManifest) {
|
|
|
|
this.webappJson.app.updateManifest = app.updateManifest;
|
|
|
|
}
|
|
|
|
|
2013-10-04 10:00:13 -07:00
|
|
|
this.runtimeFolder = OS.Constants.Path.libDir;
|
2013-08-26 12:04:33 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function retrieves the icon for an app.
|
|
|
|
* If the retrieving fails, it uses the default chrome icon.
|
|
|
|
*/
|
|
|
|
getIcon: function() {
|
|
|
|
try {
|
2013-09-13 05:32:47 -07:00
|
|
|
// If the icon is in the zip package, we should modify the url
|
|
|
|
// to point to the zip file (we can't use the app protocol yet
|
|
|
|
// because the app isn't installed yet).
|
|
|
|
if (this.iconURI.scheme == "app") {
|
2014-01-30 08:23:55 -08:00
|
|
|
let zipUrl = OS.Path.toFileURI(OS.Path.join(this.tmpInstallDir,
|
|
|
|
"application.zip"));
|
2013-09-13 05:32:47 -07:00
|
|
|
|
|
|
|
let filePath = this.iconURI.QueryInterface(Ci.nsIURL).filePath;
|
|
|
|
|
|
|
|
this.iconURI = Services.io.newURI("jar:" + zipUrl + "!" + filePath,
|
|
|
|
null, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-26 12:04:33 -07:00
|
|
|
let [ mimeType, icon ] = yield downloadIcon(this.iconURI);
|
|
|
|
yield this.processIcon(mimeType, icon);
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
Cu.reportError("Failure retrieving icon: " + e);
|
|
|
|
|
|
|
|
let iconURI = Services.io.newURI(DEFAULT_ICON_URL, null, null);
|
|
|
|
|
|
|
|
let [ mimeType, icon ] = yield downloadIcon(iconURI);
|
|
|
|
yield this.processIcon(mimeType, icon);
|
|
|
|
|
|
|
|
// Set the iconURI property so that the user notification will have the
|
|
|
|
// correct icon.
|
|
|
|
this.iconURI = iconURI;
|
|
|
|
}
|
|
|
|
},
|
2013-08-27 20:41:50 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates the profile to be used for this app.
|
|
|
|
*/
|
|
|
|
createAppProfile: function() {
|
|
|
|
let profSvc = Cc["@mozilla.org/toolkit/profile-service;1"]
|
|
|
|
.getService(Ci.nsIToolkitProfileService);
|
|
|
|
|
|
|
|
try {
|
|
|
|
this.appProfile = profSvc.createDefaultProfileForApp(this.uniqueName,
|
|
|
|
null, null);
|
|
|
|
} catch (ex if ex.result == Cr.NS_ERROR_ALREADY_INITIALIZED) {}
|
|
|
|
},
|
2013-08-01 17:00:39 -07:00
|
|
|
};
|
2012-04-17 07:17:23 -07:00
|
|
|
|
2012-04-18 15:17:54 -07:00
|
|
|
#ifdef XP_WIN
|
2013-10-04 10:00:13 -07:00
|
|
|
|
|
|
|
const PROGS_DIR = OS.Constants.Path.winStartMenuProgsDir;
|
|
|
|
const APP_DATA_DIR = OS.Constants.Path.winAppDataDir;
|
|
|
|
|
2012-04-18 15:17:54 -07:00
|
|
|
/*************************************
|
|
|
|
* Windows app installer
|
|
|
|
*
|
|
|
|
* The Windows installation process will generate the following files:
|
|
|
|
*
|
2013-08-01 17:00:22 -07:00
|
|
|
* ${FolderName} = sanitized app name + "-" + manifest url hash
|
2012-04-18 15:17:54 -07:00
|
|
|
*
|
|
|
|
* %APPDATA%/${FolderName}
|
|
|
|
* - webapp.ini
|
|
|
|
* - webapp.json
|
|
|
|
* - ${AppName}.exe
|
|
|
|
* - ${AppName}.lnk
|
|
|
|
* / uninstall
|
|
|
|
* - webapp-uninstaller.exe
|
2012-04-19 18:47:54 -07:00
|
|
|
* - shortcuts_log.ini
|
|
|
|
* - uninstall.log
|
2012-04-18 15:17:54 -07:00
|
|
|
* / chrome/icons/default/
|
2012-04-19 18:47:54 -07:00
|
|
|
* - default.ico
|
2012-04-18 15:17:54 -07:00
|
|
|
*
|
|
|
|
* After the app runs for the first time, a profiles/ folder will also be
|
|
|
|
* created which will host the user profile for this app.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor for the Windows native app shell
|
|
|
|
*
|
2013-08-01 17:00:39 -07:00
|
|
|
* @param aData the data object provided to the install function
|
2012-04-18 15:17:54 -07:00
|
|
|
*/
|
|
|
|
function WinNativeApp(aData) {
|
|
|
|
NativeApp.call(this, aData);
|
2013-08-26 12:04:50 -07:00
|
|
|
|
|
|
|
if (aData.isPackage) {
|
|
|
|
this.size = aData.app.updateManifest.size / 1024;
|
2013-10-08 05:26:41 -07:00
|
|
|
this.isPackaged = true;
|
2013-08-26 12:04:50 -07:00
|
|
|
}
|
|
|
|
|
2013-10-04 10:00:13 -07:00
|
|
|
let filenameRE = new RegExp("[<>:\"/\\\\|\\?\\*]", "gi");
|
|
|
|
|
|
|
|
this.appNameAsFilename = this.appNameAsFilename.replace(filenameRE, "");
|
|
|
|
if (this.appNameAsFilename == "") {
|
|
|
|
this.appNameAsFilename = "webapp";
|
|
|
|
}
|
|
|
|
|
|
|
|
this.webapprt = this.appNameAsFilename + ".exe";
|
|
|
|
this.configJson = "webapp.json";
|
|
|
|
this.webappINI = "webapp.ini";
|
|
|
|
this.iconPath = OS.Path.join("chrome", "icons", "default", "default.ico");
|
|
|
|
this.uninstallDir = "uninstall";
|
|
|
|
this.uninstallerFile = OS.Path.join(this.uninstallDir,
|
|
|
|
"webapp-uninstaller.exe");
|
|
|
|
this.shortcutLogsINI = OS.Path.join(this.uninstallDir, "shortcuts_log.ini");
|
|
|
|
|
|
|
|
this.uninstallSubkeyStr = this.uniqueName;
|
2012-04-18 15:17:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
WinNativeApp.prototype = {
|
2013-08-01 17:00:39 -07:00
|
|
|
__proto__: NativeApp.prototype,
|
2013-08-26 12:04:50 -07:00
|
|
|
size: null,
|
2013-08-01 17:00:39 -07:00
|
|
|
|
2012-04-18 15:17:54 -07:00
|
|
|
/**
|
2013-08-01 17:00:39 -07:00
|
|
|
* Install the app in the system
|
2012-04-18 15:17:54 -07:00
|
|
|
*
|
|
|
|
*/
|
2013-09-13 05:32:47 -07:00
|
|
|
install: function(aZipPath) {
|
2013-08-26 12:04:33 -07:00
|
|
|
return Task.spawn(function() {
|
2014-01-30 08:10:41 -08:00
|
|
|
yield this._getInstallDir();
|
2013-10-04 10:00:13 -07:00
|
|
|
|
2013-08-26 12:04:33 -07:00
|
|
|
try {
|
2013-10-04 10:00:13 -07:00
|
|
|
yield this._createDirectoryStructure();
|
|
|
|
yield this._copyPrebuiltFiles();
|
2013-08-26 12:04:33 -07:00
|
|
|
this._createConfigFiles();
|
2013-09-13 05:32:47 -07:00
|
|
|
|
|
|
|
if (aZipPath) {
|
2013-10-04 10:00:13 -07:00
|
|
|
yield OS.File.move(aZipPath, OS.Path.join(this.tmpInstallDir,
|
2013-09-13 05:32:47 -07:00
|
|
|
"application.zip"));
|
|
|
|
}
|
|
|
|
|
2013-08-26 12:04:33 -07:00
|
|
|
yield this.getIcon();
|
2013-10-04 10:00:13 -07:00
|
|
|
|
|
|
|
// Remove previously installed app
|
|
|
|
this._removeInstallation(true);
|
|
|
|
} catch (ex) {
|
|
|
|
removeFiles([this.tmpInstallDir]);
|
|
|
|
throw(ex);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
// On Windows, the webapprt executable can't be overwritten while it's
|
|
|
|
// running.
|
|
|
|
// As it takes care of updating itself, there's no need to update
|
|
|
|
// it here.
|
|
|
|
let filesToIgnore = [ this.webapprt ];
|
|
|
|
yield moveDirectory(this.tmpInstallDir, this.installDir, filesToIgnore);
|
|
|
|
|
|
|
|
this._createShortcutFiles();
|
|
|
|
this._writeSystemKeys();
|
2013-08-26 12:04:33 -07:00
|
|
|
} catch (ex) {
|
|
|
|
this._removeInstallation(false);
|
|
|
|
throw(ex);
|
|
|
|
}
|
|
|
|
}.bind(this));
|
2012-04-18 15:17:54 -07:00
|
|
|
},
|
|
|
|
|
2013-10-04 10:00:13 -07:00
|
|
|
_getInstallDir: function() {
|
2013-08-01 17:00:22 -07:00
|
|
|
// The ${InstallDir} is: sanitized app name + "-" + manifest url hash
|
2013-10-04 10:00:13 -07:00
|
|
|
this.installDir = WebappOSUtils.getInstallPath(this.app);
|
|
|
|
if (this.installDir) {
|
|
|
|
if (this.uniqueName != OS.Path.basename(this.installDir)) {
|
|
|
|
// Bug 919799: If the app is still in the registry, migrate its data to
|
|
|
|
// the new format.
|
|
|
|
throw("Updates for apps installed with the old naming scheme unsupported");
|
|
|
|
}
|
2013-08-06 07:04:17 -07:00
|
|
|
|
2013-10-04 10:00:13 -07:00
|
|
|
let shortcutLogsINIfile = getFile(this.installDir, this.shortcutLogsINI);
|
2013-08-06 07:04:17 -07:00
|
|
|
// If it's a reinstallation (or an update) get the shortcut names
|
|
|
|
// from the shortcut_log.ini file
|
2013-10-04 10:00:13 -07:00
|
|
|
let parser = Cc["@mozilla.org/xpcom/ini-processor-factory;1"]
|
|
|
|
.getService(Ci.nsIINIParserFactory)
|
|
|
|
.createINIParser(shortcutLogsINIfile);
|
2013-08-06 07:04:17 -07:00
|
|
|
this.shortcutName = parser.getString("STARTMENU", "Shortcut0");
|
|
|
|
} else {
|
2013-10-04 10:00:13 -07:00
|
|
|
this.installDir = OS.Path.join(APP_DATA_DIR, this.uniqueName);
|
2013-08-06 07:04:17 -07:00
|
|
|
|
|
|
|
// Check in both directories to see if a shortcut with the same name
|
|
|
|
// already exists.
|
2014-01-30 08:10:41 -08:00
|
|
|
this.shortcutName = yield getAvailableFileName([ PROGS_DIR, DESKTOP_DIR ],
|
|
|
|
this.appNameAsFilename,
|
|
|
|
".lnk");
|
2013-08-06 07:04:17 -07:00
|
|
|
}
|
2012-04-18 15:17:54 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the current installation
|
|
|
|
*/
|
2013-10-04 10:00:13 -07:00
|
|
|
_removeInstallation: function(keepProfile) {
|
2012-04-18 15:17:54 -07:00
|
|
|
let uninstallKey;
|
|
|
|
try {
|
|
|
|
uninstallKey = Cc["@mozilla.org/windows-registry-key;1"]
|
|
|
|
.createInstance(Ci.nsIWindowsRegKey);
|
|
|
|
uninstallKey.open(uninstallKey.ROOT_KEY_CURRENT_USER,
|
|
|
|
"SOFTWARE\\Microsoft\\Windows\\" +
|
|
|
|
"CurrentVersion\\Uninstall",
|
|
|
|
uninstallKey.ACCESS_WRITE);
|
|
|
|
if(uninstallKey.hasChild(this.uninstallSubkeyStr)) {
|
|
|
|
uninstallKey.removeChild(this.uninstallSubkeyStr);
|
|
|
|
}
|
2012-04-26 07:34:39 -07:00
|
|
|
} catch (e) {
|
2012-04-18 15:17:54 -07:00
|
|
|
} finally {
|
|
|
|
if(uninstallKey)
|
|
|
|
uninstallKey.close();
|
|
|
|
}
|
|
|
|
|
2013-10-04 10:00:13 -07:00
|
|
|
let filesToRemove = [ OS.Path.join(DESKTOP_DIR, this.shortcutName),
|
|
|
|
OS.Path.join(PROGS_DIR, this.shortcutName) ];
|
2012-06-27 17:14:55 -07:00
|
|
|
|
|
|
|
if (keepProfile) {
|
2013-10-04 10:00:13 -07:00
|
|
|
[ this.iconPath, this.webapprt, this.configJson,
|
|
|
|
this.webappINI, this.uninstallDir ].forEach((filePath) => {
|
|
|
|
filesToRemove.push(OS.Path.join(this.installDir, filePath));
|
|
|
|
});
|
2012-06-27 17:14:55 -07:00
|
|
|
} else {
|
|
|
|
filesToRemove.push(this.installDir);
|
2013-10-04 10:00:13 -07:00
|
|
|
filesToRemove.push(this.tmpInstallDir);
|
2012-04-18 15:17:54 -07:00
|
|
|
}
|
2012-06-27 17:14:55 -07:00
|
|
|
|
|
|
|
removeFiles(filesToRemove);
|
2012-04-18 15:17:54 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates the main directory structure.
|
|
|
|
*/
|
|
|
|
_createDirectoryStructure: function() {
|
2013-10-04 10:00:13 -07:00
|
|
|
let dir = getFile(TMP_DIR, this.uniqueName);
|
|
|
|
dir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, PERMS_DIRECTORY);
|
|
|
|
this.tmpInstallDir = dir.path;
|
|
|
|
|
|
|
|
yield OS.File.makeDir(OS.Path.join(this.tmpInstallDir, this.uninstallDir),
|
|
|
|
{ ignoreExisting: true });
|
|
|
|
|
|
|
|
// Recursively create the icon path's directory structure.
|
|
|
|
let path = this.tmpInstallDir;
|
|
|
|
let components = OS.Path.split(OS.Path.dirname(this.iconPath)).components;
|
|
|
|
for (let component of components) {
|
|
|
|
path = OS.Path.join(path, component);
|
|
|
|
yield OS.File.makeDir(path, { ignoreExisting: true });
|
2013-08-01 17:00:39 -07:00
|
|
|
}
|
2012-04-18 15:17:54 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy the pre-built files into their destination folders.
|
|
|
|
*/
|
|
|
|
_copyPrebuiltFiles: function() {
|
2013-10-04 10:00:13 -07:00
|
|
|
yield OS.File.copy(OS.Path.join(this.runtimeFolder, "webapprt-stub.exe"),
|
|
|
|
OS.Path.join(this.tmpInstallDir, this.webapprt));
|
2012-04-18 15:17:54 -07:00
|
|
|
|
2013-10-04 10:00:13 -07:00
|
|
|
yield OS.File.copy(OS.Path.join(this.runtimeFolder, "webapp-uninstaller.exe"),
|
|
|
|
OS.Path.join(this.tmpInstallDir, this.uninstallerFile));
|
2012-04-18 15:17:54 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates the configuration files into their destination folders.
|
|
|
|
*/
|
|
|
|
_createConfigFiles: function() {
|
|
|
|
// ${InstallDir}/webapp.json
|
2013-10-04 10:00:13 -07:00
|
|
|
writeToFile(OS.Path.join(this.tmpInstallDir, this.configJson),
|
|
|
|
JSON.stringify(this.webappJson));
|
2012-04-18 15:17:54 -07:00
|
|
|
|
|
|
|
let factory = Cc["@mozilla.org/xpcom/ini-processor-factory;1"]
|
|
|
|
.getService(Ci.nsIINIParserFactory);
|
|
|
|
|
2012-06-27 17:14:55 -07:00
|
|
|
// ${InstallDir}/webapp.ini
|
2013-10-04 10:00:13 -07:00
|
|
|
let webappINIfile = getFile(this.tmpInstallDir, this.webappINI);
|
|
|
|
|
|
|
|
let writer = factory.createINIParser(webappINIfile)
|
|
|
|
.QueryInterface(Ci.nsIINIParserWriter);
|
2012-04-18 15:17:54 -07:00
|
|
|
writer.setString("Webapp", "Name", this.appName);
|
2013-10-04 10:00:13 -07:00
|
|
|
writer.setString("Webapp", "Profile", OS.Path.basename(this.installDir));
|
2012-04-19 18:47:54 -07:00
|
|
|
writer.setString("Webapp", "Executable", this.appNameAsFilename);
|
2013-10-04 10:00:13 -07:00
|
|
|
writer.setString("WebappRT", "InstallDir", this.runtimeFolder);
|
2012-05-23 10:09:11 -07:00
|
|
|
writer.writeFile(null, Ci.nsIINIParserWriter.WRITE_UTF16);
|
2012-04-18 15:17:54 -07:00
|
|
|
|
2013-10-04 10:00:13 -07:00
|
|
|
let shortcutLogsINIfile = getFile(this.tmpInstallDir, this.shortcutLogsINI);
|
|
|
|
|
|
|
|
writer = factory.createINIParser(shortcutLogsINIfile)
|
|
|
|
.QueryInterface(Ci.nsIINIParserWriter);
|
2013-08-06 07:04:17 -07:00
|
|
|
writer.setString("STARTMENU", "Shortcut0", this.shortcutName);
|
|
|
|
writer.setString("DESKTOP", "Shortcut0", this.shortcutName);
|
2012-04-18 15:17:54 -07:00
|
|
|
writer.setString("TASKBAR", "Migrated", "true");
|
2012-05-23 10:09:11 -07:00
|
|
|
writer.writeFile(null, Ci.nsIINIParserWriter.WRITE_UTF16);
|
2012-04-18 15:17:54 -07:00
|
|
|
|
|
|
|
// ${UninstallDir}/uninstall.log
|
|
|
|
let uninstallContent =
|
|
|
|
"File: \\webapp.ini\r\n" +
|
|
|
|
"File: \\webapp.json\r\n" +
|
|
|
|
"File: \\webapprt.old\r\n" +
|
2012-04-19 18:47:54 -07:00
|
|
|
"File: \\chrome\\icons\\default\\default.ico";
|
2013-10-08 05:26:41 -07:00
|
|
|
if (this.isPackaged) {
|
|
|
|
uninstallContent += "\r\nFile: \\application.zip";
|
|
|
|
}
|
2013-10-04 10:00:13 -07:00
|
|
|
|
|
|
|
writeToFile(OS.Path.join(this.tmpInstallDir, this.uninstallDir,
|
|
|
|
"uninstall.log"),
|
|
|
|
uninstallContent);
|
2012-04-18 15:17:54 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Writes the keys to the system registry that are necessary for the app operation
|
|
|
|
* and uninstall process.
|
|
|
|
*/
|
|
|
|
_writeSystemKeys: function() {
|
|
|
|
let parentKey;
|
|
|
|
let uninstallKey;
|
|
|
|
let subKey;
|
|
|
|
|
|
|
|
try {
|
|
|
|
parentKey = Cc["@mozilla.org/windows-registry-key;1"]
|
|
|
|
.createInstance(Ci.nsIWindowsRegKey);
|
|
|
|
parentKey.open(parentKey.ROOT_KEY_CURRENT_USER,
|
|
|
|
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion",
|
|
|
|
parentKey.ACCESS_WRITE);
|
|
|
|
uninstallKey = parentKey.createChild("Uninstall", parentKey.ACCESS_WRITE)
|
|
|
|
subKey = uninstallKey.createChild(this.uninstallSubkeyStr, uninstallKey.ACCESS_WRITE);
|
|
|
|
|
|
|
|
subKey.writeStringValue("DisplayName", this.appName);
|
|
|
|
|
2013-10-04 10:00:13 -07:00
|
|
|
let uninstallerPath = OS.Path.join(this.installDir,
|
|
|
|
this.uninstallerFile);
|
2012-04-18 15:17:54 -07:00
|
|
|
|
2013-10-04 10:00:13 -07:00
|
|
|
subKey.writeStringValue("UninstallString", '"' + uninstallerPath + '"');
|
|
|
|
subKey.writeStringValue("InstallLocation", '"' + this.installDir + '"');
|
|
|
|
subKey.writeStringValue("AppFilename", this.appNameAsFilename);
|
|
|
|
subKey.writeStringValue("DisplayIcon", OS.Path.join(this.installDir,
|
|
|
|
this.iconPath));
|
2012-04-18 15:17:54 -07:00
|
|
|
|
2013-08-26 12:04:50 -07:00
|
|
|
let date = new Date();
|
|
|
|
let year = date.getYear().toString();
|
|
|
|
let month = date.getMonth();
|
|
|
|
if (month < 10) {
|
|
|
|
month = "0" + month;
|
|
|
|
}
|
|
|
|
let day = date.getDate();
|
|
|
|
if (day < 10) {
|
|
|
|
day = "0" + day;
|
|
|
|
}
|
|
|
|
subKey.writeStringValue("InstallDate", year + month + day);
|
|
|
|
if (this.manifest.version) {
|
|
|
|
subKey.writeStringValue("DisplayVersion", this.manifest.version);
|
|
|
|
}
|
|
|
|
if (this.developerName) {
|
|
|
|
subKey.writeStringValue("Publisher", this.developerName);
|
|
|
|
}
|
|
|
|
subKey.writeStringValue("URLInfoAbout", this.developerUrl);
|
|
|
|
if (this.size) {
|
|
|
|
subKey.writeIntValue("EstimatedSize", this.size);
|
|
|
|
}
|
|
|
|
|
2012-04-18 15:17:54 -07:00
|
|
|
subKey.writeIntValue("NoModify", 1);
|
|
|
|
subKey.writeIntValue("NoRepair", 1);
|
|
|
|
} catch(ex) {
|
|
|
|
throw(ex);
|
|
|
|
} finally {
|
|
|
|
if(subKey) subKey.close();
|
|
|
|
if(uninstallKey) uninstallKey.close();
|
|
|
|
if(parentKey) parentKey.close();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a shortcut file inside the app installation folder and makes
|
|
|
|
* two copies of it: one into the desktop and one into the start menu.
|
|
|
|
*/
|
|
|
|
_createShortcutFiles: function() {
|
2013-10-04 10:00:13 -07:00
|
|
|
let shortcut = getFile(this.installDir, this.shortcutName).
|
|
|
|
QueryInterface(Ci.nsILocalFileWin);
|
2012-04-18 15:17:54 -07:00
|
|
|
|
|
|
|
/* function nsILocalFileWin.setShortcut(targetFile, workingDir, args,
|
|
|
|
description, iconFile, iconIndex) */
|
|
|
|
|
2013-10-04 10:00:13 -07:00
|
|
|
shortcut.setShortcut(getFile(this.installDir, this.webapprt),
|
|
|
|
getFile(this.installDir),
|
|
|
|
null,
|
|
|
|
this.shortDescription,
|
|
|
|
getFile(this.installDir, this.iconPath),
|
|
|
|
0);
|
2012-04-18 15:17:54 -07:00
|
|
|
|
2013-10-04 10:00:13 -07:00
|
|
|
shortcut.copyTo(getFile(DESKTOP_DIR), this.shortcutName);
|
|
|
|
shortcut.copyTo(getFile(PROGS_DIR), this.shortcutName);
|
2012-04-19 18:47:54 -07:00
|
|
|
|
|
|
|
shortcut.followLinks = false;
|
|
|
|
shortcut.remove(false);
|
2012-04-18 15:17:54 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process the icon from the imageStream as retrieved from
|
|
|
|
* the URL by getIconForApp(). This will save the icon to the
|
|
|
|
* topwindow.ico file.
|
|
|
|
*
|
|
|
|
* @param aMimeType ahe icon mimetype
|
|
|
|
* @param aImageStream the stream for the image data
|
|
|
|
*/
|
2013-08-26 12:04:33 -07:00
|
|
|
processIcon: function(aMimeType, aImageStream) {
|
|
|
|
let deferred = Promise.defer();
|
2013-08-26 07:31:49 -07:00
|
|
|
|
2013-08-26 12:04:33 -07:00
|
|
|
let imgTools = Cc["@mozilla.org/image/tools;1"]
|
|
|
|
.createInstance(Ci.imgITools);
|
|
|
|
|
|
|
|
let imgContainer = imgTools.decodeImage(aImageStream, aMimeType);
|
|
|
|
let iconStream = imgTools.encodeImage(imgContainer,
|
|
|
|
"image/vnd.microsoft.icon",
|
|
|
|
"format=bmp;bpp=32");
|
|
|
|
|
2013-10-04 10:00:13 -07:00
|
|
|
let tmpIconFile = getFile(this.tmpInstallDir, this.iconPath);
|
|
|
|
|
|
|
|
let outputStream = FileUtils.openSafeFileOutputStream(tmpIconFile);
|
2013-08-26 12:04:33 -07:00
|
|
|
NetUtil.asyncCopy(iconStream, outputStream, function(aResult) {
|
|
|
|
if (Components.isSuccessCode(aResult)) {
|
|
|
|
deferred.resolve();
|
|
|
|
} else {
|
|
|
|
deferred.reject("Failure copying icon: " + aResult);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return deferred.promise;
|
2012-04-18 15:17:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#elifdef XP_MACOSX
|
2012-04-17 07:17:23 -07:00
|
|
|
|
2013-10-04 10:00:13 -07:00
|
|
|
const USER_LIB_DIR = OS.Constants.Path.macUserLibDir;
|
|
|
|
const LOCAL_APP_DIR = OS.Constants.Path.macLocalApplicationsDir;
|
|
|
|
|
2012-04-17 07:17:23 -07:00
|
|
|
function MacNativeApp(aData) {
|
|
|
|
NativeApp.call(this, aData);
|
|
|
|
|
2013-10-04 10:00:13 -07:00
|
|
|
let filenameRE = new RegExp("[<>:\"/\\\\|\\?\\*]", "gi");
|
|
|
|
this.appNameAsFilename = this.appNameAsFilename.replace(filenameRE, "");
|
|
|
|
if (this.appNameAsFilename == "") {
|
|
|
|
this.appNameAsFilename = "Webapp";
|
|
|
|
}
|
2012-04-17 07:17:23 -07:00
|
|
|
|
2013-10-04 10:00:13 -07:00
|
|
|
// The ${ProfileDir} is: sanitized app name + "-" + manifest url hash
|
|
|
|
this.appProfileDir = OS.Path.join(USER_LIB_DIR, "Application Support",
|
|
|
|
this.uniqueName);
|
2013-08-01 17:00:39 -07:00
|
|
|
|
2013-10-04 10:00:13 -07:00
|
|
|
this.contentsDir = "Contents";
|
|
|
|
this.macOSDir = OS.Path.join(this.contentsDir, "MacOS");
|
|
|
|
this.resourcesDir = OS.Path.join(this.contentsDir, "Resources");
|
|
|
|
this.iconFile = OS.Path.join(this.resourcesDir, "appicon.icns");
|
|
|
|
}
|
2013-08-01 17:00:39 -07:00
|
|
|
|
2013-10-04 10:00:13 -07:00
|
|
|
MacNativeApp.prototype = {
|
|
|
|
__proto__: NativeApp.prototype,
|
2012-04-17 07:17:23 -07:00
|
|
|
|
2013-09-13 05:32:47 -07:00
|
|
|
install: function(aZipPath) {
|
2013-08-26 12:04:33 -07:00
|
|
|
return Task.spawn(function() {
|
2014-01-30 08:10:41 -08:00
|
|
|
yield this._getInstallDir();
|
2013-10-04 10:00:13 -07:00
|
|
|
|
2013-08-26 12:04:33 -07:00
|
|
|
try {
|
2013-10-04 10:00:13 -07:00
|
|
|
yield this._createDirectoryStructure();
|
2013-08-26 12:04:33 -07:00
|
|
|
this._copyPrebuiltFiles();
|
|
|
|
this._createConfigFiles();
|
2013-09-13 05:32:47 -07:00
|
|
|
|
|
|
|
if (aZipPath) {
|
2013-10-04 10:00:13 -07:00
|
|
|
yield OS.File.move(aZipPath, OS.Path.join(this.tmpInstallDir,
|
2013-09-13 05:32:47 -07:00
|
|
|
"application.zip"));
|
|
|
|
}
|
|
|
|
|
2013-08-26 12:04:33 -07:00
|
|
|
yield this.getIcon();
|
2013-10-04 10:00:13 -07:00
|
|
|
|
|
|
|
// Remove previously installed app
|
|
|
|
this._removeInstallation(true);
|
|
|
|
} catch (ex) {
|
|
|
|
removeFiles([this.tmpInstallDir]);
|
|
|
|
throw(ex);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
// Move the temp installation directory to the /Applications directory
|
|
|
|
yield moveDirectory(this.tmpInstallDir, this.installDir, []);
|
2013-08-26 12:04:33 -07:00
|
|
|
} catch (ex) {
|
|
|
|
this._removeInstallation(false);
|
|
|
|
throw(ex);
|
|
|
|
}
|
|
|
|
}.bind(this));
|
2012-04-17 07:17:23 -07:00
|
|
|
},
|
|
|
|
|
2013-10-04 10:00:13 -07:00
|
|
|
_getInstallDir: function() {
|
|
|
|
let [ oldUniqueName, installPath ] = WebappOSUtils.getLaunchTarget(this.app);
|
|
|
|
if (installPath) {
|
|
|
|
this.installDir = installPath;
|
|
|
|
|
|
|
|
if (this.uniqueName != oldUniqueName) {
|
|
|
|
// Bug 919799: If the app is still in the registry, migrate its data to
|
|
|
|
// the new format.
|
|
|
|
throw("Updates for apps installed with the old naming scheme unsupported");
|
|
|
|
}
|
|
|
|
} else {
|
2014-01-30 08:10:41 -08:00
|
|
|
let localAppDir = getFile(LOCAL_APP_DIR);
|
|
|
|
if (!localAppDir.isWritable()) {
|
|
|
|
throw("Not enough privileges to install apps");
|
2013-10-04 10:00:13 -07:00
|
|
|
}
|
|
|
|
|
2014-01-30 08:10:41 -08:00
|
|
|
let destinationName = yield getAvailableFileName([ LOCAL_APP_DIR ],
|
|
|
|
this.appNameAsFilename,
|
|
|
|
".app");
|
|
|
|
|
2013-10-04 10:00:13 -07:00
|
|
|
this.installDir = OS.Path.join(LOCAL_APP_DIR, destinationName);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-04-17 07:17:23 -07:00
|
|
|
_removeInstallation: function(keepProfile) {
|
2012-06-27 17:14:55 -07:00
|
|
|
let filesToRemove = [this.installDir];
|
2012-04-17 07:17:23 -07:00
|
|
|
|
2012-06-27 17:14:55 -07:00
|
|
|
if (!keepProfile) {
|
|
|
|
filesToRemove.push(this.appProfileDir);
|
2012-04-17 07:17:23 -07:00
|
|
|
}
|
2012-06-27 17:14:55 -07:00
|
|
|
|
|
|
|
removeFiles(filesToRemove);
|
2012-04-17 07:17:23 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_createDirectoryStructure: function() {
|
2013-10-04 10:00:13 -07:00
|
|
|
let dir = getFile(TMP_DIR, this.appNameAsFilename + ".app");
|
|
|
|
dir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, PERMS_DIRECTORY);
|
|
|
|
this.tmpInstallDir = dir.path;
|
|
|
|
|
|
|
|
yield OS.File.makeDir(this.appProfileDir,
|
|
|
|
{ unixMode: PERMS_DIRECTORY, ignoreExisting: true });
|
|
|
|
|
|
|
|
yield OS.File.makeDir(OS.Path.join(this.tmpInstallDir, this.contentsDir),
|
|
|
|
{ unixMode: PERMS_DIRECTORY, ignoreExisting: true });
|
|
|
|
|
|
|
|
yield OS.File.makeDir(OS.Path.join(this.tmpInstallDir, this.macOSDir),
|
|
|
|
{ unixMode: PERMS_DIRECTORY, ignoreExisting: true });
|
2012-04-17 07:17:23 -07:00
|
|
|
|
2013-10-04 10:00:13 -07:00
|
|
|
yield OS.File.makeDir(OS.Path.join(this.tmpInstallDir, this.resourcesDir),
|
|
|
|
{ unixMode: PERMS_DIRECTORY, ignoreExisting: true });
|
2012-04-17 07:17:23 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_copyPrebuiltFiles: function() {
|
2013-10-04 10:00:13 -07:00
|
|
|
let destDir = getFile(this.tmpInstallDir, this.macOSDir);
|
|
|
|
let stub = getFile(this.runtimeFolder, "webapprt-stub");
|
|
|
|
stub.copyTo(destDir, "webapprt");
|
2012-04-17 07:17:23 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_createConfigFiles: function() {
|
2012-04-20 15:56:02 -07:00
|
|
|
// ${ProfileDir}/webapp.json
|
2013-10-04 10:00:13 -07:00
|
|
|
writeToFile(OS.Path.join(this.appProfileDir, "webapp.json"),
|
|
|
|
JSON.stringify(this.webappJson));
|
2012-04-17 07:17:23 -07:00
|
|
|
|
|
|
|
// ${InstallDir}/Contents/MacOS/webapp.ini
|
2013-10-04 10:00:13 -07:00
|
|
|
let applicationINI = getFile(this.tmpInstallDir, this.macOSDir, "webapp.ini");
|
2012-04-17 07:17:23 -07:00
|
|
|
|
2013-10-04 10:00:13 -07:00
|
|
|
let writer = Cc["@mozilla.org/xpcom/ini-processor-factory;1"]
|
|
|
|
.getService(Ci.nsIINIParserFactory)
|
|
|
|
.createINIParser(applicationINI)
|
|
|
|
.QueryInterface(Ci.nsIINIParserWriter);
|
2012-04-17 07:17:23 -07:00
|
|
|
writer.setString("Webapp", "Name", this.appName);
|
2013-10-04 10:00:13 -07:00
|
|
|
writer.setString("Webapp", "Profile", OS.Path.basename(this.appProfileDir));
|
2012-04-17 07:17:23 -07:00
|
|
|
writer.writeFile();
|
2013-10-04 10:00:13 -07:00
|
|
|
applicationINI.permissions = PERMS_FILE;
|
2012-04-17 07:17:23 -07:00
|
|
|
|
2012-04-22 14:30:03 -07:00
|
|
|
// ${InstallDir}/Contents/Info.plist
|
2012-04-17 07:17:23 -07:00
|
|
|
let infoPListContent = '<?xml version="1.0" encoding="UTF-8"?>\n\
|
|
|
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n\
|
|
|
|
<plist version="1.0">\n\
|
|
|
|
<dict>\n\
|
|
|
|
<key>CFBundleDevelopmentRegion</key>\n\
|
|
|
|
<string>English</string>\n\
|
|
|
|
<key>CFBundleDisplayName</key>\n\
|
|
|
|
<string>' + escapeXML(this.appName) + '</string>\n\
|
|
|
|
<key>CFBundleExecutable</key>\n\
|
|
|
|
<string>webapprt</string>\n\
|
|
|
|
<key>CFBundleIconFile</key>\n\
|
|
|
|
<string>appicon</string>\n\
|
|
|
|
<key>CFBundleIdentifier</key>\n\
|
2013-08-01 17:00:22 -07:00
|
|
|
<string>' + escapeXML(this.uniqueName) + '</string>\n\
|
2012-04-17 07:17:23 -07:00
|
|
|
<key>CFBundleInfoDictionaryVersion</key>\n\
|
|
|
|
<string>6.0</string>\n\
|
|
|
|
<key>CFBundleName</key>\n\
|
|
|
|
<string>' + escapeXML(this.appName) + '</string>\n\
|
|
|
|
<key>CFBundlePackageType</key>\n\
|
|
|
|
<string>APPL</string>\n\
|
|
|
|
<key>CFBundleVersion</key>\n\
|
|
|
|
<string>0</string>\n\
|
2013-07-31 10:03:04 -07:00
|
|
|
<key>NSHighResolutionCapable</key>\n\
|
|
|
|
<true/>\n\
|
|
|
|
<key>NSPrincipalClass</key>\n\
|
|
|
|
<string>GeckoNSApplication</string>\n\
|
2012-04-17 07:17:23 -07:00
|
|
|
<key>FirefoxBinary</key>\n\
|
2012-04-29 13:00:12 -07:00
|
|
|
#expand <string>__MOZ_MACBUNDLE_ID__</string>\n\
|
2012-04-17 07:17:23 -07:00
|
|
|
</dict>\n\
|
|
|
|
</plist>';
|
|
|
|
|
2013-10-04 10:00:13 -07:00
|
|
|
writeToFile(OS.Path.join(this.tmpInstallDir, this.contentsDir, "Info.plist"),
|
|
|
|
infoPListContent);
|
2012-04-26 07:37:34 -07:00
|
|
|
},
|
|
|
|
|
2012-04-17 07:17:23 -07:00
|
|
|
/**
|
|
|
|
* Process the icon from the imageStream as retrieved from
|
|
|
|
* the URL by getIconForApp(). This will bundle the icon to the
|
|
|
|
* app package at Contents/Resources/appicon.icns.
|
|
|
|
*
|
|
|
|
* @param aMimeType the icon mimetype
|
|
|
|
* @param aImageStream the stream for the image data
|
|
|
|
*/
|
2013-08-26 12:04:33 -07:00
|
|
|
processIcon: function(aMimeType, aIcon) {
|
|
|
|
let deferred = Promise.defer();
|
|
|
|
|
|
|
|
function conversionDone(aSubject, aTopic) {
|
|
|
|
if (aTopic == "process-finished") {
|
|
|
|
deferred.resolve();
|
|
|
|
} else {
|
|
|
|
deferred.reject("Failure converting icon.");
|
|
|
|
}
|
2012-04-17 07:17:23 -07:00
|
|
|
}
|
2013-08-26 12:04:33 -07:00
|
|
|
|
|
|
|
let process = Cc["@mozilla.org/process/util;1"].
|
|
|
|
createInstance(Ci.nsIProcess);
|
2013-10-04 10:00:13 -07:00
|
|
|
let sipsFile = getFile("/usr/bin/sips");
|
2013-08-26 12:04:33 -07:00
|
|
|
|
|
|
|
process.init(sipsFile);
|
|
|
|
process.runAsync(["-s",
|
|
|
|
"format", "icns",
|
|
|
|
aIcon.path,
|
2013-10-04 10:00:13 -07:00
|
|
|
"--out", OS.Path.join(this.tmpInstallDir, this.iconFile),
|
2013-08-26 12:04:33 -07:00
|
|
|
"-z", "128", "128"],
|
|
|
|
9, conversionDone);
|
|
|
|
|
|
|
|
return deferred.promise;
|
2012-04-17 07:17:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-06-03 18:57:41 -07:00
|
|
|
#elifdef XP_UNIX
|
|
|
|
|
|
|
|
function LinuxNativeApp(aData) {
|
|
|
|
NativeApp.call(this, aData);
|
|
|
|
|
2013-10-04 10:00:13 -07:00
|
|
|
this.iconFile = "icon.png";
|
|
|
|
this.webapprt = "webapprt-stub";
|
|
|
|
this.configJson = "webapp.json";
|
|
|
|
this.webappINI = "webapp.ini";
|
2012-06-03 18:57:41 -07:00
|
|
|
|
2013-10-04 10:00:13 -07:00
|
|
|
let xdg_data_home = Cc["@mozilla.org/process/environment;1"]
|
|
|
|
.getService(Ci.nsIEnvironment)
|
|
|
|
.get("XDG_DATA_HOME");
|
|
|
|
if (!xdg_data_home) {
|
|
|
|
xdg_data_home = OS.Path.join(HOME_DIR, ".local", "share");
|
|
|
|
}
|
2013-08-01 17:00:39 -07:00
|
|
|
|
2013-10-04 10:00:13 -07:00
|
|
|
this.desktopINI = OS.Path.join(xdg_data_home, "applications",
|
|
|
|
"owa-" + this.uniqueName + ".desktop");
|
|
|
|
}
|
2013-08-01 18:51:12 -07:00
|
|
|
|
2013-10-04 10:00:13 -07:00
|
|
|
LinuxNativeApp.prototype = {
|
|
|
|
__proto__: NativeApp.prototype,
|
2013-08-01 17:00:39 -07:00
|
|
|
|
2013-09-13 05:32:47 -07:00
|
|
|
install: function(aZipPath) {
|
2013-08-26 12:04:33 -07:00
|
|
|
return Task.spawn(function() {
|
2013-10-04 10:00:13 -07:00
|
|
|
this._getInstallDir();
|
|
|
|
|
2013-08-26 12:04:33 -07:00
|
|
|
try {
|
2013-10-04 10:00:13 -07:00
|
|
|
this._createDirectoryStructure();
|
2013-08-26 12:04:33 -07:00
|
|
|
this._copyPrebuiltFiles();
|
|
|
|
this._createConfigFiles();
|
2013-09-13 05:32:47 -07:00
|
|
|
|
|
|
|
if (aZipPath) {
|
2013-10-04 10:00:13 -07:00
|
|
|
yield OS.File.move(aZipPath, OS.Path.join(this.tmpInstallDir,
|
2013-09-13 05:32:47 -07:00
|
|
|
"application.zip"));
|
|
|
|
}
|
|
|
|
|
2013-08-26 12:04:33 -07:00
|
|
|
yield this.getIcon();
|
2013-10-04 10:00:13 -07:00
|
|
|
|
|
|
|
// Remove previously installed app
|
|
|
|
this._removeInstallation(true);
|
|
|
|
} catch (ex) {
|
|
|
|
removeFiles([this.tmpInstallDir]);
|
|
|
|
throw(ex);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
yield moveDirectory(this.tmpInstallDir, this.installDir, []);
|
|
|
|
|
|
|
|
this._createSystemFiles();
|
2013-08-26 12:04:33 -07:00
|
|
|
} catch (ex) {
|
|
|
|
this._removeInstallation(false);
|
|
|
|
throw(ex);
|
|
|
|
}
|
|
|
|
}.bind(this));
|
2012-06-03 18:57:41 -07:00
|
|
|
},
|
|
|
|
|
2013-10-04 10:00:13 -07:00
|
|
|
_getInstallDir: function() {
|
|
|
|
// The ${InstallDir} and desktop entry filename are: sanitized app name +
|
|
|
|
// "-" + manifest url hash
|
|
|
|
this.installDir = WebappOSUtils.getInstallPath(this.app);
|
|
|
|
if (this.installDir) {
|
|
|
|
let baseName = OS.Path.basename(this.installDir)
|
|
|
|
let oldUniqueName = baseName.substring(1, baseName.length);
|
|
|
|
if (this.uniqueName != oldUniqueName) {
|
|
|
|
// Bug 919799: If the app is still in the registry, migrate its data to
|
|
|
|
// the new format.
|
|
|
|
throw("Updates for apps installed with the old naming scheme unsupported");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.installDir = OS.Path.join(HOME_DIR, "." + this.uniqueName);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-06-27 17:14:55 -07:00
|
|
|
_removeInstallation: function(keepProfile) {
|
|
|
|
let filesToRemove = [this.desktopINI];
|
|
|
|
|
|
|
|
if (keepProfile) {
|
2013-10-04 10:00:13 -07:00
|
|
|
[ this.iconFile, this.webapprt,
|
|
|
|
this.configJson, this.webappINI ].forEach((filePath) => {
|
|
|
|
filesToRemove.push(OS.Path.join(this.installDir, filePath));
|
|
|
|
});
|
2012-06-27 17:14:55 -07:00
|
|
|
} else {
|
|
|
|
filesToRemove.push(this.installDir);
|
2013-10-04 10:00:13 -07:00
|
|
|
filesToRemove.push(this.tmpInstallDir);
|
2012-06-03 18:57:41 -07:00
|
|
|
}
|
2012-06-27 17:14:55 -07:00
|
|
|
|
|
|
|
removeFiles(filesToRemove);
|
2012-06-03 18:57:41 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_createDirectoryStructure: function() {
|
2013-10-04 10:00:13 -07:00
|
|
|
let dir = getFile(TMP_DIR, this.uniqueName);
|
|
|
|
dir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, PERMS_DIRECTORY);
|
|
|
|
this.tmpInstallDir = dir.path;
|
2012-06-03 18:57:41 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_copyPrebuiltFiles: function() {
|
2013-10-04 10:00:13 -07:00
|
|
|
let destDir = getFile(this.tmpInstallDir);
|
|
|
|
let stub = getFile(this.runtimeFolder, this.webapprt);
|
|
|
|
|
|
|
|
stub.copyTo(destDir, null);
|
2012-06-03 18:57:41 -07:00
|
|
|
},
|
|
|
|
|
2012-08-06 18:23:00 -07:00
|
|
|
/**
|
|
|
|
* Translate marketplace categories to freedesktop.org categories.
|
|
|
|
*
|
|
|
|
* @link http://standards.freedesktop.org/menu-spec/menu-spec-latest.html#category-registry
|
|
|
|
*
|
|
|
|
* @return an array of categories
|
|
|
|
*/
|
|
|
|
_translateCategories: function() {
|
|
|
|
let translations = {
|
2013-07-03 16:14:34 -07:00
|
|
|
"books": "Education;Literature",
|
2012-08-06 18:23:00 -07:00
|
|
|
"business": "Finance",
|
|
|
|
"education": "Education",
|
2013-07-03 16:14:34 -07:00
|
|
|
"entertainment": "Amusement",
|
|
|
|
"sports": "Sports",
|
2012-08-06 18:23:00 -07:00
|
|
|
"games": "Game",
|
|
|
|
"health-fitness": "MedicalSoftware",
|
|
|
|
"lifestyle": "Amusement",
|
|
|
|
"music": "Audio;Music",
|
|
|
|
"news-weather": "News",
|
2013-07-03 16:14:34 -07:00
|
|
|
"photo-video": "Video;AudioVideo;Photography",
|
2012-08-06 18:23:00 -07:00
|
|
|
"productivity": "Office",
|
|
|
|
"shopping": "Amusement",
|
|
|
|
"social": "Chat",
|
|
|
|
"travel": "Amusement",
|
2013-07-03 16:14:34 -07:00
|
|
|
"reference": "Science;Education;Documentation",
|
|
|
|
"maps-navigation": "Maps",
|
2012-08-06 18:23:00 -07:00
|
|
|
"utilities": "Utility"
|
|
|
|
};
|
|
|
|
|
|
|
|
// The trailing semicolon is needed as written in the freedesktop specification
|
|
|
|
let categories = "";
|
2013-08-01 17:00:39 -07:00
|
|
|
for (let category of this.categories) {
|
2012-10-06 19:04:36 -07:00
|
|
|
let catLower = category.toLowerCase();
|
|
|
|
if (catLower in translations) {
|
|
|
|
categories += translations[catLower] + ";";
|
|
|
|
}
|
2012-08-06 18:23:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return categories;
|
|
|
|
},
|
|
|
|
|
2012-06-03 18:57:41 -07:00
|
|
|
_createConfigFiles: function() {
|
|
|
|
// ${InstallDir}/webapp.json
|
2013-10-04 10:00:13 -07:00
|
|
|
writeToFile(OS.Path.join(this.tmpInstallDir, this.configJson),
|
|
|
|
JSON.stringify(this.webappJson));
|
2012-06-03 18:57:41 -07:00
|
|
|
|
2012-08-27 19:54:22 -07:00
|
|
|
let webappsBundle = Services.strings.createBundle("chrome://global/locale/webapps.properties");
|
2012-08-18 05:25:48 -07:00
|
|
|
|
2012-06-27 17:14:55 -07:00
|
|
|
// ${InstallDir}/webapp.ini
|
2013-10-04 10:00:13 -07:00
|
|
|
let webappINIfile = getFile(this.tmpInstallDir, this.webappINI);
|
|
|
|
|
|
|
|
let writer = Cc["@mozilla.org/xpcom/ini-processor-factory;1"]
|
|
|
|
.getService(Ci.nsIINIParserFactory)
|
|
|
|
.createINIParser(webappINIfile)
|
|
|
|
.QueryInterface(Ci.nsIINIParserWriter);
|
2012-06-03 18:57:41 -07:00
|
|
|
writer.setString("Webapp", "Name", this.appName);
|
|
|
|
writer.setString("Webapp", "Profile", this.uniqueName);
|
2012-08-27 19:54:22 -07:00
|
|
|
writer.setString("Webapp", "UninstallMsg", webappsBundle.formatStringFromName("uninstall.notification", [this.appName], 1));
|
2013-10-04 10:00:13 -07:00
|
|
|
writer.setString("WebappRT", "InstallDir", this.runtimeFolder);
|
2012-06-03 18:57:41 -07:00
|
|
|
writer.writeFile();
|
2013-10-04 10:00:13 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_createSystemFiles: function() {
|
|
|
|
let webappsBundle = Services.strings.createBundle("chrome://global/locale/webapps.properties");
|
|
|
|
|
|
|
|
let webapprtPath = OS.Path.join(this.installDir, this.webapprt);
|
2012-06-03 18:57:41 -07:00
|
|
|
|
|
|
|
// $XDG_DATA_HOME/applications/owa-<webappuniquename>.desktop
|
2013-10-04 10:00:13 -07:00
|
|
|
let desktopINIfile = getFile(this.desktopINI);
|
2012-06-03 18:57:41 -07:00
|
|
|
|
2013-10-04 10:00:13 -07:00
|
|
|
let writer = Cc["@mozilla.org/xpcom/ini-processor-factory;1"]
|
|
|
|
.getService(Ci.nsIINIParserFactory)
|
|
|
|
.createINIParser(desktopINIfile)
|
|
|
|
.QueryInterface(Ci.nsIINIParserWriter);
|
2012-06-03 18:57:41 -07:00
|
|
|
writer.setString("Desktop Entry", "Name", this.appName);
|
|
|
|
writer.setString("Desktop Entry", "Comment", this.shortDescription);
|
2013-10-04 10:00:13 -07:00
|
|
|
writer.setString("Desktop Entry", "Exec", '"' + webapprtPath + '"');
|
|
|
|
writer.setString("Desktop Entry", "Icon", OS.Path.join(this.installDir,
|
|
|
|
this.iconFile));
|
2012-06-03 18:57:41 -07:00
|
|
|
writer.setString("Desktop Entry", "Type", "Application");
|
|
|
|
writer.setString("Desktop Entry", "Terminal", "false");
|
2012-08-06 18:23:00 -07:00
|
|
|
|
|
|
|
let categories = this._translateCategories();
|
|
|
|
if (categories)
|
|
|
|
writer.setString("Desktop Entry", "Categories", categories);
|
|
|
|
|
2012-08-18 05:25:48 -07:00
|
|
|
writer.setString("Desktop Entry", "Actions", "Uninstall;");
|
2012-08-27 19:54:22 -07:00
|
|
|
writer.setString("Desktop Action Uninstall", "Name", webappsBundle.GetStringFromName("uninstall.label"));
|
2013-10-04 10:00:13 -07:00
|
|
|
writer.setString("Desktop Action Uninstall", "Exec", webapprtPath + " -remove");
|
2012-08-18 05:25:48 -07:00
|
|
|
|
2012-06-03 18:57:41 -07:00
|
|
|
writer.writeFile();
|
2013-10-04 10:00:13 -07:00
|
|
|
|
|
|
|
desktopINIfile.permissions = PERMS_FILE | OS.Constants.libc.S_IXUSR;
|
2012-06-03 18:57:41 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process the icon from the imageStream as retrieved from
|
|
|
|
* the URL by getIconForApp().
|
|
|
|
*
|
|
|
|
* @param aMimeType ahe icon mimetype
|
|
|
|
* @param aImageStream the stream for the image data
|
|
|
|
*/
|
2013-08-26 12:04:33 -07:00
|
|
|
processIcon: function(aMimeType, aImageStream) {
|
|
|
|
let deferred = Promise.defer();
|
2013-08-26 07:31:49 -07:00
|
|
|
|
2013-08-26 12:04:33 -07:00
|
|
|
let imgTools = Cc["@mozilla.org/image/tools;1"]
|
|
|
|
.createInstance(Ci.imgITools);
|
|
|
|
|
|
|
|
let imgContainer = imgTools.decodeImage(aImageStream, aMimeType);
|
|
|
|
let iconStream = imgTools.encodeImage(imgContainer, "image/png");
|
2012-06-03 18:57:41 -07:00
|
|
|
|
2013-10-04 10:00:13 -07:00
|
|
|
let iconFile = getFile(this.tmpInstallDir, this.iconFile);
|
|
|
|
let outputStream = FileUtils.openSafeFileOutputStream(iconFile);
|
2013-08-26 12:04:33 -07:00
|
|
|
NetUtil.asyncCopy(iconStream, outputStream, function(aResult) {
|
|
|
|
if (Components.isSuccessCode(aResult)) {
|
|
|
|
deferred.resolve();
|
|
|
|
} else {
|
|
|
|
deferred.reject("Failure copying icon: " + aResult);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return deferred.promise;
|
2012-06-03 18:57:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-17 07:17:23 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Helper Functions */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Async write a data string into a file
|
|
|
|
*
|
2013-10-04 10:00:13 -07:00
|
|
|
* @param aPath the path to the file to write to
|
2012-04-17 07:17:23 -07:00
|
|
|
* @param aData a string with the data to be written
|
|
|
|
*/
|
2013-10-04 10:00:13 -07:00
|
|
|
function writeToFile(aPath, aData) {
|
2013-08-08 10:31:58 -07:00
|
|
|
return Task.spawn(function() {
|
|
|
|
let data = new TextEncoder().encode(aData);
|
2013-10-04 10:00:13 -07:00
|
|
|
let file = yield OS.File.open(aPath, { truncate: true }, { unixMode: PERMS_FILE });
|
2013-08-08 10:31:58 -07:00
|
|
|
yield file.write(data);
|
|
|
|
yield file.close();
|
|
|
|
});
|
2012-04-17 07:17:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes unprintable characters from a string.
|
|
|
|
*/
|
|
|
|
function sanitize(aStr) {
|
|
|
|
let unprintableRE = new RegExp("[\\x00-\\x1F\\x7F]" ,"gi");
|
|
|
|
return aStr.replace(unprintableRE, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Strips all non-word characters from the beginning and end of a string
|
|
|
|
*/
|
|
|
|
function stripStringForFilename(aPossiblyBadFilenameString) {
|
|
|
|
//strip everything from the front up to the first [0-9a-zA-Z]
|
|
|
|
|
|
|
|
let stripFrontRE = new RegExp("^\\W*","gi");
|
2012-04-26 22:11:43 -07:00
|
|
|
let stripBackRE = new RegExp("\\s*$","gi");
|
2012-04-17 07:17:23 -07:00
|
|
|
|
|
|
|
let stripped = aPossiblyBadFilenameString.replace(stripFrontRE, "");
|
|
|
|
stripped = stripped.replace(stripBackRE, "");
|
|
|
|
return stripped;
|
|
|
|
}
|
|
|
|
|
2012-04-26 07:37:34 -07:00
|
|
|
/**
|
|
|
|
* Finds a unique name available in a folder (i.e., non-existent file)
|
|
|
|
*
|
2013-10-04 10:00:13 -07:00
|
|
|
* @param aPathSet a set of paths that represents the set of
|
2013-08-06 07:04:17 -07:00
|
|
|
* directories where we want to write
|
2012-04-26 07:37:34 -07:00
|
|
|
* @param aName string with the filename (minus the extension) desired
|
|
|
|
* @param aExtension string with the file extension, including the dot
|
|
|
|
|
2013-08-06 07:04:17 -07:00
|
|
|
* @return file name or null if folder is unwritable or unique name
|
2012-04-26 07:37:34 -07:00
|
|
|
* was not available
|
|
|
|
*/
|
2013-10-04 10:00:13 -07:00
|
|
|
function getAvailableFileName(aPathSet, aName, aExtension) {
|
2014-01-30 08:10:41 -08:00
|
|
|
return Task.spawn(function*() {
|
|
|
|
let name = aName + aExtension;
|
|
|
|
|
|
|
|
function checkUnique(aName) {
|
|
|
|
return Task.spawn(function*() {
|
|
|
|
for (let path of aPathSet) {
|
|
|
|
if (yield OS.File.exists(OS.Path.join(path, aName))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2013-10-04 10:00:13 -07:00
|
|
|
|
2014-01-30 08:10:41 -08:00
|
|
|
return true;
|
|
|
|
});
|
2013-08-06 07:04:17 -07:00
|
|
|
}
|
|
|
|
|
2014-01-30 08:10:41 -08:00
|
|
|
if (yield checkUnique(name)) {
|
|
|
|
return name;
|
2013-08-06 07:04:17 -07:00
|
|
|
}
|
2012-04-26 07:37:34 -07:00
|
|
|
|
2014-01-30 08:10:41 -08:00
|
|
|
// If we're here, the plain name wasn't enough. Let's try modifying the name
|
|
|
|
// by adding "(" + num + ")".
|
|
|
|
for (let i = 2; i < 100; i++) {
|
|
|
|
name = aName + " (" + i + ")" + aExtension;
|
2013-08-06 07:04:17 -07:00
|
|
|
|
2014-01-30 08:10:41 -08:00
|
|
|
if (yield checkUnique(name)) {
|
|
|
|
return name;
|
2013-08-06 07:04:17 -07:00
|
|
|
}
|
2012-04-26 07:37:34 -07:00
|
|
|
}
|
2013-08-06 07:04:17 -07:00
|
|
|
|
2014-01-30 08:10:41 -08:00
|
|
|
throw "No available filename";
|
|
|
|
});
|
2012-04-26 07:37:34 -07:00
|
|
|
}
|
|
|
|
|
2012-06-27 17:14:55 -07:00
|
|
|
/**
|
|
|
|
* Attempts to remove files or directories.
|
|
|
|
*
|
2013-10-04 10:00:13 -07:00
|
|
|
* @param aPaths An array with paths to files to remove
|
2012-06-27 17:14:55 -07:00
|
|
|
*/
|
2013-10-04 10:00:13 -07:00
|
|
|
function removeFiles(aPaths) {
|
|
|
|
for (let path of aPaths) {
|
|
|
|
let file = getFile(path);
|
|
|
|
|
2012-06-27 17:14:55 -07:00
|
|
|
try {
|
|
|
|
if (file.exists()) {
|
|
|
|
file.followLinks = false;
|
|
|
|
file.remove(true);
|
|
|
|
}
|
|
|
|
} catch(ex) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-04 10:00:13 -07:00
|
|
|
/**
|
|
|
|
* Move (overwriting) the contents of one directory into another.
|
|
|
|
*
|
|
|
|
* @param srcPath A path to the source directory
|
|
|
|
* @param destPath A path to the destination directory
|
|
|
|
* @param filesToIgnore An array of files. If one of those files can't be
|
|
|
|
* overwritten the function will not fail.
|
|
|
|
*/
|
|
|
|
function moveDirectory(srcPath, destPath, filesToIgnore) {
|
|
|
|
let srcDir = getFile(srcPath);
|
|
|
|
let destDir = getFile(destPath);
|
|
|
|
|
|
|
|
let entries = srcDir.directoryEntries;
|
|
|
|
let array = [];
|
|
|
|
while (entries.hasMoreElements()) {
|
|
|
|
let entry = entries.getNext().QueryInterface(Ci.nsIFile);
|
|
|
|
|
|
|
|
if (entry.isDirectory()) {
|
|
|
|
yield moveDirectory(entry.path, OS.Path.join(destPath, entry.leafName));
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
entry.moveTo(destDir, entry.leafName);
|
|
|
|
} catch (ex if ex.result == Cr.NS_ERROR_FILE_ACCESS_DENIED) {
|
|
|
|
if (filesToIgnore.indexOf(entry.leafName) != -1) {
|
|
|
|
yield OS.File.remove(entry.path);
|
|
|
|
} else {
|
|
|
|
throw(ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The source directory is now empty, remove it.
|
|
|
|
yield OS.File.removeEmptyDir(srcPath);
|
|
|
|
}
|
|
|
|
|
2012-04-17 07:17:23 -07:00
|
|
|
function escapeXML(aStr) {
|
|
|
|
return aStr.toString()
|
|
|
|
.replace(/&/g, "&")
|
|
|
|
.replace(/"/g, """)
|
|
|
|
.replace(/'/g, "'")
|
|
|
|
.replace(/</g, "<")
|
|
|
|
.replace(/>/g, ">");
|
|
|
|
}
|
|
|
|
|
2013-10-04 10:00:13 -07:00
|
|
|
// Helper to create a nsIFile from a set of path components
|
|
|
|
function getFile() {
|
|
|
|
let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
|
|
|
|
file.initWithPath(OS.Path.join.apply(OS.Path, arguments));
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
2012-04-17 07:17:23 -07:00
|
|
|
/* More helpers for handling the app icon */
|
|
|
|
#include WebappsIconHelpers.js
|