NDog Posted January 27, 2009 Share Posted January 27, 2009 I am trying to improve myself at autoit language and syntax. I am trying something new. I have a base folder which has software organised into subfolders, and I want these to be copied to another drive in a structured folder way. I have created a ini file which I want the script to read the values and then use that in the script. The ini is divided into section headers [example] this is the name of the app I have designated it I want the GUI to detect which operating system the host is running or provide a choice to the user, so it will only copy the files that will run on it. This is the approach I though best. For example if there are 2 versions of a software, the current version and an older version that is supported on eg windows 98 i would use this form [PICASA_NEW] NAME=Picasa BIT=32 OS_2K=yes OS_XP=yes OS_2K3=yes OS_Vista=yes OS_2K8=yes TYPE=Graphics SOURCE=Picasa\9x [PICASA_OLD] NAME=Picasa BIT=32 OS_95=yes OS_98=yes OS_ME=yes TYPE=Graphics SOURCE=Picasa\xp A lot of the code I have reused, parts are from the DcoTmenu, I partially understand it, but not that much. At the moment the priority is to tighten the code. I cant understand how i can use multiple if condition = true ifnextcondition = true etc. Also should I create an array for all the OS'es I am using? which method do you recommend? Sorry if this should be in the GUI forum, but I think it is more related to code-behind than GUI stuff at the moment thanks image.ini expandcollapse popup[directx_nov2008_redist] NAME=DirectX 9.0c (Nov 08) BIT=32 HTTP=http://www.filehippo.com/download_directx/ TYPE=System SOURCE=DX\directx_nov2008_redist SUBTYPE=directx_nov2008_redist [LIBRARYFILES] NAME=Library Files BIT=32 TYPE=System SOURCE=libraryfiles SUBTYPE= [VB6RUNTIMES] NAME=VB Runtimes 6 SP 6 BIT=32 TYPE=System SOURCE=vb SUBTYPE= [DOTNET2] NAME=.NET Framework Version 2.0 SP1 BIT=32 OS_XP=yes OS_2K3=yes TYPE=System SOURCE=dot NET\2 SUBTYPE= [JAVA] NAME=Java Runtime Environment BIT=32 HTTP=http://www.filehippo.com/download_java_runt ime/ TYPE=System SUBTYPE=Library SOURCE=java SUBTYPE= script.au3 expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.2.12.1 Author: NDog Script Function: Parse update.ini a) read ini contents [directx_nov2008_redist] <- Section Seperator NAME=DirectX 9.0c (Nov 08) <- get NAME and show in Menu BIT=32 <- use BIT in filter HTTP=http://www.filehippo.com/download_directx/ OS_95=yes OS_98=yes OS_ME=yes OS_2K=yes <- Use OS Values in filter OS_XP=yes OS_2K3=yes OS_Vista=yes TYPE=System <- Use Type as directory store SOURCE=DX\directx_nov2008_redist <- Source is source subdir of type SUBTYPE=directx_nov2008_redist <- Subtype is destination subdir of type #ce ---------------------------------------------------------------------------- HotKeySet("{ESC}", "MyExit") Func MyExit() Exit EndFunc #include <Array.au3> #Include <Constants.au3> #include <GUIConstants.au3> Opt("TrayMenuMode",1) $ini = "image.ini" Dim $DriveLetter = StringLeft(@ScriptDir,2) ;gets drive letter of current drive Dim $AppListFile = @ScriptDir & "\" & $ini ;reads ini file in CWD Dim $AppList ;retrieves ini headers sections eg [DX] Dim $AppItem[1] ;array of apps Dim $AppCounter ;LIST temporary string for parsing Dim $NAME ;under NAME in INI (used) Dim $BIT Dim $HTTP Dim $OS_95 Dim $OS_98 Dim $OS_ME Dim $OS_NT4 Dim $OS_2K Dim $OS_XP Dim $OS_2K3 Dim $OS_Vista DIM $OS_2K8 Dim $TYPE Dim $SOURCE Dim $SUBTYPE Dim $MenuItem[1] ;menu item name (x) Dim $AppSectionName ;LIST ini header section name (retrieved after parsing AppList) ; Read contents of ini file and retrieve head values $AppList = IniReadSectionNames($AppListFile) If @error Then MsgBox(4096, "", "Error occurred, probably no INI file.") Exit EndIf ; Show contents of the array ;_ArrayDisplay($AppList , "ini head values") Dim $OS = @OSVersion; OS Version Switch $OS; A Switch statement. We are going to make the value returned by @OSVERSION more readable. Case "WIN_2008" $OS = "Windows Server 2008" Case "WIN_VISTA" $OS = "Windows Vista" Case "WIN_2003" $OS = "Windows Server 2003" Case "WIN_XP" $OS = "Windows XP" Case "WIN_2000" $OS = "Windows 2000" Case "WIN_NT4" $OS = "Windows NT 4.0" Case "WIN_ME" $OS = "Windows ME" Case "WIN_98" $OS = "Windows 98" Case "WIN_95" $OS = "Windows 95" Case Else $OS = "Unknown!" EndSwitch ;MsgBox(0, "Computer Infomation", $OS) ;Create GUI #include <GUIConstants.au3> #Region ### START Koda GUI section ### Form=g:\ns3\assembly\scripting\autoit\koda_2007-12-15\forms\update_xp.kxf $Form1_1 = GUICreate("Update", 217, 169, 258, 149) $Combo1 = GUICtrlCreateCombo("", 8, 24, 145, 25) GUICtrlSetData(-1, "Windows 95|Windows 98|Windows ME|Windows NT 4.0|Windows 2000|Windows XP|Windows Server 2003|Windows Vista|Windows Server 2008", $OS) $Label1 = GUICtrlCreateLabel("Selected Operating System", 8, 8, 132, 17) $button_image = GUICtrlCreateButton("D:\Image\Software", 8, 80, 75, 25, 0) $button_wpiw = GUICtrlCreateButton("E:\WPI\Install", 8, 112, 75, 25, 0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### ;=================================================== ; GUI MESSAGE LOOP While 1 $msg = GUIGetMsg() Select Case $msg = $button_image ;MsgBox(0, "Button Event", "You clicked D:\Image button") ;MsgBox(0, "Selected listbox entry", GUICtrlRead($combo1)) $OS = GUICtrlRead($combo1) CopyList() Case $msg = $button_wpiw MsgBox(0, "Combo Event", "You clicked WPIW button") Case $msg = $GUI_EVENT_CLOSE ;MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting...") GUIDelete("Update") ExitLoop EndSelect WEnd Func CopyList() ; Creates AppItems Array and gets numbers of items in ini file sections ReDim $AppItem[$AppList[0]+1] For $AppCounter = 1 To $AppList[0] $AppSectionName = $AppList[$AppCounter] $NAME = IniRead($AppListFile,$AppSectionName,"NAME","") $BIT = IniRead($AppListFile,$AppSectionName,"BIT","") $HTTP = IniRead($AppListFile,$AppSectionName,"HTTP","") $OS_95 = IniRead($AppListFile,$AppSectionName,"OS_95","") $OS_98 = IniRead($AppListFile,$AppSectionName,"OS_98","") $OS_ME = IniRead($AppListFile,$AppSectionName,"OS_ME","") $OS_NT4 = IniRead($AppListFile,$AppSectionName,"OS_NT4","") $OS_2K = IniRead($AppListFile,$AppSectionName,"OS_2K","") $OS_XP = IniRead($AppListFile,$AppSectionName,"OS_XP","") $OS_2K3 = IniRead($AppListFile,$AppSectionName,"OS_2K3","") $OS_Vista = IniRead($AppListFile,$AppSectionName,"OS_Vista","") $OS_2K8 = IniRead($AppListFile,$AppSectionName,"OS_2K8","") $TYPE = IniRead($AppListFile,$AppSectionName,"TYPE","") $SOURCE = IniRead($AppListFile,$AppSectionName,"SOURCE","") $SUBTYPE = IniRead($AppListFile,$AppSectionName,"SUBTYPE","") If $OS_95 == "" Then If $OS_98 == "" Then If $OS_ME == "" Then If $OS_NT4 == "" Then If $OS_2K == "" Then If $OS_XP == "" Then If $OS_2K3 == "" Then If $OS_VISTA == "" Then If $OS_2K8 == "" Then ;MsgBox(0,"TITLE",$Name & " \\ will work on all OS'es") ItemToList() EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndIf If $OS == "Windows XP" Then If $OS_XP == "yes" Then ;MsgBox(1,"",$Name & " is Windows XP Item") ItemToList() EndIf EndIf Next EndFunc Func ItemToList() $AppItem[$AppCounter] = TrayCreateItem($NAME) ;MsgBox(1,"",$Name & " is added to list") DirCopy(@ScriptDir & "\" & $TYPE & "\" & $SOURCE , "D:\Image\Software" & "\" & $TYPE & "\" & $SUBTYPE , 0) MsgBox(1, "", "Copied" & @CRLF & @ScriptDir & "\" & $TYPE & "\" & $SOURCE & @CRLF & "D:\Image\Software" & "\" & $TYPE & "\" & $SUBTYPE , 0) EndFunc Link to comment Share on other sites More sharing options...
bo8ster Posted January 27, 2009 Share Posted January 27, 2009 (edited) Thanks for posting the code - helpful Have you tried using the IN statement with the for loop? Also if you are trying to tighten up code, don't use Dim, use Global or Local within functions. for CopyList() I see your issue. Try something like this, I assume that only one of the conditions are going to be true. Global $aOS[15] = ["NAME", "BIT", "HTTP", "and so on"] Global $ini_os = "" Func CopyList() Local $i = 0 ;your stuff here While $ini_os = "" $ini_os = IniRead($AppListFile, $AppSectionName, $aOS[$i], "") $i = $i + 1 WEnd MsgBox(0, "OS from INI", $$ini_os) EndFunc ;==>CopyList Edited January 27, 2009 by bo8ster Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic] 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