Back to index

lightning-sunbird  0.9+nobinonly
Functions
InstallCleanupWin.cpp File Reference
#include "InstallCleanup.h"
#include "InstallCleanupDefines.h"
#include <windows.h>
#include <string.h>

Go to the source code of this file.

Functions

int NativeDeleteFile (const char *aFileToDelete)
int NativeReplaceFile (const char *replacementFile, const char *doomedFile)
int WINAPI WinMain (HINSTANCE, HINSTANCE, LPSTR args, int)

Function Documentation

int NativeDeleteFile ( const char *  aFileToDelete)

Definition at line 45 of file InstallCleanupWin.cpp.

{
    if (GetFileAttributes(aFileToDelete) == 0xFFFFFFFF)
    {
      return DONE;// No file to delete, do nothing.
    }
    else 
    {
        if(!DeleteFile(aFileToDelete))
          return TRY_LATER;
    }
    return DONE;
}

Here is the caller graph for this function:

int NativeReplaceFile ( const char *  replacementFile,
const char *  doomedFile 
)

Definition at line 62 of file InstallCleanupWin.cpp.

{
    // replacement file must exist, doomed file doesn't have to
    if (GetFileAttributes(replacementFile) == 0xFFFFFFFF)
        return DONE;

    // don't have to do anything if the files are the same
    if (CompareString(LOCALE_SYSTEM_DEFAULT,
                      NORM_IGNORECASE | SORT_STRINGSORT,
                      replacementFile, -1,
                      doomedFile, -1) == CSTR_EQUAL)
        return DONE;

    if (!DeleteFile(doomedFile))
    {
        if (GetFileAttributes(doomedFile) != 0xFFFFFFFF) // file exists          
            return TRY_LATER;
    }
    
    // doomedFile is gone move new file into place
    if (!MoveFile(replacementFile, doomedFile))
        return TRY_LATER; // this shouldn't happen

    return DONE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int WINAPI WinMain ( HINSTANCE  ,
HINSTANCE  ,
LPSTR  args,
int   
)

Definition at line 89 of file InstallCleanupWin.cpp.

{
    HREG  reg;
    HKEY  hkRunOnceHandle;
    DWORD dwDisp;
    bool foundSpecialFile = FALSE;

    int status = DONE;

    if ( REGERR_OK == NR_StartupRegistry())
    {
        DWORD charsWritten;
        char appPath[_MAX_PATH];
        charsWritten = GetModuleFileName(NULL, appPath, _MAX_PATH);
        if (charsWritten > 0)
        {
            char regFilePath[_MAX_PATH];
            
            strcpy(regFilePath, appPath);
            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 ( GetFileAttributes(regFilePath) == 0xFFFFFFFF ) // file doesn't exist
              strcpy(regFilePath, ""); // an empty reg file tells RegOpen to get the "default"
            else
              foundSpecialFile = TRUE;

            if ( REGERR_OK == NR_RegOpen(regFilePath, &reg) )
            {
                RegCreateKeyEx(HKEY_CURRENT_USER,
                               "Software\\Microsoft\\Windows\\CurrentVersion\\RunOnce",
                               0,
                               NULL,
                               REG_OPTION_NON_VOLATILE,
                               KEY_WRITE,
                               NULL,
                               &hkRunOnceHandle,
                               &dwDisp);
                
                LPCTSTR cleanupKeyName = "mozilla_cleanup";
            
                RegSetValueEx(hkRunOnceHandle,
                              cleanupKeyName,
                              0,
                              REG_SZ,
                              (const unsigned char*)appPath,
                              strlen(appPath));

                do 
                {
                    status = PerformScheduledTasks(reg);
                    if (status != DONE)
                        Sleep(1000); // Sleep for 1 second
                } while (status == TRY_LATER);

                RegDeleteValue(hkRunOnceHandle, cleanupKeyName);
                NR_RegClose(&reg);
            }
            NR_ShutdownRegistry();
            DeleteFile(regFilePath);
        }
    }
    return(0);
}

Here is the call graph for this function: