1999-09-11 18:51:55 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/*
|
1999-11-06 06:43:54 +03:00
|
|
|
* 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/
|
1999-09-11 18:51:55 +04:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* 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.
|
1999-09-11 18:51:55 +04:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1999-09-11 18:51:55 +04:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 06:43:54 +03:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2000-02-01 17:26:27 +03:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
1999-09-11 18:51:55 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream.h>
|
2000-01-27 08:51:40 +03:00
|
|
|
|
|
|
|
#ifdef XP_MAC
|
|
|
|
#include "macstdlibextras.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
1999-09-11 18:51:55 +04:00
|
|
|
#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"
|
1999-09-11 18:51:55 +04:00
|
|
|
|
|
|
|
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,
|
2000-02-01 17:26:27 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2000-05-05 09:54:15 +04:00
|
|
|
rv = spec->InitWithPath(path);
|
2000-01-25 00:28:28 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
rv = nsComponentManager::AutoRegisterComponent(nsIComponentManager::NS_Startup, spec);
|
|
|
|
return rv;
|
1999-09-11 18:51:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult Unregister(const char *path)
|
|
|
|
{
|
2000-04-18 10:20:35 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2000-05-05 09:54:15 +04:00
|
|
|
rv = spec->InitWithPath(path);
|
2000-04-18 10:20:35 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
rv = nsComponentManager::AutoUnregisterComponent(nsIComponentManager::NS_Startup, spec);
|
|
|
|
return rv;
|
1999-09-11 18:51:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2000-01-27 08:51:40 +03:00
|
|
|
#ifdef XP_MAC
|
|
|
|
#if DEBUG
|
|
|
|
InitializeSIOUX(1);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2000-01-06 04:05:13 +03:00
|
|
|
NS_InitXPCOM(NULL, NULL);
|
1999-10-22 01:31:53 +04:00
|
|
|
|
1999-09-11 18:51:55 +04:00
|
|
|
/* 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);
|
|
|
|
|
1999-10-22 01:31:53 +04:00
|
|
|
NS_ShutdownXPCOM(NULL);
|
1999-09-11 18:51:55 +04:00
|
|
|
return ret;
|
|
|
|
}
|