Jump to content

Check for Updates msgbox problem


Recommended Posts

Ok guys here my code

;cs---------------------------------------------------------------------------------------------------------------------------------#
;//Student manager project - Auto Updates
;Author : Nguy?n Huy Tru?ng
;Yahoo Address : nht3004@yahoo.com
;Do not make illegal copy!
;#ce---------------------------------------------------------------------------------------------------------------------------------#

#include <checkconfig.au3>
#include <GuiEdit.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <String.au3>
#include <Array.au3>
#include <File.au3>

;########################################## These are some basic script to use ###############################################

Func getValue($url)
    $fileDownloadable=InetGet($url, @ScriptDir&"\"&$dataFileName);
    If($fileDownloadable==1) Then
    $returnValue=FileRead(@ScriptDir&"\"&$dataFileName);
    Return $returnValue;
    ElseIf($fileDownloadable==0) Then
    Return -1;
    EndIf
EndFunc

Func alert($txt)
    MsgBox(0, $alertTitle, $txt);
EndFunc

Func readReg($regKey, $regName)
    Return RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\D2AI\"&$regKey,$regName);
EndFunc
   
Func writeReg($regKey, $regName, $regValue)
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\D2AI\"&$regKey,$regName,"REG_SZ",$regValue);
EndFunc

Func deleteReg($regKey, $regValue)
    RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\D2AI\"&$regKey,$regValue);
EndFunc

Func progressBy($IDOfProgressBar, $valueToProgressBy)
    $aimValue=Execute($currentProgress+$valueToProgressBy);
    If($aimValue>=100) Then
        GUICtrlSetData($IDOfProgressBar,100);
    Else
        While $currentProgress<$aimValue
            GUICtrlSetData($IDOfProgressBar,Execute($currentProgress+$percentPerUp));
            $currentProgress+=$percentPerUp;
            Sleep($speedOfUpdate);
        WEnd
    EndIf
    $currentProgress=$aimValue;
EndFunc

Func progressTo($IDOfProgressBar,$valueToProgressTo)
    If($valueToProgressTo>=100) Then
        GUICtrlSetData($IDOfProgressBar,100);
    Else
        While $currentProgress<$valueToProgressTo
            GUICtrlSetData($IDOfProgressBar,Execute($currentProgress+$percentPerUp));
            $currentProgress+=$percentPerUp;
            Sleep($speedOfUpdate);
        WEnd
    EndIf
    $currentProgress=$valueToProgressTo;
EndFunc

Func downloadFile($fileDownloadLink, $fileDownloadName)
   
    Global $downloadProgress;

    $progressForm=GUICreate("Downloading updates...", 220, 50, 0, 0);
    $downloadProgress=GUICtrlCreateProgress(10, 10, 200, 20);
    GUICtrlSetColor(-1, 32250);
    GUISetState(@SW_SHOW);
    
    $downloadFileSize=InetGetSize($fileDownloadLink);
    $isDownloaded=InetGet($fileDownloadLink, $fileDownloadName, "", 1);
   
    While @InetGetBytesRead<$downloadFileSize;
        progressTo($downloadProgress, @InetGetBytesRead/$downloadFileSize*100);
    WEnd
   
    GUIDelete($progressForm);Aftet delete progressForm, plz set $currentProgress to 0;
    $currentProgress=0;
   
    Return $isDownloaded;
EndFunc

Func sizeOf($arrayName)
    SetError(0);
    $index=0;
    Do
        $pop=_ArrayPop($arrayName);
        $index+=1;
    Until @error=1;
    Return $index-1;
EndFunc

Func encode($txt, $pass, $lvl)
    Return _StringEncrypt(1, BinaryToString(StringToBinary($txt, $Flag_UTF8), $Flag_ANSI), $pass, $lvl);
EndFunc

Func decode($txt, $pass, $lvl)
    Return BinaryToString(StringToBinary(_StringEncrypt(0, $txt, $pass, $lvl), $Flag_ANSI), $Flag_UTF8);
EndFunc

;########################################## End basic script programmed ######################################################
Func Msg()
            $downloadConfirm=msgbox(1, "New Update!", "The new version : "&$newVersion&" available."&@LF&"New features include: "&@LF&$newFeatures&@LF&"Do you want to download?")
WinActivate("New Update!")
            If($downloadConfirm==1) Then
                sleep(2500)
                $downloadable=downloadFile($fileLink, $fileName);
                $downloadable=downloadFile($configLink, $configname);
                $downloadable=downloadFile($updateLink, $updatename);
                writeReg("PM","Version",$newVersion);
                If($downloadable==0) Then
                ToolTip("Cannot download updates, please try again later! The server may be down or your firewall is blocking it. Please manually download.",10,10,"Updater",1,1)
            EndIf
            If($downloadable==1) Then
                    writeReg("PM","Version",$newVersion);
                    If $RunConfiguration = 1 Then
                    Run($configName);
Else
                ToolTip("D2AI sucessfully updated and no new configuration changes were needed. Go ahead and start the bot.",10,10,"Updater",1,1)
                sleep(10000)
                Exit
                EndIf
                EndIf
            EndIf
            endfunc

;****************************************** Start main script of project *****************************************************
;-------------------------------------------------Create a progress bar---------------------------------------------------

Global $updateProgress

$progressForm=GUICreate("Checking for D2Ai Updates!", 530, 50, 0, 0);
$updateProgress=GUICtrlCreateProgress(10, 10, 500, 20);
GUICtrlSetColor(-1, 32250);
GUISetState(@SW_SHOW);

;-------------------------------------------------Get new and old Version-------------------------------------------------

$newVersion=getValue($linkCheckVersion);After getValue(), plz delete the file downloaded!
progressBy($updateProgress,$percentPerAction)
FileDelete(@ScriptDir&"\"&$dataFileName);

If Not($newVersion==-1) Then
    progressBy($updateProgress,$percentPerAction);
    $currentVersion=readReg("PM","Version");
    progressBy($updateProgress,$percentPerAction);
    $fileLink=getValue($linkCheckFileUrl);After getValue(), plz delete the file downloaded!
    progressBy($updateProgress,$percentPerAction);
    $configLink=getValue($linkCheckconfigFileUrl);After getValue(), plz delete the file downloaded!
    progressBy($updateProgress,$percentPerAction);
    $UpdateLink=getValue($linkCheckupdaterurl);After getValue(), plz delete the file downloaded!
    $RunConfiguration=getValue($configlinkCheckVersion);After getValue(), plz delete the file downloaded!
    progressBy($updateProgress,$percentPerAction);
    FileDelete(@ScriptDir&"\"&$dataFileName);
    $newFeatures=getValue($linkCheckNewFeatures);After getValue(), plz delete the file downloaded!
    progressBy($updateProgress,$percentPerAction);
    FileDelete(@ScriptDir&"\"&$dataFileName);
    progressBy($updateProgress,$percentPerAction);

;-------------------------------------------------Start check for updates-------------------------------------------------

    GUIDelete($progressForm);Aftet delete progressForm, plz set $currentProgress to 0;
    $currentProgress=0;
   
    If($currentVersion=="") Then
        writeReg("SM","Version",$projectVersion);
    Else
        If(Execute($newVersion)>Execute($currentVersion)) Then
            Msg()
        EndIf
    EndIf
;-------------------------------------------------End updates check-------------------------------------------------------
Else
        ToolTip("D2AI is current, no updates released.",10,10,"Updater",1,1)
    progressTo($updateProgress,100);
    GUIDelete($progressForm);
EndIf

;****************************************** End script of this project *******************************************************

This is a opensource example of someone's.

So my problem is where i get to Func MSG()

It shows the MSGBOX of conformation, then it immedietly minimizes.

Does anyone know why?

Link to comment
Share on other sites

well did start to have a quick look 4 ya but after

#include <checkconfig.au3> :-i duno what this UDF is ?

$dataFileName :- variable not set ?

$alertTitle :- variable not set ?

& loads more syntax check problems.

i kinda gave up, also although its prob works fine it looks odd to me having the beginning of the script at the bottom ^_^

but nothing wrong with the MSGBOX in Func Msg() , its a OK Cancel box and stays there until you click on one of the buttons on it (as long as the variables are set) i duno about "minimizing immediately" ?

Edited by JackDinn

Thx all,Jack Dinn.

 

JD's Auto Internet Speed Tester

JD's Clip Catch (With Screen Shot Helper)

Projects :- AutoIt - My projects

My software never has bugs. It just develops random features. :-D

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