Jump to content
Sign in to follow this  
mlukac89

Help with read .ini file, search and output founded data in listview

Recommended Posts

mlukac89

Hey

I have few questions, i have gui like this, it have open file button so you open ini file for edit.

Now how i can make it when i start to type in search filed, to show me only rows he founded in ini file and show it in listview ?

I don't want to read whole ini file in listview if not required.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Search in ini file", 290, 295, 298, 253)
$searchbox = GUICtrlCreateInput("", 8, 25, 273, 21)
GUICtrlCreateLabel("Search for text", 8, 8, 73, 17)
$List1 = GUICtrlCreateList("", 8, 82, 273, 175)
GUICtrlCreateLabel("Founded results", 8, 64, 79, 17)
$openini = GUICtrlCreateButton("Open INI", 8, 264, 75, 25)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $openini
            $FilePath = FileOpenDialog('Select INI file', '', '(*.ini)') ; opens ini file

    EndSwitch
WEnd 

Share this post


Link to post
Share on other sites
Melba23

mlukac89,

Perhaps this will give some ideas: :)

#include <GUIConstantsEx.au3>
#include <Array.au3>
#Include <GuiListBox.au3>

Global $hGUI, $hInput, $hList, $sPartialData, $asKeyWords[100]

; Create list full of random 5 character "words"
Keywords()

$hGUI = GUICreate("Example", 200, 400)
$hInput = GUICtrlCreateInput("", 5, 5, 190, 20)
$hList = GUICtrlCreateList("", 5, 30, 190, 325, BitOR(0x00100000, 0x00200000))
$hButton = GUICtrlCreateButton("Read", 60, 360, 80, 30)
$hUP = GUICtrlCreateDummy()
$hDOWN = GUICtrlCreateDummy()
$hENTER = GUICtrlCreateDummy()
GUISetState(@SW_SHOW, $hGUI)

; Set accelerators for Cursor up/down and Enter
Dim $AccelKeys[3][2]=[["{UP}", $hUP], ["{DOWN}", $hDOWN], ["{ENTER}", $hENTER]]
GUISetAccelerators($AccelKeys)

$sCurr_Input = ""
$iCurrIndex = -1

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hList
            $sChosen = GUICtrlRead($hList)
            If $sChosen <> "" Then GUICtrlSetData($hInput, $sChosen)
        Case $hButton
            If $sPartialData <> "" Then
                $sFinal = GUICtrlRead($hInput)
                If _ArraySearch($asKeyWords, $sFinal) > 0 Then
                    MsgBox(0, "Chosen", $sFinal)
                EndIf
            EndIf
        Case $hUP
            If $sPartialData <> "" Then
                $iCurrIndex -= 1
                If $iCurrIndex < 0 Then $iCurrIndex = 0
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
        Case $hDOWN
            If $sPartialData <> "" Then
                $iTotal = _GUICtrlListBox_GetCount($hList)
                $iCurrIndex += 1
                If $iCurrIndex > $iTotal - 1 Then $iCurrIndex = $iTotal - 1
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
        Case $hENTER
            If $iCurrIndex <> -1 Then
                $sText = _GUICtrlListBox_GetText($hList, $iCurrIndex)
                GUICtrlSetData($hInput, $sText)
                $iCurrIndex = -1
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
    EndSwitch

    ; If input has changed, refill list with matching items
    If GUICtrlRead($hInput) <> $sCurr_Input Then
        CheckInputText()
        $sCurr_Input = GUICtrlRead($hInput)
    EndIf

WEnd

Func CheckInputText()

    $sPartialData = "|" ; Start with delimiter so new data always replaces old
    Local $sInput = GUICtrlRead($hInput)
    If $sInput <> "" Then
        For $i = 0 To 99
            If StringInStr($asKeyWords[$i], $sInput) <> 0 Then $sPartialData &= $asKeyWords[$i] & "|"
        Next
        GUICtrlSetData($hList, $sPartialData)
    EndIf
EndFunc   ;==>CheckInputText

Func Keywords()

    Local $sData
    For $i = 0 To 99
        $asKeyWords[$i] = Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1))
        $sData &= $asKeyWords[$i] & "|"
    Next
    GUICtrlSetData($hList, $sData)
    $iCurrIndex = -1
    _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)

EndFunc   ;==>Keywords
Please ask if you have any questions. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
mlukac89

I implement your script in mine and i got this error

"C:UsersxooooxDesktopNew AutoIt v3 Script (3).au3" (60) : ==> Subscript used on non-accessible variable.:
$asKeyWords[$i] = $filelist

$asKeyWords^ ERROR 

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <File.au3>

Global $FilePath, $CurrentInput, $asKeyWords, $filelist

Keywords()

$Form1 = GUICreate("Form1", 290, 295, 298, 253)
$searchbox = GUICtrlCreateInput("", 8, 25, 273, 21)
GUICtrlCreateLabel("Search for text", 8, 8, 73, 17)
$List1 = GUICtrlCreateList("", 8, 82, 273, 175, BitOR(0x00100000, 0x00200000))
GUICtrlCreateLabel("Founded results", 8, 64, 79, 17)
$openini = GUICtrlCreateButton("Open INI", 8, 264, 75, 25)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $openini
            $FilePath = FileOpenDialog('Select INI file', '', '(*.ini)') ; opens ini file
            $filelist = _FileReadToArray($FilePath, $asKeyWords) ; put ini file in array
        Case $List1
            $Chosen = GUICtrlRead($List1)
            If $Chosen <> '' Then GUICtrlSetData($searchbox, $Chosen)

    EndSwitch

    ; If input has changed, refill list with matching items
    If GUICtrlRead($searchbox) <> $CurrentInput Then
        CheckInputText()
        $CurrentInput = GUICtrlRead($searchbox)
    EndIf

WEnd

Func CheckInputText()

    $sPartialData = '|' ; Start with delimiter so new data always replaces old
    Local $sInput = GUICtrlRead($searchbox)
    If $sInput <> '' Then
        For $i = 0 To 99
            If StringInStr($asKeyWords[$i], $sInput) <> 0 Then $sPartialData &= $asKeyWords[$i] & '|'
        Next
        GUICtrlSetData($List1, $sPartialData)
    EndIf
EndFunc   ;==>CheckInputText

Func Keywords()

    Local $sData
    For $i = 0 To UBound($filelist)
        $asKeyWords[$i] = $filelist ; line 60
        $sData &= $asKeyWords[$i] & '|'
    Next
    GUICtrlSetData($List1, $sData)
    $iCurrIndex = -1
    _GUICtrlListBox_SetCurSel($List1, $iCurrIndex)

EndFunc   ;==>Keywords

and i tried to edit your script a bit and it give me only few results but not all,  maybe because ini file is over 15 mb ?

here is download link to ini file, try to open it and search for Karkaen it will give you many results for that.

http://www.speedyshare.com/fBbuk/Opened-ini.ini

#include <GUIConstantsEx.au3>
#include <Array.au3>
#Include <GuiListBox.au3>
#include <File.au3>

Global $hGUI, $hInput, $hList, $sPartialData, $asKeyWords, $filelist, $ini

$ini = @ScriptDir&'\Opened ini.ini' ; opens ini file
$filelist = _FileReadToArray($ini, $asKeyWords) ; puts ini file to array

; Create list full of random 5 character "words"
Keywords()

$hGUI = GUICreate("Example", 200, 400)
$hInput = GUICtrlCreateInput("", 5, 5, 190, 20)
$hList = GUICtrlCreateList("", 5, 30, 190, 325, BitOR(0x00100000, 0x00200000))
$hButton = GUICtrlCreateButton("Read", 60, 360, 80, 30)
$hUP = GUICtrlCreateDummy()
$hDOWN = GUICtrlCreateDummy()
$hENTER = GUICtrlCreateDummy()
GUISetState(@SW_SHOW, $hGUI)

; Set accelerators for Cursor up/down and Enter
Dim $AccelKeys[3][2]=[["{UP}", $hUP], ["{DOWN}", $hDOWN], ["{ENTER}", $hENTER]]
GUISetAccelerators($AccelKeys)

$sCurr_Input = ""
$iCurrIndex = -1

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hList
            $sChosen = GUICtrlRead($hList) ;
            If $sChosen <> "" Then GUICtrlSetData($hInput, $sChosen) ;
        Case $hButton
            If $sPartialData <> "" Then
                $sFinal = GUICtrlRead($hInput)
                If _ArraySearch($asKeyWords, $sFinal) > 0 Then
                    MsgBox(0, "Chosen", $sFinal)
                EndIf
            EndIf
        Case $hUP
            If $sPartialData <> "" Then
                $iCurrIndex -= 1
                If $iCurrIndex < 0 Then $iCurrIndex = 0
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
        Case $hDOWN
            If $sPartialData <> "" Then
                $iTotal = _GUICtrlListBox_GetCount($hList)
                $iCurrIndex += 1
                If $iCurrIndex > $iTotal - 1 Then $iCurrIndex = $iTotal - 1
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
        Case $hENTER
            If $iCurrIndex <> -1 Then
                $sText = _GUICtrlListBox_GetText($hList, $iCurrIndex)
                GUICtrlSetData($hInput, $sText)
                $iCurrIndex = -1
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
    EndSwitch

    ; If input has changed, refill list with matching items
    If GUICtrlRead($hInput) <> $sCurr_Input Then
        CheckInputText()
        $sCurr_Input = GUICtrlRead($hInput)
    EndIf

WEnd

Func CheckInputText()

    $sPartialData = "|" ; Start with delimiter so new data always replaces old
    Local $sInput = GUICtrlRead($hInput)
    If $sInput <> "" Then
        For $i = 0 To 99 ; i tried to change this to more but i get same results
            If StringInStr($asKeyWords[$i], $sInput) <> 0 Then $sPartialData &= $asKeyWords[$i] & "|"
        Next
        GUICtrlSetData($hList, $sPartialData)
    EndIf
EndFunc   ;==>CheckInputText

Func Keywords()

    Local $sData
    For $i = 0 To UBound($filelist)
        $asKeyWords[$i] = $filelist
        $sData &= $asKeyWords[$i] & "|"
    Next
    GUICtrlSetData($hList, $sData)
    $iCurrIndex = -1
    _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)

EndFunc   ;==>Keywords

Share this post


Link to post
Share on other sites
Melba23

mlukac89,

That looks very much like a game-related file - you have read the Forum rules I take it? :huh:

Please explain why this script does not break those rules and why I should not lock this thread. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
mlukac89

Yes it is game related but dont affect gameplay in any way and its allowed to change it because that only for show items that drop on ground and only you can see it, and you cant change any part of game with it + its for private server you can check here http://forum.justac.net/index.php?topic=1672.0 here is already maded tool but its diferent than this i want to make.

Share this post


Link to post
Share on other sites
Melba23

mlukac89,

Having looked into it I am happy for the thread to remain open as all you are doing is searching a file. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
mlukac89

Melba23,

Thx for understanding.

So anyone can help me or tell me how to search string in ini file ? :)

Share this post


Link to post
Share on other sites
jdelaney

Have you tried the INI functions yet :)...check them out in the helpfile, they start with INI.

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
Melba23

mlukac89,

Use FilereadToArray to get your file into an array - then the code I gave should be able to deal with it. :)

M23

Edit:

This works - but because of the size of the file you are searching it is pretty slow, so I added a splash screen: :(

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <Array.au3>
#include <File.au3>
#Include <GuiListBox.au3>

Global $cSearch, $cList, $aIniEntries[1] = [0]

$hGUI = GUICreate("Search in ini file", 290, 295, 298, 253)
$cSearch = GUICtrlCreateInput("", 8, 25, 273, 21)
GUICtrlCreateLabel("Search for text", 8, 8, 73, 17)
$cList = GUICtrlCreateList("", 8, 82, 273, 175) ; , BitOR(0x00100000, 0x00200000))
GUICtrlCreateLabel("Found results", 8, 64, 79, 17)
$cOpenIni = GUICtrlCreateButton("Open INI", 8, 264, 75, 25)
GUISetState(@SW_SHOW, $hGUI)

$hGUI_Splash = GUICreate("", 200, 200, 50, 50, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
GUISetBkColor(0xFFCCCC)
GUICtrlCreateLabel("Working - please be patient", 0, 0, 200, 200, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUISetState(@SW_HIDE, $hGUI_Splash)

$sCurr_Input = ""

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cList
            $sChosen = GUICtrlRead($cList)
            If $sChosen <> "" Then GUICtrlSetData($cSearch, $sChosen)
        Case $cOpenIni
            $sFilePath = FileOpenDialog("Select INI file", "", "(*.ini)")
            If $sFilePath <> "" Then
                GUISetState(@SW_SHOW, $hGUI_Splash)
                $aIniEntries = _FileReadToArray($sFilePath)
            Else
                Global $aIniEntries[1] = [0]
            EndIf
            GUISetState(@SW_HIDE, $hGUI_Splash)
    EndSwitch

    ; If input has changed, refill list with matching items
    If GUICtrlRead($cSearch) <> $sCurr_Input Then
        GUISetState(@SW_SHOW, $hGUI_Splash)
        CheckInputText()
        $sCurr_Input = GUICtrlRead($cSearch)
        GUISetState(@SW_HIDE, $hGUI_Splash)
    EndIf

WEnd

Func CheckInputText()

    Local $sPartialData = "|" ; Start with delimiter so new data always replaces old
    Local $sInput = GUICtrlRead($cSearch)
    If $sInput <> "" Then
        For $i = 1 To $aIniEntries[0]
            If StringInStr($aIniEntries[$i], $sInput) <> 0 Then
                $sPartialData &= $aIniEntries[$i] & "|"
                ConsoleWrite($i & @CRLF)
            EndIf
        Next
        GUICtrlSetData($cList, $sPartialData)
    EndIf
EndFunc   ;==>CheckInputText
I think you might be better off with a database - but that is for you to decide (and code). ;)

M23

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
mlukac89

Melba23,

I make it to work, i changed _FileReadToArray to FileReadToArray now it show me all result as it need to but its too slow, any way to speed it up ?

Example with your code

#include <GUIConstantsEx.au3>
#include <Array.au3>
#Include <GuiListBox.au3>
#include <File.au3>

Global $hGUI, $hInput, $hList, $sPartialData, $filelist, $ini

$ini = @ScriptDir&'\Opened ini.ini'
$filelist = FileReadToArray($ini)

Keywords()

$hGUI = GUICreate("Example", 200, 400)
$hInput = GUICtrlCreateInput("", 5, 5, 190, 20)
$hList = GUICtrlCreateList("", 5, 30, 190, 325, BitOR(0x00100000, 0x00200000))
$hButton = GUICtrlCreateButton("Read", 60, 360, 80, 30)
$hUP = GUICtrlCreateDummy()
$hDOWN = GUICtrlCreateDummy()
$hENTER = GUICtrlCreateDummy()
GUISetState(@SW_SHOW, $hGUI)

; Set accelerators for Cursor up/down and Enter
Dim $AccelKeys[3][2]=[["{UP}", $hUP], ["{DOWN}", $hDOWN], ["{ENTER}", $hENTER]]
GUISetAccelerators($AccelKeys)

$sCurr_Input = ""
$iCurrIndex = -1

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hList
            $sChosen = GUICtrlRead($hList) ;
            If $sChosen <> "" Then GUICtrlSetData($hInput, $sChosen) ;
        Case $hButton
            If $sPartialData <> "" Then
                $sFinal = GUICtrlRead($hInput)
                If _ArraySearch($filelist, $sFinal) > 0 Then
                    MsgBox(0, "Chosen", $sFinal)
                EndIf
            EndIf
        Case $hUP
            If $sPartialData <> "" Then
                $iCurrIndex -= 1
                If $iCurrIndex < 0 Then $iCurrIndex = 0
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
        Case $hDOWN
            If $sPartialData <> "" Then
                $iTotal = _GUICtrlListBox_GetCount($hList)
                $iCurrIndex += 1
                If $iCurrIndex > $iTotal - 1 Then $iCurrIndex = $iTotal - 1
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
        Case $hENTER
            If $iCurrIndex <> -1 Then
                $sText = _GUICtrlListBox_GetText($hList, $iCurrIndex)
                GUICtrlSetData($hInput, $sText)
                $iCurrIndex = -1
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
    EndSwitch

    ; If input has changed, refill list with matching items
    If GUICtrlRead($hInput) <> $sCurr_Input Then
        CheckInputText()
        $sCurr_Input = GUICtrlRead($hInput)
    EndIf

WEnd

Func CheckInputText()

    $sPartialData = "|" ; Start with delimiter so new data always replaces old
    Local $sInput = GUICtrlRead($hInput)
    If $sInput <> "" Then
        For $i = 0 To UBound($filelist) - 1
            If StringInStr($filelist[$i], $sInput) <> 0 Then $sPartialData &= $filelist[$i] & "|"
        Next
        GUICtrlSetData($hList, $sPartialData)
    EndIf
EndFunc   ;==>CheckInputText

Func Keywords()

    Local $sData
    For $i = 0 To UBound($filelist) - 1
        $sData = $filelist[$i] & "|"
    Next
    GUICtrlSetData($hList, $sData)
    $iCurrIndex = -1
    _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)

EndFunc   ;==>Keywords

Share this post


Link to post
Share on other sites
Melba23

mlukac89,

Our posts crossed - look at the edit above. :D

We came to the same conclusion - I suggested an alternative route. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
mlukac89

:D i see btw you have error on line 37

error: _FileReadToArray() called with wrong number of args.
                $aIniEntries = _FileReadToArray($sFilePath)

Share this post


Link to post
Share on other sites
Melba23

mlukac89,

No, I am running the Beta and that is the correct syntax as the Beta _FileReadToArray returns an array directly. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
mlukac89

Ok i installed beta i tested it and its again too slow :( 

What was you think with this "I think you might be better off with a database." ?

Share this post


Link to post
Share on other sites
Melba23

mlukac89,

Exactly what I said: Loading the file data into a database will allow you to scan it much faster, although the initial load might take a bit longer. AutoIt has a library to use with the SQLite database engine so it is not too difficult a task to try it and see what difference it makes - if I find time today I might have a go, but there is nothing stopping you from doing the same. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Melba23

mlukac89,

I found some time! :D

I tested this using the reduced ini file attached (in zip format) - loading the full file takes far too long: :(

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

_SQLite_Startup()

If FileExists("OpenedIni.dat") Then
    FileDelete("OpenedIni.dat")
EndIf
$hDB = _SQLite_Open("OpenedIni.dat")

_SQLite_Exec($hDB, "CREATE TABLE tblData (P_ID INTEGER PRIMARY KEY, Line text);")

$hGUI = GUICreate("Search in ini file", 290, 295, 298, 253)
$cSearch = GUICtrlCreateInput("", 8, 25, 273, 21)
GUICtrlCreateLabel("Search for text", 8, 8, 73, 17)
$cList = GUICtrlCreateList("", 8, 82, 273, 175, BitOR($WS_BORDER, $WS_VSCROLL))
GUICtrlCreateLabel("Found results", 8, 64, 79, 17)
$cOpenIni = GUICtrlCreateButton("Open INI", 8, 264, 75, 25)
GUISetState(@SW_SHOW, $hGUI)

$hGUI_Splash = GUICreate("", 200, 200, 50, 50, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
GUISetBkColor(0xFFCCCC)
GUICtrlCreateLabel("Working - please be patient", 0, 0, 200, 200, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUISetState(@SW_HIDE, $hGUI_Splash)

$sCurr_Input = ""

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $cList
            $sChosen = GUICtrlRead($cList)
            If $sChosen <> "" Then GUICtrlSetData($cSearch, $sChosen)
        Case $cOpenIni
            $sFilePath = FileOpenDialog("Select INI file", "", "(*.ini)")
            If $sFilePath <> "" Then
                GUISetState(@SW_SHOW, $hGUI_Splash)
                $aIniEntries = _FileReadToArray($sFilePath)
                _SQLite_Exec($hDB, 'BEGIN;')
                For $i = 1 To $aIniEntries[0]
                    _SQLite_Exec($hDB, 'INSERT INTO tblData VALUES (NULL, "' & $aIniEntries[$i] & '");')
                Next
                _SQLite_Exec($hDB, 'COMMIT;')
            EndIf
            GUISetState(@SW_HIDE, $hGUI_Splash)
    EndSwitch

    ; If input has changed, refill list with matching items
    If GUICtrlRead($cSearch) <> $sCurr_Input Then
        CheckInputText()
        $sCurr_Input = GUICtrlRead($cSearch)
    EndIf

WEnd

_SQLite_Close($hDB)

_SQLite_Shutdown()

Func CheckInputText()

    Local $aResult,$iRows, $iColumns
    Local $sPartialData = "|" ; Start with delimiter so new data always replaces old
    Local $sInput = GUICtrlRead($cSearch)
    If $sInput <> "" Then
        _SQLite_GetTable2d($hDB, "SELECT * FROM tblData WHERE Line LIKE '%" & $sInput & "%';", $aResult, $iRows, $iColumns)
        For $i = 1 To UBound($aResult) - 1
            $sPartialData &= $aResult[$i][1] & "|"
        Next
        GUICtrlSetData($cList, $sPartialData)
    EndIf
EndFunc   ;==>CheckInputText

You may have to open another thread about loading the file into the database - there must be a faster way, but I am not that experienced with SQL databases. ;)

M23

 

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
jchd

mlukac89,

I've had a look at your actual (15+ Mb) file. There are two problems with its format, which make it non-compliant to .INI specifications.

First, the 155 first lines don't belong to a section.

Then almost every following section has duplicate keys, i.e. there are many sections with two lines with 5=...

This precludes processing the file as is under the .INI expectations.

While it is quite possible to perform various queries very efficiently in an SQLite database loaded with the data herein, you will need to make many points explicit about file structure and expected queries to be run for anyone to give you sensible advice about how to proceed.


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 here
RegExp tutorial: enough to get started
PCRE 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)

Share this post


Link to post
Share on other sites
mikell

Depending on what you have to search, if the only things you need to know are the line number and the section name then you can do it like this

This search takes 6 seconds on my old XP using the original 15 Mb huge "ini"  :)

#include <GUIConstantsEx.au3>

$Form1 = GUICreate("Search in ini file", 290, 325, 298, 253)
$searchbox = GUICtrlCreateInput("Marshmallows", 8, 25, 273, 21)
$btn = GUICtrlCreateButton("Search", 200, 50, 75, 25)
GUICtrlCreateLabel("Search for text", 8, 8, 73, 17)
$List1 = GUICtrlCreateList("", 8, 82, 273, 175)
GUICtrlCreateLabel("Founded results", 8, 64, 79, 17)
$input = GUICtrlCreateInput("", 8, 264, 273, 21)
$openini = GUICtrlCreateButton("Open INI", 8, 294, 75, 25)
GUISetState(@SW_SHOW)
 
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $openini
            $FilePath = FileOpenDialog('Select INI file', '', '(*.ini)') ; opens ini file
           GuiCtrlSetData($input, $FilePath)
         Case $btn
;  $begin = TimerInit()
           $ini = GuiCtrlRead($input)
           $search = GuiCtrlRead($searchbox)
           $file = FileRead($ini)
           $lines = StringRegExp($file, '(?m)(^.*)\R?', 3)
           $txt = ""
           For $i = 0 to UBound($lines)-1
               If StringInStr($lines[$i], $search) Then
                   $k = 0
                   Do
                     $k += 1
                   Until StringInStr($lines[$i-$k], "[")
                   $txt &= "line " & $i-$k+1 & " : " & $lines[$i-$k] & "|"
                   $txt &= "line " & $i+1 & " : " & $lines[$i] & "|"
                EndIf
           Next
          GuiCtrlSetData($List1, $txt)
;  Msgbox(0,"", Round(TimerDiff($begin)/1000) & "  seconds")
    EndSwitch
WEnd
Edited by mikell

Share this post


Link to post
Share on other sites
mlukac89

Melba23,

First thx for your time but this get too complicated for me :D

i see i must make something more efficient to rename all in 2-5 minutes because there is not so much items i need to rename

I extracted all from 1 item, ok so now i think better way will be to make automatic replacer to replace only as it show on example below 1=Karkaen necklace with 1=@@@@ Karkaen necklace @@@@ this must not exceed 50 chars, i tried that before but then it replaces me all where is Karkaen necklace, even those 1=Excellent Karkaen Necklace that i don't need.

And for section names, i think its not always the same because if coders add new item in INI then it changes section number and can't make some pattern to extract only for example 'uniqs' and put in array [5018], [9358], [10363], [20043], [20159] to it search only for it but its same because it search in whole file :D

Is there a way to use it like this StringReplace() Karkaen necklace where is 1=Karkaen necklace on first place and dont replace where is 1=Inteligent Karkaen necklace ? 

///////////// items i need to change names ///////////////

name like @@@@@ Karkaen necklace @@@@@ ; max 50 chars lenght

//////////////////////////////////////////////////////////

[5018]
0=AgpmItem
1=Karkaen Necklace

[9358]
0=AgpmItem
1=Karkaen Necklace

[10363]
0=AgpmItem
1=Karkaen Necklace

[20043]
0=AgpmItem
1=Karkaen Necklace

[20159]
0=AgpmItem
1=Karkaen Necklace


//////////////// items that i dont need to search /////////////////

[7659]
0=AgpmItem
1=Karkaen Necklace Piece

[11617]
0=AgpmItem
1=Brilliant Karkaen Necklace

[11640]
0=AgpmItem
1=Intelligent Karkaen Necklace

[11663]
0=AgpmItem
1=Glorious Karkaen Necklace

[11686]
0=AgpmItem
1=Excellent Karkaen Necklace

[11803]
0=AgpmItem
1=Karkaen Necklace Piece

[12583]
0=AgpmItem
1=Karkaen Necklace Piece

[20068]
0=AgpmItem
1=Brilliant Karkaen Necklace

[20091]
0=AgpmItem
1=Intelligent Karkaen Necklace

[20114]
0=AgpmItem
1=Glorious Karkaen Necklace

[20137]
0=AgpmItem
1=Excellent Karkaen Necklace

[20184]
0=AgpmItem
1=Brilliant Karkaen Necklace

[20207]
0=AgpmItem
1=Intelligent Karkaen Necklace

[20230]
0=AgpmItem
1=Glorious Karkaen Necklace

[20253]
0=AgpmItem
1=Excellent Karkaen Necklace

Share this post


Link to post
Share on other sites
mikell

Tested with the 15 Mb "Opened ini.ini"

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

$Form1 = GUICreate("Search in ini file", 290, 375, 298, 253)
GUICtrlCreateLabel("Search for text", 8, 8, 73, 17)
$searchbox = GUICtrlCreateInput("Karkaen necklace", 8, 25, 273, 21)
$btn = GUICtrlCreateButton("Search", 200, 50, 75, 25)
GUICtrlSetState(-1, $GUI_DISABLE)
$input_replace = GUICtrlCreateInput("@@@Karkaen necklace@@@", 8, 80, 273, 21)
$btn_replace = GUICtrlCreateButton("Replace", 200, 105, 75, 25)
GUICtrlSetState(-1, $GUI_DISABLE)
$List1 = GUICtrlCreateListView(" | ", 8, 132, 273, 175, $LVS_NOCOLUMNHEADER)
GUICtrlSendMsg($List1, $LVM_SETCOLUMNWIDTH, 0, 60)
GUICtrlSendMsg($List1, $LVM_SETCOLUMNWIDTH, 1, 210)

GUICtrlCreateLabel("Founded results", 8, 114, 79, 17)
$input = GUICtrlCreateInput("", 8, 314, 273, 21)
$openini = GUICtrlCreateButton("Open INI", 8, 344, 75, 25)
GUISetState(@SW_SHOW)
 
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $openini
            $FilePath = FileOpenDialog('Select INI file', '', '(*.ini)') ; opens ini file
           GuiCtrlSetData($input, $FilePath)
           $a = GUICtrlCreateListViewItem("Loading...", $List1)
           $ini = GuiCtrlRead($input)
           $file = FileRead($ini)
           $lines = StringRegExp($file, '(?m)(^.*)\R?', 3)
           GUICtrlSetState($btn, $GUI_ENABLE)
           GUICtrlSetState($btn_replace, $GUI_ENABLE)
           GuiCtrlDelete($a)

       Case $btn
           $search = GuiCtrlRead($searchbox)
           For $i = 0 to UBound($lines)-1
               If StringInStr($lines[$i], $search) Then 
                   $k = 0
                   Do
                       $k += 1
                   Until StringInStr($lines[$i-$k], "[")
                   GUICtrlCreateListViewItem($i-$k+1 & "|" & $lines[$i-$k], $List1)
                   GUICtrlCreateListViewItem($i+1 & "|" & $lines[$i], $List1)
                EndIf
           Next

       Case $btn_replace
           _GUICtrlListView_DeleteAllItems($List1)
           $search = GuiCtrlRead($searchbox)
            $replace = GuiCtrlRead($input_replace)
           For $i = 0 to UBound($lines)-1
               If StringInStr($lines[$i], $search) Then 
                   $k = 0
                   Do
                       $k += 1
                   Until StringInStr($lines[$i-$k], "[")
                  $lines[$i] = StringRegExpReplace($lines[$i], '(?im)^(.*=)(' & $search & ')$', '$1' & $replace)
                   GUICtrlCreateListViewItem($i-$k+1 & "|" & $lines[$i-$k], $List1)
                   GUICtrlCreateListViewItem($i+1 & "|" & $lines[$i], $List1)
                EndIf
           Next
           _FileWriteFromArray("ini2.ini", $lines, 0)
    EndSwitch
WEnd
Edited by mikell

Share this post


Link to post
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
Sign in to follow this  

×