Skip to content

Instantly share code, notes, and snippets.

@EncodeTheCode
Created May 14, 2026 14:25
Show Gist options
  • Select an option

  • Save EncodeTheCode/c7a73c871b2c1d6643200e3bb85ba738 to your computer and use it in GitHub Desktop.

Select an option

Save EncodeTheCode/c7a73c871b2c1d6643200e3bb85ba738 to your computer and use it in GitHub Desktop.
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIListView.au3>
#include <File.au3>
#include <GUITab.au3>
#include <Array.au3>
Global $C1 = "Game Title", $C2 = "Game ID", $C3 = "Serial", $C4 = "Release Date", $C5 = "Version"
Global $Columns = String($C1 & "|" & $C2 & "|" & $C3 & "|" & $C4 & "|" & $C5)
; Create GUI and Tab Control
Global $hGUI = GUICreate("PlayStation One - Game Library", 850, 650)
Global $hTab = GUICtrlCreateTab(10, 10, 830, 630)
Global $hTab1 = GUICtrlCreateTabItem("PAL")
Global $hListView1 = GUICtrlCreateListView($Columns, 20, 40, 808, 580, $LVS_SHOWSELALWAYS)
GUICtrlSetStyle($hListView1, $LVS_REPORT)
GUICtrlCreateTabItem("NTSC-U (America)")
Global $hListView2 = GUICtrlCreateListView($Columns, 20, 40, 808, 580, $LVS_SHOWSELALWAYS)
GUICtrlSetStyle($hListView2, $LVS_REPORT)
GUICtrlCreateTabItem("NTSC-J (Asia/Japan)")
Global $hListView3 = GUICtrlCreateListView($Columns, 20, 40, 808, 580, $LVS_SHOWSELALWAYS)
GUICtrlSetStyle($hListView3, $LVS_REPORT)
GUICtrlCreateTabItem("") ; End tab creation
Global $btnDelete1 = GUICtrlCreateButton("Delete Items on Tab 1", 265, 12, 150, 19)
Global $btnDelete2 = GUICtrlCreateButton("Delete Items on Tab 2", 418, 12, 150, 19)
Global $btnDelete3 = GUICtrlCreateButton("Delete Items on Tab 3", 571, 12, 150, 19)
; Sort direction state for each ListView and each column.
; 0 = ascending next, 1 = descending next.
Global $g_aSortOrder[3][5]
For $iLV = 0 To 2
For $iCol = 0 To 4
$g_aSortOrder[$iLV][$iCol] = 0
Next
Next
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
GUISetState(@SW_SHOW, $hGUI)
; Function to read and parse the CSV file
Func _ReadCSV($sFilePath, $hListView)
Local $aLines, $aFields, $iIndex
; Read the entire file
$aLines = FileReadToArray($sFilePath)
If @error Then
MsgBox(16, "Error", "Failed to read the CSV file: " & $sFilePath)
Return False
EndIf
; Clear existing items
_GUICtrlListView_DeleteAllItems($hListView)
; Loop through each line and split it into fields
For $iIndex = 0 To UBound($aLines) - 1
$aFields = StringSplit($aLines[$iIndex], "|")
; Add the fields to the ListView
_GUICtrlListView_AddItem($hListView, $aFields[1])
For $i = 2 To $aFields[0]
_GUICtrlListView_AddSubItem($hListView, $iIndex, $aFields[$i], $i - 1)
Next
Next
Return True
EndFunc
; Function to sort the ListView items
Func _SortListView($hListView, $iColumn, $iDescending)
Local $iItemCount = _GUICtrlListView_GetItemCount($hListView)
If $iItemCount <= 1 Then Return
Local $aItems = _GUICtrlListView_CreateArray($hListView)
If @error Then Return
; _ArraySort uses 0 for ascending and 1 for descending.
; For a 2D array, the sort column is passed with iSubItem.
_ArraySort($aItems, $iDescending, 0, UBound($aItems) - 1, $iColumn)
; Clear the ListView
_GUICtrlListView_DeleteAllItems($hListView)
; Add the sorted items back to the ListView
For $i = 0 To UBound($aItems) - 1
_GUICtrlListView_AddItem($hListView, $aItems[$i][0])
For $j = 1 To UBound($aItems, 2) - 1
_GUICtrlListView_AddSubItem($hListView, $i, $aItems[$i][$j], $j)
Next
Next
EndFunc
; Function to create an array from ListView
Func _GUICtrlListView_CreateArray($hListView)
Local $iItemCount = _GUICtrlListView_GetItemCount($hListView)
Local $aItems[$iItemCount][5]
For $i = 0 To $iItemCount - 1
$aItems[$i][0] = _GUICtrlListView_GetItemText($hListView, $i, 0)
For $j = 1 To 4
$aItems[$i][$j] = _GUICtrlListView_GetItemText($hListView, $i, $j)
Next
Next
Return $aItems
EndFunc
; Notification handler for ListView header clicks
Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
Local $tNMLV = DllStructCreate("hwnd hWndFrom;uint_ptr IDFrom;int Code;int iItem;int iSubItem", $lParam)
If @error Then Return $GUI_RUNDEFMSG
If DllStructGetData($tNMLV, "Code") <> -108 Then Return $GUI_RUNDEFMSG
Local $hFrom = DllStructGetData($tNMLV, "hWndFrom")
Local $iColumn = DllStructGetData($tNMLV, "iSubItem")
Local $iListIndex = -1
Switch $hFrom
Case GUICtrlGetHandle($hListView1)
$iListIndex = 0
Case GUICtrlGetHandle($hListView2)
$iListIndex = 1
Case GUICtrlGetHandle($hListView3)
$iListIndex = 2
EndSwitch
If $iListIndex = -1 Then Return $GUI_RUNDEFMSG
If $iColumn < 0 Or $iColumn > 4 Then Return $GUI_RUNDEFMSG
; Sort using the current direction for this specific column, then toggle it.
_SortListView($hFrom, $iColumn, $g_aSortOrder[$iListIndex][$iColumn])
$g_aSortOrder[$iListIndex][$iColumn] = 1 - $g_aSortOrder[$iListIndex][$iColumn]
Return $GUI_RUNDEFMSG
EndFunc
; Specify the paths to your CSV files
Local $sCSVPath1 = "PAL.csv"
Local $sCSVPath2 = "NTSC-U.csv"
Local $sCSVPath3 = "NTSC-J.csv"
Func SetColumnWidth()
; Set the width of each column
Local $s = [25,50,85,100,125,150,175,200,225,250,275,300,325,350]
_GUICtrlListView_SetColumnWidth($hListView1, 0, $s[10])
_GUICtrlListView_SetColumnWidth($hListView1, 1, $s[2])
_GUICtrlListView_SetColumnWidth($hListView1, 2, $s[8])
_GUICtrlListView_SetColumnWidth($hListView1, 3, $s[4])
_GUICtrlListView_SetColumnWidth($hListView1, 4, $s[3])
_GUICtrlListView_SetColumnWidth($hListView2, 0, $s[10])
_GUICtrlListView_SetColumnWidth($hListView2, 1, $s[2])
_GUICtrlListView_SetColumnWidth($hListView2, 2, $s[8])
_GUICtrlListView_SetColumnWidth($hListView2, 3, $s[4])
_GUICtrlListView_SetColumnWidth($hListView2, 4, $s[3])
_GUICtrlListView_SetColumnWidth($hListView3, 0, $s[10])
_GUICtrlListView_SetColumnWidth($hListView3, 1, $s[2])
_GUICtrlListView_SetColumnWidth($hListView3, 2, $s[8])
_GUICtrlListView_SetColumnWidth($hListView3, 3, $s[4])
_GUICtrlListView_SetColumnWidth($hListView3, 4, $s[3])
EndFunc
SetColumnWidth()
; Read and parse the CSV files
If _ReadCSV($sCSVPath1, $hListView1) Then
; MsgBox(64, "Success", "CSV file 1 loaded successfully.")
Else
MsgBox(16, "Error", "Failed to load Europe region list.")
EndIf
If _ReadCSV($sCSVPath2, $hListView2) Then
; MsgBox(64, "Success", "CSV file 2 loaded successfully.")
Else
MsgBox(16, "Error", "Failed to load America region list.")
EndIf
If _ReadCSV($sCSVPath3, $hListView3) Then
; MsgBox(64, "Success", "CSV file 3 loaded successfully.")
Else
MsgBox(16, "Error", "Failed to load Asia region list.")
EndIf
; Main loop with sorting handling
While 1
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
Exit
Case $btnDelete1
; Clears PAL Tab of list items
_GUICtrlListView_DeleteAllItems($hListView1)
Case $btnDelete2
; Clears PAL Tab of list items
_GUICtrlListView_DeleteAllItems($hListView2)
Case $btnDelete3
; Clears PAL Tab of list items
_GUICtrlListView_DeleteAllItems($hListView3)
EndSwitch
WEnd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment