telmob Posted December 8, 2012 Share Posted December 8, 2012 (edited) I have a ini file with different sections, like this: [section1] c:=1 d:=1 e:=1 d:=1 [section2] c:=1 Is there a way to find duplicates within the same section and between sections? For example. My gui adds keys to these sections in to different places. One to allow (section1) and another to block (section2). When i try to add something to section1 (for ex.), i want my script to search for duplicates in section1 and in section2 and warn me if any duplicates were found. Basic question is...: How can i search ini files for duplicates (without using arrays)? Edited December 8, 2012 by telmob Link to comment Share on other sites More sharing options...
guinness Posted December 8, 2012 Share Posted December 8, 2012 Why the restriction on not using arrays? 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...
telmob Posted December 8, 2012 Author Share Posted December 8, 2012 I use that single ini file for a bunch of settings and i'd like to keep it all in one place. And i always found arrays to be more complicated to 'play' with. Link to comment Share on other sites More sharing options...
jchd Posted December 8, 2012 Share Posted December 8, 2012 Duplicates in same .INI section means that the INI file is essentially invalid. They should never occur if editing the INI is done using the INI* functions. Duplicates accross distinct sections will need massaging multiple arrays anyway. 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...
JohnOne Posted December 8, 2012 Share Posted December 8, 2012 (edited) Then you simply have to type it all out manually. $Section1C = Iniread("bla", "section1","c","") If Iniread("bla", "section2","c","") = $Section1C Or Iniread("bla", "section2","d","") etc... You get the idea. Use an array and stop being silly. Edited December 8, 2012 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
telmob Posted December 8, 2012 Author Share Posted December 8, 2012 (edited) ahahah. I'm not trying to be silly, i'm just a bit afraid to use new stuff Thank you both for your replies. But can i use an array and still use the ini file for settings 'storage'? If so, how? Because the GUI will need to compare the data the user selects to add to one section to the data that already is in another section. (now that i know that adding two identical keys is impossible.) So, for example, the section1 will allow apps to run and section2 will block them. And i don't want to create any kind of conflict here, that's why i need to compare the data inserted to any of the sections to the other section. If the ini had fixed keys for these section it would be easy for me, but this way, its just all to confusing for my noobish eyes. Edited December 8, 2012 by telmob Link to comment Share on other sites More sharing options...
JohnOne Posted December 8, 2012 Share Posted December 8, 2012 IniReadSection() will read a whole section and put the keys and values into a 2D array It's a matter of learning how to loop through them and compare with another. It's much better, and when you expand your sections in ini file the code does not have to be altered. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
telmob Posted December 8, 2012 Author Share Posted December 8, 2012 Wow! Completely forgot about inireadsection... I think i can solve it now. Thank you JohnOne! Link to comment Share on other sites More sharing options...
telmob Posted December 9, 2012 Author Share Posted December 9, 2012 Hummm... ran into a problem... If I do this, it works.: $ButtonAddWhitelist $varFile = FileOpenDialog("Select executable to add to the Whitelist.", @WindowsDir & "", "All Files(*.*) | Known Executables (*.A6P;*.AC)", 1) Local $sFileNameExtA = StringRegExpReplace($varFile, "^.*\\", "") Local $MsgAdd2AllowList = 0 For $i = 1 To $varBlockedIni[0][0] If $varBlockedIni[$i][0]=$sFileNameExtA then $MsgAdd2AllowList = MsgBox(048, "File Conflict !", "File already exists in Blocked Files list.") EndIf If $MsgAdd2AllowList = 0 then GUICtrlSetData($ListWhitelist, $varFile) IniWrite($inifile, "CustomPoliciesAllow", $varFile, "1") WritePath($varFile) EndIf If i do this, it works, but it still adds the file even if its a duplicate. But $MsgAdd2BlockList = 0, right?? : Case $ButtonAddBlacklist $varFileB = FileOpenDialog("Select executable to add to the Blacklist.", @WindowsDir & "", "Executable Files (*.BAT;*.CMD)", 1) Local $sFileNameExtB = StringRegExpReplace($varFileB, "^.*\\", "") Local $MsgAdd2BlockList = 0 For $i = 1 To $varAllowedIni[0][0] If $varAllowedIni[$i][0]=$varFileB then $MsgAdd2BlockList = MsgBox(048, "File Conflict !", "File already exists in Allowed Files list.") EndIf If $MsgAdd2BlockList = 0 then GUICtrlSetData($ListBlockList, $sFileNameExtB) RegWrite( 'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\DisallowRun',$sFileNameExtB, "REG_SZ", $sFileNameExtB) Iniwrite( $inifile, "CustomPoliciesBlock", $sFileNameExtB, "1") EndIf Next Globals: Global $varAllowedIni = IniReadSection($inifile, "CustomPoliciesAllow") Global $varBlockedIni = IniReadSection($inifile, "CustomPoliciesBlock") I'm sorry i couldn't trim the code a bit more... So i assume this is the wrong part in the second portion of the code, but its basically the same as the first part: If $MsgAdd2BlockList = 0 then GUICtrlSetData($ListBlockList, $sFileNameExtB) RegWrite( 'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\DisallowRun',$sFileNameExtB, "REG_SZ", $sFileNameExtB) Iniwrite( $inifile, "CustomPoliciesBlock", $sFileNameExtB, "1") EndIf Next What are my alternatives here? Link to comment Share on other sites More sharing options...
telmob Posted December 9, 2012 Author Share Posted December 9, 2012 Solved! Misplaced Next Sorry to bother you guys. Link to comment Share on other sites More sharing options...
telmob Posted January 6, 2013 Author Share Posted January 6, 2013 Just found that even after i remove the duplicate found, i still get the duplicate file warning. In this example: Func AddBlacklist() $varFileB = FileOpenDialog("Select executable to add to the Blacklist.", @WindowsDir & "", "Executable Files (*.BAT;*.CMD;*.COM;*.EXE;*.JS;*.MSI;*.MSP;*.VBS)",5, '', $SRPEGUI) $FiledivB = StringSplit($VarFileB, '|') Local $sFileNameExtB = StringRegExpReplace($varFileB, "^.*\\", "") Local $FileDuplicateB=0 For $i = 1 To $varAllowedIni[0][0] If $varFileB<>"" And $varAllowedIni[$i][0]<>$varFileB then $FileDuplicateB=0 ElseIf $varFileB<>"" And $varAllowedIni[$i][0]=$varFileB then $FileDuplicateB=1 MsgBox(048, "File Conflict !", "File already exists in Allowed Files list." & @CRLF & "Two files with the same name cannot co-exist in both lists.") EndIf Next EndFunc Func AddFileWhitelist() $varFile = FileOpenDialog("Select executable to add to the Whitelist.", @WindowsDir & "", "Known Executables (*.A6P;*.AC;*.AS;*.ACR;*.ACTION;*.AIR;*.APP;*.AWK;*.CGI)", 5, '', $SRPEGUI) $Filediv = StringSplit($VarFile, '|') Local $sFileNameExtA = StringRegExpReplace($varFile, "^.*\\", "") Local $FileDuplicate=0 For $i = 1 To $varBlockedIni[0][0] If $varFile<>"" And $varBlockedIni[$i][0]<>$sFileNameExtA then $FileDuplicate=0 ElseIf $varFile<>"" And $varBlockedIni[$i][0]=$sFileNameExtA then $FileDuplicate=1 MsgBox(048, "File Conflict !", "File already exists in Blocked Files list.") EndIf Next The warning only goes away after i restart the script. Any way to bypass this? Also, is there a way to look for duplicates when adding multiple files? Thanks for your support. Link to comment Share on other sites More sharing options...
jackraymund Posted January 6, 2013 Share Posted January 6, 2013 (edited) create a array, with blacklisted worlds, because if u have d: c: d: e: for example, that compare 2 times d so, its like this d: <- added to black list c:<- added to black list d: <- i found d: in black list, and dont message e:<- added to black list sry for imagine, but im bad in english xD local $blacklistworlds[ubound($varAllowedIni[0][0])] For $i = 1 To $varAllowedIni[0][0] for $z = 0 to ubound($varAllowedIni[0][0]) - 1 if $blacklistworlds[$z-1] = $varAllowedIni[$i][0] then $FileDuplicateB=0 else If $varFileB<>"" And $varAllowedIni[$i][0]<>$varFileB then $FileDuplicateB=0 ElseIf $varFileB<>"" And $varAllowedIni[$i][0]=$varFileB then $FileDuplicateB=1 MsgBox(048, "File Conflict !", "File already exists in Allowed Files list." &amp;amp; @CRLF &amp;amp; "Two files with the same name cannot co-exist in both lists.") $blacklistworlds[$i] = $varAllowedIni[$i][0] EndIf endif next Next EndFunc Edited January 6, 2013 by jackraymund thanks you BrewManNH Link to comment Share on other sites More sharing options...
telmob Posted January 7, 2013 Author Share Posted January 7, 2013 Thanks for your help jackraymund! However, i'm getting this in the console: C:UsersTelmoDesktopSRP EnforcerSRPE Final.au3 (2181) : ==> Array variable subscript badly formatted.: local $blacklistworlds[ubound($varAllowedIni[0][0])] Link to comment Share on other sites More sharing options...
kylomas Posted January 7, 2013 Share Posted January 7, 2013 (edited) telmob, See comments in the code below for a couple errors: ;Local $blacklistworlds[UBound($varAllowedIni[0][0])] Local $blacklistworlds[UBound($varAllowedIni)] ; this should probably be declared like this or "ubound($array) - 1" For $i = 1 To $varAllowedIni[0][0] ;For $z = 0 To UBound($varAllowedIni[0][0]) - 1 For $z = 0 To UBound($varAllowedIni) - 1 ; this should not be using subscripts. ubound of 2nd dim = "UBound($varAllowedIni,2) - 1 If $blacklistworlds[$z - 1] = $varAllowedIni[$i][0] Then $FileDuplicateB = 0 Else If $varFileB <> "" And $varAllowedIni[$i][0] <> $varFileB Then $FileDuplicateB = 0 ElseIf $varFileB <> "" And $varAllowedIni[$i][0] = $varFileB Then $FileDuplicateB = 1 MsgBox(048, "File Conflict !", "File already exists in Allowed Files list." & amp;amp;amp; @CRLF &amp;amp; "Two files with the same name cannot co-exist in both lists.") $blacklistworlds[$i] = $varAllowedIni[$i][0] EndIf EndIf Next Next EndFunc ;==> kylomas edit: additional info The to value in the for loop with the error can use either a ubound value or an array value. E.G. it could be written as For $z = 0 To $varAllowedIni[0][0] if you wantto use the VALUE in the array element Edited January 7, 2013 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
telmob Posted January 7, 2013 Author Share Posted January 7, 2013 I need to search more examples in how to use ubound properly, but thats a start. There's also an error in: If $blacklistworlds[$z - 1] = $varAllowedIni[$i][0] Then I think it should become: If $blacklistworlds[$z]-1 = $varAllowedIni[$i][0] Then Right? Still... It founds the duplicate only if i add one file to the list and still adds it to the blacklist. The second time i try it, it doesn't even recognize the duplicate Link to comment Share on other sites More sharing options...
kylomas Posted January 7, 2013 Share Posted January 7, 2013 (edited) telmob, If $blacklistworlds[$z - 1] = $varAllowedIni[$i][0] Then is subtracting 1 form the variable "$z" (the element beng pointed at) of the array whereas If $blacklistworlds[$z]-1 = $varAllowedIni[$i][0] Then is subtracting 1 from whatever is at element "$z" To understand ubound you need to understand arrays. They are not complicated. Think of 2D arrays as a spreadsheet and 1D arrays as a list. UBOUND is just a value that represents the max element (size) of the array. You can use UBOUND to get the number of dimensions "0", or the size of each dimension "1", "2", etc. kylomas edit: additional info - there is an excellent WIKI about AutoIT arrays, just search for it. Edited January 7, 2013 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
telmob Posted January 7, 2013 Author Share Posted January 7, 2013 (edited) Oh, i see. Its just that's returning this error: C:UsersTelmoDesktopSRP EnforcerSRPE Final.au3 (2185) : ==> Array variable subscript badly formatted.: If $blacklistworlds[$z - 1] = $varAllowedIni[$i][0] Then Think of 2D arrays as a spreadsheet and 1D arrays as a list. Best explanation ever! I often wondered what 1D and 2D arrays were and never quite understood. That clears it! Found it! http://www.autoitscript.com/wiki/Arrays Time to study. Edited January 7, 2013 by telmob Link to comment Share on other sites More sharing options...
kylomas Posted January 7, 2013 Share Posted January 7, 2013 telemob,To your original problem Just found that even after i remove the duplicate found, i still get the duplicate file warning.If you have deleted a line in the ini file and the script is stillrunning, you need to sync the array (delete element) with the ini filekylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
telmob Posted January 7, 2013 Author Share Posted January 7, 2013 (edited) Actually the files names/paths are added to the listview, registry and ini file and when i press remove in the listview window, its removed from the listview as well as the registry and ini file, but even after that, somehow it remains in memory, because its still found as duplicate until i restart the script, which i find really weird. Edit: Just understood what you meant... lol Edited January 7, 2013 by telmob Link to comment Share on other sites More sharing options...
AZJIO Posted January 7, 2013 Share Posted January 7, 2013 telmobIt while the draft copy, but function of duplicates already is.IniVirtual My other projects or all 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