AutoHotkey Community

It is currently May 25th, 2012, 1:50 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Drive Icons
PostPosted: April 19th, 2007, 3:01 pm 
Offline

Joined: April 17th, 2007, 1:49 pm
Posts: 14
Location: Stuttgart (Ger)
Image

Quote:
Drive-Icons Beta 0.815 - 2007 by Markus Möller

This little App allows you to change the icon and the label for a drive.
It is very usefull if you've got many partitions, virtual cd drives, multi card
reader etc.
Use icons and descriptions for your drives to make it easier to detect them in
the windows explorer.
If you have choosen an icon and/or label for a cd-rom drive it will shown as long
as no disc is inserted. When you insert a disc into the drive, you will see the
icon and label specified in the autorun.inf.

If a disc has a "real label" it will used prior to what you typed into the label
field of this app.

Sorry about the name confusing about label and label. I'll try to find better
words for the next release. ;-)

You can extend the limitations of naming a fat partition, if you don't give a
"real label" with the windows explorer, or using the label command.

2Do:
Adding ability to work with non present drives.
Multilanguage support (De/En)
Maybe a feature to disable drives (like TweakUI)


Code:

#NoEnv
#notrayicon
SendMode Input

; ########################### create GUI #######################

; --- Header ---

;header gradient
bg=ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ
Gui, Font, s14 bold ,terminal
Gui, 1:Add, Text,x0 y0 w600 h4 c0000d0 , %bg%
Gui, 1:Add, Text,y+0 w600 hp c0000c0 , %bg%
Gui, 1:Add, Text,y+0 w600 hp c0000b0 , %bg%
Gui, 1:Add, Text,y+0 w600 hp c0000a0 , %bg%
Gui, 1:Add, Text,y+0 w600 hp c000090 , %bg%
Gui, 1:Add, Text,y+0 w600 hp c000080 , %bg%
Gui, 1:Add, Text,y+0 w600 hp c000070 , %bg%
Gui, 1:Add, Text,y+0 w600 hp c000060 , %bg%
;line blow gradient
gui, add, text, x0 y+0 w565 h2 0x10,
;heading text
gui, font, s14 bold cblack,arial
gui, add, text, x13 y6 +backgroundtrans, Drive-Icons
gui, font, s14 cffffff,arial
gui, add, text, x11 y4 +backgroundtrans, Drive-Icons
;help "button"
gui,add,text,x537 y7 backgroundtrans cblack,?
gui,add,text,x535 y5 backgroundtrans cyellow gHelp,?

; --- UI controls ---

;listview
gui,font,,
Gui, Add, ListView, x10 y45 h250 w280 section gListKlick vListe AltSubmit -Multi -LV0x10 NoSort, Drive|Icon|Label  ; Create a ListView.

;Label: editfield & delete button
gui, add, text, ys section, Label:
gui, font, s18 caa0000 normal, wingdings
gui, add, text, y+7 disabled gDelete vdelLabel,û
gui, font,,
gui, add, edit, yp+2 x+2 w150 vedit_label gTextFieldChange,

;Icon: editfield & delete button
gui, add, text, xs y+18, Icon:
gui, font, s18 caa0000 normal, wingdings
gui, add, text, y+7 disabled gDelete vdelIcon,û
gui, font,,
gui, add, edit,yp+2 x+2 w200 vedit_icon gTextFieldChange,
gui, add, button, x+3 yp+1 w25 hp-2 gIconwahl,...
;Icon: picture & errormessage
gui, add, picture, xs w32 h32 vIcon32,
gui,font,bold c990000,
gui add, text,xp yp vErrorMessage, Error: Icon file not found !
gui,font,,
guicontrol,hide,ErrorMessage

;buttons at bottom
gui, add, text, x0 y310 w565 h2 0x10,
gui, add, button,x430 w120 gbuttoncancel, &Close
gui, add, button,xp-130 w120 gDoIt vDoIt, &Apply

;show gui
Gui Show, w560,Drive-Icons

;initalize LV
FirstInit := true
gosub FillDriveList

return

;############################## EVENTS ###########################

;=================================================================
; apply changes
DoIt:
gui, submit, nohide

;dieser code gewinnt keinen schönheitspreis, also noch mal überarbeiten:
reg_key := "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\" . Laufwletter%ListenNr% . "\DefaultLabel"
If (edit_label = "")
{
  RegDelete, HKEY_LOCAL_MACHINE, %reg_key%
}
Else
{
  RegWrite,REG_SZ , HKEY_LOCAL_MACHINE, %reg_key%,, %edit_label%
}

reg_key := "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\" . Laufwletter%ListenNr% . "\DefaultIcon"
If (edit_icon = "")
{
  RegDelete, HKEY_LOCAL_MACHINE, %reg_key%
}
Else
{
  RegWrite, REG_SZ, HKEY_LOCAL_MACHINE, %reg_key%, ,%edit_icon%
}

If (edit_label = "") && (edit_icon = "")
{
  reg_key := "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\" . Laufwletter%ListenNr% 
  RegDelete, HKEY_LOCAL_MACHINE, %reg_key%
}

 
IL_Destroy(ImageListID)
LV_Delete()
guicontrol,disable, DoIt
gehezu := ListenNr
gosub FillDriveList
return

;=================================================================
TextFieldChange:
GuiControlGet, wert, , %A_GuiControl%
if (A_GuiControl = "edit_label")
{
  if (LaufwMyLabel%ListenNr% <> wert)
    guicontrol,enable, DoIt 
  if (strlen(wert) = 0)
    guicontrol,disable,delLabel
  if (strlen(wert) > 0)
    guicontrol,enable,delLabel 
}

if (A_GuiControl = "edit_icon")
{
  if (LaufwMyIcon%ListenNr% <> wert)
    guicontrol,enable, DoIt   
  if (strlen(wert) = 0)
    guicontrol,disable,delIcon
  if (strlen(wert) > 0)
    guicontrol,enable,delIcon 
}

return


;=================================================================
; delete icon and/or label in editfield
Delete:
if (A_GuiControl = "delLabel")
{
  guicontrol,,edit_label,
  guicontrol,disable,delLabel
}

if (A_GuiControl = "delIcon")
{
  guicontrol,,edit_icon,   
  guicontrol,hide,Icon32
  guicontrol,disable,delIcon
}

return

;=================================================================
; ListView Events
ListKlick:

if (A_GuiEvent = "ColClick") or (A_GuiEvent = "K") or (A_GuiEvent = "f")
   return
 
ListenNr = %A_EventInfo% 

; LV item selected, continue with ControlUpdate


;=================================================================
;Update editfields, icon/errormassage and delete buttons, matching the selected drive from LV
ControlUpdate:

guicontrol,,edit_label,% LaufwMyLabel%ListenNr%
guicontrol,,edit_icon,% LaufwMyIcon%ListenNr%

IconFile := LaufwMyIcon%ListenNr%
StripIcon(IconFile,IconIndex)
IconIndex ++

if (LaufwMyIcon%ListenNr% <> "")
{
  guicontrol,enable,delIcon
  if (IconError%ListenNr% = true)
  {
    guicontrol,hide,Icon32
    guicontrol,show,ErrorMessage       
  }
  else
  {
    guicontrol,hide,ErrorMessage   
    guicontrol,show,Icon32
    guicontrol,,Icon32, *icon%iconindex% *w32 *h32 %IconFile% 
  }
}
else
{
  guicontrol,hide,Icon32
  guicontrol,hide,ErrorMessage   
  guicontrol,disable,delIcon
}

if (LaufwMyLabel%ListenNr% <> "")
{
  guicontrol,enable,delLabel
}
else
{
  guicontrol,disable,delLabel
}

  guicontrol,disable, DoIt
 
return

;=================================================================
; Browse Button
Iconwahl:

Gui, submit,nohide
IconFile := edit_icon
IconIndex := 0

StripIcon(IconFile,IconIndex)

gui, +disabled
ChooseIcon(IconFile, IconIndex, hGui)
gui, -disabled
gui, show

if instr(IconFile,"%SystemRoot%" )
{
  StringReplace, IconFile, IconFile, % "%SystemRoot%", %A_WinDir% , All
}

guicontrol,show,Icon32
guicontrol,,Icon32, % "*icon" . IconIndex+1 . " *w32 *h32 " . IconFile
guicontrol,enable,delIcon
guicontrol,hide,ErrorMessage

IconIndexText =
if (IconIndex <> 0)
IconIndexText = ,%IconIndex%
GuiControl,,edit_icon, %IconFile%%IconIndexText%

return

; ---- Bye bye ----
buttoncancel:
;guiescape:
GuiClose:

exitapp

;######################## Subroutines ##################

;=================================================================
FillDriveList:
;create IL and assign to LV.
ImageListID := IL_Create(24,0,0)
LV_SetImageList(ImageListID)

; this LV_ModifyCol command are just cosmetic surgery, when starting the app.
If (FirstInit = true )
{
  LV_ModifyCol(1,120)
  LV_ModifyCol(2,50)
  LV_ModifyCol(3,100)
  FirstInit := false
}

DriveGet, LaufwListe, list
AnzLaufw := StrLen(LaufwListe)
StringSplit, Laufwletter, LaufwListe ,,

loop, %AnzLaufw%
{
  DriveGet, LaufwTyp%A_Index%, type, % Laufwletter%A_Index% . ":"
  if (LaufwTyp%A_Index% = "FIXED") OR (LaufwTyp = "UNKNOWN")
    LaufwExIcon%A_Index% := 8+1
  if (LaufwTyp%A_Index% = "CDROM")
    LaufwExIcon%A_Index% := 11+1 
  if (LaufwTyp%A_Index% = "REMOVABLE")
    LaufwExIcon%A_Index% := 7+1 
  if (LaufwTyp%A_Index% = "RAMDISK")
    LaufwExIcon%A_Index% := 12+1 
  if (LaufwTyp%A_Index% = "NETWORK")
    LaufwExIcon%A_Index% := 9+1 

  ;eleminiate ugly noise from floppy drives (do not retrieve label from possible floppies)
  if  (Laufwletter%A_Index% <> "A") && (Laufwletter%A_Index% <> "B")
    DriveGet, LaufwExLabel%A_Index%, label, % Laufwletter%A_Index% . ":" 

  reg_key := "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\" . Laufwletter%A_Index% . "\DefaultLabel"
  RegRead, LaufwMyLabel%A_Index%, HKEY_LOCAL_MACHINE, %reg_key%,
 
  reg_key := "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\" . Laufwletter%A_Index% . "\DefaultIcon"
  RegRead, LaufwMyIcon%A_Index%, HKEY_LOCAL_MACHINE, %reg_key%,   
 
  if (LaufwMyIcon%A_Index% <> "") ; has own icon (specified in registry)
  {
    IconError%A_Index% := false
    IconIndikator := "   X   "
    IconFile := LaufwMyIcon%A_Index%
    StripIcon(IconFile,IconIndex)
    IconIndex++
    ; if icon file doesn't exist, create errormessage in LV
    ; use standard icon in IL
    IfNotExist, %IconFile%
    {
      IconError%A_Index% := true
      IL_Add(ImageListID,  "shell32.dll",LaufwExIcon%A_Index%)
      IconIndikator := "Error !"
    }
    else ; ok, add icon to IL
    {
      IL_Add(ImageListID,IconFile,IconIndex )       
    }
   

  }
  else ; no own icon, use standard icon from shell32.dll
  {
    IconIndikator :=
    IL_Add(ImageListID, "shell32.dll", LaufwExIcon%A_Index%)
  }
 
  LV_Add("Icon" . A_Index,A_Space  Laufwletter%A_Index% . ":" . A_Space LaufwExLabel%A_Index% ,IconIndikator ,LaufwMyLabel%A_Index%)
}


LV_ModifyCol()  ; Auto-adjust the column widths.


;select LV item
if (gehezu = "" )
  gehezu := 1
LV_Modify(gehezu, "Select")
LV_Modify(gehezu, "Focus")
controlfocus, SysListView321,Drive-Icons

return

;=================================================================
;split iconstring into filename and index
StripIcon(byRef IconFile, byRef IconIndex)
{
  find = ,
  StringGetPos, KommaPos, IconFile, %find%, R
  if (KommaPos > 0)
  {
    IconIndex := SubStr(IconFile, KommaPos+2)
    StringLeft,IconFile,IconFile,KommaPos
  }
  else
  {
    IconIndex := 0
  }

  Return
}

;=================================================================
; ChooseIcon
;by majkinetor, w2k fix by me

ChooseIcon(ByRef sIcon, ByRef idx, hGui=0) {                               
   
    VarSetCapacity(wIcon, 1025, 0)
    if sIcon !=
    {
        r := DllCall("MultiByteToWideChar"
             , "UInt", 0             ; CodePage: CP_ACP=0 (current Ansi), CP_UTF7=65000, CP_UTF8=65001
             , "UInt", 0             ; dwFlags
             , "Str", sIcon          ; LPSTR lpMultiByteStr
             , "Int", StrLen(sIcon)  ; cbMultiByte: -1=null terminated
             , "UInt", &wIcon        ; LPCWSTR lpWideCharStr
             , "Int", 1025)          ; cchWideChar: 0 to get required size

        if !r
            return 2
    }
   
    r := DllCall(DllCall("GetProcAddress", "Uint", DllCall("LoadLibrary", "str", "shell32.dll"), "Uint", 62), "uint", hGui, "uint", &wIcon, "uint", 1025, "intp", idx)
    if !r
        return 1

   len := DllCall("lstrlenW", "UInt", &wIcon)
   VarSetCapacity(sIcon, len, 0)
   r := DllCall("WideCharToMultiByte"
         , "UInt", 0           ; CodePage: CP_ACP=0 (current Ansi), CP_UTF7=65000, CP_UTF8=65001
         , "UInt", 0           ; dwFlags
         , "UInt", &wIcon      ; LPCWSTR lpWideCharStr
         , "Int", len          ; cchWideChar: size in WCHAR values, -1=null terminated
         , "Str", sIcon        ; LPSTR lpMultiByteStr
         , "Int", len          ; cbMultiByte: 0 to get required size
         , "UInt", 0           ; LPCSTR lpDefaultChar
         , "UInt", 0)          ; LPBOOL lpUsedDefaultChar

    if !r
        return 3
           
    return 0
}

;########################## Help ########################
; temp. soloution
Help:
gui +owndialogs
msgbox,
(
Drive-Icons Beta 0.815 - 2007 by Markus Möller

This little App allows you to change the icon and the label for a drive.
It is very usefull if you've got many partitions, virtual cd drives, multi card
reader etc.
Use icons and descriptions for your drives to make it easier to detect them in
the windows explorer.
If you have choosen an icon and/or label for a cd-rom drive it will shown as long
as no disc is inserted. When you insert a disc into the drive, you will see the
icon and label specified in the autorun.inf.

If a disc has a "real label" it will used prior to what you typed into the label
field of this app.

Sorry about the name confusing about label and label. I'll try to find better
words for the next release. ;-)

You can extend the limitations of naming a fat partition, if you don't give a
"real label" with the windows explorer, or using the label command.

2Do:
Adding ability to work with non present drives.
Multilanguage support (De/En)
Maybe a feature to disable drives (like TweakUI)
)
return


it is still beta. i posted it to get some ideas and bug reports.
did not tested on win95 and derivats (98, Me) and with networkdrives.
the code could be optimized at some places, because i'm still learnig ahk.
some variables have german names, that will be "fixed". i hope you can read the code anyway ;-)

Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 19th, 2007, 3:09 pm 
:D Der kleine blaue Elephant ist echt mal ne Abwechslung zum Knut-Der Eisbär-Rummel. Macht zwar nix - ist aber so! :wink: 8)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 19th, 2007, 3:13 pm 
Offline

Joined: April 17th, 2007, 1:49 pm
Posts: 14
Location: Stuttgart (Ger)
KNUT :evil: ich kann den namen schon nimmer hören. selbst die "ernsthaften" nachrichtesender wie n24 thematisieren diesen (sch)eis(s)bär.

Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 20th, 2007, 3:15 pm 
Offline

Joined: March 24th, 2007, 12:41 am
Posts: 15
Nice app

Seems to work fine on networkdrives.
Why does it take so long to retreive te drives? More than 15 seconds over here!!! (10 network, 3 local).

If i select an icon for a drive it is gone when i select another drive. Should be better to let a user aplly changes for all drives at once.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 20th, 2007, 4:25 pm 
Offline

Joined: April 17th, 2007, 1:49 pm
Posts: 14
Location: Stuttgart (Ger)
thanx for your reply :)

Arnoud wrote:
Nice app

Seems to work fine on networkdrives.
Why does it take so long to retreive te drives? More than 15 seconds over here!!! (10 network, 3 local).


it take about ~2 seconds to scan 13 local drives. i don't know why it takes so long with networkdrives. is it only at the first scan or always ?
i'll try to check this out when i'm at work at the end of next week.
maybe i should disable to retrieve the label from networkdrive as i did for floppies (a: and b: drives). but on the other hand it would not be very comfortable to have only the drive letters and not the names from the netdrives.


Arnoud wrote:
If i select an icon for a drive it is gone when i select another drive. Should be better to let a user aplly changes for all drives at once.


good point ;-) i did not considered it as an disadvantage, but you're right. I'll gonna change this.

Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 21st, 2007, 11:29 am 
Offline

Joined: March 16th, 2005, 10:33 pm
Posts: 968
Location: Frisia
Nice! 8)

Tip: Don't use the JavaScript [copy]-link, it breaks on the Ûs etcet.

_________________
Image mirror 1mirror 2mirror 3ahk4.me • PM or Image


Report this post
Top
 Profile  
Reply with quote  
PostPosted: August 28th, 2010, 11:53 pm 
Offline

Joined: April 24th, 2009, 7:06 pm
Posts: 87
Image

Thanks to Markus M. for his work.
I have made some changes. Perhaps someone will find it useful:

Changelog:
Code:

Drive-Icons Beta 0.815 UPDATE - 2010 by Deep-Silence
Additionals:

==>> Comment-Column
This Comment is shown in Windows-Explorer for
a Description

==>> Support for Autorun.inf and Desktop.ini
If those files are present "Icon" and "Label"
are read out of Autorun.inf & "Comment" is read
out of Desktop.ini

==>> Button to restart Explorer-Shell
For "Comments" to be shown in Explorer

==>> Button to export the Settings for all Drives.
Makes it easier to import them after a reinstallation
of Windows.
   
==>> Some GUI-Adjustments

==>> NOTES
These Code-Adjustments might still contain some Bugs.
Feel free to experience them your own way !!!

Tested under Windows XP SP3, only.
Best Regards, Deep-Silence





The New Code
Code:

#NoEnv
#notrayicon
SendMode Input
#SingleInstance, Force

/*
------------------------------------------------------------------------------------------------------------------------------
  _          _          _     ____       _   _   _                              ____ _   _ ___
 | |    __ _| |__   ___| |_  / ___|  ___| |_| |_(_)_ __   __ _   _   _ _ __    / ___| | | |_ _|
 | |   / _` | '_ \ / _ \ (_) \___ \ / _ \ __| __| | '_ \ / _` | | | | | '_ \  | |  _| | | || |
 | |___ (_| | |_) |  __/ |_   ___) |  __/ |_| |_| | | | | (_| | | |_| | |_) | | |_| | |_| || |
 |_____\__,_|_.__/ \___|_(_) |____/ \___|\__|\__|_|_| |_|\__, |  \__,_| .__/   \____|\___/|___|
                                                         |___/        |_|                     
------------------------------------------------------------------------------------------------------------------------------
*/

;header gradient
bg=ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ
Gui, Font, s14 bold ,terminal
Gui, 1:Add, Text,x0 y0 w840 h4 c0000d0 , %bg%
Gui, 1:Add, Text,y+0 w840 hp c0000c0 , %bg%
Gui, 1:Add, Text,y+0 w840 hp c0000b0 , %bg%
Gui, 1:Add, Text,y+0 w840 hp c0000a0 , %bg%
Gui, 1:Add, Text,y+0 w840 hp c000090 , %bg%
Gui, 1:Add, Text,y+0 w840 hp c000080 , %bg%
Gui, 1:Add, Text,y+0 w840 hp c000070 , %bg%
Gui, 1:Add, Text,y+0 w840 hp c000060 , %bg%

;line blow gradient
gui, add, text, x0 y+0 w840 h2 0x10,


;heading text
gui, font, s14 bold cblack,arial
gui, add, text, x13 y6 +backgroundtrans, Drive-Icons
gui, font, s14 cffffff,arial
gui, add, text, x11 y4 +backgroundtrans, Drive-Icons

;help "button"
gui,add,text,x762 y7 backgroundtrans cblack,?
gui,add,text,x760 y5 backgroundtrans cyellow gHelp,?

gui,add,text,x777 y7 backgroundtrans cblack,+
gui,add,text,x775 y5 backgroundtrans cyellow gHelp_update,+

; --- UI controls ---

;listview
gui,font,,
Gui, Add, ListView, x10 y45 h250 w520 section gListKlick vListe AltSubmit -Multi -LV0x10 NoSort, Drive|Icon|Label|Comment  ; Create a ListView.

;Label: editfield & delete button
gui, add, text, ys section, Label:
gui, font, s18 caa0000 normal, wingdings
gui, add, text, y+7 disabled gDelete vdelLabel,û
gui, font,,
gui, add, edit, yp+2 x+2 w150 vedit_label gTextFieldChange,

;Icon: editfield & delete button
gui, add, text, xs y+18, Icon:
gui, font, s18 caa0000 normal, wingdings
gui, add, text, y+7 disabled gDelete vdelIcon,û
gui, font,,
gui, add, edit,yp+2 x+2 w200 vedit_icon gTextFieldChange,
gui, add, button, x+3 yp+1 w25 hp-2 gIconwahl,...

;Hint: editfield
gui, add, text, xs y+18, Hinweis:
gui, font, s18 caa0000 normal, wingdings
gui, add, text, y+7 disabled gDelete vdelHint,û
gui, font,,
gui, add, edit,yp+2 x+2 w200 vedit_Hint gTextFieldChange,

;Icon: picture & errormessage
gui, add, picture, xs w32 h32 vIcon32,
gui,font,bold c990000,
gui add, text,xp yp vErrorMessage, Error: Icon file not found !
gui,font,,
guicontrol,hide,ErrorMessage

;buttons at bottom
gui, add, text, x0 y310 w840 h2 0x10,
gui, add, button,x670 w120 gbuttoncancel, &Close
gui, add, button,xp-130 w120 gDoIt vDoIt, &Apply
gui, add, button,xp-400 w120 gLabel_Export_Settings, &Export Settings
gui, add, button,xp-130 w120 gLabel_Restart_Explorer, &Restart-Shell

;show gui
Gui Show, w800,Drive-Icons

;initalize LV
FirstInit := true
gosub FillDriveList

return


/*
------------------------------------------------------------------------------------------------------------------------------
  _          _          _     ___       _ _     ____       _               
 | |    __ _| |__   ___| |_  |_ _|_ __ (_) |_  |  _ \ _ __(_)_   _____ ___
 | |   / _` | '_ \ / _ \ (_)  | || '_ \| | __| | | | | '__| \ \ / / _ \ __|
 | |___ (_| | |_) |  __/ |_   | || | | | | |_  | |_| | |  | |\ V /  __\__ \
 |_____\__,_|_.__/ \___|_(_) |___|_| |_|_|\__| |____/|_|  |_| \_/ \___|___/
                                                                           
------------------------------------------------------------------------------------------------------------------------------
*/

FillDriveList:
;create IL and assign to LV.
ImageListID := IL_Create(24,0,0)
LV_SetImageList(ImageListID)

; this LV_ModifyCol command are just cosmetic surgery, when starting the app.
If (FirstInit = true )
   {
   LV_ModifyCol(1,120)
   LV_ModifyCol(2,50)
   LV_ModifyCol(3,100)
   FirstInit := false
   }

DriveGet, LaufwListe, list
AnzLaufw := StrLen(LaufwListe)
StringSplit, Laufwletter, LaufwListe ,,

loop, %AnzLaufw%
   {
   DriveGet, LaufwTyp%A_Index%, type, % Laufwletter%A_Index% . ":"

   if (LaufwTyp%A_Index% = "FIXED") OR (LaufwTyp = "UNKNOWN")
      LaufwExIcon%A_Index% := 8+1
   if (LaufwTyp%A_Index% = "CDROM")
      LaufwExIcon%A_Index% := 11+1 
   if (LaufwTyp%A_Index% = "REMOVABLE")
      LaufwExIcon%A_Index% := 7+1 
   if (LaufwTyp%A_Index% = "RAMDISK")
      LaufwExIcon%A_Index% := 12+1 
   if (LaufwTyp%A_Index% = "NETWORK")
      LaufwExIcon%A_Index% := 9+1 

  ;eleminiate ugly noise from floppy drives (do not retrieve label from possible floppies)
  if  (Laufwletter%A_Index% <> "A") && (Laufwletter%A_Index% <> "B")
   DriveGet, LaufwExLabel%A_Index%, label, % Laufwletter%A_Index% . ":" 
 
  DefaultLabel_reg_key := "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\" . Laufwletter%A_Index% . "\DefaultLabel"
  RegRead, LaufwMyLabel%A_Index%, HKEY_LOCAL_MACHINE, %DefaultLabel_reg_key%,
 
  DefaultIcon_reg_key := "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\" . Laufwletter%A_Index% . "\DefaultIcon"
  RegRead, LaufwMyIcon%A_Index%, HKEY_LOCAL_MACHINE, %DefaultIcon_reg_key%,
 
  DefaultHint_reg_key := "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\" . Laufwletter%A_Index% . "\DefaultHint"
  RegRead, LaufwMyHint%A_Index%, HKEY_LOCAL_MACHINE, %DefaultHint_reg_key%, 
 
 
  if (LaufwMyIcon%A_Index% <> "") ; has own icon (specified in registry)
   {
   IconError%A_Index% := false
    IconIndikator := "   X   "
    IconFile := LaufwMyIcon%A_Index%
    StripIcon(IconFile,IconIndex)
    IconIndex++
    ; if icon file doesn't exist, create errormessage in LV
    ; use standard icon in IL
   
      IfNotExist, %IconFile%
         {
         IconError%A_Index% := true
         IL_Add(ImageListID,  "shell32.dll",LaufwExIcon%A_Index%)
         IconIndikator := "Error !"
         }
      else ; ok, add icon to IL
         {
         IL_Add(ImageListID,IconFile,IconIndex )       
         }
   
   }
   else ; no own icon, use standard icon from shell32.dll
      {
      IconIndikator :=
      IL_Add(ImageListID, "shell32.dll", LaufwExIcon%A_Index%)
      }
 
   LV_Add("Icon" . A_Index,A_Space  Laufwletter%A_Index% . ":" . A_Space LaufwExLabel%A_Index% ,IconIndikator ,LaufwMyLabel%A_Index%, LaufwMyHint%A_Index%)
   
   }   

LV_ModifyCol()  ; Auto-adjust the column widths.


;select LV item
if (gehezu = "" )
   gehezu := 1

LV_Modify(gehezu, "Select")
LV_Modify(gehezu, "Focus")
controlfocus, SysListView321,Drive-Icons

return

/*
------------------------------------------------------------------------------------------------------------------------------
  _          _          _     _     _     _ __     ___                    _        _   _             
 | |    __ _| |__   ___| |_  | |   (_)___| |_ \   / (_) _____      __    / \   ___| |_(_) ___  _ __ 
 | |   / _` | '_ \ / _ \ (_) | |   | / __| __\ \ / /| |/ _ \ \ /\ / /   / _ \ / __| __| |/ _ \| '_ \
 | |___ (_| | |_) |  __/ |_  | |___| \__ \ |_ \ V / | |  __/\ V  V /   / ___ \ (__| |_| | (_) | | | |
 |_____\__,_|_.__/ \___|_(_) |_____|_|___/\__| \_/  |_|\___| \_/\_/   /_/   \_\___|\__|_|\___/|_| |_|
                                                                                                     
------------------------------------------------------------------------------------------------------------------------------
*/

ListKlick:
; LV item selected, continue with ControlUpdate
if (A_GuiEvent = "DoubleClick")
   {
   ListenNr = %A_EventInfo%
   
   DefaultLabel =
   IconFile =
   DefaultHint =
   
   guicontrol,,edit_label,
   guicontrol,,edit_icon,
   guicontrol,,edit_hint,
      
   
   
   ;=================================================================
   ;Update editfields, icon/errormassage and delete buttons, matching the selected drive from LV
   ControlUpdate:

   VarSetCapacity(Check_Drive,0)               ;   Check_Drive Zurücksetzen
   LV_GetText(Check_Drive, A_EventInfo, 1)         ;   Check_Drive auslesen


   ;   Exclude Drive A from the Action
   IfEqual, ListenNr, "1"
      Goto, NoAction

   ;   Failure-Correction for "Dr"
   IfEqual, Check_Drive, "Dr"
      Goto, NoAction

   
   ;   Isolation of DriveLetter from "%Check_Drive%"
   StringReplace, Check_Drive, Check_Drive, %A_Space%, , All
   StringLeft, Check_Drive, Check_Drive, 2
   Check_Drive = %Check_Drive%\
   StringLeft, D_Letter, Check_Drive, 1
   ;Msgbox, Check_Drive: %Check_Drive%`nD_Letter: %D_Letter%

   
   ;   Auslesen der Werte aus "Autorun.inf" falls vorhanden
   IfExist, %Check_Drive%AutoRun.inf
      {
      IniRead, IconFile_Value, %Check_Drive%AutoRun.inf, autorun, Icon
      IniRead, DefaultLabel_Value, %Check_Drive%AutoRun.inf, autorun, Label
      This_DriveLetter := Check_Drive
      }
   
   If (IconFile_Value = "") Or (DefaultLabel_Value = "")
      {
      IconFile = SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\%D_Letter%\DefaultIcon\
      RegRead, IconFile_Value, HKEY_LOCAL_MACHINE, %IconFile%,
      
      DefaultLabel = SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\%D_Letter%\DefaultLabel\
      RegRead, DefaultLabel_Value, HKEY_LOCAL_MACHINE, %DefaultLabel%,
      
      ;Msgbox, IconFile_Value: %IconFile_Value%`nDefaultLabel_Value: %DefaultLabel_Value%
      This_DriveLetter =
      }
   
   
   ;   Auslesen der Werte aus "Desktop.ini" falls vorhanden
   IfExist, %Check_Drive%\Desktop.ini
      {
      IniRead, DefaultHint_Value, %Check_Drive%\Desktop.ini, .ShellClassInfo, InfoTip
      }
   Else
      {
      DefaultHint = SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\%D_Letter%\DefaultHint\
      RegRead, DefaultHint_Value, HKEY_LOCAL_MACHINE, %DefaultHint%,
      }
   
   If (DefaultHint_Value = "") Or (DefaultHint_Value = Error)
      {
      DefaultHint = SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\%D_Letter%\DefaultHint\
      RegRead, DefaultHint_Value, HKEY_LOCAL_MACHINE, %DefaultHint%,
      }


   ;Writing Values to File for debugging
   ;FileAppend , DefaultLabel:  %DefaultLabel%`nIconFile: %IconFile%`nDefaultHint:  %DefaultHint%`n`n`n, Debug.txt
   
   IconFile = %This_DriveLetter%%IconFile_Value%
   LaufwMyIcon%ListenNr% := IconFile
   ;Msgbox, %IconFile%
   
   guicontrol,,edit_label, %DefaultLabel_Value%
   guicontrol,,edit_icon, %This_DriveLetter%%IconFile_Value%
   guicontrol,,edit_hint, %DefaultHint_Value%
   guicontrol,,Icon32, %IconFile%
   
   ;IconFile = %Check_Drive%%IconFile_Value%
   ;IconFile2 := LaufwMyIcon%ListenNr%
   
   StripIcon(IconFile,IconIndex)
   IconIndex ++

   if (LaufwMyIcon%ListenNr% <> "")
      {
      guicontrol,enable,delIcon
      if (IconError%ListenNr% = true)
         {
         guicontrol,hide,Icon32
         guicontrol,show,ErrorMessage       
         }
      else
         {   
         guicontrol,hide,ErrorMessage   
         guicontrol,show,Icon32
         guicontrol,,Icon32, *icon%iconindex% *w32 *h32 %IconFile% 
         }
      }
   else
      {
      guicontrol,hide,Icon32
      guicontrol,hide,ErrorMessage   
      guicontrol,disable,delIcon
      }

   
   if (LaufwMyLabel%ListenNr% <> "")
      {
      guicontrol,enable,delLabel
      }
   else
      {
      guicontrol,disable,delLabel
      }
      

   if (LaufwMyLabel%ListenNr% <> "")
      {
      guicontrol,enable,delHint
      }
   else
      {
      guicontrol,disable,delHint
      }


   guicontrol,disable, DoIt
   }

NoAction:
return

/*
------------------------------------------------------------------------------------------------------------------------------
  _          _          _     _____         _   _____ _      _     _    ____ _                               
 | |    __ _| |__   ___| |_  |_   _|____  __ |_|  ___(_) ___| | __| |  / ___| |__   __ _ _ __   __ _  ___ ___
 | |   / _` | '_ \ / _ \ (_)   | |/ _ \ \/ / __| |_  | |/ _ \ |/ _` | | |   | '_ \ / _` | '_ \ / _` |/ _ \ __|
 | |___ (_| | |_) |  __/ |_    | |  __/>  <| |_|  _| | |  __/ | (_| | | |___| | | | (_| | | | | (_| |  __\__ \
 |_____\__,_|_.__/ \___|_(_)   |_|\___/_/\_\\__|_|   |_|\___|_|\__,_|  \____|_| |_|\__,_|_| |_|\__, |\___|___/
                                                                                               |___/         
------------------------------------------------------------------------------------------------------------------------------
*/

TextFieldChange:

GuiControlGet, wert, , %A_GuiControl%
if (A_GuiControl = "edit_label")
   {
   if (LaufwMyLabel%ListenNr% <> wert)
      guicontrol,enable, DoIt 
   if (strlen(wert) = 0)
      guicontrol,disable,delLabel
   if (strlen(wert) > 0)
      guicontrol,enable,delLabel 
   }

if (A_GuiControl = "edit_icon")
   {
   if (LaufwMyIcon%ListenNr% <> wert)
      guicontrol,enable, DoIt   
   if (strlen(wert) = 0)
      guicontrol,disable,delIcon
   if (strlen(wert) > 0)
      guicontrol,enable,delIcon 
   }
   
if (A_GuiControl = "edit_Hint")
   {
   if (LaufwMyHint%ListenNr% <> wert)
      guicontrol,enable, DoIt   
   if (strlen(wert) = 0)
      guicontrol,disable,delHint,
   if (strlen(wert) > 0)
      guicontrol,enable,delHint, 
   }
   
return

/*
------------------------------------------------------------------------------------------------------------------------------
  _          _          _     _   _           _       _         ___                                  _   _          _          _
 | |    __ _| |__   ___| |_  | | | |_ __   __| | __ _| |_ ___  |_ _|___ ___  _ __     __ _ _ __   __| | | |    __ _| |__   ___| |
 | |   / _` | '_ \ / _ \ (_) | | | | '_ \ / _` |/ _` | __/ _ \  | |/ __/ _ \| '_ \   / _` | '_ \ / _` | | |   / _` | '_ \ / _ \ |
 | |___ (_| | |_) |  __/ |_  | |_| | |_) | (_| | (_| | |_  __/  | | (__ (_) | | | | | (_| | | | | (_| | | |___ (_| | |_) |  __/ |
 |_____\__,_|_.__/ \___|_(_)  \___/| .__/ \__,_|\__,_|\__\___| |___\___\___/|_| |_|  \__,_|_| |_|\__,_| |_____\__,_|_.__/ \___|_|
                                   |_|                                                                                           
------------------------------------------------------------------------------------------------------------------------------
*/

; delete icon and/or label in editfield
Delete:

if (A_GuiControl = "delLabel")
   {
   guicontrol,,edit_label,
   guicontrol,disable,delLabel
   }

if (A_GuiControl = "delIcon")
   {
   guicontrol,,edit_icon,   
   guicontrol,hide,Icon32
   guicontrol,disable,delIcon
   }
   
if (A_GuiControl = "delHint")
   {
   guicontrol,,edit_hint,   
   guicontrol,hide,Icon32
   guicontrol,disable,delHint
   }
   
return

/*
------------------------------------------------------------------------------------------------------------------------------
  _          _          _     _____                       _     ____       _   _   _                 
 | |    __ _| |__   ___| |_  | ____|_  ___ __   ___  _ __| |_  / ___|  ___| |_| |_(_)_ __   __ _ ___
 | |   / _` | '_ \ / _ \ (_) |  _| \ \/ / '_ \ / _ \| '__| __| \___ \ / _ \ __| __| | '_ \ / _` / __|
 | |___ (_| | |_) |  __/ |_  | |___ >  <| |_) | (_) | |  | |_   ___) |  __/ |_| |_| | | | | (_| \__ \
 |_____\__,_|_.__/ \___|_(_) |_____/_/\_\ .__/ \___/|_|   \__| |____/ \___|\__|\__|_|_| |_|\__, |___/
                                        |_|                                                |___/     

------------------------------------------------------------------------------------------------------------------------------
*/

Label_Export_Settings:
EnvGet, This_Computer, Computername

FileSelectFile, Outputfile,S 2,::{20d04fe0-3aea-1069-a2d8-08002b30309d}\%This_Computer%_DriveSettings.reg , Where to save?, Registry-Settings (*.reg)
if Outputfile =
    MsgBox, Saving aborted!
else
   {
   ;Msgbox, %Outputfile%
   RunWait, %comspec% /c "REG EXPORT HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons %Outputfile%",, Hide
   }
Return




/*
------------------------------------------------------------------------------------------------------------------------------
  _          _          _     ____          _             _     _____            _                       ____  _          _ _
 | |    __ _| |__   ___| |_  |  _ \ ___ ___| |_ __ _ _ __| |_  | ____|_  ___ __ | | ___  _ __ ___ _ __  / ___|| |__   ___| | |
 | |   / _` | '_ \ / _ \ (_) | |_) / _ \ __| __/ _` | '__| __| |  _| \ \/ / '_ \| |/ _ \| '__/ _ \ '__| \___ \| '_ \ / _ \ | |
 | |___ (_| | |_) |  __/ |_  |  _ <  __\__ \ |_ (_| | |  | |_  | |___ >  <| |_) | | (_) | | |  __/ |     ___) | | | |  __/ | |
 |_____\__,_|_.__/ \___|_(_) |_| \_\___|___/\__\__,_|_|   \__| |_____/_/\_\ .__/|_|\___/|_|  \___|_|    |____/|_| |_|\___|_|_|
                                                                          |_|                                                 
------------------------------------------------------------------------------------------------------------------------------
*/

Label_Restart_Explorer:

Msgbox_Text =
(Ltrim
For the Comments to take affect, you
need to restart the Explorer Shell!

Do you really want to do that?
All open Folders will be lost!
)
MsgBox, 4, Restart Explorer-Shell, %Msgbox_Text%,
IfMsgBox, Yes
   {
   Runwait, taskkill -f -im explorer.exe
   Run, explorer.exe
   }
Else
   {
   ; Do Nothing
   }
Return





/*
------------------------------------------------------------------------------------------------------------------------------
  _          _          _     ____                                __              ___               
 | |    __ _| |__   ___| |_  | __ ) _ __ _____      _____  ___   / _| ___  _ __  |_ _|___ ___  _ __ 
 | |   / _` | '_ \ / _ \ (_) |  _ \| '__/ _ \ \ /\ / / __|/ _ \ | |_ / _ \| '__|  | |/ __/ _ \| '_ \
 | |___ (_| | |_) |  __/ |_  | |_) | | | (_) \ V  V /\__ \  __/ |  _| (_) | |     | | (__ (_) | | | |
 |_____\__,_|_.__/ \___|_(_) |____/|_|  \___/ \_/\_/ |___/\___| |_|  \___/|_|    |___\___\___/|_| |_|
                                                                                                     
------------------------------------------------------------------------------------------------------------------------------
*/

Iconwahl:

Gui, submit,nohide
IconFile := edit_icon
IconIndex := 0

StripIcon(IconFile,IconIndex)

gui, +disabled
ChooseIcon(IconFile, IconIndex, hGui)
gui, -disabled
gui, show

if instr(IconFile,"%SystemRoot%" )
   {
   StringReplace, IconFile, IconFile, % "%SystemRoot%", %A_WinDir% , All
   }

guicontrol,show,Icon32
guicontrol,,Icon32, % "*icon" . IconIndex+1 . " *w32 *h32 " . IconFile
guicontrol,enable,delIcon
guicontrol,hide,ErrorMessage

IconIndexText =
if (IconIndex <> 0)
IconIndexText = ,%IconIndex%
GuiControl,,edit_icon, %IconFile%%IconIndexText%

return


;=================================================================
;split iconstring into filename and index
StripIcon(byRef IconFile, byRef IconIndex)
   {
     find = ,
     StringGetPos, KommaPos, IconFile, %find%, R
    
     if (KommaPos > 0)
      {
      IconIndex := SubStr(IconFile, KommaPos+2)
      StringLeft,IconFile,IconFile,KommaPos
      }
   else
      {
      IconIndex := 0
      }

     Return
   }

DeleteHint:
Return   


/*
------------------------------------------------------------------------------------------------------------------------------
  _          _          _        _                _          ____ _                                 
 | |    __ _| |__   ___| |_     / \   _ __  _ __ | |_   _   / ___| |__   __ _ _ __   __ _  ___ ___ _
 | |   / _` | '_ \ / _ \ (_)   / _ \ | '_ \| '_ \| | | | | | |   | '_ \ / _` | '_ \ / _` |/ _ \ __(_)
 | |___ (_| | |_) |  __/ |_   / ___ \| |_) | |_) | | |_| | | |___| | | | (_| | | | | (_| |  __\__ \_
 |_____\__,_|_.__/ \___|_(_) /_/   \_\ .__/| .__/|_|\__, |  \____|_| |_|\__,_|_| |_|\__, |\___|___(_)
                                     |_|   |_|      |___/                           |___/           

------------------------------------------------------------------------------------------------------------------------------
*/

DoIt:
gui, submit, nohide

;/*
;   Desktop.ini - Template
Desktop_Ini_Template =
(Ltrim
[.ShellClassInfo]
IconFile=
IconIndex=
InfoTip=%edit_Hint%
)
;*/


/*
This_Drive = "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\%D_Letter%"
DefaultLabel_reg_key = "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\%D_Letter%\DefaultLabel"
Msgbox, Check_Drive: %Check_Drive%`nD_Letter: %D_Letter%`n`nDefaultLabel_reg_key: %DefaultLabel_reg_key%`n`nThis_Drive: %This_Drive%
ExitApp
*/

DefaultLabel_reg_key = SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\%D_Letter%\DefaultLabel
If (edit_label = "")
   {
   RegDelete, HKEY_LOCAL_MACHINE, %DefaultLabel_reg_key%
   }
Else
   {
   RegWrite,REG_SZ , HKEY_LOCAL_MACHINE, %DefaultLabel_reg_key%,, %edit_label%
   IniWrite, %empty%, %Check_Drive%Autorun.inf, autorun, Label
   }

DefaultIcon_reg_key = SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\%D_Letter%\DefaultIcon
If (edit_icon = "")
   {
   RegDelete, HKEY_LOCAL_MACHINE, %DefaultIcon_reg_key%
   }
Else
   {
   RegWrite, REG_SZ, HKEY_LOCAL_MACHINE, %DefaultIcon_reg_key%, ,%edit_icon%
   IniWrite, %empty%, %Check_Drive%Autorun.inf, autorun, Icon
   }


DefaultHint_reg_key = SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\%D_Letter%\DefaultHint
If (edit_icon = "")
   {
   RegDelete, HKEY_LOCAL_MACHINE, %DefaultHint_reg_key%
   }
Else
   {
   RegWrite, REG_SZ, HKEY_LOCAL_MACHINE, %DefaultHint_reg_key%, ,%edit_Hint%
   
      IfExist, %Check_Drive%Desktop.ini
         FileMove, %Check_Drive%Desktop.ini, %Check_Drive%Desktop.in_
      Else
         {
         FileDelete, %Check_Drive%Desktop.in_
         FileAppend, %Desktop_Ini_Template%`n, %Check_Drive%Desktop.ini
         }
   }
   

If (edit_label = "") && (edit_icon = "") && (edit_hint = "")
   {
   This_Drive = SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\%D_Letter%
   RegDelete, HKEY_LOCAL_MACHINE, %This_Drive%
   }

If (edit_hint = "")
   {
   FileDelete, %Check_Drive%Desktop.ini
   FileDelete, %Check_Drive%Desktop.in_
   RegWrite, REG_SZ, HKEY_LOCAL_MACHINE, %DefaultHint_reg_key%, ,%empty%
   }
   

 
IL_Destroy(ImageListID)
LV_Delete()
guicontrol,disable, DoIt
gehezu := ListenNr
gosub FillDriveList

guicontrol,,edit_label,
guicontrol,,edit_icon,
guicontrol,,edit_hint,
guicontrol,,Icon32,
   
return


/*
------------------------------------------------------------------------------------------------------------------------------
  _          _          _     _   _      _       
 | |    __ _| |__   ___| |_  | | | | ___| |_ __ 
 | |   / _` | '_ \ / _ \ (_) | |_| |/ _ \ | '_ \
 | |___ (_| | |_) |  __/ |_  |  _  |  __/ | |_) |
 |_____\__,_|_.__/ \___|_(_) |_| |_|\___|_| .__/
                                          |_|   

------------------------------------------------------------------------------------------------------------------------------
*/

Help:
gui +owndialogs
msgbox,
(
Drive-Icons Beta 0.815 - 2007 by Markus Möller

This little App allows you to change the icon and the label for a drive.
It is very usefull if you've got many partitions, virtual cd drives, multi card
reader etc.
Use icons and descriptions for your drives to make it easier to detect them in
the windows explorer.
If you have choosen an icon and/or label for a cd-rom drive it will shown as long
as no disc is inserted. When you insert a disc into the drive, you will see the
icon and label specified in the autorun.inf.

If a disc has a "real label" it will used prior to what you typed into the label
field of this app.

Sorry about the name confusing about label and label. I'll try to find better
words for the next release. ;-)

You can extend the limitations of naming a fat partition, if you don't give a
"real label" with the windows explorer, or using the label command.

2Do:
Adding ability to work with non present drives.
Multilanguage support (De/En)
Maybe a feature to disable drives (like TweakUI)
)
return

/*
------------------------------------------------------------------------------------------------------------------------------
  _          _          _     _   _      _                 _   _           _       _       
 | |    __ _| |__   ___| |_  | | | | ___| |_ __           | | | |_ __   __| | __ _| |_ ___
 | |   / _` | '_ \ / _ \ (_) | |_| |/ _ \ | '_ \   _____  | | | | '_ \ / _` |/ _` | __/ _ \
 | |___ (_| | |_) |  __/ |_  |  _  |  __/ | |_) | |_____| | |_| | |_) | (_| | (_| | |_  __/
 |_____\__,_|_.__/ \___|_(_) |_| |_|\___|_| .__/           \___/| .__/ \__,_|\__,_|\__\___|
                                          |_|                   |_|                       

------------------------------------------------------------------------------------------------------------------------------
*/

Help_update:
msgbox,
(

Drive-Icons Beta 0.815 UPDATE - 2010 by Deep-Silence
Additionals:

==>> Comment-Column
This Comment is shown in Windows-Explorer for
a Description

==>> Support for Autorun.inf and Desktop.ini
If those files are present "Icon" and "Label"
are read out of Autorun.inf & "Comment" is read
out of Desktop.ini

==>> Button to restart Explorer-Shell
For "Comments" to be shown in Explorer

==>> Button to export the Settings for all Drives.
Makes it easier to import them after a reinstallation
of Windows.
   
==>> Some GUI-Adjustments

==>> NOTES
These Code-Adjustments might still contain some Bugs.
Feel free to experience them your own way !!!

Tested under Windows XP SP3, only.
Best Regards, Deep-Silence

)
Return

/*
------------------------------------------------------------------------------------------------------------------------------
  _          _          _     _____      _ _        _                _ _           _   _             
 | |    __ _| |__   ___| |_  | ____|_  ___) |_     / \   _ __  _ __ | (_) ___ __ _| |_(_) ___  _ __ 
 | |   / _` | '_ \ / _ \ (_) |  _| \ \/ / | __|   / _ \ | '_ \| '_ \| | |/ __/ _` | __| |/ _ \| '_ \
 | |___ (_| | |_) |  __/ |_  | |___ >  <| | |_   / ___ \| |_) | |_) | | | (__ (_| | |_| | (_) | | | |
 |_____\__,_|_.__/ \___|_(_) |_____/_/\_\_|\__| /_/   \_\ .__/| .__/|_|_|\___\__,_|\__|_|\___/|_| |_|
                                                        |_|   |_|                                   

------------------------------------------------------------------------------------------------------------------------------
*/

buttoncancel:
GuiClose:
exitapp


/*
------------------------------------------------------------------------------------------------------------------------------
  _____ _   _ _   _  ____ _____ ___ ___  _   _ ____   
 |  ___| | | | \ | |/ ___|_   _|_ _/ _ \| \ | / ___|_
 | |_  | | | |  \| | |     | |  | | | | |  \| \___ (_)
 |  _| | |_| | |\  | |___  | |  | | |_| | |\  |___) |
 |_|    \___/|_| \_|\____| |_| |___\___/|_| \_|____(_)
                                                     

------------------------------------------------------------------------------------------------------------------------------
*/

; ChooseIcon by majkinetor, w2k fix by me

ChooseIcon(ByRef sIcon, ByRef idx, hGui=0) {                               
   
    VarSetCapacity(wIcon, 1025, 0)
    if sIcon !=
      {
        r := DllCall("MultiByteToWideChar"
             , "UInt", 0             ; CodePage: CP_ACP=0 (current Ansi), CP_UTF7=65000, CP_UTF8=65001
             , "UInt", 0             ; dwFlags
             , "Str", sIcon          ; LPSTR lpMultiByteStr
             , "Int", StrLen(sIcon)  ; cbMultiByte: -1=null terminated
             , "UInt", &wIcon        ; LPCWSTR lpWideCharStr
             , "Int", 1025)          ; cchWideChar: 0 to get required size

        if !r
            return 2
      }
   
    r := DllCall(DllCall("GetProcAddress", "Uint", DllCall("LoadLibrary", "str", "shell32.dll"), "Uint", 62), "uint", hGui, "uint", &wIcon, "uint", 1025, "intp", idx)
    if !r
        return 1

   len := DllCall("lstrlenW", "UInt", &wIcon)
   VarSetCapacity(sIcon, len, 0)
   r := DllCall("WideCharToMultiByte"
         , "UInt", 0           ; CodePage: CP_ACP=0 (current Ansi), CP_UTF7=65000, CP_UTF8=65001
         , "UInt", 0           ; dwFlags
         , "UInt", &wIcon      ; LPCWSTR lpWideCharStr
         , "Int", len          ; cchWideChar: size in WCHAR values, -1=null terminated
         , "Str", sIcon        ; LPSTR lpMultiByteStr
         , "Int", len          ; cbMultiByte: 0 to get required size
         , "UInt", 0           ; LPCSTR lpDefaultChar
         , "UInt", 0)          ; LPBOOL lpUsedDefaultChar

    if !r
        return 3
           
    return 0
}


Last edited by Deep-Silence on August 21st, 2011, 3:48 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 21st, 2011, 9:50 am 
Hi Deep-Silence

Thanks for your script! I've been looking for a way to get comments working on network drives for a long time, because the usual desktop.ini trick doesn't work! :(

Also there are a few errors with your script.

Did you make this for the English version of Windows?


I don't suppose you'll be updating this anymore?


thanks

Jon


Report this post
Top
  
Reply with quote  
PostPosted: August 21st, 2011, 11:25 am 
Offline

Joined: April 24th, 2009, 7:06 pm
Posts: 87
Hi Jon,

Thanks for your Feedback.
Here is the latest Update

---------------------------------------------------------------------------------
Drive-Icons Beta 0.815 UPDATE - 08/2011 by Deep-Silence
---------------------------------------------------------------------------------
* Fixed - Loading right values for each Drive
* Fixed - Graphical Elements (language)

* Added - Target Drive is going to be renamed to `%Label`%, silently
* Added - Button to Restart the Script

* Improved - handling of Desktop.ini and Autorun.inf
* Improved - Icon Handling
* Improved - Code cleaned up & more organized
* Improved - Restart Explorer-Shell, silently
---------------------------------------------------------------------------------

With Best Regards,
Deep-Silence

Code:
#NoEnv
#notrayicon
SendMode Input
#SingleInstance, Force

/*
------------------------------------------------------------------------------------------------------------------------------
  _          _          _     ____       _   _   _                              ____ _   _ ___
 | |    __ _| |__   ___| |_  / ___|  ___| |_| |_(_)_ __   __ _   _   _ _ __    / ___| | | |_ _|
 | |   / _` | '_ \ / _ \ (_) \___ \ / _ \ __| __| | '_ \ / _` | | | | | '_ \  | |  _| | | || |
 | |___ (_| | |_) |  __/ |_   ___) |  __/ |_| |_| | | | | (_| | | |_| | |_) | | |_| | |_| || |
 |_____\__,_|_.__/ \___|_(_) |____/ \___|\__|\__|_|_| |_|\__, |  \__,_| .__/   \____|\___/|___|
                                                         |___/        |_|                     
------------------------------------------------------------------------------------------------------------------------------
*/

;header gradient
bg=ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ
Gui, Font, s14 bold ,terminal
Gui, 1:Add, Text,x0 y0 w840 h4 c0000d0 , %bg%
Gui, 1:Add, Text,y+0 w840 hp c0000c0 , %bg%
Gui, 1:Add, Text,y+0 w840 hp c0000b0 , %bg%
Gui, 1:Add, Text,y+0 w840 hp c0000a0 , %bg%
Gui, 1:Add, Text,y+0 w840 hp c000090 , %bg%
Gui, 1:Add, Text,y+0 w840 hp c000080 , %bg%
Gui, 1:Add, Text,y+0 w840 hp c000070 , %bg%
Gui, 1:Add, Text,y+0 w840 hp c000060 , %bg%

;line blow gradient
gui, add, text, x0 y+0 w840 h2 0x10,


;heading text
gui, font, s14 bold cblack,arial
gui, add, text, x13 y6 +backgroundtrans, Drive-Icons
gui, font, s14 cffffff,arial
gui, add, text, x11 y4 +backgroundtrans, Drive-Icons

;help "button"
gui,add,text,x762 y7 backgroundtrans cblack,?
gui,add,text,x760 y5 backgroundtrans cyellow gHelp,?

gui,add,text,x777 y7 backgroundtrans cblack,+
gui,add,text,x775 y5 backgroundtrans cyellow gHelp_update,+

; --- UI controls ---

;listview
gui,font,,
Gui, Add, ListView, x10 y45 h250 w520 section gListKlick vListe AltSubmit -Multi -LV0x10 NoSort, Drive|Icon|Label|Comment  ; Create a ListView.

;Label: editfield & delete button
gui, add, text, ys section, Label:
gui, font, s18 caa0000 normal, wingdings
gui, add, text, y+7 disabled gDelete vdelLabel,û
gui, font,,
gui, add, edit, yp+2 x+2 w150 vedit_label gTextFieldChange,

;Icon: editfield & delete button
gui, add, text, xs y+18, Icon:
gui, font, s18 caa0000 normal, wingdings
gui, add, text, y+7 disabled gDelete vdelIcon,û
gui, font,,
gui, add, edit,yp+2 x+2 w200 vedit_icon gTextFieldChange,
gui, add, button, x+3 yp+1 w25 hp-2 gIconwahl,...

;Hint: editfield
gui, add, text, xs y+18, Comment:
gui, font, s18 caa0000 normal, wingdings
gui, add, text, y+7 disabled gDelete vdelHint,û
gui, font,,
gui, add, edit,yp+2 x+2 w200 vedit_Hint gTextFieldChange,

;Icon: picture & errormessage
gui, add, picture, xs w32 h32 vIcon32,
gui,font,bold c990000,
gui add, text,xp yp vErrorMessage, Error: Icon file not found !
gui,font,,
guicontrol,hide,ErrorMessage

;buttons at bottom
gui, add, text, x0 y310 w840 h2 0x10,
gui, add, button,x670 w120 gbuttoncancel, &Close
gui, add, button,xp-130 w120 gDoIt vDoIt, &Apply
gui, add, button,xp-400 w120 gLabel_Export_Settings, &Export Settings
gui, add, button,xp-130 w120 gLabel_Restart_Explorer, &Restart-Shell
gui, add, button,xp+260 w120 gLabel_Restart, &Restart

;show gui
Gui Show, w800,Drive-Icons

;initalize LV
FirstInit := true
gosub FillDriveList

return


/*
------------------------------------------------------------------------------------------------------------------------------
  _          _          _     ___       _ _     ____       _               
 | |    __ _| |__   ___| |_  |_ _|_ __ (_) |_  |  _ \ _ __(_)_   _____ ___
 | |   / _` | '_ \ / _ \ (_)  | || '_ \| | __| | | | | '__| \ \ / / _ \ __|
 | |___ (_| | |_) |  __/ |_   | || | | | | |_  | |_| | |  | |\ V /  __\__ \
 |_____\__,_|_.__/ \___|_(_) |___|_| |_|_|\__| |____/|_|  |_| \_/ \___|___/
                                                                           
------------------------------------------------------------------------------------------------------------------------------
*/

FillDriveList:
;create IL and assign to LV.
ImageListID := IL_Create(24,0,0)
LV_SetImageList(ImageListID)

; this LV_ModifyCol command are just cosmetic surgery, when starting the app.
If (FirstInit = true )
   {
   LV_ModifyCol(1,120)
   LV_ModifyCol(2,50)
   LV_ModifyCol(3,100)
   FirstInit := false
   }

DriveGet, LaufwListe, list
AnzLaufw := StrLen(LaufwListe)
StringSplit, Laufwletter, LaufwListe ,,

loop, %AnzLaufw%
   {
   DriveGet, LaufwTyp%A_Index%, type, % Laufwletter%A_Index% . ":"

   if (LaufwTyp%A_Index% = "FIXED") OR (LaufwTyp = "UNKNOWN")
      LaufwExIcon%A_Index% := 8+1
   if (LaufwTyp%A_Index% = "CDROM")
      LaufwExIcon%A_Index% := 11+1 
   if (LaufwTyp%A_Index% = "REMOVABLE")
      LaufwExIcon%A_Index% := 7+1 
   if (LaufwTyp%A_Index% = "RAMDISK")
      LaufwExIcon%A_Index% := 12+1 
   if (LaufwTyp%A_Index% = "NETWORK")
      LaufwExIcon%A_Index% := 9+1 

  ;eleminiate ugly noise from floppy drives (do not retrieve label from possible floppies)
  if  (Laufwletter%A_Index% <> "A") && (Laufwletter%A_Index% <> "B")
   DriveGet, LaufwExLabel%A_Index%, label, % Laufwletter%A_Index% . ":" 
 
  DefaultLabel_reg_key := "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\" . Laufwletter%A_Index% . "\DefaultLabel"
  RegRead, LaufwMyLabel%A_Index%, HKEY_LOCAL_MACHINE, %DefaultLabel_reg_key%,
 
  DefaultIcon_reg_key := "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\" . Laufwletter%A_Index% . "\DefaultIcon"
  RegRead, LaufwMyIcon%A_Index%, HKEY_LOCAL_MACHINE, %DefaultIcon_reg_key%,
 
  DefaultComment_reg_key := "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\" . Laufwletter%A_Index% . "\DefaultComment"
  RegRead, LaufwMyHint%A_Index%, HKEY_LOCAL_MACHINE, %DefaultComment_reg_key%, 
 
 
  if (LaufwMyIcon%A_Index% <> "") ; has own icon (specified in registry)
   {
   IconError%A_Index% := false
    IconIndikator := "   X   "
    IconFile := LaufwMyIcon%A_Index%
    StripIcon(IconFile,IconIndex)
    IconIndex++
    ; if icon file doesn't exist, create errormessage in LV
    ; use standard icon in IL
   
      IfNotExist, %IconFile%
         {
         IconError%A_Index% := true
         IL_Add(ImageListID,  "shell32.dll",LaufwExIcon%A_Index%)
         IconIndikator := "Error !"
         }
      else ; ok, add icon to IL
         {
         IL_Add(ImageListID,IconFile,IconIndex )       
         }
   
   }
   else ; no own icon, use standard icon from shell32.dll
      {
      IconIndikator :=
      IL_Add(ImageListID, "shell32.dll", LaufwExIcon%A_Index%)
      }
 
   LV_Add("Icon" . A_Index,A_Space  Laufwletter%A_Index% . ":" . A_Space LaufwExLabel%A_Index% ,IconIndikator ,LaufwMyLabel%A_Index%, LaufwMyHint%A_Index%)
   
   }   

LV_ModifyCol()  ; Auto-adjust the column widths.


;select LV item
if (gehezu = "" )
   gehezu := 1

LV_Modify(gehezu, "Select")
LV_Modify(gehezu, "Focus")
controlfocus, SysListView321,Drive-Icons

return

/*
------------------------------------------------------------------------------------------------------------------------------
  _          _          _     _     _     _ __     ___                    _        _   _             
 | |    __ _| |__   ___| |_  | |   (_)___| |_ \   / (_) _____      __    / \   ___| |_(_) ___  _ __ 
 | |   / _` | '_ \ / _ \ (_) | |   | / __| __\ \ / /| |/ _ \ \ /\ / /   / _ \ / __| __| |/ _ \| '_ \
 | |___ (_| | |_) |  __/ |_  | |___| \__ \ |_ \ V / | |  __/\ V  V /   / ___ \ (__| |_| | (_) | | | |
 |_____\__,_|_.__/ \___|_(_) |_____|_|___/\__| \_/  |_|\___| \_/\_/   /_/   \_\___|\__|_|\___/|_| |_|
                                                                                                     
------------------------------------------------------------------------------------------------------------------------------
*/

ListKlick:
; LV item selected, continue with ControlUpdate
if (A_GuiEvent = "DoubleClick")
   {
   ListenNr = %A_EventInfo%
   
   DefaultLabel =
   IconFile =
   DefaultComment =
   
   ; Reset the Last Values
   VarSetCapacity(DefaultLabel_Value,0)
   VarSetCapacity(This_DriveLetter,0)
   VarSetCapacity(IconFile_Value,0)
   VarSetCapacity(DefaultComment_Value,0)
   VarSetCapacity(IconFile,0)
   
   
   ;guicontrol,,edit_label, %DefaultLabel_Value%
   ;guicontrol,,edit_icon, %This_DriveLetter%%IconFile_Value%
   ;guicontrol,,edit_hint, %DefaultComment_Value%
   ;guicontrol,,Icon32, %IconFile%
   
   ;=================================================================
   ;Update editfields, icon/errormassage and delete buttons, matching the selected drive from LV
   ControlUpdate:

   VarSetCapacity(Check_Drive,0)               ;   Check_Drive Zurücksetzen
   LV_GetText(Check_Drive, A_EventInfo, 1)         ;   Check_Drive auslesen


   ;   Exclude Drive A from the Action
   IfEqual, ListenNr, "1"
      Goto, NoAction

   ;   Failure-Correction for "Dr"
   IfEqual, Check_Drive, "Dr"
      Goto, NoAction

   
   ;   Isolation of DriveLetter from "%Check_Drive%"
   Check_Drive = %Check_Drive%
   StringLeft, Check_Drive, Check_Drive, 2
   StringLeft, D_Letter, Check_Drive, 1
   ;Msgbox, Check_Drive: %Check_Drive%`nD_Letter: %D_Letter%

   
   ;   Auslesen der Werte aus "Autorun.inf" falls vorhanden
   IfExist, %Check_Drive%\AutoRun.inf
      {
      IniRead, IconFile_Value, %Check_Drive%\AutoRun.inf, autorun, Icon
      IniRead, DefaultLabel_Value, %Check_Drive%\AutoRun.inf, autorun, Label
      This_DriveLetter = %Check_Drive%\
      }
   
   If (IconFile_Value = "") Or (DefaultLabel_Value = "")
      {
      IconFile = SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\%D_Letter%\DefaultIcon\
      RegRead, IconFile_Value, HKEY_LOCAL_MACHINE, %IconFile%,
       
      DefaultLabel = SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\%D_Letter%\DefaultLabel\
      RegRead, DefaultLabel_Value, HKEY_LOCAL_MACHINE, %DefaultLabel%,
       
      ;Msgbox, IconFile_Value: %IconFile_Value%`nDefaultLabel_Value: %DefaultLabel_Value%
      This_DriveLetter =
      }
   
   
   ;   Auslesen der Werte aus "Desktop.ini" falls vorhanden
   IfExist, %Check_Drive%\Desktop.ini
      {
      IniRead, DefaultComment_Value, %Check_Drive%\Desktop.ini, .ShellClassInfo, InfoTip
      }
   Else
      {
      DefaultComment = SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\%D_Letter%\DefaultComment\
      RegRead, DefaultComment_Value, HKEY_LOCAL_MACHINE, %DefaultComment%,
      }
   
   If (DefaultComment_Value = "") Or (DefaultComment_Value = Error)
      {
      DefaultComment = SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\%D_Letter%\DefaultComment\
      RegRead, DefaultComment_Value, HKEY_LOCAL_MACHINE, %DefaultComment%,
      }


   ;Writing Values to File for debugging
   ;FileAppend , DefaultLabel:  %DefaultLabel%`nIconFile: %IconFile%`nDefaultComment:  %DefaultComment%`n`n`n, Debug.txt
   
   ;IconFile = %This_DriveLetter%%IconFile_Value%
   IconFile = %IconFile_Value%
   LaufwMyIcon%ListenNr% := IconFile
   ;Msgbox, %IconFile%
   
   ;guicontrol,,edit_icon, %This_DriveLetter%%IconFile_Value%
   guicontrol,,edit_label, %DefaultLabel_Value%
   guicontrol,,edit_icon, %IconFile_Value%
   guicontrol,,edit_hint, %DefaultComment_Value%
   guicontrol,,Icon32, %IconFile_Value%
 
   ;IconFile = %Check_Drive%%IconFile_Value%
   ;IconFile2 := LaufwMyIcon%ListenNr%
   
   StripIcon(IconFile,IconIndex)
   IconIndex ++

   if (LaufwMyIcon%ListenNr% <> "")
      {
      guicontrol,enable,delIcon
      if (IconError%ListenNr% = true)
         {
         guicontrol,hide,Icon32
         guicontrol,show,ErrorMessage       
         }
      else
         {   
         guicontrol,hide,ErrorMessage   
         guicontrol,show,Icon32
         guicontrol,,Icon32, *icon%iconindex% *w32 *h32 %IconFile% 
         }
      }
   else
      {
      guicontrol,hide,Icon32
      guicontrol,hide,ErrorMessage   
      guicontrol,disable,delIcon
      }

   
   if (LaufwMyLabel%ListenNr% <> "")
      {
      guicontrol,enable,delLabel
      }
   else
      {
      guicontrol,disable,delLabel
      }
       

   if (LaufwMyLabel%ListenNr% <> "")
      {
      guicontrol,enable,delHint
      }
   else
      {
      guicontrol,disable,delHint
      }


   guicontrol,disable, DoIt
   }

NoAction:
return

/*
------------------------------------------------------------------------------------------------------------------------------
  _          _          _     _____         _   _____ _      _     _    ____ _                               
 | |    __ _| |__   ___| |_  |_   _|____  __ |_|  ___(_) ___| | __| |  / ___| |__   __ _ _ __   __ _  ___ ___
 | |   / _` | '_ \ / _ \ (_)   | |/ _ \ \/ / __| |_  | |/ _ \ |/ _` | | |   | '_ \ / _` | '_ \ / _` |/ _ \ __|
 | |___ (_| | |_) |  __/ |_    | |  __/>  <| |_|  _| | |  __/ | (_| | | |___| | | | (_| | | | | (_| |  __\__ \
 |_____\__,_|_.__/ \___|_(_)   |_|\___/_/\_\\__|_|   |_|\___|_|\__,_|  \____|_| |_|\__,_|_| |_|\__, |\___|___/
                                                                                               |___/         
------------------------------------------------------------------------------------------------------------------------------
*/

TextFieldChange:

GuiControlGet, wert, , %A_GuiControl%
if (A_GuiControl = "edit_label")
   {
   if (LaufwMyLabel%ListenNr% <> wert)
      guicontrol,enable, DoIt 
   if (strlen(wert) = 0)
      guicontrol,disable,delLabel
   if (strlen(wert) > 0)
      guicontrol,enable,delLabel 
   }

if (A_GuiControl = "edit_icon")
   {
   if (LaufwMyIcon%ListenNr% <> wert)
      guicontrol,enable, DoIt   
   if (strlen(wert) = 0)
      guicontrol,disable,delIcon
   if (strlen(wert) > 0)
      guicontrol,enable,delIcon 
   }
   
if (A_GuiControl = "edit_Hint")
   {
   if (LaufwMyHint%ListenNr% <> wert)
      guicontrol,enable, DoIt   
   if (strlen(wert) = 0)
      guicontrol,disable,delHint,
   if (strlen(wert) > 0)
      guicontrol,enable,delHint, 
   }
   
return

/*
------------------------------------------------------------------------------------------------------------------------------
  _          _          _     _   _           _       _         ___                                  _   _          _          _
 | |    __ _| |__   ___| |_  | | | |_ __   __| | __ _| |_ ___  |_ _|___ ___  _ __     __ _ _ __   __| | | |    __ _| |__   ___| |
 | |   / _` | '_ \ / _ \ (_) | | | | '_ \ / _` |/ _` | __/ _ \  | |/ __/ _ \| '_ \   / _` | '_ \ / _` | | |   / _` | '_ \ / _ \ |
 | |___ (_| | |_) |  __/ |_  | |_| | |_) | (_| | (_| | |_  __/  | | (__ (_) | | | | | (_| | | | | (_| | | |___ (_| | |_) |  __/ |
 |_____\__,_|_.__/ \___|_(_)  \___/| .__/ \__,_|\__,_|\__\___| |___\___\___/|_| |_|  \__,_|_| |_|\__,_| |_____\__,_|_.__/ \___|_|
                                   |_|                                                                                           
------------------------------------------------------------------------------------------------------------------------------
*/

; delete icon and/or label in editfield
Delete:

if (A_GuiControl = "delLabel")
   {
   guicontrol,,edit_label,
   guicontrol,disable,delLabel
   }

if (A_GuiControl = "delIcon")
   {
   guicontrol,,edit_icon,   
   guicontrol,hide,Icon32
   guicontrol,disable,delIcon
   }
   
if (A_GuiControl = "delHint")
   {
   guicontrol,,edit_hint,   
   guicontrol,hide,Icon32
   guicontrol,disable,delHint
   }
   
return

/*
------------------------------------------------------------------------------------------------------------------------------
  _          _          _     _____                       _     ____       _   _   _                 
 | |    __ _| |__   ___| |_  | ____|_  ___ __   ___  _ __| |_  / ___|  ___| |_| |_(_)_ __   __ _ ___
 | |   / _` | '_ \ / _ \ (_) |  _| \ \/ / '_ \ / _ \| '__| __| \___ \ / _ \ __| __| | '_ \ / _` / __|
 | |___ (_| | |_) |  __/ |_  | |___ >  <| |_) | (_) | |  | |_   ___) |  __/ |_| |_| | | | | (_| \__ \
 |_____\__,_|_.__/ \___|_(_) |_____/_/\_\ .__/ \___/|_|   \__| |____/ \___|\__|\__|_|_| |_|\__, |___/
                                        |_|                                                |___/     

------------------------------------------------------------------------------------------------------------------------------
*/

Label_Export_Settings:
EnvGet, This_Computer, Computername

FileSelectFile, Outputfile,S 2,::{20d04fe0-3aea-1069-a2d8-08002b30309d}\%This_Computer%_DriveSettings.reg , Where to save?, Registry-Settings (*.reg)
if Outputfile =
    MsgBox, Saving aborted!
else
   {
   ;Msgbox, %Outputfile%
   RunWait, %comspec% /c "REG EXPORT HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons %Outputfile%",, Hide
   }
Return




/*
------------------------------------------------------------------------------------------------------------------------------
  _          _          _     ____          _             _     _____            _                       ____  _          _ _
 | |    __ _| |__   ___| |_  |  _ \ ___ ___| |_ __ _ _ __| |_  | ____|_  ___ __ | | ___  _ __ ___ _ __  / ___|| |__   ___| | |
 | |   / _` | '_ \ / _ \ (_) | |_) / _ \ __| __/ _` | '__| __| |  _| \ \/ / '_ \| |/ _ \| '__/ _ \ '__| \___ \| '_ \ / _ \ | |
 | |___ (_| | |_) |  __/ |_  |  _ <  __\__ \ |_ (_| | |  | |_  | |___ >  <| |_) | | (_) | | |  __/ |     ___) | | | |  __/ | |
 |_____\__,_|_.__/ \___|_(_) |_| \_\___|___/\__\__,_|_|   \__| |_____/_/\_\ .__/|_|\___/|_|  \___|_|    |____/|_| |_|\___|_|_|
                                                                          |_|                                                 
------------------------------------------------------------------------------------------------------------------------------
*/

Label_Restart_Explorer:

Msgbox_Text =
(Ltrim
For the Changes to take affect, you
need to restart the Explorer-Shell!

Do you really want to do that?
All open Folders will be lost!
)
MsgBox, 4, Restart Explorer-Shell, %Msgbox_Text%,
IfMsgBox, Yes
   {
   Runwait, %comspec% /c "taskkill -f -im explorer.exe" , , hide
   Run, explorer.exe
   }
Else
   {
   ; Do Nothing
   }
Return





/*
------------------------------------------------------------------------------------------------------------------------------
  _          _          _     ____                                __              ___               
 | |    __ _| |__   ___| |_  | __ ) _ __ _____      _____  ___   / _| ___  _ __  |_ _|___ ___  _ __ 
 | |   / _` | '_ \ / _ \ (_) |  _ \| '__/ _ \ \ /\ / / __|/ _ \ | |_ / _ \| '__|  | |/ __/ _ \| '_ \
 | |___ (_| | |_) |  __/ |_  | |_) | | | (_) \ V  V /\__ \  __/ |  _| (_) | |     | | (__ (_) | | | |
 |_____\__,_|_.__/ \___|_(_) |____/|_|  \___/ \_/\_/ |___/\___| |_|  \___/|_|    |___\___\___/|_| |_|
                                                                                                     
------------------------------------------------------------------------------------------------------------------------------
*/

Iconwahl:

Gui, submit,nohide
IconFile := edit_icon
IconIndex := 0

StripIcon(IconFile,IconIndex)

gui, +disabled
ChooseIcon(IconFile, IconIndex, hGui)
gui, -disabled
gui, show

if instr(IconFile,"%SystemRoot%" )
   {
   StringReplace, IconFile, IconFile, % "%SystemRoot%", %A_WinDir% , All
   }

guicontrol,show,Icon32
guicontrol,,Icon32, % "*icon" . IconIndex+1 . " *w32 *h32 " . IconFile
guicontrol,enable,delIcon
guicontrol,hide,ErrorMessage

IconIndexText =
if (IconIndex <> 0)
IconIndexText = ,%IconIndex%
GuiControl,,edit_icon, %IconFile%%IconIndexText%

return


;=================================================================
;split iconstring into filename and index
StripIcon(byRef IconFile, byRef IconIndex)
   {
     find = ,
     StringGetPos, KommaPos, IconFile, %find%, R
     
     if (KommaPos > 0)
      {
      IconIndex := SubStr(IconFile, KommaPos+2)
      StringLeft,IconFile,IconFile,KommaPos
      }
   else
      {
      IconIndex := 0
      }

     Return
   }

DeleteHint:
Return   


/*
------------------------------------------------------------------------------------------------------------------------------
  _          _          _        _                _          ____ _                                 
 | |    __ _| |__   ___| |_     / \   _ __  _ __ | |_   _   / ___| |__   __ _ _ __   __ _  ___ ___ _
 | |   / _` | '_ \ / _ \ (_)   / _ \ | '_ \| '_ \| | | | | | |   | '_ \ / _` | '_ \ / _` |/ _ \ __(_)
 | |___ (_| | |_) |  __/ |_   / ___ \| |_) | |_) | | |_| | | |___| | | | (_| | | | | (_| |  __\__ \_
 |_____\__,_|_.__/ \___|_(_) /_/   \_\ .__/| .__/|_|\__, |  \____|_| |_|\__,_|_| |_|\__, |\___|___(_)
                                     |_|   |_|      |___/                           |___/           

------------------------------------------------------------------------------------------------------------------------------
*/

DoIt:
VarSetCapacity(Label_Drive,0)
VarSetCapacity(edit_label,0)
gui, submit, nohide

/*
This_Drive = "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\%D_Letter%"
DefaultLabel_reg_key = "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\%D_Letter%\DefaultLabel"
Msgbox, Check_Drive: %Check_Drive%`nD_Letter: %D_Letter%`n`nDefaultLabel_reg_key: %DefaultLabel_reg_key%`n`nThis_Drive: %This_Drive%
ExitApp
*/


;################################################################
; Label the Disk
;################################################################
StringTrimRight, Label_Drive, Check_Drive, 1
Runwait, %comspec% /c "label %Label_Drive%: %edit_label%",, Hide


;################################################################
; Processing the Data for "DefaultLabel"
;################################################################

DefaultLabel_reg_key = SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\%D_Letter%\DefaultLabel
If (edit_label = "")
   {
   RegDelete, HKEY_LOCAL_MACHINE, %DefaultLabel_reg_key%
   }
Else
   {
   RegWrite,REG_SZ , HKEY_LOCAL_MACHINE, %DefaultLabel_reg_key%,, %edit_label%
   ;IniWrite, %empty%, %Check_Drive%Autorun.inf, autorun, Label
   }

;################################################################
; Processing the Data for "DefaultIcon"
;################################################################

DefaultIcon_reg_key = SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\%D_Letter%\DefaultIcon
If (edit_icon = "")
   {
   RegDelete, HKEY_LOCAL_MACHINE, %DefaultIcon_reg_key%
   }
Else
   {
   RegWrite, REG_SZ, HKEY_LOCAL_MACHINE, %DefaultIcon_reg_key%, ,%edit_icon%
   ;IniWrite, %empty%, %Check_Drive%\Autorun.inf, autorun, Icon
   }

;################################################################
; Processing the Data for "DefaultComment"
;################################################################

DefaultComment_reg_key = SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\%D_Letter%\DefaultComment
If (edit_icon = "")
   {
   RegDelete, HKEY_LOCAL_MACHINE, %DefaultComment_reg_key%
   }
Else
   {
   RegWrite, REG_SZ, HKEY_LOCAL_MACHINE, %DefaultComment_reg_key%, ,%edit_Hint%
   }

;################################################################
; Updating necessary Files
;################################################################

FileDelete, %Check_Drive%\Desktop.ini
FileDelete, %Check_Drive%\Autorun.inf

;Desktop.ini - Template
Desktop_Ini_Template =
   (Ltrim
   [.ShellClassInfo]
   IconFile=
   IconIndex=
   InfoTip=%edit_Hint%
   )

FileAppend, %Desktop_Ini_Template%, %Check_Drive%\DESKTOP.INI


;Autorun.inf - Template
Autorun_inf_Template =
   (Ltrim    
   [autorun]
   Label=%edit_label%
   Icon=%edit_icon%
   )

FileAppend, %Autorun_inf_Template%, %Check_Drive%\AUTORUN.INF


;################################################################
; All Edits are Empty
;################################################################

If (edit_label = "") && (edit_icon = "") && (edit_hint = "")
   {
   This_Drive = SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\%D_Letter%
   RegDelete, HKEY_LOCAL_MACHINE, %This_Drive%
   }

If (edit_hint = "")
   {
   FileDelete, %Check_Drive%Desktop.ini
   FileDelete, %Check_Drive%Desktop.in_
   RegWrite, REG_SZ, HKEY_LOCAL_MACHINE, %DefaultComment_reg_key%, ,%empty%
   }
   

;################################################################
; Update Listview
;################################################################

IL_Destroy(ImageListID)
LV_Delete()
guicontrol,disable, DoIt
gehezu := ListenNr
gosub FillDriveList

guicontrol,,edit_label,
guicontrol,,edit_icon,
guicontrol,,edit_hint,
guicontrol,,Icon32,
   
return


/*
------------------------------------------------------------------------------------------------------------------------------
  _          _          _     _   _      _       
 | |    __ _| |__   ___| |_  | | | | ___| |_ __ 
 | |   / _` | '_ \ / _ \ (_) | |_| |/ _ \ | '_ \
 | |___ (_| | |_) |  __/ |_  |  _  |  __/ | |_) |
 |_____\__,_|_.__/ \___|_(_) |_| |_|\___|_| .__/
                                          |_|   

------------------------------------------------------------------------------------------------------------------------------
*/

Help:
gui +owndialogs
msgbox,
(
Drive-Icons Beta 0.815 - 2007 by Markus Möller

This little App allows you to change the icon and the label for a drive.
It is very usefull if you've got many partitions, virtual cd drives, multi card
reader etc.
Use icons and descriptions for your drives to make it easier to detect them in
the windows explorer.
If you have choosen an icon and/or label for a cd-rom drive it will shown as long
as no disc is inserted. When you insert a disc into the drive, you will see the
icon and label specified in the autorun.inf.

If a disc has a "real label" it will used prior to what you typed into the label
field of this app.

Sorry about the name confusing about label and label. I'll try to find better
words for the next release. ;-)

You can extend the limitations of naming a fat partition, if you don't give a
"real label" with the windows explorer, or using the label command.

2Do:
Adding ability to work with non present drives.
Multilanguage support (De/En)
Maybe a feature to disable drives (like TweakUI)
)
return

/*
------------------------------------------------------------------------------------------------------------------------------
  _          _          _     _   _      _                 _   _           _       _       
 | |    __ _| |__   ___| |_  | | | | ___| |_ __           | | | |_ __   __| | __ _| |_ ___
 | |   / _` | '_ \ / _ \ (_) | |_| |/ _ \ | '_ \   _____  | | | | '_ \ / _` |/ _` | __/ _ \
 | |___ (_| | |_) |  __/ |_  |  _  |  __/ | |_) | |_____| | |_| | |_) | (_| | (_| | |_  __/
 |_____\__,_|_.__/ \___|_(_) |_| |_|\___|_| .__/           \___/| .__/ \__,_|\__,_|\__\___|
                                          |_|                   |_|                       

------------------------------------------------------------------------------------------------------------------------------
*/

Help_update:
msgbox,
(ltrim
---------------------------------------------------------------------------------
Drive-Icons Beta 0.815 UPDATE - 2010 by Deep-Silence
---------------------------------------------------------------------------------

Additionals:

* Comment-Column
This Comment is shown in Windows-Explorer for a Description

* Support for Autorun.inf and Desktop.ini. If those files are present
"Icon" and "Label" are read out of Autorun.inf & "Comment" is read  out
of Desktop.ini

* Button to restart Explorer-Shell For "Comments" to be shown in Explorer

* Button to export the Settings for all Drives. Makes it easier to import
them after a reinstallation of Windows.

* Some GUI-Adjustments

---------------------------------------------------------------------------------
Drive-Icons Beta 0.815 UPDATE - 08/2011 by Deep-Silence
---------------------------------------------------------------------------------
* Fixed - Loading right values for each Drive
* Fixed - Graphical Elements (language)

* Added - Target Drive is going to be renamed to `%Label`%, silently
* Added - Button to Restart the Script

* Improved - handling of Desktop.ini and Autorun.inf
* Improved - Icon Handling
* Improved - Code cleaned up & more organized
* Improved - Restart Explorer-Shell, silently
---------------------------------------------------------------------------------

[NOTES]
These Code-Adjustments might still contain some Bugs.


Tested under Windows XP SP3 German, only.
Best Regards,

Deep-Silence

)
Return

/*
------------------------------------------------------------------------------------------------------------------------------
  _          _          _     _____      _ _        _                _ _           _   _             
 | |    __ _| |__   ___| |_  | ____|_  ___) |_     / \   _ __  _ __ | (_) ___ __ _| |_(_) ___  _ __ 
 | |   / _` | '_ \ / _ \ (_) |  _| \ \/ / | __|   / _ \ | '_ \| '_ \| | |/ __/ _` | __| |/ _ \| '_ \
 | |___ (_| | |_) |  __/ |_  | |___ >  <| | |_   / ___ \| |_) | |_) | | | (__ (_| | |_| | (_) | | | |
 |_____\__,_|_.__/ \___|_(_) |_____/_/\_\_|\__| /_/   \_\ .__/| .__/|_|_|\___\__,_|\__|_|\___/|_| |_|
                                                        |_|   |_|                                   

------------------------------------------------------------------------------------------------------------------------------
*/

buttoncancel:
GuiClose:
exitapp

Label_Restart:
Reload
return


/*
------------------------------------------------------------------------------------------------------------------------------
  _____ _   _ _   _  ____ _____ ___ ___  _   _ ____   
 |  ___| | | | \ | |/ ___|_   _|_ _/ _ \| \ | / ___|_
 | |_  | | | |  \| | |     | |  | | | | |  \| \___ (_)
 |  _| | |_| | |\  | |___  | |  | | |_| | |\  |___) |
 |_|    \___/|_| \_|\____| |_| |___\___/|_| \_|____(_)
                                                     

------------------------------------------------------------------------------------------------------------------------------
*/

; ChooseIcon by majkinetor, w2k fix by me

ChooseIcon(ByRef sIcon, ByRef idx, hGui=0) {                               
   
    VarSetCapacity(wIcon, 1025, 0)
    if sIcon !=
      {
        r := DllCall("MultiByteToWideChar"
             , "UInt", 0             ; CodePage: CP_ACP=0 (current Ansi), CP_UTF7=65000, CP_UTF8=65001
             , "UInt", 0             ; dwFlags
             , "Str", sIcon          ; LPSTR lpMultiByteStr
             , "Int", StrLen(sIcon)  ; cbMultiByte: -1=null terminated
             , "UInt", &wIcon        ; LPCWSTR lpWideCharStr
             , "Int", 1025)          ; cchWideChar: 0 to get required size

        if !r
            return 2
      }
   
    r := DllCall(DllCall("GetProcAddress", "Uint", DllCall("LoadLibrary", "str", "shell32.dll"), "Uint", 62), "uint", hGui, "uint", &wIcon, "uint", 1025, "intp", idx)
    if !r
        return 1

   len := DllCall("lstrlenW", "UInt", &wIcon)
   VarSetCapacity(sIcon, len, 0)
   r := DllCall("WideCharToMultiByte"
         , "UInt", 0           ; CodePage: CP_ACP=0 (current Ansi), CP_UTF7=65000, CP_UTF8=65001
         , "UInt", 0           ; dwFlags
         , "UInt", &wIcon      ; LPCWSTR lpWideCharStr
         , "Int", len          ; cchWideChar: size in WCHAR values, -1=null terminated
         , "Str", sIcon        ; LPSTR lpMultiByteStr
         , "Int", len          ; cbMultiByte: 0 to get required size
         , "UInt", 0           ; LPCSTR lpDefaultChar
         , "UInt", 0)          ; LPBOOL lpUsedDefaultChar

    if !r
        return 3
           
    return 0
}


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 24 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group