Jump to content

Scan/Parse INI file for a certain word


aa2zz6
 Share

Recommended Posts

I'm trying to scan an INI file for a certain word but I'm not sure how to parse through text for "No Match". If it's not found then loop until pixel orientation changes in $ListFile2.

INI File looks like this: Examine filled

[Scanner]
IGNORE_ERRORS=0
1=0F0D07 116:805 Match
2=222222 117:806 Match
3=261D1D 118:807 Match
4=777F8D 119:808 Match
5=839EB5 120:809 Match
6=766D53 121:810 Match
7=7B6339 122:811 Match
8=7F673D 123:812 Match

Code

#include <MsgBoxConstants.au3>

read()

Func read()

    Local Const $hostfile = @ScriptDir & "\" & "Final_List.ini"

    $Readvar = IniReadSection($hostfile, "Scanner")
    ;----------------------------------------------------------------------------------------
    ; Read ini
    ;----------------------------------------------------------------------------------------

    If Not @error Then
        For $number = 2 To $Readvar[0][0]
            If $Readvar[$number][1] == "No Match" Then
                Global $DisplayNumber = $Readvar[$number][0]
                Global $DisplayName = $Readvar[$number][1]
                MsgBox($MB_SYSTEMMODAL, "Results", "Found a match.", 1)
            Else
                MsgBox($MB_SYSTEMMODAL, "Results", "Match not found.", 1)
                ;ExitLoop
            EndIf
        Next
    EndIf
EndFunc   ;==>read

Updated: selective words changed in first. New help question on read() function below..

Edited by aa2zz6
Noted: Selective words are cancer
Link to comment
Share on other sites

  • Moderators

aa2zz6,

You have been a member here long enough to know that we frown on anything to do with gaming and yet you post an script which might as well have a large red "GAME" flag attached to it while sounding a very loud hooter to attract even more attention.

So, as the basis to the question has nothing to do with gaming as such, I suggest you do 2 things:

  1. Rewrite the script above to use more neutral terms.
  2. Engage your brain before posting in future.

All clear?

M23

 

Edited by Melba23
Fixed formatting

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

#include <Array.au3>
#include <MsgBoxConstants.au3>
Global $aDisplay[0][2]
MsgBox($MB_SYSTEMMODAL, 'Results', 'Found ' & read("Search") & ' Matches.')
_ArrayDisplay($aDisplay)

Func read($sSearch)

    Local Const $hostfile = @ScriptDir & "\" & "Final_List.ini"
    Local $iCount = 0
    $Readvar = IniReadSection($hostfile, "Scanner")
    ;----------------------------------------------------------------------------------------
    ; Read ini
    ;----------------------------------------------------------------------------------------
    If Not @error Then
        For $i = 2 To $Readvar[0][0]
            If StringInStr($Readvar[$i][1], $sSearch) Then
                _ArrayAdd($aDisplay, $Readvar[$i][0] & '|' & $Readvar[$i][1])
                $iCount += 1
                MsgBox($MB_SYSTEMMODAL, "Results", "Found a match.", 1)
            Else
                MsgBox($MB_SYSTEMMODAL, "Results", "Match not found.", 1)
                ;ExitLoop
            EndIf
        Next
        Return $iCount
    EndIf
    Return $iCount
EndFunc   ;==>read

 

Edited by Subz
Link to comment
Share on other sites

  • Moderators

aa2zz6,

Quote

I figured it's easier to use simple terms rather than something that makes no sense

And I entirely agree with this sentiment. But please choose terms which are not so game-related in future - could I suggest that using the names of fruit or cartoon characters would be less likely to attract attention.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

How is the read() function being called? I think once the processing tool initials I'll have to use _2ndPixelScan and read() function to loop until the pixel orientation of "Writing Features 1" changes pixel orientation to "Completed". I'll need to include a filedelete for _2ndpixelscan so it compares against 1stpixelscan and read() function will detect change and move to the next processing tool.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <File.au3>

Opt('PixelCoordMode', 1)

Global $ListFile1 = @ScriptDir & '\List_1.ini'
Global $Ignore = 'IGNORE_ERRORS=' & IniWrite($ListFile1, "Scanner", "IGNORE_ERRORS", 0)

Global $ListFile2 = @ScriptDir & '\List_2.ini'
Global $Ignore = 'IGNORE_ERRORS=' & IniWrite($ListFile2, "Settings", "IGNORE_ERRORS", 0)

If $CmdLine[0] = 1 Then $ListFile1 = $CmdLine[1]
If $CmdLine[0] = 1 Then $ListFile2 = $CmdLine[1]

;First pixel scan:
_1stPixelScan(115, 804, 479, 829) ;topleft x, topleft y, bottomright x, bottomright y

;Second pixel scan:
_2ndPixelScan(115, 804, 479, 829) ;topleft x, topleft y, bottomright x, bottomright y

;Compares $ListFile1() and $ListFile2
Final_List()

MsgBox($MB_SYSTEMMODAL, 'Results', 'Found ' & read("No Match") & ' Matches', 1)


; ----------------------------------------------------------------------------
;   Script Function: Sets ArcGIS Desktop 10.2 window as active
; ----------------------------------------------------------------------------

Func ActiveWindow()
    $hWnd1 = WinGetHandle("[CLASS:]")
    If IsHWnd($hWnd1) Then
        WinActivate($hWnd1)
    EndIf
EndFunc   ;==>ActiveWindow

; ----------------------------------------------------------------------------
;   Script Function: Scans Pixel location & color
; ----------------------------------------------------------------------------

Func _1stPixelScan($left, $top, $right, $bottom)
    ActiveWindow()
    $PixelCount = Abs($left - $right) + Abs($top - $bottom)
    Dim $aPixelMap[$PixelCount + 1][3]
    $aPixelMap[$PixelCount][0] = UBound($aPixelMap)
    ConsoleWrite('Total number of pixels to check: ' & $aPixelMap[$PixelCount][0] & @LF)

    For $i = 1 To $aPixelMap[$PixelCount][0] - 1

        $x = $left + $i
        $y = $top + $i
        $aPixelMap[$i][0] = Hex(PixelGetColor($x, $y), 6)
        $aPixelMap[$i][1] = $x
        $aPixelMap[$i][2] = $y
        $num = $i
        ConsoleWrite('Pixel at: ' & $aPixelMap[$i][1] & ',' & $aPixelMap[$i][2] & ' has color ' & $aPixelMap[$i][0] & @LF)

        FileWrite($ListFile1, $num & '=' & $aPixelMap[$i][0] & " " & $aPixelMap[$i][1] & ":" & $aPixelMap[$i][2] & @CRLF)
    Next
EndFunc   ;==>_1stPixelScan

Func _2ndPixelScan($left, $top, $right, $bottom)
    ActiveWindow()
    $PixelCount = Abs($left - $right) + Abs($top - $bottom)
    Dim $aPixelMap[$PixelCount + 1][3]
    $aPixelMap[$PixelCount][0] = UBound($aPixelMap)
    ConsoleWrite('Total number of pixels to check: ' & $aPixelMap[$PixelCount][0] & @LF)

    For $i = 1 To $aPixelMap[$PixelCount][0] - 1

        $x = $left + $i
        $y = $top + $i
        $aPixelMap[$i][0] = Hex(PixelGetColor($x, $y), 6)
        $aPixelMap[$i][1] = $x
        $aPixelMap[$i][2] = $y

        ConsoleWrite('Pixel at: ' & $aPixelMap[$i][1] & ',' & $aPixelMap[$i][2] & ' has color ' & $aPixelMap[$i][0] & @LF)
        $num = $i
        FileWrite($ListFile2, $num & '=' & $aPixelMap[$i][0] & " " & $aPixelMap[$i][1] & ":" & $aPixelMap[$i][2] & @CRLF)
    Next
EndFunc   ;==>_2ndPixelScan

; ----------------------------------------------------------------------------
;   Script Function: [Compare List_1 And List_2] = Final_List
; ----------------------------------------------------------------------------

Func Final_List()
    Dim $array1
    Dim $array2

    _FileReadToArray("List_1.ini", $array1)
    _FileReadToArray("List_2.ini", $array2)

    ; ----------------------------------------------------------------------------
    ;   Script Function: Compare List_1 to List_2
    ; ----------------------------------------------------------------------------

    For $x = 3 To $array1[0]

        If $x <= $array2[0] Then
            If $array1[$x] = $array2[$x] Then
                $array1[$x] &= " Match"
            Else
                $array1[$x] &= " No Match"
            EndIf
        Else
            ExitLoop
        EndIf
    Next

    _FileWriteFromArray("Final_List.ini", $array1, 1)
EndFunc   ;==>Final_List

;----------------------------------------------------------------------------------------
; Read ini to figure out if process tool has completed
;----------------------------------------------------------------------------------------

Func read($sSearch)

    Local Const $hostfile = @ScriptDir & "\" & "Final_List.ini"
    Local $i = 0
    $Readvar = IniReadSection($hostfile, "Scanner")

    Local $numberofitems = 0
    If Not @error Then
        For $number = 1 To $Readvar[0][0]
            If StringInStr($Readvar[$number][1], $sSearch) Then
                $i += 1
                ;MsgBox($MB_SYSTEMMODAL, "Results", "Found a match.", 1)
            Else
                ;MsgBox($MB_SYSTEMMODAL, "Results", "Match not found.", 1)
                ;ExitLoop
            EndIf
        Next
        Return $i
    EndIf
    Return 0
EndFunc   ;==>read

 

ArcGIS Desktop 10.2.png

Edited by aa2zz6
Link to comment
Share on other sites

Something like this but I'm not sure how to call the read() function. I tried read($search) but it's being called before it happens and I think i'll need to research how to calculate overall rows verses No match again Match to determine percentage. 

Do
    FileDelete($ListFile2)
    FileDelete($Final_List)
    _2ndPixelScan(115, 804, 479, 829)
    Final_List()
until read("Match") > 100%

 

Link to comment
Share on other sites

Sorry I don't follow?  Can you re-explain?  Here is what I gather from your posts, but not sure if its correct and what you want to have happen?

a. You create List_1.ini using _1stPixelScan function
nb: Not sure why you use 2ndPixelScan function as it's exactly the same as _1stPixelScan function, you just need to add a parameter for the filename.
b. You create List_2.ini using _2ndPixelScan function
c. You compare the two files using Final_List function
d. You want to show the matches only?

Link to comment
Share on other sites

My previous scripts used a sleep function but depending on how big the data was being processed and which analysis tools was being used would varied on time completion. So needless to say it didn't work properly. 

So the goal was to find or create a pixel scanner to scan the general words on the analysis tools, such as "Writing Features 1" and would repeat until the process is done and will say "Complete". 

How I figured the script would have to be to work.

So I figured the first pixel scan would collect the pixel color along with the coordinates and stores the information in a file called List_1

 _1stPixelScan(115, 804, 479, 829) function to collect the pixel color and coordinates within the set boundaries specified. 

At this point I wasn't sure how to re scan the area to know if the text changed so I made another scan function and stores the information in a file called List_2

_2ndPixelScan(115, 804, 479, 829) ;topleft x, topleft y, bottomright x, bottomright y

I applied a function that Compared the (2) List_1 and List_2 files and determined if they had a "Matched" or "No match" at the end. The function creates a new file called Final_List.ini and stores the "Match" and "No Match" for each one. See below:

Final_List.ini looks like this..

[Scanner]
IGNORE_ERRORS=0
1=4A80BE 116:805 No Match
2=F0F4F9 117:806 Match

Func Final_List()
    Dim $array1
    Dim $array2

    _FileReadToArray("List_1.ini", $array1)
    _FileReadToArray("List_2.ini", $array2)

    #cs ----------------------------------------------------------------------------
        Script Function: Compare List_1 to List_2
    #ce ----------------------------------------------------------------------------

    For $x = 3 To $array1[0]

        If $x <= $array2[0] Then
            If $array1[$x] = $array2[$x] Then
                $array1[$x] &= " Match"
            Else
                $array1[$x] &= " No Match"
            EndIf
        Else
            ExitLoop
        EndIf
    Next

    _FileWriteFromArray("Final_List.ini", $array1, 1)
EndFunc   ;==>Final_List

After the Final_List.ini file is created the read function would parse through and determine whether everything looks the same or has changed. 

I would imagine a while loop would need to be present for it to scan until it changes and apply a continue loop to the next function which will use the same principle.

My apologies if things can be completed in a more simpler way. I'm a slow learner :(

Edited by aa2zz6
Link to comment
Share on other sites

I'm not sure but you may need to do the PixelScan for List_File1 again during the loop otherwise it would just continue looping

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <File.au3>

Opt('PixelCoordMode', 1)

Global $sFinalList = @ScriptDir & '\Final_List.ini'
Global $sListFile1 = @ScriptDir & '\List_1.ini'
    FileDelete($sListFile1)
    IniWrite($sListFile1, "Scanner", "IGNORE_ERRORS", 0)

Global $sListFile2 = @ScriptDir & '\List_2.ini'
    FileDelete($sListFile2)
If $CmdLine[0] = 1 Then $ListFile1 = $CmdLine[1]
If $CmdLine[0] = 1 Then $ListFile2 = $CmdLine[1]

;First pixel scan:
_PixelScan($sListFile1, 'Scanner', 115, 804, 479, 829) ;IniFile, topleft x, topleft y, bottomright x, bottomright y

While 1
    IniWrite($sListFile2, "Settings", "IGNORE_ERRORS", 0)

    ;Second pixel scan:
    _PixelScan($sListFile2, 'Settings', 115, 804, 479, 829) ;IniFile, topleft x, topleft y, bottomright x, bottomright y

    ;Compares $ListFile1() and $ListFile2
    Final_List()

    Read('No Match')
    If @error <> 0 Then
        FileDelete($sFinalList)
        FileDelete($sListFile2)
        ContinueLoop
    Else
        ExitLoop
    EndIf
WEnd
MsgBox($MB_SYSTEMMODAL, 'Results', 'Found ' & read("No Match") & ' Matches', 1)


; ----------------------------------------------------------------------------
;   Script Function: Sets ArcGIS Desktop 10.2 window as active
; ----------------------------------------------------------------------------

Func ActiveWindow()
    $hWnd1 = WinGetHandle("[CLASS:]")
    If IsHWnd($hWnd1) Then
        WinActivate($hWnd1)
    EndIf
EndFunc   ;==>ActiveWindow

; ----------------------------------------------------------------------------
;   Script Function: Scans Pixel location & color
; ----------------------------------------------------------------------------

Func _PixelScan($sListFile, $sSection, $left, $top, $right, $bottom)
    ActiveWindow()
    $PixelCount = Abs($left - $right) + Abs($top - $bottom)
    Dim $aPixelMap[$PixelCount + 1][3]
    $aPixelMap[$PixelCount][0] = UBound($aPixelMap)
    ConsoleWrite('Total number of pixels to check: ' & $aPixelMap[$PixelCount][0] & @LF)

    For $i = 1 To $aPixelMap[$PixelCount][0] - 1

        $x = $left + $i
        $y = $top + $i
        $aPixelMap[$i][0] = Hex(PixelGetColor($x, $y), 6)
        $aPixelMap[$i][1] = $x
        $aPixelMap[$i][2] = $y
        $num = $i
  ;      ConsoleWrite('Pixel at: ' & $aPixelMap[$i][1] & ',' & $aPixelMap[$i][2] & ' has color ' & $aPixelMap[$i][0] & @LF)

        IniWrite($sListFile, $sSection, $i, $aPixelMap[$i][0] & " " & $aPixelMap[$i][1] & ":" & $aPixelMap[$i][2])
    Next
EndFunc   ;==>_1stPixelScan

; ----------------------------------------------------------------------------
;   Script Function: [Compare List_1 And List_2] = Final_List
; ----------------------------------------------------------------------------

Func Final_List()
    Local $aListFile1 = IniReadSection($sListFile1, 'Scanner')
    Local $aListFile2 = IniReadSection($sListFile2, 'Settings')
    Local $iListFile
    If $aListFile1[0][0] = $aListFile2[0][0] Then
        ConsoleWrite('$aListFile1 Row Size = $aListFile2 Row Size' & @CRLF)
        $iListFile = $aListFile1[0][0]
    ElseIf $aListFile1[0][0] > $aListFile2[0][0] Then
        ConsoleWrite('$aListFile1 Row Size > $aListFile2 Row Size' & @CRLF)
        $iListFile = $aListFile1[0][0]
    Else
        ConsoleWrite('$aListFile1 Row Size < $aListFile2 Row Size' & @CRLF)
        $iListFile = $aListFile2[0][0]
    EndIf
    ; ----------------------------------------------------------------------------
    ;   Script Function: Compare List_1 to List_2
    ; ----------------------------------------------------------------------------

    For $i = 2 To $iListFile
        If $aListFile1[$i][1] = $aListFile2[$i][1] Then
            IniWrite($sFinalList, 'Scanner', $i, $aListFile1[$i][1] & " Match")
        Else
            IniWrite($sFinalList, 'Scanner', $i, $aListFile1[$i][1] & " No Match")
        EndIf
    Next
EndFunc   ;==>Final_List

;----------------------------------------------------------------------------------------
; Read ini to figure out if process tool has completed
;----------------------------------------------------------------------------------------

Func read($sSearch = 'No Match')
    Local $i = 0
    $Readvar = IniReadSection($sFinalList, "Scanner")
    If Not @error Then
        For $number = 1 To $Readvar[0][0]
            If StringInStr($Readvar[$number][1], $sSearch) Then
                Return SetError(1, 0, False)
            Else
                $i += 1
            EndIf
        Next
        Return SetError(0, 0, $i)
    EndIf
    Return SetError(-1, 0, False)
EndFunc   ;==>read

 

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