Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

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

Select an option

Save EncodeTheCode/74b43125527bca4c6055b66ff7653041 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)
; --- Toast settings you can customize ---
Global $g_iToastWidth = 360
Global $g_iToastHeight = 110
Global $g_iToastRadius = 18
Global $g_iToastStayMs = 6000 ; How long the toast stays fully visible
Global $g_iToastFadeInMs = 440 ; How long it takes to fade in
Global $g_iToastFadeOutMs = 1350 ; How long it takes to fade out
Global $g_iToastEdgePad = 9 ; Distance from the bottom-right corner
; Create GUI and Tab Control
Global $hAppT = "List View Manager"
Global $hGUI = GUICreate("PlayStation One - Game Library - " & $hAppT, 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, $iRow
; 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
If StringStripWS($aLines[$iIndex], 3) = "" Then ContinueLoop
$aFields = StringSplit($aLines[$iIndex], "|")
If $aFields[0] < 1 Then ContinueLoop
$iRow = _GUICtrlListView_AddItem($hListView, $aFields[1])
For $i = 2 To $aFields[0]
_GUICtrlListView_AddSubItem($hListView, $iRow, $aFields[$i], $i - 1)
Next
Next
Return True
EndFunc
; Create 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
Func __SwapRows(ByRef $aData, $iA, $iB)
Local $aTemp[5]
For $i = 0 To 4
$aTemp[$i] = $aData[$iA][$i]
$aData[$iA][$i] = $aData[$iB][$i]
$aData[$iB][$i] = $aTemp[$i]
Next
EndFunc
Func __QuickSort2D(ByRef $aData, $iLeft, $iRight, $iColumn, $bDescending)
Local $i = $iLeft
Local $j = $iRight
Local $sPivot = $aData[Int(($iLeft + $iRight) / 2)][$iColumn]
Local $bAsc = Not $bDescending
While $i <= $j
If $bAsc Then
While StringCompare($aData[$i][$iColumn], $sPivot, 0) < 0
$i += 1
WEnd
While StringCompare($aData[$j][$iColumn], $sPivot, 0) > 0
$j -= 1
WEnd
Else
While StringCompare($aData[$i][$iColumn], $sPivot, 0) > 0
$i += 1
WEnd
While StringCompare($aData[$j][$iColumn], $sPivot, 0) < 0
$j -= 1
WEnd
EndIf
If $i <= $j Then
If $i <> $j Then __SwapRows($aData, $i, $j)
$i += 1
$j -= 1
EndIf
WEnd
If $iLeft < $j Then __QuickSort2D($aData, $iLeft, $j, $iColumn, $bDescending)
If $i < $iRight Then __QuickSort2D($aData, $i, $iRight, $iColumn, $bDescending)
EndFunc
; Function to sort the ListView items
Func _SortListView($hListView, $iColumn, $iDescending)
Local $aItems = _GUICtrlListView_CreateArray($hListView)
If @error Then Return
If UBound($aItems, 1) <= 1 Then Return
__QuickSort2D($aItems, 0, UBound($aItems) - 1, $iColumn, $iDescending)
; Clear the ListView
_GUICtrlListView_DeleteAllItems($hListView)
; Add the sorted items back to the ListView
For $i = 0 To UBound($aItems) - 1
Local $iRow = _GUICtrlListView_AddItem($hListView, $aItems[$i][0])
For $j = 1 To UBound($aItems, 2) - 1
_GUICtrlListView_AddSubItem($hListView, $iRow, $aItems[$i][$j], $j)
Next
Next
EndFunc
Func _GetWorkAreaRect()
Local $tRect = DllStructCreate("long Left;long Top;long Right;long Bottom")
DllCall("user32.dll", "bool", "SystemParametersInfoW", "uint", 0x0030, "uint", 0, "ptr", DllStructGetPtr($tRect), "uint", 0)
Return $tRect
EndFunc
Func _SetRoundedCorners($hWnd, $iWidth, $iHeight, $iRadius)
Local $aRgn = DllCall("gdi32.dll", "handle", "CreateRoundRectRgn", _
"int", 0, "int", 0, "int", $iWidth + 1, "int", $iHeight + 1, _
"int", $iRadius, "int", $iRadius)
If @error Or Not IsArray($aRgn) Then Return False
DllCall("user32.dll", "int", "SetWindowRgn", "hwnd", $hWnd, "handle", $aRgn[0], "int", True)
Return True
EndFunc
Func _ToastFade($hWnd, $iFrom, $iTo, $iDuration)
Local $iSteps = 20
If $iSteps < 1 Then $iSteps = 1
Local $iDelay = Int($iDuration / $iSteps)
If $iDelay < 1 Then $iDelay = 1
For $i = 0 To $iSteps
Local $iAlpha = Int($iFrom + (($iTo - $iFrom) * $i / $iSteps))
If $iAlpha < 0 Then $iAlpha = 0
If $iAlpha > 255 Then $iAlpha = 255
WinSetTrans($hWnd, "", $iAlpha)
Sleep($iDelay)
Next
EndFunc
; Toast-style notification with rounded corners and configurable timing
Func _ShowToast($sText)
Local $tWork = _GetWorkAreaRect()
Local $iLeft = DllStructGetData($tWork, "Right") - $g_iToastWidth - $g_iToastEdgePad
Local $iTop = DllStructGetData($tWork, "Bottom") - $g_iToastHeight - $g_iToastEdgePad
Local $hToast = GUICreate("", $g_iToastWidth, $g_iToastHeight, $iLeft, $iTop, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW, $WS_EX_LAYERED))
GUISetBkColor(0x1E1E1E, $hToast)
Local $idLabel = GUICtrlCreateLabel($sText, 16, 14, $g_iToastWidth - 32, $g_iToastHeight - 28)
GUICtrlSetColor($idLabel, 0xFFFFFF)
GUICtrlSetFont($idLabel, 10, 400, 0, "Segoe UI")
GUISetState(@SW_SHOW, $hToast)
_SetRoundedCorners($hToast, $g_iToastWidth, $g_iToastHeight, $g_iToastRadius)
WinSetTrans($hToast, "", 0)
_ToastFade($hToast, 0, 255, $g_iToastFadeInMs)
Sleep($g_iToastStayMs)
_ToastFade($hToast, 255, 0, $g_iToastFadeOutMs)
GUIDelete($hToast)
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
Local $bPAL = _ReadCSV($sCSVPath1, $hListView1)
If Not $bPAL Then
MsgBox(16, "Error", "Failed to load Europe region list.")
EndIf
Local $bNTSCU = _ReadCSV($sCSVPath2, $hListView2)
If Not $bNTSCU Then
MsgBox(16, "Error", "Failed to load America region list.")
EndIf
Local $bNTSCJ = _ReadCSV($sCSVPath3, $hListView3)
If Not $bNTSCJ Then
MsgBox(16, "Error", "Failed to load Asia region list.")
EndIf
; Show toast only when all CSVs loaded correctly
If $bPAL And $bNTSCU And $bNTSCJ Then
Local $iPALCount = _GUICtrlListView_GetItemCount($hListView1)
Local $iNTSCUCount = _GUICtrlListView_GetItemCount($hListView2)
Local $iNTSCJCount = _GUICtrlListView_GetItemCount($hListView3)
_ShowToast( _
$hAppT & @CRLF & _
"" & @CRLF & _
"Number of PAL game entries: " & $iPALCount & @CRLF & _
"Number of NTSC-U game entries: " & $iNTSCUCount & @CRLF & _
"Number of NTSC-J game entries: " & $iNTSCJCount _
)
EndIf
; Notification handler for ListView header clicks
Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
Local $tNMLV = DllStructCreate($tagNMLISTVIEW, $lParam)
If @error Then Return $GUI_RUNDEFMSG
; LVN_COLUMNCLICK = -108
If DllStructGetData($tNMLV, "Code") <> $LVN_COLUMNCLICK Then Return $GUI_RUNDEFMSG
Local $hFrom = DllStructGetData($tNMLV, "hWndFrom")
Local $iColumn = DllStructGetData($tNMLV, "SubItem")
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
; đŸ”„ Always toggle correctly per column
Local $bDesc = $g_aSortOrder[$iListIndex][$iColumn]
_SortListView($hFrom, $iColumn, $bDesc)
; flip state AFTER sorting
$g_aSortOrder[$iListIndex][$iColumn] = Not $bDesc
Return $GUI_RUNDEFMSG
EndFunc
; Main loop
While 1
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
Exit
Case $btnDelete1
_GUICtrlListView_DeleteAllItems($hListView1)
Case $btnDelete2
_GUICtrlListView_DeleteAllItems($hListView2)
Case $btnDelete3
_GUICtrlListView_DeleteAllItems($hListView3)
EndSwitch
WEnd
@EncodeTheCode

Copy link
Copy Markdown
Author

Produkten togs bort med Windows Installer. Produktnamn: Microsoft .NET Host FX Resolver - 6.0.16 (x64). Produktversion: 48.67.58427. ProduktsprÄk: 1033. Tillverkare: Microsoft Corporation. Slutförande- eller felstatus efter borttagningen: 0.

Produkten installerades med Windows Installer. Produktnamn: Microsoft .NET Runtime - 6.0.36 (x64). Produktversion: 48.144.23141. ProduktsprÄk: 1033. Tillverkare: Microsoft Corporation. Slutförande- eller felstatus efter installationen: 0.

After upgrading from 6.0.16 (x64) to 6.0.36 (x64) some features somehow got deprecated and caused BSoD issues and other problems, after SFC scanning and DISM scanning, and disabling hardware acceleration in my browser, things has stabilized for now. The AutoIt script above now works correctly as the WM Notify had some things that needed to be altered because of some memory offset thingy being wrong, but worked earlier in the older codebase of .NET framework. So it's strange how that impacted the code after just a simple update. Anyways I am glad it's fixed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment