1999-09-11 18:51:55 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2001-09-29 00:14:13 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1999-09-11 18:51:55 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04: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/
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:43:54 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
2000-02-01 17:26:27 +03:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2001-05-15 21:46:55 +04:00
|
|
|
* Mike Shaver <shaver@mozilla.org>
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-09-11 18:51:55 +04:00
|
|
|
|
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
|
|
|
|
2001-05-15 21:46:55 +04:00
|
|
|
static PRBool gUnreg = PR_FALSE, gSilent = PR_FALSE, gQuiet = PR_FALSE;
|
1999-09-11 18:51:55 +04:00
|
|
|
|
|
|
|
|
|
|
|
nsresult Register(const char *path)
|
|
|
|
{
|
2000-01-25 00:28:28 +03:00
|
|
|
nsCOMPtr<nsILocalFile> spec;
|
2000-09-14 03:57:52 +04:00
|
|
|
nsresult rv = nsComponentManager::CreateInstance(NS_LOCAL_FILE_CONTRACTID,
|
2000-01-25 00:28:28 +03:00
|
|
|
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;
|
2000-09-14 03:57:52 +04:00
|
|
|
nsresult rv = nsComponentManager::CreateInstance(NS_LOCAL_FILE_CONTRACTID,
|
2000-04-18 10:20:35 +04:00
|
|
|
nsnull,
|
|
|
|
NS_GET_IID(nsILocalFile),
|
|
|
|
getter_AddRefs(spec));
|
|
|
|
|
|
|
|
if (NS_FAILED(rv) || (!spec))
|
|
|
|
{
|
2001-05-15 21:46:55 +04:00
|
|
|
fputs("create nsILocalFile failed\n", stderr);
|
2000-04-18 10:20:35 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2001-05-15 21:46:55 +04:00
|
|
|
void ReportSuccess(const char *file)
|
|
|
|
{
|
|
|
|
if (gQuiet)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (gUnreg)
|
|
|
|
printf("Unregistration successful for %s\n", file);
|
|
|
|
else
|
|
|
|
printf("Registration successful for %s\n", file);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReportError(nsresult err, const char *file)
|
|
|
|
{
|
|
|
|
if (gSilent)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (gUnreg)
|
|
|
|
fputs("Unregistration failed: (", stderr);
|
|
|
|
else
|
|
|
|
fputs("Registration failed: (", stderr);
|
|
|
|
|
|
|
|
switch (err) {
|
|
|
|
case NS_ERROR_FACTORY_NOT_LOADED:
|
|
|
|
fputs("Factory not loaded", stderr);
|
|
|
|
break;
|
|
|
|
case NS_NOINTERFACE:
|
|
|
|
fputs("No Interface", stderr);
|
|
|
|
break;
|
|
|
|
case NS_ERROR_NULL_POINTER:
|
|
|
|
fputs("Null pointer", stderr);
|
|
|
|
break;
|
|
|
|
case NS_ERROR_OUT_OF_MEMORY:
|
|
|
|
fputs("Out of memory", stderr);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "%x", (unsigned)err);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr, ") %s\n", file);
|
|
|
|
}
|
|
|
|
|
1999-09-11 18:51:55 +04:00
|
|
|
int ProcessArgs(int argc, char *argv[])
|
|
|
|
{
|
2001-05-15 21:46:55 +04:00
|
|
|
int i = 1, result = 0;
|
1999-09-11 18:51:55 +04:00
|
|
|
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;
|
2001-05-15 21:46:55 +04:00
|
|
|
case 'Q':
|
|
|
|
gSilent = PR_TRUE;
|
|
|
|
/* fall through */
|
|
|
|
case 'q':
|
|
|
|
gQuiet = PR_TRUE;
|
|
|
|
break;
|
1999-09-11 18:51:55 +04:00
|
|
|
default:
|
2001-05-15 21:46:55 +04:00
|
|
|
fprintf(stderr, "Unknown option '%c'\n", argv[i][j]);
|
1999-09-11 18:51:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2001-05-15 21:46:55 +04:00
|
|
|
if (gUnreg == PR_TRUE)
|
1999-09-11 18:51:55 +04:00
|
|
|
res = Unregister(argv[i]);
|
2001-05-15 21:46:55 +04:00
|
|
|
else
|
1999-09-11 18:51:55 +04:00
|
|
|
res = Register(argv[i]);
|
2001-05-15 21:46:55 +04:00
|
|
|
if (NS_FAILED(res)) {
|
|
|
|
ReportError(res, argv[i]);
|
|
|
|
result = -1;
|
|
|
|
} else {
|
|
|
|
ReportSuccess(argv[i]);
|
1999-09-11 18:51:55 +04:00
|
|
|
}
|
|
|
|
}
|
2001-06-29 05:44:35 +04:00
|
|
|
i++;
|
1999-09-11 18:51:55 +04:00
|
|
|
}
|
2001-05-15 21:46:55 +04:00
|
|
|
return result;
|
1999-09-11 18:51:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2001-05-15 21:46:55 +04:00
|
|
|
int ret;
|
1999-09-11 18:51:55 +04:00
|
|
|
|
2000-01-27 08:51:40 +03:00
|
|
|
#ifdef XP_MAC
|
|
|
|
#if DEBUG
|
|
|
|
InitializeSIOUX(1);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2001-10-16 07:35:52 +04:00
|
|
|
NS_InitXPCOM2(nsnull, nsnull, nsnull);
|
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;
|
|
|
|
}
|