~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/xpinstall/src/nsInstallUninstall.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
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/
 
7
 *
 
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.
 
12
 *
 
13
 * The Original Code is Mozilla Communicator client code, 
 
14
 * released March 31, 1998. 
 
15
 *
 
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
 
19
 * Rights Reserved.
 
20
 *
 
21
 * Contributor(s): 
 
22
 *     Daniel Veditz <dveditz@netscape.com>
 
23
 *     Douglas Turner <dougt@netscape.com>
 
24
 */
 
25
 
 
26
#include "nsInstall.h"
 
27
#include "nsInstallUninstall.h"
 
28
#include "nsInstallResources.h"
 
29
#include "VerReg.h"
 
30
#include "nsCRT.h"
 
31
#include "prmem.h"
 
32
#include "ScheduledTasks.h"
 
33
#include "nsReadableUtils.h"
 
34
#include "nsILocalFile.h"
 
35
 
 
36
extern "C" NS_EXPORT PRInt32 SU_Uninstall(char *regPackageName);
 
37
REGERR su_UninstallProcessItem(char *component_path);
 
38
 
 
39
MOZ_DECL_CTOR_COUNTER(nsInstallUninstall)
 
40
 
 
41
nsInstallUninstall::nsInstallUninstall( nsInstall* inInstall,
 
42
                                        const nsString& regName,
 
43
                                        PRInt32 *error)
 
44
 
 
45
: nsInstallObject(inInstall)
 
46
{
 
47
    MOZ_COUNT_CTOR(nsInstallUninstall);
 
48
 
 
49
    if (regName.IsEmpty()) 
 
50
    {
 
51
        *error = nsInstall::INVALID_ARGUMENTS;
 
52
        return;
 
53
    }
 
54
    
 
55
    mRegName.Assign(regName);
 
56
 
 
57
    char* userName = (char*)PR_Malloc(MAXREGPATHLEN);
 
58
    PRInt32 err = VR_GetUninstallUserName( NS_CONST_CAST(char*, NS_ConvertUCS2toUTF8(regName).get()),
 
59
                                           userName, 
 
60
                                           MAXREGPATHLEN );
 
61
    
 
62
    mUIName.AssignWithConversion(userName);
 
63
    
 
64
    if (err != REGERR_OK)
 
65
    {
 
66
        *error = nsInstall::NO_SUCH_COMPONENT;
 
67
    }
 
68
    
 
69
    PR_FREEIF(userName);
 
70
    
 
71
}
 
72
 
 
73
nsInstallUninstall::~nsInstallUninstall()
 
74
{
 
75
    MOZ_COUNT_DTOR(nsInstallUninstall);
 
76
}
 
77
 
 
78
 
 
79
PRInt32 nsInstallUninstall::Prepare()
 
80
{
 
81
    // no set-up necessary
 
82
    return nsInstall::SUCCESS;
 
83
}
 
84
 
 
85
PRInt32 nsInstallUninstall::Complete()
 
86
{
 
87
    PRInt32 err = nsInstall::SUCCESS;
 
88
 
 
89
    if (mInstall == NULL) 
 
90
       return nsInstall::INVALID_ARGUMENTS;
 
91
 
 
92
    err = SU_Uninstall( NS_CONST_CAST(char*, NS_ConvertUCS2toUTF8(mRegName).get()) );
 
93
    
 
94
    return err;
 
95
}
 
96
 
 
97
void nsInstallUninstall::Abort()
 
98
{
 
99
}
 
100
 
 
101
char* nsInstallUninstall::toString()
 
102
{
 
103
    char* buffer = new char[1024];
 
104
    char* rsrcVal = nsnull;
 
105
 
 
106
    if (buffer == nsnull || !mInstall)
 
107
        return buffer;
 
108
    
 
109
    char* temp = ToNewCString(mUIName);
 
110
    
 
111
    if (temp)
 
112
    {
 
113
        rsrcVal = mInstall->GetResourcedString(NS_LITERAL_STRING("Uninstall"));
 
114
 
 
115
        if (rsrcVal)
 
116
        {
 
117
            sprintf( buffer, rsrcVal, temp);
 
118
            nsCRT::free(rsrcVal);
 
119
        }
 
120
    }
 
121
 
 
122
    if (temp)
 
123
         Recycle(temp);
 
124
 
 
125
    return buffer;
 
126
}
 
127
 
 
128
 
 
129
PRBool
 
130
nsInstallUninstall::CanUninstall()
 
131
{
 
132
    return PR_FALSE;
 
133
}
 
134
 
 
135
PRBool
 
136
nsInstallUninstall::RegisterPackageNode()
 
137
{
 
138
    return PR_FALSE;
 
139
}
 
140
 
 
141
extern "C" NS_EXPORT PRInt32 SU_Uninstall(char *regPackageName)
 
142
{
 
143
    REGERR status = REGERR_FAIL;
 
144
    char pathbuf[MAXREGPATHLEN+1] = {0};
 
145
    char sharedfilebuf[MAXREGPATHLEN+1] = {0};
 
146
    REGENUM state = 0;
 
147
    int32 length;
 
148
    int32 err;
 
149
 
 
150
    if (regPackageName == NULL)
 
151
        return REGERR_PARAM;
 
152
 
 
153
    if (pathbuf == NULL)
 
154
        return REGERR_PARAM;
 
155
 
 
156
    /* Get next path from Registry */
 
157
    status = VR_Enum( regPackageName, &state, pathbuf, MAXREGPATHLEN );
 
158
 
 
159
    /* if we got a good path */
 
160
    while (status == REGERR_OK)
 
161
    {
 
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 );  
 
170
    }
 
171
    
 
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
 
174
    // FIX!
 
175
    state = 0;
 
176
    status = VR_UninstallEnumSharedFiles( regPackageName, &state, sharedfilebuf, MAXREGPATHLEN );
 
177
    while (status == REGERR_OK)
 
178
    {
 
179
        err = su_UninstallProcessItem(sharedfilebuf);
 
180
        err = VR_UninstallDeleteFileFromList(regPackageName, sharedfilebuf);
 
181
        status = VR_UninstallEnumSharedFiles( regPackageName, &state, sharedfilebuf, MAXREGPATHLEN );
 
182
    }
 
183
 
 
184
    err = VR_UninstallDeleteSharedFilesKey(regPackageName);
 
185
    err = VR_UninstallDestroy(regPackageName);
 
186
    return err;
 
187
}
 
188
 
 
189
REGERR su_UninstallProcessItem(char *component_path)
 
190
{
 
191
    int refcount;
 
192
    int err;
 
193
    char filepath[MAXREGPATHLEN];
 
194
    nsCOMPtr<nsILocalFile> nsLFPath;
 
195
    nsCOMPtr<nsIFile> nsFPath;
 
196
 
 
197
    err = VR_GetPath(component_path, sizeof(filepath), filepath);
 
198
    if ( err == REGERR_OK )
 
199
    {
 
200
        NS_NewNativeLocalFile(nsDependentCString(filepath), PR_TRUE, getter_AddRefs(nsLFPath));
 
201
        nsFPath = nsLFPath;
 
202
        err = VR_GetRefCount(component_path, &refcount);  
 
203
        if ( err == REGERR_OK )
 
204
        {
 
205
            --refcount;
 
206
            if (refcount > 0)
 
207
                err = VR_SetRefCount(component_path, refcount);  
 
208
            else 
 
209
            {
 
210
                err = VR_Remove(component_path);
 
211
                DeleteFileNowOrSchedule(nsFPath);
 
212
            }
 
213
        }
 
214
        else
 
215
        {
 
216
            /* delete node and file */
 
217
            err = VR_Remove(component_path);
 
218
            DeleteFileNowOrSchedule(nsFPath);
 
219
        }
 
220
    }
 
221
    return err;
 
222
}
 
223