source: trunk/third/mozilla/xpinstall/cleanup/InstallCleanup.cpp @ 18860

Revision 18860, 4.4 KB checked in by rbasch, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18859, which included commits to RCS files with non-trunk default branches.
Line 
1/*
2 * The contents of this file are subject to the Mozilla Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/MPL/
6 *
7 * Software distributed under the License is distributed on an "AS
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9 * implied. See the License for the specific language governing
10 * rights and limitations under the License.
11 *
12 * The Original Code is Mozilla Navigator.
13 *
14 * The Initial Developer of the Original Code is Netscape Communications
15 * Corp.  Portions created by Netscape Communications Corp. are
16 * Copyright (C) 1998, 1999, 2000, 2001 Netscape Communications Corp.  All
17 * Rights Reserved.
18 *
19 * Contributor(s):
20 *   Don Bragg <dbragg@netscape.com>
21 */
22#include "InstallCleanup.h"
23
24int PerformScheduledTasks(HREG reg)
25{
26    int deleteComplete  = DONE;
27    int replaceComplete = DONE;
28
29    deleteComplete  = DeleteScheduledFiles( reg );
30    replaceComplete = ReplaceScheduledFiles( reg );
31    if ((deleteComplete == DONE) && (replaceComplete == DONE))
32        return DONE;
33    else
34        return TRY_LATER;
35}
36
37
38//----------------------------------------------------------------------------
39// ReplaceScheduledFiles
40//----------------------------------------------------------------------------
41int ReplaceScheduledFiles( HREG reg )
42{
43    RKEY    key;
44    int rv = DONE;
45
46    /* replace files if any listed */
47    if (REGERR_OK == NR_RegGetKey(reg,ROOTKEY_PRIVATE,REG_REPLACE_LIST_KEY,&key))
48    {
49        char keyname[MAXREGNAMELEN];
50        char doomedFile[MAXREGPATHLEN];
51        char srcFile[MAXREGPATHLEN];
52
53        uint32 bufsize;
54        REGENUM state = 0;
55        while (REGERR_OK == NR_RegEnumSubkeys( reg, key, &state,
56                               keyname, sizeof(keyname), REGENUM_CHILDREN))
57        {
58            bufsize = sizeof(srcFile);
59            REGERR err1 = NR_RegGetEntry( reg, (RKEY)state,
60                               REG_REPLACE_SRCFILE, &srcFile, &bufsize);
61
62            bufsize = sizeof(doomedFile);
63            REGERR err2 = NR_RegGetEntry( reg, (RKEY)state,
64                               REG_REPLACE_DESTFILE, &doomedFile, &bufsize);
65
66            if ( err1 == REGERR_OK && err2 == REGERR_OK )
67            {
68                int result = NativeReplaceFile( srcFile, doomedFile );
69                if (result == DONE)
70                {
71                    // This one is done
72                    NR_RegDeleteKey( reg, key, keyname );
73                }
74            }
75        }
76
77        /* delete list node if empty */
78        state = 0;
79        if (REGERR_NOMORE == NR_RegEnumSubkeys( reg, key, &state, keyname,
80                                     sizeof(keyname), REGENUM_CHILDREN ))
81        {
82            NR_RegDeleteKey(reg, ROOTKEY_PRIVATE, REG_REPLACE_LIST_KEY);
83            rv = DONE;
84        }
85        else
86        {
87            rv = TRY_LATER;
88        }
89    }
90    return rv;
91}
92
93//----------------------------------------------------------------------------
94// DeleteScheduledFiles
95//----------------------------------------------------------------------------
96int DeleteScheduledFiles( HREG reg )
97{
98    REGERR  err;
99    RKEY    key;
100    REGENUM state = 0;
101    int rv = DONE;
102
103    /* perform scheduled file deletions  */
104    if (REGERR_OK == NR_RegGetKey(reg,ROOTKEY_PRIVATE,REG_DELETE_LIST_KEY,&key))
105    {
106        // the delete key exists, so we loop through its children
107        // and try to delete all the listed files
108
109        char    namebuf[MAXREGNAMELEN];
110        char    valbuf[MAXREGPATHLEN];
111
112        while (REGERR_OK == NR_RegEnumEntries( reg, key, &state, namebuf,
113                                               sizeof(namebuf), 0 ) )
114        {
115            uint32 bufsize = sizeof(valbuf); // gets changed, must reset
116            err = NR_RegGetEntry( reg, key, namebuf, valbuf, &bufsize );
117            if ( err == REGERR_OK )
118            {
119                rv = NativeDeleteFile(valbuf);
120                if (rv == DONE)
121                    NR_RegDeleteEntry( reg, key, namebuf);
122            }
123        }
124
125        /* delete list node if empty */
126        state = 0;
127        err = NR_RegEnumEntries(reg, key, &state, namebuf, sizeof(namebuf), 0);
128        if ( err == REGERR_NOMORE )
129        {
130            NR_RegDeleteKey(reg, ROOTKEY_PRIVATE, REG_DELETE_LIST_KEY);
131            rv = DONE;
132        }
133        else
134        {
135            rv = TRY_LATER;
136        }
137    }
138    return rv;
139}
140
Note: See TracBrowser for help on using the repository browser.