Sign in to follow this  
Followers 0

Desktop Icon Config Saver

39 posts in this topic

Posted (edited)

NEW 2.1 VERSION: Uploaded 15 Jan 10

Hi,

KaFu and I found we were working on very similar ideas to restore the Desktop icons to their normal place if they became "rearranged". Vista seems to like this doing on occasion just for fun - but we all know some apps and games which change the display resolution or move icons around. This annoys "tidy" people who like their desktops arranged "just so" - I am particularly thinking of this desktop when I say that! :D

We combined efforts and here is the result of our labours (script and icon):

Operation is easy - press "Save" to store a particular configuration and "Restore" to reset the icons to the saved positions in the selected configuration file. "Delete" allows you to remove unwanted configuration files from the list. Thanks to KaFu there is a commandline option so that the restoration can be run via HotKeys if required (that is why the script warns that it should be compiled for full functionality). You can decide what to do with any icons that have been added since you last saved the configuration file - the default is to put them in the top-left cormer, but you can also banish them way off-screen or, more sensibly, specify a location for them.

We hope you find it useful. As usual, comments and suggstions are most welcome.

M23 & KaFu

Edit: New 2.1 version uploaded 15 Jan 10

Edited by Melba23

Share this post


Link to post
Share on other sites



Posted

2 things I want to mention:

  • display for screen resolution for multi monitor is not working properly, only main screen resolution will be displayed
  • restore did not work properly because after sorting desktop icons e.g. by size and restore it the position of the icons were not set as before
Regards,

UEZ

Share this post


Link to post
Share on other sites

Posted (edited)

@UEZ:

Could you please test this?

#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.0.0.0
#AutoIt3Wrapper_Res_LegalCopyright=Melba23 2009-2010, KaFu 2010
#AutoIt3Wrapper_Res_Field=ProductName|ICU
#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.0
;   As at 13 Jan 10
;
#Region    ;----- Includes -----

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <ComboConstants.au3>
#include <GuiListView.au3>
#include <Date.au3>
#include <File.au3>
#include <WinAPI.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

Global $hDesktop = _WinAPI_GetDesktopWindow()
Global $tRcDesktop, $DesktopWidth, $DesktopHeight

; 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 @OSArch = "X86" 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
	$sConfig_Name = $sConfig_Path & "\" & $aConfig_List[Number($CmdLine[2])]
	If FileExists($sConfig_Name) Then _Set_Locations_Desktop()
	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

	GUICtrlSetData($hState_Label, "Working")
	GUICtrlSetBkColor($hState_Label, 0xCC0000)

	; Get new config filename
	If IsArray($aConfig_List) Then
		Local $iNew_Index = $aConfig_List[0] + 1
		$sConfig_Name = $sConfig_Path & "\IconConfigFile" & StringFormat("%03i", $iNew_Index) & ".icf"
	Else
		$sConfig_Name = $sConfig_Path & "\IconConfigFile001.icf"
	EndIf

	; Write config file data
	IniWrite($sConfig_Name, "Data", "Type", $sConfig_Type)
	IniWrite($sConfig_Name, "Data", "Date", _NowCalc())
	$tRcDesktop = _WinAPI_GetWindowRect($hDesktop)
	$DesktopWidth = DllStructGetData($tRcDesktop, 3)
	$DesktopHeight = DllStructGetData($tRcDesktop, 4)
	IniWrite($sConfig_Name, "Data", "Resolution", $DesktopWidth & "x" & $DesktopHeight)
	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", $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"))

	; Move all icons out of the viewable area to guarantee clear space for relocation
	$tRcDesktop = _WinAPI_GetWindowRect($hDesktop)
	$DesktopWidth = DllStructGetData($tRcDesktop, 3)
	$DesktopHeight = DllStructGetData($tRcDesktop, 4)
	For $i = 0 To _GUICtrlListView_GetItemCount($hExplorer_List) - 1
		_GUICtrlListView_SetItemPosition($hExplorer_List, $i, $DesktopWidth, $DesktopHeight + 100 * $i)
	Next

	; Now replace icons back in stored positions
	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", $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"
					Local $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

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)
		; Renumber remaining config files
		$aConfig_List = _FileListToArray($sConfig_Path, "*.icf", 1)
		If IsArray($aConfig_List) Then
			For $i = 1 To $aConfig_List[0]
				Local $sSource = $sConfig_Path & "\" & $aConfig_List[$i]
				Local $sDest = $sConfig_Path & "\IconConfigFile" & StringFormat("%03i", $i) & ".icf"
				FileMove($sSource, $sDest)
			Next
		EndIf
	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($i & "|" & $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.0" & @CRLF & @CRLF & "Melba23 2009-2010, KaFu 2010")

EndFunc   ;==>_On_Info

#EndRegion    ;----- Info Functions -----

Edit: And as far as I can see, all out-arranging options of desktop icons need to be switched off of course.

Edited by KaFu

Share this post


Link to post
Share on other sites

Posted

Ok, seems to be problem with "Align to Grid" option when it is selected (I assume standardly selected)!

But anyway it should also work with that feature enabled!

I tested it on Vista x32 (#AutoIt3Wrapper_UseX64=y was set in your code - have to remove it ;-))

Regards,

UEZ

Share this post


Link to post
Share on other sites

Posted

UEZ,

It works perfectly for me on Vista x32 with the "Align to grid" selected. :D

M23

P.S. KaFu keeps adding that x64 line - you have no idea how many times I have deleted it! :huggles:

Share this post


Link to post
Share on other sites

Posted

It works perfectly for me on Vista x32 with the "Align to grid" selected. :huggles:

Maybe the reason was the usage of @DesktopHeight and @DesktopWidth macros in a multi-monitor setup? I replaced them by _WinAPI_GetDesktopWindow() + _WinAPI_GetWindowRect() calls in my example above.

@UEZ: Did just the second version work, or also the initial version with snap-to-grid/auto-align disabled?

@Melba: Works fine on Win7 with snap-to-grid enabled too.

P.S. KaFu keeps adding that x64 line - you have no idea how many times I have deleted it! :

Now you know why I insisted on the line "If @OSArch = "X64" And @AutoItX64 = 0 Then" :D. For info, this script MUST be complied aligned to @OSArch, otherwise the _GUICtrlListView_GetItemPosition() function can't access the desktop window (listview limitation).

Share this post


Link to post
Share on other sites

Posted

Hi !

problem with "Align to Grid" selected

+1

(Test on: Win-7-32 ; the 4:50 PM Kafu's release)

No problem with "Align to Grid" unselected

Share this post


Link to post
Share on other sites

Posted

It seems to be a problem with the "Move all icons out of the viewable area to guarantee clear space for relocation" routine!

Further if you run "Now replace icons back in stored positions" twice it will place the icons properly!

And I also added to get real monitor size (should support multi monitor size)!

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=Desktop.ico
#AutoIt3Wrapper_Outfile=ICU.exe
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Res_Description=Icon Configuration Utility
#AutoIt3Wrapper_Res_Fileversion=2.0.0.0
#AutoIt3Wrapper_Res_LegalCopyright=Melba23 2009-2010, KaFu 2010
#AutoIt3Wrapper_Res_Field=ProductName|ICU
#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.0
; As at 13 Jan 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

Global $hScreen = WinGetHandle("Program Manager")
Global $aScreen_Res = WinGetPos($hScreen)

; 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	; ----- Command line -----

If $CmdLine[0] = 2 And StringLower($CmdLine[1]) = "restore" Then
	$sConfig_Name = $sConfig_Path & "\" & $aConfig_List[Number($CmdLine[2])]
	If FileExists($sConfig_Name) Then _Set_Locations_Desktop()
	Exit
EndIf

#EndRegion	; ----- Command line -----
#Region	;----- Create GUI -----

Global $sGUITitle = "Icon Configuration Utility - 64bit version"
If @OSArch = "X86" 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

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

	GUICtrlSetData($hState_Label, "Working")
	GUICtrlSetBkColor($hState_Label, 0xCC0000)

	; Get new config filename
	If IsArray($aConfig_List) Then
		Local $iNew_Index = $aConfig_List[0] + 1
		$sConfig_Name = $sConfig_Path & "\IconConfigFile" & StringFormat("%03i", $iNew_Index) & ".icf"
	Else
		$sConfig_Name = $sConfig_Path & "\IconConfigFile001.icf"
	EndIf

	; Write config file data
	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", $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"))

	; Move all icons out of the viewable area to guarantee clear space for relocation
;~ 	For $i = 0 To _GUICtrlListView_GetItemCount($hExplorer_List) - 1
;~ 		_GUICtrlListView_SetItemPosition($hExplorer_List, $i, $aScreen_Res[2], $aScreen_Res[3] + 100 * $i)
;~ 	Next

	; Now replace icons back in stored positions
	For $j = 0 To 1
		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", $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"
						Local $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
	Next
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)
		; Renumber remaining config files
		$aConfig_List = _FileListToArray($sConfig_Path, "*.icf", 1)
		If IsArray($aConfig_List) Then
			For $i = 1 To $aConfig_List[0]
				Local $sSource = $sConfig_Path & "\" & $aConfig_List[$i]
				Local $sDest = $sConfig_Path & "\IconConfigFile" & StringFormat("%03i", $i) & ".icf"
				FileMove($sSource, $sDest)
			Next
		EndIf
	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($i & "|" & $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.0" & @CRLF & @CRLF & "Melba23 2009-2010, KaFu 2010")

EndFunc ;==>_On_Info

#EndRegion	;----- Info Functions -----

Please test it!

Regards,

UEZ

Share this post


Link to post
Share on other sites

Posted (edited)

Two small things:

- $aScreen_Res = WinGetPos($hScreen) needs to be called in _Save_Config() as the resolution is subject to change

- the command line restore calls _Set_Locations_Desktop(), and in that function we are updating GUI controls... thus the command line call needs to be relocated to directly before the call of GuiSetState() or the scripts crashes with undefined variable (was already wrong in the initial script).

#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.0.0.0
#AutoIt3Wrapper_Res_LegalCopyright=Melba23 2009-2010, KaFu 2010
#AutoIt3Wrapper_Res_Field=ProductName|ICU
#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.0
; As at 13 Jan 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 @OSArch = "X86" 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
    $sConfig_Name = $sConfig_Path & "\" & $aConfig_List[Number($CmdLine[2])]
    If FileExists($sConfig_Name) Then _Set_Locations_Desktop()
    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

    GUICtrlSetData($hState_Label, "Working")
    GUICtrlSetBkColor($hState_Label, 0xCC0000)

    ; Get new config filename
    If IsArray($aConfig_List) Then
        Local $iNew_Index = $aConfig_List[0] + 1
        $sConfig_Name = $sConfig_Path & "\IconConfigFile" & StringFormat("%03i", $iNew_Index) & ".icf"
    Else
        $sConfig_Name = $sConfig_Path & "\IconConfigFile001.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", $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
    For $j = 0 To 1
        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", $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"
                        Local $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
    Next
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)
        ; Renumber remaining config files
        $aConfig_List = _FileListToArray($sConfig_Path, "*.icf", 1)
        If IsArray($aConfig_List) Then
            For $i = 1 To $aConfig_List[0]
                Local $sSource = $sConfig_Path & "\" & $aConfig_List[$i]
                Local $sDest = $sConfig_Path & "\IconConfigFile" & StringFormat("%03i", $i) & ".icf"
                FileMove($sSource, $sDest)
            Next
        EndIf
    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($i & "|" & $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.0" & @CRLF & @CRLF & "Melba23 2009-2010, KaFu 2010")

EndFunc ;==>_On_Info

#EndRegion  ;----- Info Functions -----

Edit: Now a three man effort :huggles:, simple script with many tripwires. Thanks a lot and keep it up UEZ :D

Edited by KaFu

Share this post


Link to post
Share on other sites

Posted (edited)

Small update:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=Desktop.ico
#AutoIt3Wrapper_outfile=ICU.exe
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_Description=Icon Configuration Utility
#AutoIt3Wrapper_Res_Fileversion=2.0.0.0
#AutoIt3Wrapper_Res_LegalCopyright=Melba23 2009-2010, KaFu 2010
#AutoIt3Wrapper_Res_Field=ProductName|ICU
#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.0
; As at 13 Jan 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 @OSArch = "X86" 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
	$sConfig_Name = $sConfig_Path & "\" & $aConfig_List[Number($CmdLine[2])]
	If FileExists($sConfig_Name) Then _Set_Locations_Desktop()
	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

	GUICtrlSetData($hState_Label, "Working")
	GUICtrlSetBkColor($hState_Label, 0xCC0000)

	; Get new config filename
	If IsArray($aConfig_List) Then
 	Local $iNew_Index = $aConfig_List[0] + 1
 	$sConfig_Name = $sConfig_Path & "\IconConfigFile" & StringFormat("%03i", $iNew_Index) & ".icf"
	Else
 	$sConfig_Name = $sConfig_Path & "\IconConfigFile001.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", $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
	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", $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"
						Local $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
				$j += 1
			EndIf
		Next
		$j += 1
		If $j > 1 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)
 	; Renumber remaining config files
 	$aConfig_List = _FileListToArray($sConfig_Path, "*.icf", 1)
 	If IsArray($aConfig_List) Then
 	For $i = 1 To $aConfig_List[0]
 	Local $sSource = $sConfig_Path & "\" & $aConfig_List[$i]
 	Local $sDest = $sConfig_Path & "\IconConfigFile" & StringFormat("%03i", $i) & ".icf"
 	FileMove($sSource, $sDest)
 	Next
 	EndIf
	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($i & "|" & $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.0" & @CRLF & @CRLF & "Melba23 2009-2010, KaFu 2010")

EndFunc ;==>_On_Info

#EndRegion ;----- Info Functions -----

Just to avoid double entry procedure when entering a position x,y manually!

UEZ

PS: script is not my effort, just small modification :D! Btw, nice idea!

Edited by UEZ

Share this post


Link to post
Share on other sites

Posted

Just to avoid double entry procedure when entering a position x,y manually!

Good point! But the logic used in _Set_Locations_Desktop() didn't work, adjusted it a little:

#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.0.0.0
#AutoIt3Wrapper_Res_LegalCopyright=Melba23 2009-2010, KaFu 2010
#AutoIt3Wrapper_Res_Field=ProductName|ICU
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#Obfuscator_Parameters=/sf /sv /om /cs=0 /cn=0
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;
; ##### Icon Configuration Utility #####
;
; Script Version: 2.0
; As at 13 Jan 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 @OSArch = "X86" 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
	$sConfig_Name = $sConfig_Path & "\" & $aConfig_List[Number($CmdLine[2])]
	If FileExists($sConfig_Name) Then _Set_Locations_Desktop()
	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

	GUICtrlSetData($hState_Label, "Working")
	GUICtrlSetBkColor($hState_Label, 0xCC0000)

	; Get new config filename
	If IsArray($aConfig_List) Then
		Local $iNew_Index = $aConfig_List[0] + 1
		$sConfig_Name = $sConfig_Path & "\IconConfigFile" & StringFormat("%03i", $iNew_Index) & ".icf"
	Else
		$sConfig_Name = $sConfig_Path & "\IconConfigFile001.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", $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", $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)
		; Renumber remaining config files
		$aConfig_List = _FileListToArray($sConfig_Path, "*.icf", 1)
		If IsArray($aConfig_List) Then
			For $i = 1 To $aConfig_List[0]
				Local $sSource = $sConfig_Path & "\" & $aConfig_List[$i]
				Local $sDest = $sConfig_Path & "\IconConfigFile" & StringFormat("%03i", $i) & ".icf"
				FileMove($sSource, $sDest)
			Next
		EndIf
	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($i & "|" & $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.0" & @CRLF & @CRLF & "Melba23 2009-2010, KaFu 2010")

EndFunc   ;==>_On_Info

#EndRegion ;----- Info Functions -----

Share this post


Link to post
Share on other sites

Posted

Have a small problem - on domain, windows xp sp 3, running two monitors (extended desktop) - also tried with only one desktop

used the program to take a copy of where all icons were, replaced, logged off and logged back on - icons do not go back to where they were to begin with - just randomized on desktop

Any clues?

Share this post


Link to post
Share on other sites

Posted

Found another issue - when you open explorer and go to tools and then Folder Options and then change a file type the icons all go back to randomized.

Share this post


Link to post
Share on other sites

Posted

used the program to take a copy of where all icons were, replaced, logged off and logged back on - icons do not go back to where they were to begin with - just randomized on desktop

ICU does not automatically restore the position. You have to either click "restore" or call "icu.exe restore 1" (where 1 is the first config file).

Found another issue - when you open explorer and go to tools and then Folder Options and then change a file type the icons all go back to randomized.

Did you press restore? Error sounds strange to me. If this doesn't solve your problem, maybe PM me respective IconConfigFile*.icf file and I'll take a look.

Share this post


Link to post
Share on other sites

Posted (edited)

Simple question...

Is it possible to have some basic functions in an UDF such as

- GetDesktopInconList()

- IconGetPos()

- IconSetPos($xPos, $Ypos)

Thanks :D

Apzo.

Edited by Apzo

Share this post


Link to post
Share on other sites

Posted

Apzo,

Is it possible to have some basic functions in an UDF - GetDesktopIconList(), IconGetPos(), IconSetPos($xPos, $Ypos)?

Yes. Will we write it for you? No.

All the functionality you are asking for is within this UDF. Feel free to extract the relevant sections and put them in your own wrapper so you can have the functions you want easily available. :D

M23

P.S. And please post it in the Examples section when you have finished so others can share! :huggles:

Share this post


Link to post
Share on other sites

Posted

Nice app :D

BTW I just made little change by replacing:

If @OSArch = "X86" Then $sGUITitle = "Icon Configuration Utility - 32bit version"

by this one:

If @AutoItX64 = 0 Then $sGUITitle = "Icon Configuration Utility - 32bit version"

Share this post


Link to post
Share on other sites

Posted

cool exactly what i was looking for ! thanks a lot guys !

i found a small bug ... but it's not only your fault ...

sometime i go to other forums ... (it's a shame i'm not often here) :oP

and i like to drag and drop the webbrowser link of interesting message on my desktop ...

so in some sites like Ubuntu forum the thread link title start often with

[ubuntu] Hello world blah blah

so when i save the link on my desktop, the shortcut name is also

[ubuntu] Hello world blah blah

that is not save correctly into you .ini file

[ubuntu] become of an .ini section. ...

maybe some error / warning message could be useful.

another improvement maybe,

config file name could reflect the name in the gui

ex. IconConfigFile003.icf doesn't reflet my guiname "blahblah" inside GUI,

sugg, IconConfigFile003blahblah.icf

so i can easily restore from command line the right layout without searching alot into files.

but hey ur thing is great !

:D

Share this post


Link to post
Share on other sites

Posted

[ubuntu] become of an .ini section. ...

You're right, thanks for the feedback :D... the same will happen if the name contains a "=", will add a string replacement for theses cases...

sugg, IconConfigFile003blahblah.icf

Makes sense too :huggles:, and additionally there should be a position prefix 2_, 3_ etc. which does not change when you're deleting e.g. 1_ or else command-line calls will target the wrong config-file. Will add that too :...

Share this post


Link to post
Share on other sites

Posted (edited)

Version 2.3

  • Added _URIEncode() function to make icon filenames save for iniwrite / iniread
  • Name of the config file is now saved as part of the filename
  • Config filenames are not re-enumerated if a file is deleted
  • Illegal filename characters in config name are deleted automatically
Check it out and let me know any shortcomings :mellow:...

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_Res_Field=ProductName|ICU
#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
Edited by KaFu

Share this post


Link to post
Share on other sites

Posted

Cool :mellow:

Share this post


Link to post
Share on other sites

Posted (edited)

I took a look at you code few weeks ago and found your are redisplaying icons twice :)

maybe using something like this will help

_GUICtrlListView_beginUpdate($hExplorer_List)

display icons only once

_GUICtrlListView_endUpdate($hExplorer_List)

in this way you are not fighting windoze desktop refresh .

:(

Edited by JoeCool

Share this post


Link to post
Share on other sites

Posted

I took a look at you code few weeks ago and found your are redisplaying icons twice :(

Thanks for the hint :), seems to work fine for me too...

Version 2.4

  • Replaced dual refresh with _GUICtrlListView_BeginUpdate($hExplorer_List) & _GUICtrlListView_EndUpdate($hExplorer_List)

#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.4.0.0
#AutoIt3Wrapper_Res_LegalCopyright=Melba23 2009-2010, KaFu 2010
#AutoIt3Wrapper_Res_Field=ProductName|ICU
#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.4
; As at 30 Mar 10
;
; Changelog
; 2.4
;		100330: JoeCool: Avoid setting desktop twice, added _GUICtrlListView_BeginUpdate($hExplorer_List) & _GUICtrlListView_EndUpdate($hExplorer_List)
;				http://www.autoitscript.com/forum/index.php?showtopic=108245&view=findpost&p=784489
;
#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
	_GUICtrlListView_BeginUpdate($hExplorer_List)
	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
	_GUICtrlListView_EndUpdate($hExplorer_List)
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

Share this post


Link to post
Share on other sites

Posted

Thanks. I haven't tested it out yet but this is excatly what I was looking for. My Work places a bunch of icons on my desktop and in the process they always seem to re-arrange them. They also put Ready-Only and System Attribs on them which have to be removed before an autoIt3 script can remove them, at least from my testing.

I'll report back once I test this one and see if it can handle icons that don't want me be removed/moved (i have admin rights).

Share this post


Link to post
Share on other sites

Posted

Changelog v2.4 > v2.8

  • Added a 32/64bit wrapper, so that now it's a single exe for both OS architectures
  • Added Desktop ContextMenu Integration for Win7

Posted Image

Source and Executable are available on my website at

http://www.funk.eu

Best Regards

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  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.