Jump to content

Recommended Posts

Posted

progress of my code. to which it would be better if we add the full path of the executable in the ListView.

but save the executable in one test01.ini and full path in another test02.ini, but always load executable and full path in ListView when opening gui.

test01.ini ; only the .exe executable

test02.ini ; only the full path of the executable

this is my code;

#include <GuiListView.au3>
#include <GUIConstants.au3>
#include <WINAPI.au3>
#include <misc.au3>
#include <ColorConstants.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>

#include <Array.au3>
#include <File.au3>
#include <GuiComboBox.au3>
#include <GuiConstantsEx.au3>
#include <GuiEdit.au3>
#include <GuiListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Word.au3>


Global $aList[0]

Opt("GUIResizeMode", $GUI_DOCKAUTO)



$hGUI = GUICreate("Test", 1024, 800)
GUISetBkColor(0xFFFF00)


$iLVStyle = BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS)
$iLVExtStyle = BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)
$hListView = GUICtrlCreateListView("#|EXE NAME|ADD|", 34, 274, 850, 444, $iLVStyle, $iLVExtStyle)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOr($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
_GuiCtrlListView_SetColumnWidth($hListView,0,35)
_GuiCtrlListView_SetColumnWidth($hListView,1,290)
_GuiCtrlListView_SetColumnWidth($hListView,2,490)

$OkButton = GUICtrlCreateButton("SAVE", 42, 200, 75, 23,$WS_BORDER)
$AddButton = GUICtrlCreateButton("Add", 122, 242, 75, 23,$WS_BORDER)
$RemButton = GUICtrlCreateButton("Delete", 202, 242, 75, 23,$WS_BORDER)
$RemButton3 = GUICtrlCreateButton("Delete All", 298, 242, 88, 23,$WS_BORDER)


GUISetState(@SW_SHOW, $hGUI)

_FillList(@ScriptDir & "\test01.ini")

While 1
    $msg = GUIGetMsg(1)
    Switch $msg[0]
        Case $GUI_EVENT_CLOSE

                Exit



            Case $msg =$OkButton
            $sData = ""

            For $i = 0 To _GUICtrlListView_GetItemCount($hListView) - 1
                $sData &= _GUICtrlListView_GetItemText($hListView, $i, 1)  & @CRLF

            Next

            $hFile = FileOpen(@ScriptDir & "\test01.ini", 2)
            FileWrite($hFile, $sData)
            FileClose($hFile)



        Case $AddButton

             REPIT()

        Case $RemButton
            _GUICtrlListView_DeleteItemsSelected($hListView)

        Case $RemButton3

         _GUICtrlListView_DeleteAllItems($hListView)


    EndSwitch
WEnd




Func REPIT()

            Local $sBrowseFolder = FileSelectFolder ("Select Folder with Documents to merge", "", 4, @ScriptDir)

            IF @ERROR THEN

            Else

            _AddSelectFolder($sBrowseFolder)

            EndIf
EndFunc




Func _AddSelectFolder($_sFolderPath)
  Local $aFolderList = _FileListToArrayRec($_sFolderPath, "*.exe", $FLTAR_FILES, $FLTAR_RECUR)
  If @error Then Return
  For $i = 1 To $aFolderList[0]
    $aFolderList[$i] = StringRegExpReplace($aFolderList[$i], "^.*\\", "")
  Next
  _ArrayConcatenate($aList, $aFolderList, 1)
  $aList = _ArrayUnique($aList, Default, Default, Default, $ARRAYUNIQUE_NOCOUNT)
  _ArraySort($aList)
  _GUICtrlListView_DeleteAllItems($hListView)
  For $i = 0 To UBound($aList) - 1
    GUICtrlCreateListViewItem(String($i + 1) & "|" & $aList[$i], $hListView)
  Next
EndFunc   ;==>_AddSelectFolder




Func _FillList($sFile)
    Local $iRead = FileRead($sFile)
    Local $aString = StringSplit(StringStripCR($iRead), @LF)

    For $i = 1 To $aString[0]
        If $aString[$i] = "" Then ContinueLoop
        GUICtrlCreateListViewItem($i & "|" & StringRegExpReplace($aString[$i], "^.*\\", "")  , $hListView)

    Next
EndFunc

 

Posted

You could just use one ini file, using the full path as unique key, example:

[File Paths]
C:\Folder 1\filename.exe = filename.exe
C:\Folder 2\filename.exe = filename.exe

Basic example:

#include <GuiListView.au3>
#include <GUIConstants.au3>
#include <WINAPI.au3>
#include <misc.au3>
#include <ColorConstants.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>

#include <Array.au3>
#include <File.au3>
#include <GuiComboBox.au3>
#include <GuiConstantsEx.au3>
#include <GuiEdit.au3>
#include <GuiListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Word.au3>

Global $g_aFileList[0]
Global $g_sIniFile = @ScriptDir & "\Test.ini"

Opt("GUIResizeMode", $GUI_DOCKAUTO)

$hGUI = GUICreate("Test", 1024, 800)
GUISetBkColor(0xFFFF00)

$iLVStyle = BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS)
$iLVExtStyle = BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)
$hListView = GUICtrlCreateListView("#|EXE NAME|EXE PATH|ADD|", 34, 274, 850, 444, $iLVStyle, $iLVExtStyle)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOr($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
_GuiCtrlListView_SetColumnWidth($hListView,0,35)
_GuiCtrlListView_SetColumnWidth($hListView,1,290)
_GuiCtrlListView_SetColumnWidth($hListView,2,290)

$OkButton = GUICtrlCreateButton("SAVE", 42, 200, 75, 23,$WS_BORDER)
$AddButton = GUICtrlCreateButton("Add", 122, 242, 75, 23,$WS_BORDER)
$RemButton = GUICtrlCreateButton("Delete", 202, 242, 75, 23,$WS_BORDER)
$RemButton3 = GUICtrlCreateButton("Delete All", 298, 242, 88, 23,$WS_BORDER)

GUISetState(@SW_SHOW, $hGUI)

_FillList($g_sIniFile)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $OkButton
            For $i = 0 To _GUICtrlListView_GetItemCount($hListView) - 1
                IniWrite($g_sIniFile, "File Paths", _GUICtrlListView_GetItemText($hListView, $i, 2) & "\" & _GUICtrlListView_GetItemText($hListView, $i, 1), _GUICtrlListView_GetItemText($hListView, $i, 1))
            Next
        Case $AddButton
             REPIT()
        Case $RemButton
            _GUICtrlListView_DeleteItemsSelected($hListView)
        Case $RemButton3
         _GUICtrlListView_DeleteAllItems($hListView)
    EndSwitch
WEnd

Func REPIT()
    Local $sBrowseFolder = FileSelectFolder ("Select Folder with Documents to merge", "", 4, @ScriptDir)
    IF Not @error Then
        _AddSelectFolder($sBrowseFolder)
    EndIf
EndFunc

Func _AddSelectFolder($_sFolderPath)
    Local $aFolderList = _FileListToArrayRec($_sFolderPath, "*.exe", $FLTAR_FILES, $FLTAR_RECUR, 0, 2)
        If @error Then Return
    _ArrayConcatenate($g_aFileList, $aFolderList, 1)
    _AddListViewArray()
EndFunc   ;==>_AddSelectFolder

Func _AddListViewArray()
    $g_aFileList = _ArrayUnique($g_aFileList, Default, Default, Default, $ARRAYUNIQUE_NOCOUNT)
    _ArraySort($g_aFileList)
    Local $aFileList = $g_aFileList
    _ArrayColInsert($aFileList, 0)
    _ArrayColInsert($aFileList, 1)
    For $i = 0 To UBound($aFileList) - 1
        $aFileList[$i][0] = $i+1
        $aFileList[$i][1] = StringRegExpReplace($aFileList[$i][2], ".*\\", "")
        $aFileList[$i][2] = StringRegExpReplace($aFileList[$i][2], "\\[^\\]*$", "")
    Next
    _GUICtrlListView_DeleteAllItems($hListView)
    _GUICtrlListView_AddArray($hListView, $aFileList)
EndFunc

Func _FillList($sFile)
    Local $aIniList = IniReadSection($g_sIniFile, "File Paths")
    If Not @error Then
        ;~ Delete Row Count
        _ArrayDelete($aIniList, 0)
        $g_aFileList = $aIniList
        _ArrayColDelete($g_aFileList, 1)
        _AddListViewArray()
    EndIf
EndFunc

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...