...
Edit: Fixed an error, if ICU was called with non-existing config set number via command line-
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=Desktop.ico
#AutoIt3Wrapper_outfile=ICU.exe
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Res_Description=Icon Configuration Utility
#AutoIt3Wrapper_Res_Fileversion=2.3.0.0
#AutoIt3Wrapper_Res_LegalCopyright=Melba23 2009-2010, KaFu 2010
://////=__=
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/sf /sv /om /cs=0 /cn=0
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;
; ##### Icon Configuration Utility #####
;
; Script Version: 2.3
; As at 15 Feb 10
;
#Region ;----- Includes -----
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <ComboConstants.au3>
#include <GuiListView.au3>
#include <Date.au3>
#include <File.au3>
#EndRegion ;----- Includes -----
#Region ;----- Declarations -----
If Not @Compiled Then MsgBox(64, "ICU Info", "ICU needs to be compiled for full functionality")
If @OSArch = "X64" And @AutoItX64 = 0 Then
MsgBox(16, "ICU Error", "This version of ICU is 32-bit compiled" & @CRLF & _
"and will not run correctly with a 64-bit OS" & @CRLF & @CRLF & _
"Please recompile as a 64-bit executable")
Exit
EndIf
Global $sConfig_Name, $sConfig_Path, $hList_Start, $aScreen_Res
Global $hScreen = WinGetHandle("Program Manager")
; Match only exact window titles
Global $iOldOpt = Opt("WinTitleMatchMode", 3)
; Set Desktop path
Global $sDesktop_Path = @DesktopDir
; See if app is in Program Files
If @ScriptDir = @ProgramFilesDir Then
; If app in Program Files need to save config files elsewhere
If Not FileExists(@AppDataDir & "\ICF") Then DirCreate(@AppDataDir & "\ICF")
$sConfig_Path = @AppDataDir & "\ICF"
Else
; Can use working directory
$sConfig_Path = @ScriptDir
EndIf
; Get list of existing config files
Global $aConfig_List = _FileListToArray($sConfig_Path, "*.icf", 1)
#EndRegion ;----- Declarations -----
#Region ;----- Create GUI -----
Global $sGUITitle = "Icon Configuration Utility - 64bit version"
If @AutoItX64 = 0 Then $sGUITitle = "Icon Configuration Utility - 32bit version"
Global $hMain_GUI = GUICreate($sGUITitle, 370, 247)
GUISetBkColor(0xFFFFFF)
Global $hSave_Button = GUICtrlCreateButton("Save", 10, 175, 80, 25)
Global $hRestore_Button = GUICtrlCreateButton("Restore", 100, 175, 80, 25)
Global $hDelete_Button = GUICtrlCreateButton("Delete", 190, 175, 80, 25)
Global $hAbout_Button = GUICtrlCreateButton("About", 280, 175, 80, 25)
GUICtrlCreateLabel("List of icon configuration files (*.icf)", 10, 8, 200, 20)
Global $hState_Label = GUICtrlCreateLabel("Ready", 280, 7, 80, 16, $SS_CENTER + $SS_CENTERIMAGE)
GUICtrlSetBkColor(-1, 0xCCFFCC)
GUICtrlCreateLabel("Command line restore via", 10, 210, 120, 13)
GUICtrlSetFont(-1, 7, 400, 0, "Lucida Console")
GUICtrlCreateLabel("icu.exe restore #", 10, 225, 120, 13)
GUICtrlSetFont(-1, 7, 400, 0, "Lucida Console")
GUICtrlCreateLabel("Move unknown icons", 152, 214, 110, 13)
Global $cID_Combo_Unknown_Icon = GUICtrlCreateCombo("to position 0,0", 260, 210, 100, 20, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "off-screen|ask per icon")
Global $hFile_List = GUICtrlCreateListView("#|Name|Date|Resolution", 10, 30, 350, 135, $LVS_SINGLESEL, $LVS_EX_FULLROWSELECT)
; Set up alt line colouring
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE)
; Set col width
_GUICtrlListView_SetColumnWidth(-1, 0, 20)
_GUICtrlListView_SetColumnWidth(-1, 1, 117)
_GUICtrlListView_SetColumnWidth(-1, 2, 145)
_GUICtrlListView_SetColumnWidth(-1, 3, $LVSCW_AUTOSIZE_USEHEADER)
If IsArray($aConfig_List) Then
_Fill
_ListView
()
Else
GUICtrlCreateListViewItem("|No Files Found", $hFile_List)
GUICtrlSetState($hRestore_Button, $GUI_DISABLE)
EndIf
#Region ; ----- Command line -----
If $CmdLine[0] = 2 And StringLower($CmdLine[1]) = "restore" Then
If Not IsArray($aConfig_List) Then Exit
For $i = 1 To $aConfig_List[0]
If Number(StringLeft($aConfig_List[$i], 3)) = Number($CmdLine[2]) Then
$sConfig_Name = $sConfig_Path & "\" & $aConfig_List[$i]
If FileExists($sConfig_Name) Then _Set
_Locations
_Desktop
()
Exit
EndIf
Next
MsgBox(64 + 262144, "ICU", "ICU could not find called config # " & $CmdLine[2])
Exit
EndIf
#EndRegion ; ----- Command line -----
GUISetState()
#EndRegion ;----- Create GUI -----
#Region ;----- Main loop -----
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Opt("WinTitleMatchMode", $iOldOpt)
Exit
Case $hSave_Button
_Save
_Config
()
Case $hRestore_Button
_Restore
_Config
()
Case $hDelete_Button
Global $iIndex = _GUICtrlListView_GetSelectedIndices($hFile_List, True)
If $iIndex[0] = 1 Then
If MsgBox(4 + 16, $sGUITitle, "Are you sure you want to delete """ & _GUICtrlListView_GetItemText($hFile_List, $iIndex[1], 1) & """") = 6 Then _Delete
_Config
()
EndIf
Case $hAbout_Button
_On
_Info
()
EndSwitch
WEnd
#EndRegion ;----- Main loop -----
; Functions
#Region ;----- Save -----
Func _Save
_Config
()
Local $sConfig_Type = InputBox($sGUITitle, "Enter a name for the new icon configuration file:", Default, Default, 300, 130)
If @error Then Return
$sConfig_Type = StringRegExpReplace($sConfig_Type, '[\Q\/:?*"<>|\E]', '') ; force valid filename
GUICtrlSetData($hState_Label, "Working")
GUICtrlSetBkColor($hState_Label, 0xCC0000)
; Get new config filename
If IsArray($aConfig_List) Then
Local $iNew_Index = 0
For $i = 0 To UBound($aConfig_List) - 1
If Number(StringLeft($aConfig_List[$i], 3)) >= $iNew_Index Then $iNew_Index = Number(StringLeft($aConfig_List[$i], 3)) + 1
Next
$sConfig_Name = $sConfig_Path & "\" & StringFormat("%03i", $iNew_Index) & "_" & $sConfig_Type & ".icf"
Else
$sConfig_Name = $sConfig_Path & "\001_" & $sConfig_Type & ".icf"
EndIf
; Write config file data
$aScreen_Res = WinGetPos($hScreen)
IniWrite($sConfig_Name, "Data", "Type", $sConfig_Type)
IniWrite($sConfig_Name, "Data", "Date", _NowCalc())
IniWrite($sConfig_Name, "Data", "Resolution", $aScreen_Res[2] & "x" & $aScreen_Res[3])
IniWrite($sConfig_Name, "Data", "Unknown_Icon_Handling", GUICtrlRead($cID_Combo_Unknown_Icon))
; Save Desktop locations
_Save
_Locations
_Desktop
()
; Refill list
_Fill
_ListView
()
; Reset GUI
GUICtrlSetData($hState_Label, "Ready")
GUICtrlSetBkColor($hState_Label, 0xCCFFCC)
GUICtrlSetState($hRestore_Button, $GUI_ENABLE)
EndFunc ;==>_Save_Config
; ------------
Func _Save
_Locations
_Desktop
()
Local $hExplorer_List = ControlGetHandle("Program Manager", "", "SysListView321")
; Loop through folder contents
For $i = 0 To _GUICtrlListView_GetItemCount($hExplorer_List) - 1
; Get name
Local $sKey_Name = _GUICtrlListView_GetItemText($hExplorer_List, $i)
; Get position
Local $aPos = _GUICtrlListView_GetItemPosition($hExplorer_List, $i)
Local $sValue_Pos = $aPos[0] & ":" & $aPos[1]
; Write to config file
IniWrite($sConfig_Name, "Desktop", _URIEncode
($sKey_Name), $sValue_Pos)
Next
EndFunc ;==>_Save_Locations_Desktop
#EndRegion ;----- Save -----
#Region ;----- Restore -----
Func _Restore
_Config
()
GUICtrlSetData($hState_Label, "Working")
GUICtrlSetBkColor($hState_Label, 0xCC0000)
; Get config file name
Local $iIndex = GUICtrlRead($hFile_List) - $hList_Start
If $iIndex > 0 Then
$sConfig_Name = $sConfig_Path & "\" & $aConfig_List[$iIndex]
; Restore Desktop
_Set
_Locations
_Desktop
()
Else
MsgBox(0, "Error", "No Configuration File Selected")
EndIf
; Reset GUI
GUICtrlSetData($hState_Label, "Ready")
GUICtrlSetBkColor($hState_Label, 0xCCFFCC)
EndFunc ;==>_Restore_Config
; --------
Func _Set
_Locations
_Desktop
()
Local $hExplorer_List = ControlGetHandle("Program Manager", "", "SysListView321")
GUICtrlSetData($cID_Combo_Unknown_Icon, IniRead($sConfig_Name, "Data", "Unknown_Icon_Handling", "to position 0,0"))
; Now replace icons back in stored positions
Local $j = 0, $sAskAnswer
While True
For $i = 0 To _GUICtrlListView_GetItemCount($hExplorer_List) - 1
; Get name & position
Local $sIcon_Name = _GUICtrlListView_GetItemText($hExplorer_List, $i)
Local $sPos_Saved = IniRead($sConfig_Name, "Desktop", _URIEncode
($sIcon_Name), "")
If $sPos_Saved <> "" Then
Local $aPos = StringSplit($sPos_Saved, ":")
_GUICtrlListView_SetItemPosition($hExplorer_List, $i, $aPos[1], $aPos[2])
Else
Switch GUICtrlRead($cID_Combo_Unknown_Icon)
Case "off-screen"
_GUICtrlListView_SetItemPosition($hExplorer_List, $i, 9999, 9999)
Case "ask per icon"
If $j = 0 Then $sAskAnswer = InputBox($sGUITitle, "Enter a position x,y", Default, Default, 300, 130)
If @error Or Not StringInStr($sAskAnswer, ",") Then
_GUICtrlListView_SetItemPosition($hExplorer_List, $i, 0, 0)
Else
Local $aAskAnswer = StringSplit($sAskAnswer, ",")
If $aAskAnswer[0] = 2 Then
_GUICtrlListView_SetItemPosition($hExplorer_List, $i, Number($aAskAnswer[1]), Number($aAskAnswer[2]))
Else
_GUICtrlListView_SetItemPosition($hExplorer_List, $i, 0, 0)
EndIf
EndIf
Case Else
_GUICtrlListView_SetItemPosition($hExplorer_List, $i, 0, 0)
EndSwitch
EndIf
Next
$j += 1
If $j = 2 Then ExitLoop
WEnd
EndFunc ;==>_Set_Locations_Desktop
#EndRegion ;----- Restore -----
#Region ;----- Delete -----
Func _Delete
_Config
()
GUICtrlSetData($hState_Label, "Deleting")
GUICtrlSetBkColor($hState_Label, 0xCC0000)
; Get config file name
Local $iIndex = GUICtrlRead($hFile_List) - $hList_Start
If $iIndex > 0 Then
$sConfig_Name = $sConfig_Path & "\" & $aConfig_List[$iIndex]
; Delete config file
FileRecycle($sConfig_Name)
EndIf
; Refill list
_Fill
_ListView
()
; Reset GUI
GUICtrlSetData($hState_Label, "Ready")
GUICtrlSetBkColor($hState_Label, 0xCCFFCC)
EndFunc ;==>_Delete_Config
#EndRegion ;----- Delete -----
#Region ;----- Misc -----
Func _Fill
_ListView
()
_GUICtrlListView_DeleteAllItems($hFile_List)
; Get list of files
$aConfig_List = _FileListToArray($sConfig_Path, "*.icf", 1)
; Fill Listview
If Not IsArray($aConfig_List) Then
GUICtrlCreateListViewItem("|No Files Found", $hFile_List)
GUICtrlSetState($hRestore_Button, $GUI_DISABLE)
Return
EndIf
$hList_Start = GUICtrlCreateDummy() ; Start of list handles
; If > 9 files reduce final col size to leave place for v-scroll so no h-scroll
If $aConfig_List[0] > 9 Then _GUICtrlListView_SetColumnWidth($hFile_List, 2, 95)
; Get data from files
For $i = 1 To $aConfig_List[0]
Local $sType = IniRead($sConfig_Path & "\" & $aConfig_List[$i], "Data", "Type", "Unknown")
Local $sDate = IniRead($sConfig_Path & "\" & $aConfig_List[$i], "Data", "Date", "Unknown")
Local $sRes = IniRead($sConfig_Path & "\" & $aConfig_List[$i], "Data", "Resolution", "Unknown")
GUICtrlCreateListViewItem(Number(StringLeft($aConfig_List[$i], 3)) & "|" & $sType & "|" & $sDate & "|" & $sRes, $hFile_List)
GUICtrlSetBkColor(-1, 0xCCFFCC)
Next
EndFunc ;==>_Fill_ListView
#EndRegion ;----- Misc -----
#Region ;----- Info Functions -----
Func _On
_Info
()
;Show info messagebox
MsgBox(4160, "About", "Icon Configuration Utility v2.2" & @CRLF & @CRLF & "Melba23 2009-2010, KaFu 2010")
EndFunc ;==>_On_Info
#EndRegion ;----- Info Functions -----
; #FUNCTION# ====================================================================================================================
; Name...........: _URIEncode
; Description ...: Encodes a string to be used in an URI
; Syntax.........: _URIEncode($sData)
; Parameters ....: $sData - String to encode
; Return values .: Encoded String
; Author ........: Prog@ndy
; Modified.......:
; Remarks .......: This function uses UTF-8 encoding for special chars
; Related .......: _URIDecode
; Link ..........;
; Example .......;
; ===============================================================================================================================
Func _URIEncode
($sData)
; Prog@ndy
Local $aData = StringSplit(BinaryToString(StringToBinary($sData, 4), 1), "")
Local $nChar
$sData = ""
For $i = 1 To $aData[0]
;~ ConsoleWrite($aData[$i] & @CRLF)
$nChar = Asc($aData[$i])
Switch $nChar
Case 45, 46, 48 - 57, 65 To 90, 95, 97 To 122, 126
$sData &= $aData[$i]
Case 32
$sData &= "+"
Case Else
$sData &= "%" & Hex($nChar, 2)
EndSwitch
Next
Return $sData
EndFunc ;==>_URIEncode
Func _URIDecode
($sData)
; Prog@ndy
Local $aData = StringSplit(StringReplace($sData, "+", " ", 0, 1), "%")
$sData = ""
For $i = 2 To $aData[0]
$aData[1] &= Chr(Dec(StringLeft($aData[$i], 2))) & StringTrimLeft($aData[$i], 2)
Next
Return BinaryToString(StringToBinary($aData[1], 1), 4)
EndFunc ;==>_URIDecode