gecko-dev/xpcom/tools/registry/regxpcom.cpp

170 строки
4.4 KiB
C++
Исходник Обычный вид История

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
*/
#include <iostream.h>
#ifdef XP_MAC
#include "macstdlibextras.h"
#endif
#include "plstr.h"
#include "prlink.h"
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsCOMPtr.h"
2000-01-25 00:28:28 +03:00
#include "nsILocalFile.h"
static PRBool gUnreg = PR_FALSE;
void print_err(nsresult err)
{
switch (err) {
case NS_ERROR_FACTORY_NOT_LOADED:
cerr << "Factory not loaded";
break;
case NS_NOINTERFACE:
cerr << "No Interface";
break;
case NS_ERROR_NULL_POINTER:
cerr << "Null pointer";
break;
case NS_ERROR_OUT_OF_MEMORY:
cerr << "Out of memory";
break;
default:
cerr << hex << err << dec;
}
}
nsresult Register(const char *path)
{
2000-01-25 00:28:28 +03:00
nsCOMPtr<nsILocalFile> spec;
nsresult rv = nsComponentManager::CreateInstance(NS_LOCAL_FILE_PROGID,
nsnull,
NS_GET_IID(nsILocalFile),
2000-01-25 00:28:28 +03:00
getter_AddRefs(spec));
if (NS_FAILED(rv) || (!spec))
{
printf("create nsILocalFile failed\n");
return NS_ERROR_FAILURE;
}
rv = spec->InitWithPath((char *)path);
if (NS_FAILED(rv)) return rv;
rv = nsComponentManager::AutoRegisterComponent(nsIComponentManager::NS_Startup, spec);
return rv;
}
nsresult Unregister(const char *path)
{
nsCOMPtr<nsILocalFile> spec;
nsresult rv = nsComponentManager::CreateInstance(NS_LOCAL_FILE_PROGID,
nsnull,
NS_GET_IID(nsILocalFile),
getter_AddRefs(spec));
if (NS_FAILED(rv) || (!spec))
{
printf("create nsILocalFile failed\n");
return NS_ERROR_FAILURE;
}
rv = spec->InitWithPath((char *)path);
if (NS_FAILED(rv)) return rv;
rv = nsComponentManager::AutoUnregisterComponent(nsIComponentManager::NS_Startup, spec);
return rv;
}
int ProcessArgs(int argc, char *argv[])
{
int i = 1;
nsresult res;
while (i < argc) {
if (argv[i][0] == '-') {
int j;
for (j = 1; argv[i][j] != '\0'; j++) {
switch (argv[i][j]) {
case 'u':
gUnreg = PR_TRUE;
break;
default:
cerr << "Unknown option '" << argv[i][j] << "'\n";
}
}
i++;
} else {
if (gUnreg == PR_TRUE) {
res = Unregister(argv[i]);
if (NS_SUCCEEDED(res)) {
cout << "Successfully unregistered: " << argv[i] << "\n";
} else {
cerr << "Unregister failed (";
print_err(res);
cerr << "): " << argv[i] << "\n";
}
} else {
res = Register(argv[i]);
if (NS_SUCCEEDED(res)) {
cout << "Successfully registered: " << argv[i] << "\n";
} else {
cerr << "Register failed (";
print_err(res);
cerr << "): " << argv[i] << "\n";
}
}
i++;
}
}
return 0;
}
int main(int argc, char *argv[])
{
int ret = 0;
#ifdef XP_MAC
#if DEBUG
InitializeSIOUX(1);
#endif
#endif
I know it's unorthodox to do a top level checkin like this, but I've got so many files in so many different directories, that I think it's the best way. I've pulled and clobber_all'd my tree and got r=dp on this checkin. Here are the touched files: M mozilla/embedding/browser/activex/src/control/MozillaBrowser.cpp M mozilla/embedding/browser/activex/src/control/MozillaBrowser.h M mozilla/js/src/xpconnect/shell/xpcshell.cpp M mozilla/netwerk/protocol/res/src/nsResProtocolHandler.cpp M mozilla/xpcom/build/nsXPComInit.cpp M mozilla/xpcom/components/nsComponentManager.cpp M mozilla/xpcom/components/nsIServiceManager.h M mozilla/xpcom/components/nsServiceManager.cpp M mozilla/xpcom/io/nsSpecialSystemDirectory.cpp M mozilla/xpcom/io/nsSpecialSystemDirectory.h M mozilla/xpcom/tests/TestBuffers.cpp M mozilla/xpcom/tests/TestPipes.cpp M mozilla/xpcom/tests/TestShutdown.cpp M mozilla/xpcom/tests/windows/TestHelloXPLoop.cpp M mozilla/xpcom/tools/registry/regExport.cpp M mozilla/xpcom/tools/registry/regxpcom.cpp M mozilla/xpinstall/stub/xpistub.cpp M mozilla/webshell/embed/ActiveX/MozillaBrowser.cpp M mozilla/webshell/embed/ActiveX/MozillaBrowser.h M mozilla/webshell/tests/viewer/nsMacMain.cpp M mozilla/webshell/tests/viewer/nsPhMain.cpp M mozilla/webshell/tests/viewer/nsWinMain.cpp M mozilla/webshell/tests/viewer/unix/gtk/nsGtkMain.cpp M mozilla/xpfe/appshell/src/nsFileLocations.cpp M mozilla/xpfe/bootstrap/nsAppRunner.cpp The heart of this checkin is a change in the signature and symantics of NS_InitXPCOM. The new signature is extern NS_COM nsresult NS_InitXPCOM(nsIServiceManager* *result, nsFileSpec* binDirectory); I filed a bug for this problem: b=23157 The original manifestation of this bug was in mozilla/netwerk/protocol/res/src/nsResProtocolHandler.cpp It used the current process directory to find resources, which is not correct when the current process is not mozilla.exe. I have added a new type to nsSpecialSystemDirectory, Moz_BinDirectory, and made nsResProtocolHandler use that value.
2000-01-06 04:05:13 +03:00
NS_InitXPCOM(NULL, NULL);
/* With no arguments, RegFactory will autoregister */
if (argc <= 1)
{
nsresult rv = nsComponentManager::AutoRegister(
nsIComponentManager::NS_Startup,
NULL /* default location */);
ret = (NS_FAILED(rv)) ? -1 : 0;
}
else
ret = ProcessArgs(argc, argv);
NS_ShutdownXPCOM(NULL);
return ret;
}