Jump to content

Program Updater


Klexen
 Share

Recommended Posts

I wrote this program because I was always making changes to my program at work, that other users use. They would have to browse to network drive and overwrite their current version with the one I just sent.

Well this makes that a little easier.

Here is the code.

#include <GuiConstants.au3>

Dim $File_Location = @ScriptDir & "\Data\stored.ini"
Dim $data_Location = @ScriptDir & "\Data\"

DirGetSize($data_Location)
If @error = 1 Then
    DirCreate($data_Location)
EndIf

AdlibEnable("CloseNameOfYourProgram",100)

Func CloseNameOfYourProgram()
If ProcessExists("NameOfYourProgram.exe") Then ProcessClose("NameOfYourProgram.exe")
EndFunc

;-------Creates the Main Gui-------
$GUI_Main = GUICreate("Program Updater", 200, 50)

;-----Creates Button on GUI------
$GetUpdate = GUICtrlCreateButton("Get Update", 30, 10)
GUICtrlSetTip(-1, "Click here to retrieve new version")

$SendUpdate = GUICtrlCreateButton("Send Update", 95, 10)
GUICtrlSetTip(-1, "This is for sending updated version" & @CRLF & "For Admin use only")

GUISetIcon("Your.ico")

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            CleanExit()
        Case $GetUpdate
            GetUpdate()
        Case $SendUpdate
            $Pass = "pass"
            $PassAsk = InputBox("Auth Required", "Please Enter Password", "", "*", 100, 125)
            If $PassAsk = $Pass Then
                SendUpdate()
            Else
                MsgBox(262160, "ERROR", "Incorrect Password")
                Exit
            EndIf
        Case Else
            ;-------------;
    EndSwitch

WEnd


Func GetUpdate()
    ;-------Checks if program is already running. If it is, the closes it.-------
    $CheckFirstRun = IniRead($File_Location, "ProgramUpdate", "PathToFile", "")
    If $CheckFirstRun = "" Then
        $UpdatePath = "X:\PATH TO YOUR UPDATE FILE\"
        $PathtoFile = FileOpenDialog("Please Select file to be updated.", @ScriptDir, "Executables (*.exe)", 1, "YourProgram.exe")
        If @error Then
            MsgBox(262160, "ERROR", "No file Selected")
            Exit
        EndIf
        $PathtoUpdate = FileOpenDialog("Please Select the update file.", $UpdatePath, "Executables (*.exe)", 1, "YourProgram.exe")
        If @error Then
            MsgBox(262160, "ERROR", "No file Selected")
            Exit
        EndIf
        IniWrite($File_Location, "ProgramUpdate", "PathToFile", $PathtoFile)
        IniWrite($File_Location, "ProgramUpdate", "PathToUpdate", $PathtoUpdate)
        $UpdateVersion = FileGetTime($PathtoUpdate)
        $CurrentVersion = FileGetTime($PathtoFile)
        $UpdateVersiondate = $UpdateVersion[0]  & $UpdateVersion[1]  & $UpdateVersion[2] & $UpdateVersion[3] & $UpdateVersion[4] & $UpdateVersion[5] 
        $CurrentVersiondate = $CurrentVersion[0]  & $CurrentVersion[1]  & $CurrentVersion[2] & $CurrentVersion[3] & $CurrentVersion[4] & $CurrentVersion[5]
        
        If $UpdateVersiondate > $CurrentVersiondate Then
            FileCopy($PathtoUpdate, $PathtoFile, 1)
            MsgBox(262208, "Success", "The update was successful.")
            Exit
        Else
            MsgBox(262208, "Alert", "You have the latest version.")
            Exit
        EndIf
    Else
        $PathtoFile = IniRead($File_Location, "ProgramUpdate", "PathToFile", "")
        $PathtoUpdate = IniRead($File_Location, "ProgramUpdate", "PathToUpdate", "")
        $UpdateVersion = FileGetTime($PathtoUpdate)
        $CurrentVersion = FileGetTime($PathtoFile)
        $UpdateVersiondate = $UpdateVersion[0]  & $UpdateVersion[1]  & $UpdateVersion[2] & $UpdateVersion[3] & $UpdateVersion[4] & $UpdateVersion[5] 
        $CurrentVersiondate = $CurrentVersion[0]  & $CurrentVersion[1]  & $CurrentVersion[2] & $CurrentVersion[3] & $CurrentVersion[4] & $CurrentVersion[5]
        If Not FileExists($PathtoFile) Then
            MsgBox(262160, "ERROR", "File no longer exists!")
            CreatePathGet()
        EndIf
        If $UpdateVersiondate > $CurrentVersiondate Then
            FileCopy($PathtoUpdate, $PathtoFile, 1)
            MsgBox(262208, "Success", "The update was successful.")
            Exit
        Else
            MsgBox(262208, "Alert", "You have the latest version")
            Exit
        EndIf
    EndIf
EndFunc   ;==>GetUpdate


Func SendUpdate()
    $CheckFirstRun = IniRead($File_Location, "ProgramUpdate", "PathToUpdateFile", "")
    If $CheckFirstRun = "" Then
        $UpdatePath = "X:\PATH TO YOUR UPDATE FILE\"
        $PathtoUpdateFile = FileOpenDialog("Please select the updated version.", @ScriptDir, "Executables (*.exe)", 1, "YourProgram.exe")
        If @error Then
            MsgBox(262160, "ERROR", "No file Selected")
            Exit
        EndIf
        $PathtoSendUpdate = FileOpenDialog("Please select your current version.", $UpdatePath, "Executables (*.exe)", 1, "YourProgram.exe")
        If @error Then
            MsgBox(262160, "ERROR", "No file Selected")
            Exit
        EndIf
        IniWrite($File_Location, "ProgramUpdate", "PathToUpdateFile", $PathtoUpdateFile)
        IniWrite($File_Location, "ProgramUpdate", "PathToSendUpdate", $PathtoSendUpdate)
        $UpdateVersion = FileGetTime($PathtoUpdateFile)
        $CurrentVersion = FileGetTime($PathtoSendUpdate)
        $UpdateVersiondate = $UpdateVersion[0]  & $UpdateVersion[1]  & $UpdateVersion[2] & $UpdateVersion[3] & $UpdateVersion[4] & $UpdateVersion[5] 
        $CurrentVersiondate = $CurrentVersion[0]  & $CurrentVersion[1]  & $CurrentVersion[2] & $CurrentVersion[3] & $CurrentVersion[4] & $CurrentVersion[5]
        If $UpdateVersiondate > $CurrentVersiondate Then
            FileCopy($PathtoUpdateFile, $PathtoSendUpdate, 1)
            MsgBox(262208, "Success", "The update was sent successfully.")
            Exit
        Else
            MsgBox(262208, "Alert", "File is already the latest version.")
            Exit
        EndIf
    Else
        $PathtoUpdateFile = IniRead($File_Location, "ProgramUpdate", "PathToUpdateFile", "")
        $PathtoSendUpdate = IniRead($File_Location, "ProgramUpdate", "PathToSendUpdate", "")
        $UpdateVersion = FileGetTime($PathtoUpdateFile)
        $CurrentVersion = FileGetTime($PathtoSendUpdate)
        $UpdateVersiondate = $UpdateVersion[0]  & $UpdateVersion[1]  & $UpdateVersion[2] & $UpdateVersion[3] & $UpdateVersion[4] & $UpdateVersion[5] 
        $CurrentVersiondate = $CurrentVersion[0]  & $CurrentVersion[1]  & $CurrentVersion[2] & $CurrentVersion[3] & $CurrentVersion[4] & $CurrentVersion[5]
        If Not FileExists($PathtoUpdateFile) Then
            MsgBox(262160, "ERROR", "File no longer exists!")
            CreatePathSend()
        EndIf
        If $UpdateVersiondate > $CurrentVersiondate Then
            FileCopy($PathtoUpdateFile, $PathtoSendUpdate, 1)
            MsgBox(262208, "Success", "The update was sent successfully.")
            Exit
        Else
            MsgBox(262208, "Alert", "File is already the latest version.")
            Exit
        EndIf
    EndIf
EndFunc   ;==>SendUpdate

Func CreatePathGet()
    $UpdatePath = "X:\PATH TO YOUR UPDATE FILE\"
    $PathtoFile = FileOpenDialog("Please Select file to be updated.", @ScriptDir, "Executables (*.exe)", 1, "YourProgram.exe")
    If @error Then
        MsgBox(262160, "ERROR", "No file Selected")
        Exit
    EndIf
    $PathtoUpdate = FileOpenDialog("Please Select the update file.", $UpdatePath, "Executables (*.exe)", 1, "YourProgram.exe")
    If @error Then
        MsgBox(262160, "ERROR", "No file Selected")
        Exit
    EndIf
    IniWrite($File_Location, "ProgramUpdate", "PathToFile", $PathtoFile)
    IniWrite($File_Location, "ProgramUpdate", "PathToUpdate", $PathtoUpdate)
EndFunc   ;==>CreatePath

Func CreatePathSend()
    $UpdatePath = "X:\PATH TO YOUR UPDATE FILE\"
    $PathtoUpdateFile = FileOpenDialog("Please select the updated version.", @ScriptDir, "Executables (*.exe)", 1, "YourProgram.exe")
    If @error Then
        MsgBox(262160, "ERROR", "No file Selected")
        Exit
    EndIf
    $PathtoSendUpdate = FileOpenDialog("Please select your current version.", $UpdatePath, "Executables (*.exe)", 1, "YourProgram.exe")
    If @error Then
        MsgBox(262160, "ERROR", "No file Selected")
        Exit
    EndIf
    IniWrite($File_Location, "ProgramUpdate", "PathToUpdateFile", $PathtoUpdateFile)
    IniWrite($File_Location, "ProgramUpdate", "PathToSendUpdate", $PathtoSendUpdate)

EndFunc   ;==>CreatePath2


;-----Close Program-----
Func CleanExit()
    GUISetState(@SW_HIDE)
    Exit
EndFunc   ;==>CleanExitoÝ÷ Øn¶Øb²)íêk¢
ÚÊ"µÈ^rK¢»©u«^jÙZºw!jëh×6Func CheckUpdate()
    $CheckFirstRun = IniRead($File_Location, "ProgramUpdate", "PathToFile", "")
    If $CheckFirstRun = "" Then
        $UpdatePath = "X:\PATH TO YOUR UPDATE FILE\"
        $PathtoFile = FileOpenDialog("Please Select your YourProgram.exe file.", @ScriptDir, "Executables (*.exe)", 1, "YourProgram.exe")
        If @error Then
            MsgBox(262160, "ERROR", "No file Selected")
            Exit
        EndIf
        $PathtoUpdate = FileOpenDialog("Please Select the file update file.", $UpdatePath, "Executables (*.exe)", 1, "YourProgram.exe")
        If @error Then
            MsgBox(262160, "ERROR", "No file Selected")
            Exit
        EndIf
        IniWrite($File_Location, "ProgramUpdate", "PathToFile", $PathtoFile)
        IniWrite($File_Location, "ProgramUpdate", "PathToUpdate", $PathtoUpdate)
        $UpdateVersion = FileGetTime($PathtoUpdate)
        $CurrentVersion = FileGetTime($PathtoFile)
        $UpdateVersiondate = $UpdateVersion[0]  & $UpdateVersion[1]  & $UpdateVersion[2] & $UpdateVersion[3] & $UpdateVersion[4] & $UpdateVersion[5] 
        $CurrentVersiondate = $CurrentVersion[0]  & $CurrentVersion[1]  & $CurrentVersion[2] & $CurrentVersion[3] & $CurrentVersion[4] & $CurrentVersion[5]
        If $UpdateVersiondate > $CurrentVersiondate Then 
        $UpdateNowBox = MsgBox(4, "Alert", "There is an update available." & @CRLF & "Would you like to run update now?",5)
        If $UpdateNowBox = 6 Then ShellExecute("ProgramUpdater.exe")
        EndIf
    Else
        $PathtoFile = IniRead($File_Location, "ProgramUpdate", "PathToFile", "")
        $PathtoUpdate = IniRead($File_Location, "ProgramUpdate", "PathToUpdate", "")
        $UpdateVersion = FileGetTime($PathtoUpdate)
        $CurrentVersion = FileGetTime($PathtoFile)
        $UpdateVersiondate = $UpdateVersion[0]  & $UpdateVersion[1]  & $UpdateVersion[2] & $UpdateVersion[3] & $UpdateVersion[4] & $UpdateVersion[5] 
        $CurrentVersiondate = $CurrentVersion[0]  & $CurrentVersion[1]  & $CurrentVersion[2] & $CurrentVersion[3] & $CurrentVersion[4] & $CurrentVersion[5]
        If Not FileExists($PathtoFile) Then
            MsgBox(262160, "ERROR", "File no longer exists!")
            CreatePathGet()
        EndIf
        If $UpdateVersiondate > $CurrentVersiondate Then 
        $UpdateNowBox = MsgBox(4, "Alert", "There is an update available." & @CRLF & "Would you like to run update now?",5)
        If $UpdateNowBox = 6 Then ShellExecute("ProgramUpdater.exe")
        EndIf
    EndIf
EndFunc   ;==>CheckUpdate 

;----Create Path to get Super Launch update from----
Func CreatePathGet()
    $UpdatePath = "X:\PATH TO YOUR UPDATE FILE\"
    $PathtoFile = FileOpenDialog("Please Select your YourProgram.exe", @ScriptDir, "Executables (*.exe)", 1, "YourProgram.exe")
    If @error Then
        MsgBox(262160, "ERROR", "No file Selected")
        Exit
    EndIf
    $PathtoUpdate = FileOpenDialog("Please Select the update file.", $UpdatePath, "Executables (*.exe)", 1, "YourProgram.exe")
    If @error Then
        MsgBox(262160, "ERROR", "No file Selected")
        Exit
    EndIf
    IniWrite($File_Location, "ProgramUpdate", "PathToFile", $PathtoFile)
    IniWrite($File_Location, "ProgramUpdate", "PathToUpdate", $PathtoUpdate)
EndFunc   ;==>CreatePath
Edited by Klexen
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...