Bug 276588 - Rework command line handling in the toolkit to use a generic API - see COMMANDLINES_20050109_BRANCH for more detailed cvs logs r=darin,caillon,mscott,mconnor
This commit is contained in:
@@ -38,8 +38,10 @@
|
||||
#include "nsGNOMEShellService.h"
|
||||
#include "nsShellService.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsILocalFile.h"
|
||||
#include "nsIProperties.h"
|
||||
#include "nsDirectoryServiceDefs.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsICmdLineService.h"
|
||||
#include "prenv.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIGConfService.h"
|
||||
@@ -98,6 +100,8 @@ static const char kDesktopColorKey[] = DG_BACKGROUND "/primary_color";
|
||||
nsresult
|
||||
nsGNOMEShellService::Init()
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// GConf and GnomeVFS _must_ be available, or we do not allow
|
||||
// CreateInstance to succeed.
|
||||
|
||||
@@ -112,39 +116,19 @@ nsGNOMEShellService::Init()
|
||||
// the locale encoding. If it's not set, they use UTF-8.
|
||||
mUseLocaleFilenames = PR_GetEnv("G_BROKEN_FILENAMES") != nsnull;
|
||||
|
||||
// Get the path we were launched from.
|
||||
nsCOMPtr<nsICmdLineService> cmdService =
|
||||
do_GetService("@mozilla.org/appshell/commandLineService;1");
|
||||
if (!cmdService)
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
nsCOMPtr<nsIProperties> dirSvc
|
||||
(do_GetService("@mozilla.org/file/directory_service;1"));
|
||||
NS_ENSURE_TRUE(dirSvc, NS_ERROR_NOT_AVAILABLE);
|
||||
|
||||
nsXPIDLCString programName;
|
||||
cmdService->GetProgramName(getter_Copies(programName));
|
||||
nsCOMPtr<nsILocalFile> appPath;
|
||||
rv = dirSvc->Get(NS_XPCOM_CURRENT_PROCESS_DIR, NS_GET_IID(nsILocalFile),
|
||||
getter_AddRefs(appPath));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Make sure we have an absolute pathname.
|
||||
if (programName[0] != '/') {
|
||||
// First search PATH if we were just launched as 'firefox-bin'.
|
||||
// If we were launched as './firefox-bin', this will just return
|
||||
// the original string.
|
||||
rv = appPath->AppendNative(NS_LITERAL_CSTRING(MOZ_APP_NAME));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
gchar *appPath = g_find_program_in_path(programName.get());
|
||||
|
||||
// Now resolve it.
|
||||
char resolvedPath[PATH_MAX] = "";
|
||||
if (realpath(appPath, resolvedPath)) {
|
||||
mAppPath.Assign(resolvedPath);
|
||||
}
|
||||
|
||||
g_free(appPath);
|
||||
} else {
|
||||
mAppPath.Assign(programName);
|
||||
}
|
||||
|
||||
// strip "-bin" off of the binary name
|
||||
if (StringEndsWith(mAppPath, NS_LITERAL_CSTRING("-bin")))
|
||||
mAppPath.SetLength(mAppPath.Length() - 4);
|
||||
|
||||
return NS_OK;
|
||||
return appPath->GetNativePath(mAppPath);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsGNOMEShellService, nsIShellService)
|
||||
|
||||
Reference in New Issue
Block a user