Bug 300139 - nsXULAppInstall fixup and xulrunner command-line flag. r=robstrong

This commit is contained in:
bsmedberg%covad.net 2005-10-07 13:59:17 +00:00
Родитель c42832559f
Коммит 22f36b709f
5 изменённых файлов: 108 добавлений и 9 удалений

Просмотреть файл

@ -68,6 +68,7 @@ REQUIRES = \
string \
appshell \
xulapp \
xulrunner \
$(NULL)
CPPSRCS = nsXULRunnerApp.cpp

Просмотреть файл

@ -47,8 +47,10 @@
#include "nsAppRunner.h"
#include "nsINIParser.h"
#include "nsILocalFile.h"
#include "nsIXULAppInstall.h"
#include "nsCOMPtr.h"
#include "nsMemory.h"
#include "nsNativeCharsetUtils.h"
#include "nsBuildID.h"
#include "plstr.h"
#include "prprf.h"
@ -270,6 +272,8 @@ static void Usage()
" --register-user\n"
" --find-gre <version> Find a GRE with version <version> and print\n"
" the path on stdout\n"
" --install-app <application> [<destination> [<directoryname>]]\n"
" Install a XUL application.\n"
"\n"
"APP-FILE\n"
" Application initialization file.\n"
@ -298,6 +302,53 @@ GetXULRunnerDir(const char *argv0, nsIFile* *aResult)
return rv;
}
static int
InstallXULApp(nsIFile* aXULRunnerDir,
const char *aAppLocation,
const char *aInstallTo,
const char *aLeafName)
{
nsCOMPtr<nsILocalFile> appLocation;
nsCOMPtr<nsILocalFile> installTo;
nsAutoString leafName;
nsresult rv = XRE_GetFileFromPath(aAppLocation, getter_AddRefs(appLocation));
if (NS_FAILED(rv))
return 2;
if (aInstallTo) {
rv = XRE_GetFileFromPath(aInstallTo, getter_AddRefs(installTo));
if (NS_FAILED(rv))
return 2;
}
if (aLeafName)
NS_CopyNativeToUnicode(nsDependentCString(aLeafName), leafName);
rv = NS_InitXPCOM2(nsnull, aXULRunnerDir, nsnull);
if (NS_FAILED(rv))
return 3;
{
// Scope our COMPtr to avoid holding XPCOM refs beyond xpcom shutdown
nsCOMPtr<nsIXULAppInstall> install
(do_GetService("@mozilla.org/xulrunner/app-install-service;1"));
if (!install) {
rv = NS_ERROR_FAILURE;
}
else {
rv = install->InstallApplication(appLocation, installTo, leafName);
}
}
NS_ShutdownXPCOM(nsnull);
if (NS_FAILED(rv))
return 3;
return 0;
}
int main(int argc, char* argv[])
{
if (argc > 1 && (IsArg(argv[1], "h") ||
@ -376,6 +427,36 @@ int main(int argc, char* argv[])
printf("%s\n", GRE_BUILD_ID);
return 0;
}
if (IsArg(argv[1], "install-app")) {
if (argc < 3 || argc > 5) {
Usage();
return 1;
}
char *appLocation = argv[2];
char *installTo = nsnull;
if (argc > 3) {
installTo = argv[3];
if (!*installTo) // left blank?
installTo = nsnull;
}
char *leafName = nsnull;
if (argc > 4) {
leafName = argv[4];
if (!*leafName)
leafName = nsnull;
}
nsCOMPtr<nsIFile> regDir;
nsresult rv = GetXULRunnerDir(argv[0], getter_AddRefs(regDir));
if (NS_FAILED(rv))
return 2;
return InstallXULApp(regDir, appLocation, installTo, leafName);
}
}
geckoVersion = ParseVersion(GRE_BUILD_ID);

Просмотреть файл

@ -42,7 +42,8 @@ VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = xulapp_setup
MODULE = xulrunner
XPIDL_MODULE = xulapp_setup
XPIDLSRCS = \
nsIXULAppInstall.idl \

Просмотреть файл

@ -46,9 +46,14 @@ const nsIZipEntry = Components.interfaces.nsIZipEntry;
const nsIZipReader = Components.interfaces.nsIZipReader;
function getDirectoryKey(aKey) {
return Components.classes["@mozilla.org/file/directory_service;1"].
getService(Components.interfaces.nsIProperties).
get(aKey, nsIFile);
try {
return Components.classes["@mozilla.org/file/directory_service;1"].
getService(Components.interfaces.nsIProperties).
get(aKey, nsIFile);
}
catch (e) {
throw "Couln't get directory service key: " + aKey;
}
}
function createINIParser(aFile) {
@ -87,7 +92,7 @@ const PR_TRUNCATE = 0x20;
function openFileOutputStream(aFile) {
var s = Components.classes["@mozilla.org/network/file-output-stream;1"].
createInstance(Components.interfaces.nsIFileOutputStream);
s.init(aFile, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE);
s.init(aFile, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 0644, 0);
return s;
}
@ -227,7 +232,7 @@ const AppInstall = {
if (aDirectory == null) {
#ifdef XP_WIN
aDirectory = getDirectoryKey("Progs");
aDirectory = getDirectoryKey("ProgF");
if (vendor)
aDirectory.append(vendor);
#else
@ -277,6 +282,12 @@ const AppInstall = {
var version = iniParser.getString("App", "Version");
var buildID = iniParser.getString("App", "BuildID");
var infoString = "";
if (vendor) {
infoString = vendor + " ";
}
infoString += appName + " " + version;
var plistFile = aDirectory.clone();
plistFile.append("Info.plist");
var ostream = openFileOutputStream(plistFile);
@ -289,13 +300,13 @@ const AppInstall = {
"<key>CFBundleInfoDictionaryVersion</key>\n" +
"<string>6.0</string>\n" +
"<key>CFBundlePackageType</key>\n" +
"<string>APPL</string>" +
"<string>APPL</string>\n" +
"<key>CFBundleExecutable</key>\n" +
"<string>xulrunner</string>\n" +
"<key>NSAppleScriptEnabled</key>\n" +
"<true/>\n" +
"<key>CFBundleGetInfoString</key>\n" +
"<string>" + vendor ? (vendor + " ") : "" + appName + " " + version + "</string>\n" +
"<string>" + infoString + "</string>\n" +
"<key>CFBundleName</key>\n" +
"<string>" + appName + "</string>\n" +
"<key>CFBundleShortVersionString</key>\n" +

Просмотреть файл

@ -70,7 +70,7 @@ main(int argc, char **argv)
absResourcesURL,
CFSTR("application.ini"),
false);
CFRelease(resourcesURL);
CFRelease(absResourcesURL);
if (!iniFileURL)
return 1;
@ -131,6 +131,11 @@ main(int argc, char **argv)
return 1;
}
char *lastSlash = strrchr(greDir, '/');
if (lastSlash) {
*lastSlash = '\0';
}
char **argv2 = (char**) alloca(sizeof(char*) * (argc + 2));
char xulBin[PATH_MAX];