Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
InstallCleanupOS2.cpp File Reference
#include "InstallCleanup.h"
#include "InstallCleanupDefines.h"
#include <os2.h>
#include <string.h>
#include <sys/stat.h>

Go to the source code of this file.

Defines

#define INCL_DOSERRORS
#define INCL_DOS

Functions

int NativeDeleteFile (const char *aFileToDelete)
int NativeReplaceFile (const char *replacementFile, const char *doomedFile)
int main (int argc, char *argv[], char *envp[])

Define Documentation

Definition at line 45 of file InstallCleanupOS2.cpp.

Definition at line 44 of file InstallCleanupOS2.cpp.


Function Documentation

int main ( int  argc,
char *  argv[],
char *  envp[] 
)

Definition at line 94 of file InstallCleanupOS2.cpp.

{
    HREG  reg;
    BOOL foundSpecialFile = FALSE;
    struct stat st;

    int status = DONE;

    if ( REGERR_OK == NR_StartupRegistry())
    {
        char regFilePath[CCHMAXPATH];

        strcpy(regFilePath, argv[0]);
        char* lastSlash = strrchr(regFilePath, '\\');
        if (lastSlash) {
          // path does contain backslash
          lastSlash++;
          *lastSlash = 0; // strip off the executable name
        } else {
          // no backslash in path, just strip off everything
          *regFilePath = 0;
        }
        strcat(regFilePath, CLEANUP_REGISTRY); // append reg file name
    
        if (stat(regFilePath, &st) != 0)
          strcpy(regFilePath, ""); // an empty reg file tells RegOpen to get the "default"
        else
          foundSpecialFile = TRUE;

        if ( REGERR_OK == NR_RegOpen(regFilePath, &reg) )
        {
            int numAttempts = 0;
            do 
            {
                status = PerformScheduledTasks(reg);
                if (status != DONE) {
                    DosSleep(1000); // Sleep for 1 second
                    numAttempts++;
                }
            } while ((status == TRY_LATER) && numAttempts <= 5);

            NR_RegClose(&reg);
        }
        NR_ShutdownRegistry();
        if (status == DONE) {
            DosDelete(regFilePath);
        }
    }
    return(0);
}

Here is the call graph for this function:

int NativeDeleteFile ( const char *  aFileToDelete)

Definition at line 52 of file InstallCleanupOS2.cpp.

{
    struct stat st;
    if (stat(aFileToDelete, &st) != 0)
    {
      return DONE;// No file to delete, do nothing.
    }
    else 
    {
        if(DosDelete(aFileToDelete) != NO_ERROR)
          return TRY_LATER;
    }
    return DONE;
}
int NativeReplaceFile ( const char *  replacementFile,
const char *  doomedFile 
)

Definition at line 70 of file InstallCleanupOS2.cpp.

{
    // replacement file must exist, doomed file doesn't have to
    struct stat st;
    if (stat(replacementFile, &st) != 0)
        return DONE;

    // don't have to do anything if the files are the same
    if (stricmp(replacementFile, doomedFile) == 0)
        return DONE;

    if (DosDelete(doomedFile) != NO_ERROR)
    {
        if (stat(doomedFile, &st) == 0)
            return TRY_LATER;
    }
    
    // doomedFile is gone move new file into place
    if (DosMove(replacementFile, doomedFile) != NO_ERROR)
        return TRY_LATER; // this shouldn't happen

    return DONE;
}