1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
3
* The contents of this file are subject to the Netscape Public
4
* License Version 1.1 (the "License"); you may not use this file
5
* except in compliance with the License. You may obtain a copy of
6
* the License at http://www.mozilla.org/NPL/
8
* Software distributed under the License is distributed on an "AS
9
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10
* implied. See the License for the specific language governing
11
* rights and limitations under the License.
13
* The Original Code is Mozilla Communicator client code,
14
* released March 31, 1998.
16
* The Initial Developer of the Original Code is Netscape Communications
17
* Corporation. Portions created by Netscape are
18
* Copyright (C) 1998 Netscape Communications Corporation. All
22
* Daniel Veditz <dveditz@netscape.com>
23
* Douglas Turner <dougt@netscape.com>
26
#include "nsInstall.h"
27
#include "nsInstallUninstall.h"
28
#include "nsInstallResources.h"
32
#include "ScheduledTasks.h"
33
#include "nsReadableUtils.h"
34
#include "nsILocalFile.h"
36
extern "C" NS_EXPORT PRInt32 SU_Uninstall(char *regPackageName);
37
REGERR su_UninstallProcessItem(char *component_path);
39
MOZ_DECL_CTOR_COUNTER(nsInstallUninstall)
41
nsInstallUninstall::nsInstallUninstall( nsInstall* inInstall,
42
const nsString& regName,
45
: nsInstallObject(inInstall)
47
MOZ_COUNT_CTOR(nsInstallUninstall);
49
if (regName.IsEmpty())
51
*error = nsInstall::INVALID_ARGUMENTS;
55
mRegName.Assign(regName);
57
char* userName = (char*)PR_Malloc(MAXREGPATHLEN);
58
PRInt32 err = VR_GetUninstallUserName( NS_CONST_CAST(char*, NS_ConvertUCS2toUTF8(regName).get()),
62
mUIName.AssignWithConversion(userName);
66
*error = nsInstall::NO_SUCH_COMPONENT;
73
nsInstallUninstall::~nsInstallUninstall()
75
MOZ_COUNT_DTOR(nsInstallUninstall);
79
PRInt32 nsInstallUninstall::Prepare()
81
// no set-up necessary
82
return nsInstall::SUCCESS;
85
PRInt32 nsInstallUninstall::Complete()
87
PRInt32 err = nsInstall::SUCCESS;
90
return nsInstall::INVALID_ARGUMENTS;
92
err = SU_Uninstall( NS_CONST_CAST(char*, NS_ConvertUCS2toUTF8(mRegName).get()) );
97
void nsInstallUninstall::Abort()
101
char* nsInstallUninstall::toString()
103
char* buffer = new char[1024];
104
char* rsrcVal = nsnull;
106
if (buffer == nsnull || !mInstall)
109
char* temp = ToNewCString(mUIName);
113
rsrcVal = mInstall->GetResourcedString(NS_LITERAL_STRING("Uninstall"));
117
sprintf( buffer, rsrcVal, temp);
118
nsCRT::free(rsrcVal);
130
nsInstallUninstall::CanUninstall()
136
nsInstallUninstall::RegisterPackageNode()
141
extern "C" NS_EXPORT PRInt32 SU_Uninstall(char *regPackageName)
143
REGERR status = REGERR_FAIL;
144
char pathbuf[MAXREGPATHLEN+1] = {0};
145
char sharedfilebuf[MAXREGPATHLEN+1] = {0};
150
if (regPackageName == NULL)
156
/* Get next path from Registry */
157
status = VR_Enum( regPackageName, &state, pathbuf, MAXREGPATHLEN );
159
/* if we got a good path */
160
while (status == REGERR_OK)
162
char component_path[2*MAXREGPATHLEN+1] = {0};
163
strcat(component_path, regPackageName);
164
length = strlen(regPackageName);
165
if (component_path[length - 1] != '/')
166
strcat(component_path, "/");
167
strcat(component_path, pathbuf);
168
err = su_UninstallProcessItem(component_path);
169
status = VR_Enum( regPackageName, &state, pathbuf, MAXREGPATHLEN );
172
err = VR_Remove(regPackageName);
173
// there is a problem here. It looks like if the file is refcounted, we still blow away the reg key
176
status = VR_UninstallEnumSharedFiles( regPackageName, &state, sharedfilebuf, MAXREGPATHLEN );
177
while (status == REGERR_OK)
179
err = su_UninstallProcessItem(sharedfilebuf);
180
err = VR_UninstallDeleteFileFromList(regPackageName, sharedfilebuf);
181
status = VR_UninstallEnumSharedFiles( regPackageName, &state, sharedfilebuf, MAXREGPATHLEN );
184
err = VR_UninstallDeleteSharedFilesKey(regPackageName);
185
err = VR_UninstallDestroy(regPackageName);
189
REGERR su_UninstallProcessItem(char *component_path)
193
char filepath[MAXREGPATHLEN];
194
nsCOMPtr<nsILocalFile> nsLFPath;
195
nsCOMPtr<nsIFile> nsFPath;
197
err = VR_GetPath(component_path, sizeof(filepath), filepath);
198
if ( err == REGERR_OK )
200
NS_NewNativeLocalFile(nsDependentCString(filepath), PR_TRUE, getter_AddRefs(nsLFPath));
202
err = VR_GetRefCount(component_path, &refcount);
203
if ( err == REGERR_OK )
207
err = VR_SetRefCount(component_path, refcount);
210
err = VR_Remove(component_path);
211
DeleteFileNowOrSchedule(nsFPath);
216
/* delete node and file */
217
err = VR_Remove(component_path);
218
DeleteFileNowOrSchedule(nsFPath);