Jump to content

Users are having problems with my update feature


Go to solution Solved by corz,

Recommended Posts

Do ; Updater
    $VersionCheckNew = "http://www.mediafire.com/download/g2e5ca2d4as5/versioncheck.ini"
    $VersionCheckOld = IniRead(@ScriptDir & "\Resources\version.ini", "Version", "Version", "NotFound")
    $DownloadLinkExe = "http://www.mediafire.com/download/061fr792s1eik/MyProgram.exe"
    $DownloadLinkChangelog = "http://www.mediafire.com/download/7znvaxbbodli8/changelog.txt"
    $DownloadLinkReadme = "http://www.mediafire.com/download/gdy45bngjxt3l/readme.txt"
    $newVersion = "0.0.0"
    $ini = InetGet($VersionCheckNew, @ScriptDir & '\Resources\versioncheck.ini') ; dl new ini

    If $ini = 0 Then ;if version is incorrect
        MsgBox(0, "Error", "Something went wrong while checking for updates.")
        $x = 2
        FileDelete(@ScriptDir & "\Resources\versioncheck.ini")
    Else ; check if update is even needed
        $newVersion = IniRead(@ScriptDir & "\Resources\versioncheck.ini", "Version", "Version", "")
        If $newVersion = $VersionCheckOld Then
            FileDelete(@ScriptDir & "\Resources\versioncheck.ini")
            $x = 2
        Else ; If needed ask user if they want to update
            $MsgNewUpdate = MsgBox(4, "Update Avaible", "There is a new update avaible. Do you wish to automaticly download it?")
            If $MsgNewUpdate = 7 Then ; If no
                FileDelete(@ScriptDir & "\Resources\versioncheck.ini")
                $x = 2
            ElseIf $MsgNewUpdate = 6 Then ; If yes
                $DlHandleExe = InetGet($DownloadLinkExe, @ScriptDir & "\MyProgram.exe", 1, 1)
                $DlChangelog = InetGet($DownloadLinkChangelog, @ScriptDir & "\changelog.txt", 1, 1)
                $DlReadme = InetGet($DownloadLinkReadme, @ScriptDir & "\readme.txt", 1, 1)

                ProgressOn("Updating", "Update in progress", "", -1, -1, 16) ; progressbar
                $DownloadSize = InetGetSize($DownloadLinkExe, 1)
                While Not InetGetInfo($DlHandleExe, 2)
                    $PercentDone = (InetGetInfo($DlHandleExe, 0) / $DownloadSize) * 100
                    ProgressSet($PercentDone, $PercentDone & " percent")
                    Sleep(1)
                WEnd
                ProgressSet(100, "Done", "Update Completed")
                Sleep(500)
                ProgressOff()
                IniWrite(@ScriptDir & "\Resources\version.ini", "Version", "Version", $newVersion) ; Write new version in
                InetClose($DlHandleExe)
                MsgBox(-1, "Success", "Download Completed. Program is exiting. Please relaunch!")
                FileDelete(@ScriptDir & "\Resources\versioncheck.ini")
                Exit
            EndIf
            FileDelete(@ScriptDir & "MyProgram.exe")
        EndIf
    EndIf
    $x = 2
Until $x = 2

It seems like its not the actual file getting dowloaded..

I wanted to give the new download a new name then delete the current script.. but i guess I can't do that while downloading.

I thought about just adding the version of the program at the end of the name, but that doesnt look good, and then there would still be 2 .exe's

any ideas?

Edited by Srex
Link to comment
Share on other sites

It is possible to rename and delete the current running script?

im thinking about doing this:

rename to  "MyProgramOld.exe" -> download "MyProgram.exe" -> close "MyProgramOld.exe" and launch "MyProgram.exe" (basicly an instant relaunch) -> delete "MyProgramOld.exe"  thats what i need.

or if I could make it overwrite 100% so if i have deleted lines that they will also get deleted.

I think the reason it doesnt do this is because the program is running whilst trying to update itself, can I start the update in between the relaunch?

Edited by Srex
Link to comment
Share on other sites

  • Solution

That's slightly trickier..

func ReLaunchUpdatedApp()
    $cmd = 'ping 192.0.0.0 -n 1 -w 2000 > nul' & @CRLF
    $cmd &= 'cd ' & @ScriptDir & @CRLF
    $cmd &= 'del my-app.exe' & @CRLF
    $cmd &= 'ren my-app-new.exe my-app.exe' & @CRLF
    $cmd &= 'start /d "' & @ScriptDir & '" my-app.exe' & @CRLF
    FileWrite(@TempDir & "\relaunch.cmd", $cmd)
    Run(@TempDir & "\relaunch.cmd", @ScriptDir, @SW_HIDE)
    exit
    ; don't forget to clean up the temp file at the start of your script!
endfunc

btw, the ping command is simply a two second pause, in case your app takes a moment to shut down.

;o) Cor

[edit]spelling![/edit]

Edited by corz

nothing is foolproof to the sufficiently talented fool..

Link to comment
Share on other sites

That's slightly trickier..

func ReLaunchUpdatedApp()
    $cmd = 'ping 192.0.0.0 -n 1 -w 2000 > nul' & @CRLF
    $cmd &= 'cd ' & @ScriptDir & @CRLF
    $cmd &= 'del my-app.exe' & @CRLF
    $cmd &= 'ren my-app-new.exe my-app.exe' & @CRLF
    $cmd &= 'start /d "' & @ScriptDir & '" my-app.exe' & @CRLF
    FileWrite(@TempDir & "\relaunch.cmd", $cmd)
    Run(@TempDir & "\relaunch.cmd", @ScriptDir, @SW_HIDE)
    exit
    ; don't forget to clean up the temp file at the start of your script!
endfunc

btw, the ping command is simply a two second pause, in case your app takes a moment to shut down.

;o) Cor

[edit]spelling![/edit]

 

Thats sweet, for now i made a seperate file, I will save this thread and go back and rewrite when all major bugs has been defeated.

;D Thanks dude

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...