source: trunk/third/mozilla/xpinstall/cleanup/InstallCleanupOS2.cpp @ 19518

Revision 19518, 3.6 KB checked in by rbasch, 21 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r19517, which included commits to RCS files with non-trunk default branches.
Line 
1
2/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 *
4 * The contents of this file are subject to the Netscape Public
5 * License Version 1.1 (the "License"); you may not use this file
6 * except in compliance with the License. You may obtain a copy of
7 * the License at http://www.mozilla.org/NPL/
8 *
9 * Software distributed under the License is distributed on an "AS
10 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11 * implied. See the License for the specific language governing
12 * rights and limitations under the License.
13 *
14 * The Original Code is Mozilla Communicator client code.
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 *   Don Bragg <dbragg@netscape.com>
23 *   IBM Corp.
24 */
25
26#include "InstallCleanup.h"
27#include "InstallCleanupDefines.h"
28#define INCL_DOSERRORS
29#define INCL_DOS
30#include <os2.h>
31#include <string.h>
32#include <sys/stat.h>
33//----------------------------------------------------------------------------
34// Native OS/2 file deletion function
35//----------------------------------------------------------------------------
36int NativeDeleteFile(const char* aFileToDelete)
37{
38    struct stat st;
39    if (stat(aFileToDelete, &st) != 0)
40    {
41      return DONE;// No file to delete, do nothing.
42    }
43    else
44    {
45        if(DosDelete(aFileToDelete) != NO_ERROR)
46          return TRY_LATER;
47    }
48    return DONE;
49}
50
51//----------------------------------------------------------------------------
52// Native OS/2 file replacement function
53//----------------------------------------------------------------------------
54int NativeReplaceFile(const char* replacementFile, const char* doomedFile )
55{
56    // replacement file must exist, doomed file doesn't have to
57    struct stat st;
58    if (stat(replacementFile, &st) != 0)
59        return DONE;
60
61    // don't have to do anything if the files are the same
62    if (stricmp(replacementFile, doomedFile) == 0)
63        return DONE;
64
65    if (DosDelete(doomedFile) != NO_ERROR)
66    {
67        if (stat(doomedFile, &st) == 0)
68            return TRY_LATER;
69    }
70   
71    // doomedFile is gone move new file into place
72    if (DosMove(replacementFile, doomedFile) != NO_ERROR)
73        return TRY_LATER; // this shouldn't happen
74
75    return DONE;
76}
77
78int main(int argc, char *argv[], char *envp[])
79{
80    HREG  reg;
81    BOOL foundSpecialFile = FALSE;
82    struct stat st;
83
84    int status = DONE;
85
86    if ( REGERR_OK == NR_StartupRegistry())
87    {
88        char regFilePath[CCHMAXPATH];
89
90        strcpy(regFilePath, argv[0]);
91        char* lastSlash = strrchr(regFilePath, '\\');
92        lastSlash++;
93        *lastSlash = 0;//strip of the executable name
94        strcat(regFilePath, CLEANUP_REGISTRY); //append reg file name
95   
96        if (stat(regFilePath, &st) != 0)
97          strcpy(regFilePath, ""); // an empty reg file tells RegOpen to get the "default"
98        else
99          foundSpecialFile = TRUE;
100
101        if ( REGERR_OK == NR_RegOpen(regFilePath, &reg) )
102        {
103            int numAttempts = 0;
104            do
105            {
106                status = PerformScheduledTasks(reg);
107                if (status != DONE) {
108                    DosSleep(1000); // Sleep for 1 second
109                    numAttempts++;
110                }
111            } while ((status == TRY_LATER) && numAttempts <= 5);
112
113            NR_RegClose(&reg);
114        }
115        NR_ShutdownRegistry();
116        if (status == DONE) {
117            DosDelete(regFilePath);
118        }
119    }
120    return(0);
121}
122
Note: See TracBrowser for help on using the repository browser.