diff --git a/xulrunner/app/Makefile.in b/xulrunner/app/Makefile.in index 74b8e5a29fe..5be50a1c631 100644 --- a/xulrunner/app/Makefile.in +++ b/xulrunner/app/Makefile.in @@ -68,6 +68,7 @@ REQUIRES = \ string \ appshell \ xulapp \ + xulrunner \ $(NULL) CPPSRCS = nsXULRunnerApp.cpp diff --git a/xulrunner/app/nsXULRunnerApp.cpp b/xulrunner/app/nsXULRunnerApp.cpp index ddd583b2857..e754e3a6b5f 100644 --- a/xulrunner/app/nsXULRunnerApp.cpp +++ b/xulrunner/app/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 Find a GRE with version and print\n" " the path on stdout\n" + " --install-app [ []]\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 appLocation; + nsCOMPtr 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 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 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); diff --git a/xulrunner/setup/Makefile.in b/xulrunner/setup/Makefile.in index 5c2d37a36ab..984a5949c80 100644 --- a/xulrunner/setup/Makefile.in +++ b/xulrunner/setup/Makefile.in @@ -42,7 +42,8 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk -MODULE = xulapp_setup +MODULE = xulrunner +XPIDL_MODULE = xulapp_setup XPIDLSRCS = \ nsIXULAppInstall.idl \ diff --git a/xulrunner/setup/nsXULAppInstall.js b/xulrunner/setup/nsXULAppInstall.js index 5846cc3a464..7e8c5dfe42e 100644 --- a/xulrunner/setup/nsXULAppInstall.js +++ b/xulrunner/setup/nsXULAppInstall.js @@ -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 = { "CFBundleInfoDictionaryVersion\n" + "6.0\n" + "CFBundlePackageType\n" + - "APPL" + + "APPL\n" + "CFBundleExecutable\n" + "xulrunner\n" + "NSAppleScriptEnabled\n" + "\n" + "CFBundleGetInfoString\n" + - "" + vendor ? (vendor + " ") : "" + appName + " " + version + "\n" + + "" + infoString + "\n" + "CFBundleName\n" + "" + appName + "\n" + "CFBundleShortVersionString\n" + diff --git a/xulrunner/stub/nsXULStubOSX.cpp b/xulrunner/stub/nsXULStubOSX.cpp index 9ff76f86432..f2acdb8861a 100644 --- a/xulrunner/stub/nsXULStubOSX.cpp +++ b/xulrunner/stub/nsXULStubOSX.cpp @@ -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];