Untitled

 avatar
unknown
plain_text
a year ago
2.0 kB
14
Indexable
CheckForUpdates() {
masterFile := “\Corp.coopervision.com\dfs\UK-MANF-DEPT-01\WC-Public\Oracle Support App\Oracle Support App.exe”
currentFile := A_ScriptFullPath

```
; Only proceed if BOTH files are .exe
if (SubStr(currentFile, -3) != ".exe" || SubStr(masterFile, -3) != ".exe")
    return  ; Skip update if either file is not .exe

; Check if master file exists
if !FileExist(masterFile)
    return  ; No master file found, continue normally 

; Get file modification times
masterTime := FileGetTime(masterFile, "M")
currentTime := FileGetTime(currentFile, "M")

; If master file is newer, perform update
if (masterTime > currentTime) {
    try {
        ; Create temp file name in same directory as current file
        currentDir := RegExReplace(currentFile, "\\[^\\]*$", "")
        tempFile := currentDir . "\temp_update.exe"
        
        ; Copy new version to temp file first
        FileCopy(masterFile, tempFile, 1)
        
        ; Create batch file to handle the update after this process exits
        batchFile := currentDir . "\update.bat"
        batchContent := '@echo off`n'
        batchContent .= 'timeout /t 2 /nobreak >nul`n'  ; Wait 2 seconds for process to fully exit
        batchContent .= 'copy "' . tempFile . '" "' . currentFile . '" /y >nul`n'
        batchContent .= 'del "' . tempFile . '" >nul 2>&1`n'  ; Delete temp file
        batchContent .= 'start "" "' . currentFile . '"`n'  ; Restart the application
        batchContent .= 'del "%~f0" >nul 2>&1`n'  ; Delete this batch file
        
        ; Write batch file
        FileAppend(batchContent, batchFile)
        
        ; Run batch file and exit current process
        Run(batchFile, , "Hide")
        ExitApp
        
    } catch Error as e {
        ; Clean up temp files if they exist and continue with old version
        try {
            if FileExist(tempFile)
                FileDelete(tempFile)
            if FileExist(batchFile)
                FileDelete(batchFile)
        }
        return
    }
}
```

}
Editor is loading...
Leave a Comment