Advertisement
Najeebsk

ICON-EX.ahk

Jul 29th, 2022
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; <COMPILER: v1.1.32.00>
  2. ;#Warn
  3. #NoEnv
  4. #SingleInstance, Force
  5. SendMode Input
  6. SetWorkingDir %A_ScriptDir%
  7. /*
  8.     Description:
  9.         Do you know Microangelo?
  10.         This program is an Icon manager. With it you can change  any icon for a file
  11.         type in a very simple way.
  12.         Folder icon can be changed. You can change the icon for  each folder separatly too.
  13.         There is also a support for themes, but differently from other  softwares,
  14.         in this program a theme is a folder containing some icons.
  15.         The name of the icon is the file type to wich the icon will be  associated.
  16.         For example an icon named mp3.ico will cause all mp3 files  to be shown with
  17.         that icon.
  18.     Version:
  19.         0.5.2 beta
  20.     License:
  21.         GPL
  22.     Note:
  23.         This is a beta version. Use it at your own risk
  24.     ToDo:
  25.         1)Drag&Drop support to drop an icon file to the program  window
  26.         2)Support for special folders like My computer or Desktop
  27.         3)Support for themes where a theme is a single zip file
  28.         4)Define special names in a theme like "folder.ico" for the  folder icon
  29.         5)Documentation
  30.         6)Rebuild icon cache:
  31.             Just refresh the icon cache by deleting the  IconCache.db
  32.             file from your profile directory (usually  /Documents and
  33.             Settings/Username/Local Settings/Application  Data). It
  34.             will be automatically recreated.
  35.     Bugs:
  36.         ?
  37.     History:
  38.         24/04/2006 - added support to restore original icons
  39.        
  40. */
  41.  
  42. #SingleInstance force
  43. #NoTrayIcon
  44. SetBatchLines -1
  45. ScanStatus := False
  46.  
  47. If ( A_OSType = "WIN32_WINDOWS" )  ; Windows 9x
  48.     ScanFolder = %A_WinDir%\system
  49. else
  50.     ScanFolder = %A_WinDir%\system32
  51.  
  52. Gui, Add, Text, Section , Scan folder
  53. Gui, Add, Edit, ys-3 w245 r1 vScanFolder, %ScanFolder%
  54. Gui, Add, Button, ys-5 gBtnBrowseFolder,&...
  55. Gui, Add, Button, ys-5 w50 vBtnScan gBtnScan, &Scan
  56. Gui, Add, Checkbox, ys vCkbRecursive , Rec&ursive
  57.  
  58. Gui, Add, ListView, xm r11 w480 -Multi AltSubmit List vLstOfFiles gLstOfFiles  ,Icon Nr.1 & File name|Path
  59.  
  60. Gui, Add, Text, w140 vTxtFilesFound Section, 0000 files found, shown as
  61. Gui, Add, Radio, ys gRadFilesReport ,&Report
  62. Gui, Add, Radio, ys gRadFilesTile , &Tile
  63. Gui, Add, Radio, ys gRadFilesIcons , &Icons
  64. Gui, Add, Radio, ys gRadFilesSmallIcons ,s&mall Icons
  65. Gui, Add, Radio, ys Checked gRadFilesList , &List
  66.  
  67. Gui, Add, ListView, xm r2 w480 -Multi AltSubmit Icon vLstOfIcons  gLstOfIcons,Icon
  68.  
  69. Gui, Add, Text, w140 vTxtIconsFound Section, 0000 Icons found, shown as
  70. Gui, Add, Radio, ys gRadIconsReport ,Report
  71. Gui, Add, Radio, ys gRadIconsTile ,Til&e
  72. Gui, Add, Radio, ys Checked gRadIconsIcons , Ic&ons
  73. Gui, Add, Radio, ys gRadIconsSmallIcons ,sm&all Icons
  74. Gui, Add, Radio, ys gRadIconsList , List
  75.  
  76. Gui,add,Text, xm  ys+40 Section, Select a file type
  77. Gui,add,Edit, x+2 ys-3 vext gExtension
  78. Gui,add,Text, x+2 , or:
  79. Gui,add,button,x+20 gBtnASITSF, Apply Selected Icon to a specified Folder
  80. Gui,add,button,x+5 gBtnSpecialIcons, Special Icons
  81.  
  82. Gui,add,Text, xm , from
  83. Gui,add,Picture, x+20 vActualIcon Icon1 w32 h-1 , %ScanFolder%\shell32.dll
  84. Gui,add,Text, x+20 , to
  85. Gui,add,Picture, x+20 vNewIcon Icon1 w32 h-1 , %ScanFolder%\shell32.dll
  86. Gui,add,Text, x+20 , ...
  87. Gui,add,button,x+20 gBtnSet vBtnSet , Set
  88. Gui,add,Text, x+20 , Original Icon:
  89. Gui,add,Picture, x+20 vfirstIcon Icon1 w32 h-1 , %ScanFolder%\shell32.dll
  90. Gui,add,button,x+20 gBtnRestore vBtnRestore , Restore
  91. Gui, Add, Button, xm vBtnSpecialActions gBtnSpecialActions Section ,Special  Action
  92. Gui, Add, Button, ys gBtnClose,&Close
  93. Gui, Show, , Icon Viewer v5
  94. Return
  95. ;#############   End of autoexec section    ####################################
  96.  
  97. BtnSpecialActions:
  98.     Menu,sf,add
  99.     Menu,sf,deleteall
  100.     Menu,sf,add,Set a theme, saction
  101.     Menu,sf,add,Refresh icon cache(beta), saction
  102.     Menu,sf,show
  103. return
  104. saction:
  105.     if(A_ThisMenuItemPos=1)
  106.         {
  107.             FileSelectFolder, fold, , , Select the folder  containg all the icons.    N.B.: A theme is a folder containing several icons whose  name is the file type for that icon. Ex: "gif.ico" will set gif files
  108.             if(fold="")
  109.                 return
  110.             Loop,%fold%\*.ico
  111.                 {
  112.                     StringTrimRight, ext,  A_LoopFileName, 4
  113.                     RegRead, from,  HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer \FileExts\.%ext%, ProgID
  114.                     if(from="")
  115.                         RegRead, from,  HKEY_CLASSES_ROOT, .%ext%
  116.                     RegWrite, REG_SZ,  HKEY_CLASSES_ROOT, %from%\DefaultIcon, , %fold%\%ext%.ico
  117.                 }
  118.             fold=
  119.         }
  120.     else if(A_ThisMenuItemPos=2)
  121.         {
  122.             SplitPath, A_WinDir, , , , , OutDrive
  123.             file=%OutDrive%/Documents and Settings/ %A_UserName%/Local Settings/Application Data/IconCache.db
  124.             FileDelete, %file%
  125.         }
  126. return
  127.  
  128. BtnASITSF:
  129.     FileSelectFolder, dir, , , Select a folder to apply this icon to it
  130.     n2=0
  131.     IfInString, newIconFile, `,
  132.         {
  133.             StringSplit, n, newIconFile, `,
  134.             trim:=StrLen(n2)+1
  135.             StringTrimRight, newIconFile, newIconFile,  %trim%
  136.         }
  137.     FileDelete, %dir%\desktop.ini  
  138. FileAppend,
  139. (
  140. [.ShellClassInfo]
  141. IconFile=%newIconFile%
  142. IconIndex=%n2%
  143. )`n, %dir%\Desktop.ini
  144.     Sleep,100
  145.     FileSetAttrib, +ASH, %dir%\Desktop.ini
  146.     FileSetAttrib, +S, %dir%
  147. return
  148.  
  149. BtnSpecialIcons:
  150.     Menu,sf,add
  151.     Menu,sf,deleteall
  152.     Menu,sf,add,Folder Icon, sicons
  153.     Menu,sf,add,My computer Icon, sicons
  154.     Menu,sf,add,Empty Recycle Bin Icon, sicons
  155.     Menu,sf,add,Full Recycle Bin Icon, sicons
  156.     Menu,sf,add,Desktop Icon, sicons
  157.     Menu,sf,show
  158. return
  159. sicons:
  160.     if(A_ThisMenuItemPos=1)
  161.             {
  162.                 from=Folder
  163.                 RegRead, ico,  HKEY_CLASSES_ROOT, %from%\DefaultIcon
  164.             }
  165.     else
  166.         msgbox,not yet implemented
  167.     if (A_ThisMenuItemPos=2)
  168.         {
  169.             from={20D04FE0-3AEA-1069-A2D8- 08002B30309D}
  170.             RegRead, ico, HKEY_LOCAL_MACHINE,  SOFTWARE\Classes\CLSID\%from%\DefaultIcon
  171.         }
  172.     else if (A_ThisMenuItemPos=3)
  173.         {
  174.             from={645FF040-5081-101B-9F08- 00AA002F954E}
  175.             RegRead, ico, HKEY_LOCAL_MACHINE,  SOFTWARE\Classes\CLSID\%from%\DefaultIcon
  176.         }  
  177.     else if (A_ThisMenuItemPos=4)
  178.         {
  179.             from={645FF040-5081-101B-9F08- 00AA002F954E}
  180.             RegRead, ico, HKEY_LOCAL_MACHINE,  SOFTWARE\Classes\CLSID\%from%\DefaultIcon,Full
  181.         }
  182.     IfInString, ico, `,
  183.     {
  184.         StringSplit, n, ico, `,
  185.         n2++
  186.         trim:=StrLen(n2)+1
  187.         StringTrimRight, ico, ico, %trim%
  188.     }
  189.     GuiControl,,actualIcon,  *icon%n2% *w32 *h-1 %ico% 
  190. return
  191.  
  192. Extension:
  193.     Gui, Submit, nohide
  194.     IniRead, orIcon, conf.ini, originalIcons, %ext%
  195.     RegRead, from, HKEY_CURRENT_USER, Software\Microsoft \Windows\CurrentVersion\Explorer\FileExts\.%ext%, ProgID
  196.     if(from="")
  197.         RegRead, from, HKEY_CLASSES_ROOT, .%ext%
  198.     RegRead, ico, HKEY_CLASSES_ROOT, %from%\DefaultIcon
  199.     if(orIcon="")
  200.         orIcon=%ico%
  201.     originalIcon=%ico%
  202.     IfInString, ico, `,
  203.     {
  204.         StringSplit, n, ico, `,
  205.         trim:=StrLen(n2)+1
  206.         StringTrimRight, ico, ico, %trim%
  207.     }
  208.     IfInString, orIcon, `,
  209.     {
  210.         StringSplit, on, orIcon, `,
  211.         trim:=StrLen(on2)+1
  212.         StringTrimRight, orIcon, orIcon, %trim%
  213.     }
  214.     GuiControl,,firstIcon,  *icon%on2% *w32 *h-1 %orIcon%
  215.     GuiControl,,actualIcon,  *icon%n2% *w32 *h-1 %ico%
  216. return
  217. BtnSet:
  218.     if(newIconFile="")
  219.         return
  220.     IniWrite, %originalIcon%, conf.ini, originalIcons, %ext%
  221.     RegWrite, REG_SZ, HKEY_CLASSES_ROOT, %from%\DefaultIcon, ,  %newIconFile%
  222. return
  223.  
  224. BtnRestore:
  225.     Gui, Submit, nohide
  226.     RegRead, from, HKEY_CURRENT_USER, Software\Microsoft \Windows\CurrentVersion\Explorer\FileExts\.%ext%, ProgID
  227.     if(from="")
  228.         RegRead, from, HKEY_CLASSES_ROOT, .%ext%
  229.     RegWrite, REG_SZ, HKEY_CLASSES_ROOT, %from%\DefaultIcon, ,  %orIcon%
  230. return
  231.  
  232.  
  233.  
  234. ;#############   Browse to the folder from where the serach should start   ####
  235. BtnBrowseFolder:
  236.  Gui, +OwnDialogs
  237.   FileSelectFolder, SelectedDir, *%ScanFolder%, 2, Select folder to start  searching for icons
  238.   If SelectedDir
  239.     {
  240.       ;remove "\" if folder is a root drive, e.g. "C:\"
  241.       StringRight, LastChar, SelectedDir, 1
  242.       If LastChar = \
  243.           StringTrimRight, SelectedDir, SelectedDir, 1
  244.  
  245.       GuiControl, ,ScanFolder, %SelectedDir%
  246.     }
  247.   Gosub, BtnScan
  248. Return
  249.  
  250. ;#############   Start or stop scanning for files    ###########################
  251. BtnScan:
  252.  If ScanStatus
  253.       ;break scan loop
  254.       ScanStatus := False
  255.   Else
  256.       ;start a new thread for scaning
  257.       SetTimer, Scan, 20
  258. return
  259.  
  260. ;#############   Scan the folder for files with icons    #######################
  261. Scan:
  262.  SetTimer, Scan, Off
  263.  
  264.   ScanStatus := True
  265.  
  266.   Gui, Submit, NoHide
  267.  
  268.   ;change lable and make default button: scan/stop
  269.   GuiControl, , BtnScan, &STOP
  270.   GuiControl, +Default, BtnScan
  271.      
  272.   ;disable redraw for speed
  273.   GuiControl, -Redraw, LstOfFiles
  274.  
  275.   ;set list of files as default
  276.   Gui, ListView, LstOfFiles
  277.  
  278.   ;clear list of files
  279.   LV_Delete()
  280.  
  281.   ;create new list of small images and replace and delete old one
  282.   IListIDFilesSmall := IL_Create(100, 100, False)
  283.   ListID := LV_SetImageList(IListIDFilesSmall)
  284.   If ListID
  285.       IL_Destroy(ListID)
  286.  
  287.   ;create new list of large images and replace and delete old one
  288.   IListIDFilesLarge := IL_Create(100, 100, True)
  289.   ListID := LV_SetImageList(IListIDFilesLarge)
  290.   If ListID
  291.       IL_Destroy(ListID)
  292.  
  293.   ;Search all files
  294.   i = 0
  295.   Loop, %ScanFolder%\*, 0, %CkbRecursive%
  296.     {
  297.       ;If their extention is exe,dll,ico,ani,cpl ...
  298.       If A_LoopFileExt Contains exe,dll,ico,ani,cpl
  299.         {
  300.           ;... get first icon (small) ...
  301.           ID := IL_Add(IListIDFilesSmall, A_LoopFileFullPath, 1)
  302.  
  303.           ;... And If they have a first Icon ...
  304.           If ID > 0
  305.             {
  306.               ;get large icon
  307.               IL_Add(IListIDFilesLarge, A_LoopFileFullPath, 1)
  308.  
  309.               ;count this file
  310.               i++
  311.  
  312.               ;add file to ListView
  313.               LV_Add("Icon" . i, A_LoopFileName, A_LoopFileDir)
  314.  
  315.               GuiControl,,TxtFilesFound,%i% files found, shown as
  316.             }
  317.         }
  318.       ;break loop if user pushes STOP button
  319.       If not ScanStatus
  320.           break
  321.     }
  322.  
  323.   ScanStatus := False
  324.  
  325.   ;Enable redraw for speed
  326.   GuiControl, +Redraw, LstOfFiles
  327.  
  328.   ;Adjust width
  329.   LV_ModifyCol()
  330.  
  331.   ;rename button to scan again
  332.   GuiControl, , BtnScan, &Scan
  333. Return
  334.  
  335. ;#############   A file got selelected in list    ##############################
  336. LstOfFiles:
  337.  ;file is selected with mouse or by keyboard
  338.   If ( A_GuiEvent = "I" )
  339.     {
  340.       ;set list of files as default
  341.       Gui, ListView, LstOfFiles
  342.  
  343.       ;get selected file
  344.       RowNumber := LV_GetNext()
  345.       LV_GetText(IV_File, RowNumber, 1)
  346.       LV_GetText(IV_Path, RowNumber, 2)
  347.  
  348.  
  349.       ;set list of icons as default
  350.       Gui, ListView, LstOfIcons
  351.  
  352.       ;diable redraw for speed
  353.       GuiControl, -Redraw, LstOfIcons
  354.  
  355.       ;clear list
  356.       LV_Delete()
  357.  
  358.       ;create new list of small images and replace and delete old one
  359.       IListIDIconsSmall := IL_Create(10, 10, False)
  360.       ListID := LV_SetImageList(IListIDIconsSmall)
  361.       If ListID
  362.           IL_Destroy(ListID)
  363.  
  364.       ;create new list of large images and replace and delete old one
  365.       IListIDIconsLarge := IL_Create(10, 10, True)
  366.       ListID := LV_SetImageList(IListIDIconsLarge)
  367.       If ListID
  368.           IL_Destroy(ListID)
  369.  
  370.       i = 0
  371.       ;Search for 9999 icons in the selected file
  372.       Loop, 9999
  373.         {
  374.           ;get small icon
  375.           ID := IL_Add(IListIDIconsSmall, IV_Path . "\" . IV_File , A_Index)
  376.  
  377.           ;if small icon exist
  378.           If ID > 0
  379.             {
  380.               ;get large icon
  381.               IL_Add(IListIDIconsLarge, IV_Path . "\" . IV_File , A_Index)
  382.  
  383.               i++
  384.              
  385.               ;add icon to list
  386.               LV_Add("Icon" . A_Index, A_Index)
  387.  
  388.               GuiControl,,TxtIconsFound,%i% icons found, shown as
  389.             }
  390.           Else
  391.               Break
  392.         }
  393.       ;enable redraw for speed
  394.       GuiControl, +Redraw, LstOfIcons
  395.  
  396.       ;clear edit field
  397.       GuiControl,,AHKCommand,
  398.     }
  399. Return
  400.  
  401. ;#############   Change of view mode for file list    ##########################
  402. RadFilesReport:
  403.  GuiControl, +Report, LstOfFiles
  404.   Gui, ListView, LstOfFiles
  405.   LV_ModifyCol()
  406. Return
  407.  
  408. RadFilesTile:
  409.  GuiControl, +Tile, LstOfFiles
  410. Return
  411.  
  412. RadFilesIcons:
  413.  GuiControl, +Icon, LstOfFiles
  414. Return
  415.  
  416. RadFilesSmallIcons:
  417.  GuiControl, +IconSmall, LstOfFiles
  418. Return
  419.  
  420. RadFilesList:
  421.  GuiControl, +List, LstOfFiles
  422. Return
  423.  
  424. ;#############   A icon got selected in list    ################################
  425. LstOfIcons:
  426.  ;icon is selected with mouse or by keyboard
  427.   If ( A_GuiEvent = "I" )
  428.       GoSub, RadAHKCommand
  429. return
  430.  
  431. ;#############   AHK command got changed    ####################################
  432. RadAHKCommand:
  433.  ;set list of icons as default
  434.   Gui, ListView, LstOfIcons
  435.  
  436.   ;get selected
  437.   RowNumber := LV_GetNext()
  438.  
  439.   ;If something is selected (might not be true if RadAHKCommand is calling)
  440.   If RowNumber
  441.     {
  442.       ;get Icon number
  443.       LV_GetText(IV_IconID, RowNumber, 1)
  444.  
  445.       ;get AHKCommand
  446.       Gui, Submit, NoHide
  447.  
  448.       GuiControl,, newIcon, *icon%IV_IconID% *w32 *h-1 %IV_Path%\%IV_File%
  449.       ;GuiControl,,AHKCommand,  icon%IV_IconID% ,
  450.             newIconFile=%IV_Path%\%IV_File%
  451.             icgroup=exe,dll
  452.             SplitPath, newIconFile, , , OutExtension
  453.             IfInString, icgroup, %OutExtension%
  454.             {
  455.                 IV_IconID--
  456.                 newIconFile=%newIconFile%, %IV_IconID%
  457.             }
  458.     }
  459. Return
  460.  
  461. ;#############   Change of view mode for icon list    ##########################
  462. RadIconsReport:
  463.  GuiControl, +Report, LstOfIcons
  464.   Gui, ListView, LstOfIcons
  465.   LV_ModifyCol()
  466. Return
  467.  
  468. RadIconsTile:
  469.  GuiControl, +Tile, LstOfIcons
  470. Return
  471.  
  472. RadIconsIcons:
  473.  GuiControl, +Icon, LstOfIcons
  474. Return
  475.  
  476. RadIconsSmallIcons:
  477.  GuiControl, +IconSmall, LstOfIcons
  478. Return
  479.  
  480. RadIconsList:
  481.  GuiControl, +List, LstOfIcons
  482. Return
  483.  
  484.  
  485. ;#############   Close window    ###############################################
  486. BtnClose:
  487. GuiClose:
  488. GuiEscape:
  489.   ExitApp
  490. Return
  491. ;#############   End of File    ################################################
  492. ;==========================
  493. #R::Reload  ;<--  ~ Reload Script ~
  494. #S::Suspend ;<--  ~ Suspend Script ~
  495. #P::Pause   ;<--  ~ Pause Script ~
  496. #M::WinMinimize, ;<--  ~ Minimize Script ~
  497. ESC::ExitApp     ;<--  ~ Exit Script ~
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement