madasraka Posted April 18, 2010 Share Posted April 18, 2010 (edited) Can someone tell me what would possibly make this function to repeat its self when its completed ? Function is called from 1st script as While 1 $nMsg = GUIGetMsg() Switch $nMsg case $Backup $ReadMaterialLibrary = GUICtrlRead ($MaterialLibrary) If $ReadMaterialLibrary = $GUI_CHECKED Then BackupMaterialLibrary() MsgBox(0,'','Loader backup function completed.') ;why does it get back to BackupMaterialLibrary() after this msgbox ???????? EndIf EndSwitch WEnd And here is the function its self located inseparate .au3 file which is included in main script. expandcollapse popupGlobal $OSbit, $progress,$Edit ;Refferenced from main script Func BackupMaterialLibrary() $Backup = (@ScriptDir & "\Saved\MaterialLibrary") DirCreate ($Backup) If $OSbit = "X64" Then $MaterialLibraryPath = (@HomeDrive & "\Program Files (x86)\Common Files\Autodesk Shared\Materials2011") $CMD = Run (@ComSpec & ' /c xcopy /E/D/Y/H/R/C "' & $MaterialLibraryPath & '" "' & $Backup & '"') $Size = DirGetSize ($MaterialLibraryPath) For $i = 1 to $Size step 1 $GetBackupSize = DirGetSize ($Backup) $RoundResult = Round ($GetBackupSize*100/$Size) GUICtrlSetData ($progress,$RoundResult) GUICtrlSetData ($Edit,"Saving/Updating Material library" & @CRLF & Round($GetBackupSize / 1024 / 1024) & "MB out of " & Round($size / 1024 / 1024) & "MB copied. Done" & $RoundResult & "%") If $RoundResult = 100 Then Msgbox(0,"","Copy 100% Done") ExitLoop ElseIf $RoundResult < 100 Then $CheckCMDRunStatus = ProcessExists ($CMD) If $CheckCMDRunStatus = 0 Then MsgBox(0,'','CMD exited, Exiting loop') ExitLoop ElseIf $CheckCMDRunStatus > 0 Then ;ContinueLoop EndIf EndIf Next ElseIf $OSbit = "X86" Then $MaterialLibraryPath = (@HomeDrive & "\Program Files\Common Files\Autodesk Shared\Materials2011") $CMD = Run (@ComSpec & ' /c xcopy /E/D/Y/H/R/C "' & $MaterialLibraryPath & '" "' & $Backup & '"') For $i = 1 to $Size step 1 $GetBackupSize = DirGetSize ($Backup) $RoundResult = Round ($GetBackupSize*100/$Size) GUICtrlSetData ($progress,$RoundResult) GUICtrlSetData ($Edit,"Saving/Updating Material library" & @CRLF & Round($GetBackupSize / 1024 / 1024) & "MB out of " & Round($size / 1024 / 1024) & "MB copied. Done" & $RoundResult & "%") If $RoundResult = 100 Then Msgbox(0,"","Copy 100% Done") ExitLoop ElseIf $RoundResult < 100 Then $CheckCMDRunStatus = ProcessExists ($CMD) If $CheckCMDRunStatus = 0 Then MsgBox(0,'','CMD exited, Exiting loop') ExitLoop ElseIf $CheckCMDRunStatus > 0 Then ;ContinueLoop EndIf EndIf Next EndIf EndFunc I just cant find the answer. I am confused. Edited April 18, 2010 by madasraka Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted April 18, 2010 Share Posted April 18, 2010 (edited) I can't see anything in the function that causes it to recurse. You're probably looping the If $Var = $GUI_CHECKED Then BackupMaterialLibrary() Endif in the wrong way, but unless you post more code (or a reproducer, short and runnable) we can't really know that Edit: I posted while you edited , but we still don't know what $Backup and $Var is! Edit2: ... If $MaterialLibrary is a CheckBox then read the helpfile again, you shouldn't check if it's checked like that. Edited April 18, 2010 by AdmiralAlkex .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
jchd Posted April 18, 2010 Share Posted April 18, 2010 ... and, as you've observed (your edit shows so) the ContinueLoop isn't guilty. It isn't even necessary, just as you see, and the ElseIf where it was isn't either. These are No-Ops in your code. Now lacking outer code like AdmiralAlex said, it's hard to tell. Is it recursing or called in sequence? This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
madasraka Posted April 18, 2010 Author Share Posted April 18, 2010 (edited) Sorry guys i should have posted it but didnt because it was kinda (if not big) to many lines to look at. Well, here it is expandcollapse popup#NoTrayIcon #RequireAdmin #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_icon=icon.ico #AutoIt3Wrapper_outfile=../3DsMax_2011 Loader.exe #AutoIt3Wrapper_Compression=4 #AutoIt3Wrapper_Res_Comment=comments #AutoIt3Wrapper_Res_Description=description #AutoIt3Wrapper_Res_Fileversion=0.0.0.0 #AutoIt3Wrapper_Res_LegalCopyright=copyright #AutoIt3Wrapper_Res_Language=1033 #AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator #AutoIt3Wrapper_Res_Icon_Add=F:\Danger\Savers fixers\Programs\3dsmax2011_licencebackup\Source\folder.ico #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <Constants.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <WindowsConstants.au3> #include <buttonrestore.au3> #include <buttonbackup.au3> #include <buttonstart.au3> #include <buttonshortcut.au3> #include <service version check.au3> #include <RestoreLicense.au3> #include <RestoreLicenseService.au3> #include <RestoreSettings.au3> #include <RestoreMaterialLibrary.au3> #include <RestoreBackBurner.au3> #include <BackupLicense.au3> #include <BackupLicenseService.au3> #include <BackupSettings.au3> #include <BackupMaterialLibrary.au3> #include <BackupBackBurner.au3> ;DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "int", 1) Opt("TrayOnEventMode",1) Opt("TrayMenuMode",1) $settingsitem = TrayCreateMenu("Max Priority") TrayCreateItem("Low",$settingsitem,"",1) TrayItemSetOnEvent(-1,"PriorityLow") ;About is the function name TrayCreateItem("Normal",$settingsitem) TrayItemSetOnEvent(-1,"PriorityNormal") ;About is the function name TrayCreateItem("HIgh",$settingsitem) TrayItemSetOnEvent(-1,"PriorityHIgh") ;About is the function name TrayCreateItem("About") TrayItemSetOnEvent(-1,"AboutFunction") ;About is the function name TrayCreateItem("Exit") TrayItemSetOnEvent(-1,"ExitFunction") ;About is the function name TraySetState() IsAdmin ( ) $3DS_Bit32 = FileExists (@ScriptDir & "\Saved\Vista\User\AppData\Local\Autodesk\3dsmax\2011 - 32bit") $3DS_Bit64 = FileExists (@ScriptDir & "\Saved\Vista\User\AppData\Local\Autodesk\3dsmax\2011 - 64bit") $OS = @OSVersion $OSbit = @OSArch FileInstall ("instsrv.exe",@TempDir & "\instsrv.exe",1) FileInstall ("icon.ico",@TempDir & "\icon.ico",1) TraySetIcon (@TempDir & "\icon.ico",1) $Form1 = GUICreate("Max Loader",260,400) $progress = GUICtrlCreateProgress(0,120,260,20) $Backup = GUICtrlCreateButton ("BACKUP",0,0,60,40) GUICtrlSetTip ($Backup, "Save's 3dsmax license/registration/activation/settings") $Restore = GUICtrlCreateButton ("RESTORE",200,0,60,40) GUICtrlSetTip ($Restore, "Restore's 3dsmax license/registration/activation/settings") $Run = GUICtrlCreateButton ("START 3DS MAX",0,40,260,40) GUICtrlSetTip ($Run, "Run's 3dsmax") $Shortcut = GUICtrlCreateButton ("Create Desktop Shortcut",0,80,260,40) GUICtrlSetTip ($Shortcut, "Create's shorctut to 3dsmax.exe on your Desktop") GUICtrlCreateGroup ("Components to Save and/or Restore",5,140,250,70) $License = GUICtrlCreateCheckbox ("License",10,160) $LicenseService = GUICtrlCreateCheckbox ("License Service",10,180) $Settings = GUICtrlCreateCheckbox ("Setting's",90,160) $MaterialLibrary = GUICtrlCreateCheckbox ("Material library",160,160) $BackBurner = GUICtrlCreateCheckbox ("BackBurner",160,180) GUICtrlCreateGroup ("Log",5,220,250,160) $Edit = GUICtrlCreateEdit ("",10,240,240,130) Global $OSbit, $progress #Region ifs if $OS = "WIN_XP" And $OSbit = "X86" and $3DS_Bit32 = 1 Then $osinfo = GUICtrlCreateLabel ("Windows XP 32bit",60,0) $maxinfo = GUICtrlCreateLabel ("3DS MAX 2010 32bit",60,16) Elseif $OS = "WIN_XP" And $OSbit = "X64" and $3DS_Bit32 = 1 Then $osinfo = GUICtrlCreateLabel ("Windows XP 64bit",60,0) $maxinfo = GUICtrlCreateLabel ("3DS MAX 2010 32bit",60,16) Elseif $OS = "WIN_XP" And $OSbit = "X86" and $3DS_Bit64 = 1 Then $osinfo = GUICtrlCreateLabel ("Max will not work",60,0) Elseif $OS = "WIN_XP" And $OSbit = "X64" and $3DS_Bit64 = 1 Then $osinfo = GUICtrlCreateLabel ("Windows XP 64bit",60,0) $maxinfo = GUICtrlCreateLabel ("3DS MAX 2010 64bit",60,16) ;7 Elseif $OS = "WIN_7" And $OSbit = "X86" and $3DS_Bit32 = 1 Then $osinfo = GUICtrlCreateLabel ("Windows 7 32bit",60,0) $maxinfo = GUICtrlCreateLabel ("3DS MAX 2010 32bit",60,16) Elseif $OS = "WIN_7" And $OSbit = "X64" and $3DS_Bit32 = 1 Then $osinfo = GUICtrlCreateLabel ("Windows 7 64bit",60,0) $maxinfo = GUICtrlCreateLabel ("3DS MAX 2010 32bit",60,16) Elseif $OS = "WIN_7" And $OSbit = "X86" and $3DS_Bit64 = 1 Then $osinfo = GUICtrlCreateLabel ("Max will not work",60,0) Elseif $OS = "WIN_7" And $OSbit = "X64" and $3DS_Bit64 = 1 Then $osinfo = GUICtrlCreateLabel ("Windows 7 64bit",60,0) $maxinfo = GUICtrlCreateLabel ("3DS MAX 2010 64bit",60,16) ;Vista Elseif $OS = "WIN_Vista" And $OSbit = "X86" and $3DS_Bit32 = 1 Then $osinfo = GUICtrlCreateLabel ("Windows Vista 32bit",60,0) $maxinfo = GUICtrlCreateLabel ("3DS MAX 2010 32bit",60,16) Elseif $OS = "WIN_Vista" And $OSbit = "X64" and $3DS_Bit32 = 1 Then $osinfo = GUICtrlCreateLabel ("Windows Vista 64bit",60,0) $maxinfo = GUICtrlCreateLabel ("3DS MAX 2010 32bit",60,16) Elseif $OS = "WIN_Vista" And $OSbit = "X86" and $3DS_Bit64 = 1 Then $osinfo = GUICtrlCreateLabel ("Max will not work",60,0) Elseif $OS = "WIN_Vista" And $OSbit = "X64" and $3DS_Bit64 = 1 Then $osinfo = GUICtrlCreateLabel ("Windows Vista 64bit",60,0) $maxinfo = GUICtrlCreateLabel ("3DS MAX 2010 64bit",60,16) Else $osinfo = GUICtrlCreateLabel (" Place loader into" & @CRLF & " 3DS MAX Root",60,0) EndIf #EndRegion ifs serviceversion() ;check for service version GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg case $Backup GUISetState(@SW_LOCK,$Form1) $ReadLicense = GUICtrlRead ($License) $ReadLicenseService = GUICtrlRead ($LicenseService) $ReadSettings = GUICtrlRead ($Settings) $ReadMaterialLibrary = GUICtrlRead ($MaterialLibrary) $ReadBackBurner = GUICtrlRead ($BackBurner) If $ReadLicense = $GUI_CHECKED Then BackupLicense() EndIf If $ReadLicenseService = $GUI_CHECKED Then BackupLicenseService() EndIf If $ReadSettings = $GUI_CHECKED Then BackupSettings() EndIf If $ReadMaterialLibrary = $GUI_CHECKED Then BackupMaterialLibrary() MsgBox(0,'','Loader backup function completed.') EndIf If $ReadBackBurner = $GUI_CHECKED Then BackupBackBurner() EndIf GUISetState(@SW_UNLOCK,$Form1) case $Restore GUISetState(@SW_LOCK,$Form1) $ReadLicense = GUICtrlRead ($License) $ReadLicenseService = GUICtrlRead ($LicenseService) $ReadSettings = GUICtrlRead ($Settings) $ReadMaterialLibrary = GUICtrlRead ($MaterialLibrary) $ReadBackBurner = GUICtrlRead ($BackBurner) If $ReadLicense = $GUI_CHECKED Then RestoreLicense() EndIf If $ReadLicenseService = $GUI_CHECKED Then RestoreLicenseService() EndIf If $ReadSettings = $GUI_CHECKED Then RestoreSettings() EndIf If $ReadMaterialLibrary = $GUI_CHECKED Then RestoreMaterialLibrary() EndIf If $ReadBackBurner = $GUI_CHECKED Then RestoreBackBurner() EndIf GUISetState(@SW_UNLOCK,$Form1) case $Run GUISetState(@SW_HIDE) buttonstart() case $Shortcut shortcut() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func PriorityLow() ProcessSetPriority ( "3dsmax.exe",0) EndFunc Func PriorityNormal() ProcessSetPriority ( "3dsmax.exe",2) EndFunc Func PriorityHIgh() ProcessSetPriority ( "3dsmax.exe",4) EndFunc Func AboutFunction() MsgBox(0,"Information","3ds max 2011 Saver/Fixer V1.0.0") EndFunc Func ExitFunction() $askexit = MsgBox(4,"Question","Close Loader and keep 3ds max running ?") If $askexit = 6 Then Exit ElseIf $askexit = 7 Then EndIf EndFunc As for checkbox: From help file: For Checkbox, Radio control several states can be returned as $GUI_FOCUS and $GUI_CHECKED,. So use i.e. BitAnd(GUICtrlRead($Item),$GUI_CHECKED) to test if the control is checked. thats all i could find helpful. Thank you guys for trying to help. I cant wait to find a solution so i can continue working on rest of functions. I attached full source code so u guys can test it your self. #1 execute 3DsMax_2011 Loader.au3 #2 Check box with material library #3 press Backup button. Once selected (with checkbox )backup function finished it repeats again and i dont understand why it does that. Edit: I simplified main and backup function code to have it working without editing anything. Someone p[lease have a look at those 2 Main.au3BackupMaterialLibrary.au3 Simply press Backup Button and see for your self. It will start copying all program files folder into newly created folder so if u want to stop it, simply close CMD windows. Thanks for help and time spared. Edited April 19, 2010 by madasraka Link to comment Share on other sites More sharing options...
madasraka Posted April 19, 2010 Author Share Posted April 19, 2010 I have simplified code as much as possible and still unable to stop function from repeating its self. expandcollapse popup#RequireAdmin #include <Constants.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <WindowsConstants.au3> $OS = @OSVersion $OSbit = @OSArch $Form1 = GUICreate("Max Loader",260,400) $MaterialLibrary = GUICtrlCreateCheckbox ("Material library",160,15) GUICtrlSetState ($MaterialLibrary,$GUI_CHECKED) $Backup = GUICtrlCreateButton ("Backup",10,140,60,20) $progress = GUICtrlCreateProgress(70,140,120,20) GUICtrlCreateGroup ("Log",5,230,250,160) ;Group $Edit = GUICtrlCreateEdit ("",10,250,240,130) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg case $Backup BackupMaterialLibrary() MsgBox(0,'','backup function completed.') Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func BackupMaterialLibrary() $Backup = (@ScriptDir & "\Saved\MaterialLibrary") DirCreate ($Backup) $MaterialLibraryPath = (@HomeDrive & "\Program Files (x86)\Internet Explorer") $CMD = Run (@ComSpec & ' /c xcopy /E/D/Y/H/R/C "' & $MaterialLibraryPath & '" "' & $Backup & '"') $Size = DirGetSize ($MaterialLibraryPath) For $i = 1 to $Size $GetBackupSize = DirGetSize ($Backup) $RoundResult = Round ($GetBackupSize*100/$Size) If $RoundResult = 100 Then MsgBox(0,'','finished') exitloop EndIf Next EndFunc I think it has something to do with 'For" but i am not very familiar with it and i need help figuring out why BackupMaterialLibrary() is constantly executed after it finished its job once button is pressed. Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted April 19, 2010 Share Posted April 19, 2010 Well now I see it, you have your main-loop check for $Backup, which is the button at the beginning, but then you use the same variable to hold @ScriptDir & "\Saved\MaterialLibrary", so now you basically have: $nMsg = GUIGetMsg() Switch $nMsg case @ScriptDir & "\Saved\MaterialLibrary" And that messes things up quite a bit. Also, I think you should use RunWait() instead of Run() and that weird loop. Something like this: #include <GUIConstantsEx.au3> $Form1 = GUICreate("Max Loader",260,400) $Backup = GUICtrlCreateButton ("Backup",10,140,60,20) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $Backup BackupMaterialLibrary() MsgBox(0,'','backup function completed.') Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func BackupMaterialLibrary() $BackupPath = (@ScriptDir & "\Saved\MaterialLibrary") DirCreate ($BackupPath) $MaterialLibraryPath = (@HomeDrive & "\Program Files (x86)\Internet Explorer") $CMD = RunWait (@ComSpec & ' /c xcopy /E/D/Y/H/R/C "' & $MaterialLibraryPath & '" "' & $BackupPath & '"') MsgBox(0,'','finished') EndFunc .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
jchd Posted April 19, 2010 Share Posted April 19, 2010 (edited) Good catch by Sweden, France was busy elsewhere. Once again, that example demonstrates the usefulness of correct variable declaration and following strict rules for coding: Global Enum, Global Const, Global, Local Enum, Local Const, Local, and of course AutoItSetOption('MustDeclareVars', 1) at top of main file. Edited April 19, 2010 by jchd This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
madasraka Posted April 19, 2010 Author Share Posted April 19, 2010 (edited) Am sorry i dont understand where did you find this line of code ?$nMsg = GUIGetMsg() Switch $nMsg case @ScriptDir & "\Saved\MaterialLibrary"There is no such thing as case @ScriptDir & "\Saved\MaterialLibrary" and that would probably give an error anyway.Instead there is:case $Backup BackupMaterialLibrary() MsgBox(0,'','backup function completed.')Case $Backup is the one triggered by backup button.I still do not see any problem with the code that would make it execute the function again and again.Also i cannot use RunWait because it pause script. I need to to keep going so i can calculate data being saved and output the result to editbox.To compensate i added processexist in same loop to see if executed CMD still running or not.OH OH am sorry i see it now You could just tell me i used variable twice for different needs.Thanks, i should have found it my self or declared it to be local within function. Edited April 19, 2010 by madasraka Link to comment Share on other sites More sharing options...
jchd Posted April 19, 2010 Share Posted April 19, 2010 (edited) Yes it's there !Func BackupMaterialLibrary() $Backup = (@ScriptDir & "\Saved\MaterialLibrary") DirCreate ($Backup)Now, you see. This causes no error (is a valid AutoIt statement) , but since $nMsg is an integer, the Case compares it against Number($Backup) and that evaluates to 0, which I believe is equivalent to "no message" for the message loop.For non trivial scripts, imagine AutoIt requires declarations like Pascal and you'll be safe ;-) Edited April 19, 2010 by jchd This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
madasraka Posted April 19, 2010 Author Share Posted April 19, 2010 thanks man, i learned my lesson, which was "Make sure you dont use same variable twice for different purpose" Or declare. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now