Darkz0r Posted December 23, 2012 Share Posted December 23, 2012 (edited) ; Write version.ini on ScriptDir for testing purposes FileDelete(@ScriptDir & "\version.ini") IniWrite(@ScriptDir & "\version.ini", "1.0", "URL", "http://www.update.com/1.0") ; __________________________________________________________________ IniWrite(@ScriptDir & "\version.ini", "1.1", "URL", "http://www.update.com/1.1") ; __________________________________________________________________ IniWrite(@ScriptDir & "\version.ini", "1.2", "URL", "http://www.update.com/1.2") ; __________________________________________________________________ ; Declare the current version of the Application Local $client_version = "1.0" ; In my actual script, I use FileRead with StringRegExp ; Read the section names Local $SectionNames = IniReadSectionNames(@ScriptDir & "\version.ini") For $a = 1 To $SectionNames[0] ; Creating a loop to get all section names ; Now we read the keys of each Section Local $keys = IniReadSection(@ScriptDir & "\version.ini", $SectionNames[$a]) ; If an error occurred when trying to Read If @error Then MsgBox(4096, "", "Error occurred, probably no INI file.") ; If no error Else ; Creates a loop to get all keys within each section For $i = 1 To $keys[0][0] ; Now show us each section, key and their values MsgBox(4096, "", "Section: " & $SectionNames[$a] & @CRLF _ ; Break line & "Key: " & $keys[$i][0] & @CRLF & "Value: " & $keys[$i][1]) Next EndIf Next So, I'm using "IniReadSectionNames" as you can see to get the sections but how can I get the last section? (Without actually have to set it manually?) I've tried some method already I've been reading, but the more I read, the more confused I get... Any help? Edited December 23, 2012 by Darkz0r Link to comment Share on other sites More sharing options...
somdcomputerguy Posted December 23, 2012 Share Posted December 23, 2012 IniReadSectionNames - The number of elements returned will be in $result[0]. That should answer your question. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
water Posted December 23, 2012 Share Posted December 23, 2012 To read the last section of the returned section list use something like this: $Keys = IniReadSection(@ScriptDir & "\version.ini", $SectionNames[$SectionNames[0]]) My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Darkz0r Posted December 23, 2012 Author Share Posted December 23, 2012 IniReadSectionNames - The number of elements returned will be in $result[0]. That should answer your question. Not really, well let me explain. This script is for an autoupdater project i'm working on, so i'll keep updating the .ini with new versions. There are 3 version currently in that script yes, but that was an example. I need this script to automatically stay up-to-date with the last version, so if I add a newer version (in this case 1.4), I don't have to edit the script to set $result[<number here>] everytime. To read the last section of the returned section list use something like this: $Keys = IniReadSection(@ScriptDir & "\version.ini", $SectionNames[$SectionNames[0]]) That is not really working... Link to comment Share on other sites More sharing options...
water Posted December 23, 2012 Share Posted December 23, 2012 If I understand you correctly: You don't want the "last" section you want the section with the "highest" number. As the section names are strings you need to make sure that all elements of the version number are in the same format. Means: "2.1.1.8" has to become "02.01.01.08" so you can sort the array of section names and then grab the last = highest one. Darkz0r 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Darkz0r Posted December 23, 2012 Author Share Posted December 23, 2012 (edited) That's exactly what I want. A simple word changes it all hehe Ok I got it, _ArrayMax($SectionNames, 0, 1) did the trick but there's no workaround for having to set them in same format? Because I need to compare the returned value of the _ArrayMax with the ones I read from a external file... and if they're in different formats that'll be hard... Edited December 23, 2012 by Darkz0r Link to comment Share on other sites More sharing options...
chesstiger Posted December 23, 2012 Share Posted December 23, 2012 (edited) You can use something like that to norm the version numbers: $sVersionNumber = "1.2.03.4" $aNumbers = StringSplit($sVersionNumber, ".") $sFormatedVersionNumber = StringFormat("%.2d.%.2d.%.2d.%.2d", $aNumbers[1], $aNumbers[2], $aNumbers[3], $aNumbers[4]) MsgBox(0, "", $sFormatedVersionNumber) Or you can compare the parts of the version number mathematical... Then "01" is "1". chess Edited December 23, 2012 by chesstiger Darkz0r 1 Link to comment Share on other sites More sharing options...
Darkz0r Posted December 23, 2012 Author Share Posted December 23, 2012 Thanks, it's working great! Link to comment Share on other sites More sharing options...
Darkz0r Posted December 23, 2012 Author Share Posted December 23, 2012 (edited) I have another question, but I'll use this thread instead of creating another one, I don't think it's really necessary... What if I want to find out the next value in the array? I'm sure I need to use a loop but I'm not getting exactly how... Here's my current code: expandcollapse popup#include <Array.au3> $Read_ClientVersion = "2.1.1.8" $aNumbers = StringSplit($Read_ClientVersion[0], ".") $Client_Version = StringFormat("%.2d.%.2d.%.2d.%.2d", $aNumbers[1], $aNumbers[2], $aNumbers[3], $aNumbers[4]) ; Write version.ini on ScriptDir for testing purposes FileDelete(@ScriptDir & "\version.ini") IniWrite(@ScriptDir & "\version.ini", "02.01.01.08", "URL", "http://www.update.com/1.0.rar") ; __________________________________________________________________________________ IniWrite(@ScriptDir & "\version.ini", "02.01.01.09", "URL", "http://www.update.com/1.1.rar") ; __________________________________________________________________________________ IniWrite(@ScriptDir & "\version.ini", "02.01.01.10", "URL", "http://www.update.com/1.2.rar") ; __________________________________________________________________________________ ; Read the section names Local $SectionNames = IniReadSectionNames(@ScriptDir & "\version.ini") ; Get the last section (last version) Local $last_section = _ArrayMax($SectionNames, 0, 1) If $client_version = $last_section Then MsgBox("", "Notice", "Your version is up-to-date.") Else MsgBox("", "Notice", "Your version is out-of-date.") EndIf For $a = 1 To $SectionNames[0] ; Creating a loop to get all section names ; Now we read the keys of each Section Local $keys = IniReadSection(@ScriptDir & "\version.ini", $SectionNames[$a]) ; If an error occurred when trying to Read If @error Then MsgBox(4096, "", "Error occurred, probably no INI file.") ; If no error Else ; Here we will get the keys, with the URL for updating. EndIf Next Edited December 23, 2012 by Darkz0r Link to comment Share on other sites More sharing options...
guinness Posted December 24, 2012 Share Posted December 24, 2012 (edited) You first want to get the last entry and then you want to get the next entry after the last entry?! Is this correct? Edited December 24, 2012 by guinness UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Darkz0r Posted December 24, 2012 Author Share Posted December 24, 2012 Haha, that doesn't even make sense... no. I want to compare the $client_version with the last version read from the .ini, then if they're not the same it will get the next version in the array after the one returned in $client_version. Link to comment Share on other sites More sharing options...
guinness Posted December 24, 2012 Share Posted December 24, 2012 My point was there is no "next one" after the last one, do you mean the one before that? Why not look at the For loop section in the help file and Step. You will want to step backwards through the array so will need to use Step -1. Ammend the code and let us know if you get stuck. Trust me this is how you learn. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Darkz0r Posted December 24, 2012 Author Share Posted December 24, 2012 I'm sorry if I made you misunderstood my question. That's not at all what I need. As you can see above in my code I have this variable that was manually defined by me: $Read_ClientVersion = "2.1.1.8". Using _ArrayMax I got the variable $last_section to hold the last version of my app (which in this case is 2.1.1.10). Then I compare if $Read_ClientVersion and $last_section hold the same values, if yes good, the application is up-to-date, if not, then it'll find the next Section (version) above 2.1.1.8 (which in my case is 2.1.1.9). Why this? Because with each update the filesize of the update package would get bigger, so a user with version 2.1.1.9 would have to download the whole package (meant to all users) just to update to 2.1.1.10. So with this method, users will download only what they need, 2.1.1.9 users will just download 2.1.1.9-2.1.1.10 patch. Hope this helped clarify my idea, but if not, take a look here please: It's not like I didn't already, but having no luck... Link to comment Share on other sites More sharing options...
guinness Posted December 24, 2012 Share Posted December 24, 2012 It's easier if I just give you the code than trying to explain it. Use the help file to get an idea of what is happening. expandcollapse popup#include <Array.au3> $Read_ClientVersion = '2.1.1.8' $aNumbers = StringSplit($Read_ClientVersion, '.') $Client_Version = StringFormat('%.2d.%.2d.%.2d.%.2d', $aNumbers[1], $aNumbers[2], $aNumbers[3], $aNumbers[4]) ; Write Version.ini on ScriptDir for testing purposes FileDelete(@ScriptDir & '\Version.ini') IniWrite(@ScriptDir & '\Version.ini', '02.01.01.08', 'URL', 'http://www.update.com/1.0.rar') IniWrite(@ScriptDir & '\Version.ini', '02.01.01.09', 'URL', 'http://www.update.com/1.1.rar') IniWrite(@ScriptDir & '\Version.ini', '02.01.01.10', 'URL', 'http://www.update.com/1.2.rar') ; Read the section names Local $aSectionNames = IniReadSectionNames(@ScriptDir & '\Version.ini') ; Get the last section (last Version) Local $Last_Section = _ArrayMax($aSectionNames, 0, 1) If $Client_Version == $Last_Section Then MsgBox('', 'Notice', 'Your Version is up-to-date.') Else MsgBox('', 'Notice', 'Your Version is out-of-date.') EndIf Local $fFound = False, $sURLsHold = '' For $i = 1 To $aSectionNames[0] If $Client_Version == $aSectionNames[$i] Then $fFound = True ContinueLoop EndIf If $fFound = False Then ContinueLoop EndIf $sURLsHold &= IniRead(@ScriptDir & '\Version.ini', $aSectionNames[$i], 'URL', '') & @LF Next $sURLsHold = StringStripWS($sURLsHold, 3) Local $aURLs = StringSplit($sURLsHold, @LF) _ArrayDisplay($aURLs) LuisMartins 1 UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 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