Back to index

lightning-sunbird  0.9+nobinonly
InstallCleanup.cpp
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is Mozilla Navigator.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corp.
00018  * Portions created by the Initial Developer are Copyright (C) 1998
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Don Bragg <dbragg@netscape.com>
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 #include "InstallCleanup.h"
00038 
00039 int PerformScheduledTasks(HREG reg)
00040 {
00041     int deleteComplete  = DONE;
00042     int replaceComplete = DONE;
00043 
00044     deleteComplete  = DeleteScheduledFiles( reg );
00045     replaceComplete = ReplaceScheduledFiles( reg );
00046     if ((deleteComplete == DONE) && (replaceComplete == DONE))
00047         return DONE;
00048     else
00049         return TRY_LATER;
00050 }
00051 
00052 
00053 //----------------------------------------------------------------------------
00054 // ReplaceScheduledFiles
00055 //----------------------------------------------------------------------------
00056 int ReplaceScheduledFiles( HREG reg )
00057 {
00058     RKEY    key;
00059     int rv = DONE;
00060 
00061     /* replace files if any listed */
00062     if (REGERR_OK == NR_RegGetKey(reg,ROOTKEY_PRIVATE,REG_REPLACE_LIST_KEY,&key))
00063     {
00064         char keyname[MAXREGNAMELEN];
00065         char doomedFile[MAXREGPATHLEN];
00066         char srcFile[MAXREGPATHLEN];
00067 
00068         uint32 bufsize;
00069         REGENUM state = 0;
00070         while (REGERR_OK == NR_RegEnumSubkeys( reg, key, &state, 
00071                                keyname, sizeof(keyname), REGENUM_CHILDREN))
00072         {
00073             bufsize = sizeof(srcFile);
00074             REGERR err1 = NR_RegGetEntry( reg, (RKEY)state,
00075                                REG_REPLACE_SRCFILE, &srcFile, &bufsize);
00076 
00077             bufsize = sizeof(doomedFile);
00078             REGERR err2 = NR_RegGetEntry( reg, (RKEY)state,
00079                                REG_REPLACE_DESTFILE, &doomedFile, &bufsize);
00080 
00081             if ( err1 == REGERR_OK && err2 == REGERR_OK )
00082             {
00083                 int result = NativeReplaceFile( srcFile, doomedFile );
00084                 if (result == DONE)
00085                 {
00086                     // This one is done
00087                     NR_RegDeleteKey( reg, key, keyname );
00088                 }
00089             }
00090         }
00091 
00092         /* delete list node if empty */
00093         state = 0;
00094         if (REGERR_NOMORE == NR_RegEnumSubkeys( reg, key, &state, keyname,
00095                                      sizeof(keyname), REGENUM_CHILDREN ))
00096         {
00097             NR_RegDeleteKey(reg, ROOTKEY_PRIVATE, REG_REPLACE_LIST_KEY);
00098             rv = DONE;
00099         }
00100         else
00101         {
00102             rv = TRY_LATER;
00103         }
00104     }
00105     return rv;
00106 }
00107 
00108 //----------------------------------------------------------------------------
00109 // DeleteScheduledFiles
00110 //----------------------------------------------------------------------------
00111 int DeleteScheduledFiles( HREG reg )
00112 {
00113     REGERR  err;
00114     RKEY    key;
00115     REGENUM state = 0;
00116     int rv = DONE;
00117 
00118     /* perform scheduled file deletions  */
00119     if (REGERR_OK == NR_RegGetKey(reg,ROOTKEY_PRIVATE,REG_DELETE_LIST_KEY,&key))
00120     {
00121         // the delete key exists, so we loop through its children
00122         // and try to delete all the listed files
00123 
00124         char    namebuf[MAXREGNAMELEN];
00125         char    valbuf[MAXREGPATHLEN];
00126 
00127         while (REGERR_OK == NR_RegEnumEntries( reg, key, &state, namebuf,
00128                                                sizeof(namebuf), 0 ) )
00129         {
00130             uint32 bufsize = sizeof(valbuf); // gets changed, must reset
00131             err = NR_RegGetEntry( reg, key, namebuf, valbuf, &bufsize );
00132             if ( err == REGERR_OK )
00133             {
00134                 rv = NativeDeleteFile(valbuf);
00135                 if (rv == DONE)
00136                     NR_RegDeleteEntry( reg, key, namebuf);
00137             }
00138         }
00139 
00140         /* delete list node if empty */
00141         state = 0;
00142         err = NR_RegEnumEntries(reg, key, &state, namebuf, sizeof(namebuf), 0);
00143         if ( err == REGERR_NOMORE )
00144         {
00145             NR_RegDeleteKey(reg, ROOTKEY_PRIVATE, REG_DELETE_LIST_KEY);
00146             rv = DONE;
00147         }
00148         else
00149         {
00150             rv = TRY_LATER;
00151         }
00152     }
00153     return rv;
00154 }
00155