OnTheFly Posted April 10, 2008 Posted April 10, 2008 Hi, i'm using an ini file to decide icons for some folders in a tray menu. But, when the foldername comtain spaces i get a problem. The icon doesn't show. and the doesn't seem to be found at all For $i = 1 To UBound($categories)-1 ;Add the category to the menu $traycategories[$categories[$i]] = _TrayCreateMenu(-1, $categories[$i]) ;Now we want an icon :D ;Change spaces to unserscores $category_nospace = StringReplace($categories[$i], " ", "_") ;Read the value from the ini file $value = IniRead("VelkyPortable/data/icons.ini", "categories", $category_nospace, "") ;Split the value $icon = StringSplit($value, ",") ;Remove spaces from the number $icon[2] = StringReplace($icon[2], " ", "") If $icon[0] > 1 Then _TrayItemSetIcon(-1, $icon[1], Int($icon[2])) ElseIf $icon[0] = 1 Then _TrayItemSetIcon(-1, $icon[1]) EndIf $apps = _FileListToArray("VelkyPortable/apps/" & $categories[$i], "*", 2) ;Put them in the tray array For $x = 1 To UBound($apps)-1 $traynr[$i][$x] = _TrayCreateItem(-1, $apps[$x], $traycategories[$categories[$i]]) $trayapp[$i][$x] = $apps[$x] _TrayItemSetIcon(-1, "VelkyPortable/apps/" & $categories[$i] & "/" & $trayapp[$i][$x] & "/" & IniRead("VelkyPortable/apps/" & $categories[$i] & "/" & $trayapp[$i][$x] & "/appinfo.ini", "appinfo", "appexe", "../../../data/setup.ico")) Next Next
someone Posted April 10, 2008 Posted April 10, 2008 Take a minute and add some error checking into this. The code is a little hard to get through without a reproducer. Can you figure out where generally the code isn't working as you expect? Why are you removing the spaces for underscores? While ProcessExists('Andrews bad day.exe') BlockInput(1) SoundPlay('Music.wav') SoundSetWaveVolume('Louder') WEnd
OnTheFly Posted April 10, 2008 Author Posted April 10, 2008 (edited) Why are you removing the spaces for underscores? Because ini keys cannot contain spaces afaik. But maybe they can? EDIT: They could. The IniRead() returns an emtpy string. It cant't read the key. The ini file: [categories] Internet = shell32.dll, 14 File Management = shell32.dll, 5 It reads the Internet key fine. But not File Management. Edited April 10, 2008 by OnTheFly
someone Posted April 10, 2008 Posted April 10, 2008 this works for me with test.ini created with the text you gave from above... $s1 = IniRead("test.ini", "categories", "Internet ", "Not found") $s2 = IniRead("test.ini", "categories", "File Management ", "Not found") MsgBox(0, "Test1", $s1) MsgBox(0, "Test2", $s2) I'm guessing you didn't add the trailing space at the end of file management. While ProcessExists('Andrews bad day.exe') BlockInput(1) SoundPlay('Music.wav') SoundSetWaveVolume('Louder') WEnd
OnTheFly Posted April 10, 2008 Author Posted April 10, 2008 this works for me with test.ini created with the text you gave from above... $s1 = IniRead("test.ini", "categories", "Internet ", "Not found") $s2 = IniRead("test.ini", "categories", "File Management ", "Not found") MsgBox(0, "Test1", $s1) MsgBox(0, "Test2", $s2) I'm guessing you didn't add the trailing space at the end of file management. Mine can only find internet. No other
someone Posted April 10, 2008 Posted April 10, 2008 If you copy paste that code, your telling me the second message box pops up with Not found in it? This is my ini - [categories] Internet = shell32.dll, 14 File Management = shell32.dll, 5 saved as test.ini in the same location as the script. My code is exactly what I posted above... just copy pasted the code again and still works. Give me a reproducer of what isn't working for you and I'll see what I can do. While ProcessExists('Andrews bad day.exe') BlockInput(1) SoundPlay('Music.wav') SoundSetWaveVolume('Louder') WEnd
OnTheFly Posted April 11, 2008 Author Posted April 11, 2008 If you copy paste that code, your telling me the second message box pops up with Not found in it? This is my ini - [categories] Internet = shell32.dll, 14 File Management = shell32.dll, 5 saved as test.ini in the same location as the script. My code is exactly what I posted above... just copy pasted the code again and still works. Give me a reproducer of what isn't working for you and I'll see what I can do. I copied your code, and the second MsgBox shows "Not Found".
someone Posted April 11, 2008 Posted April 11, 2008 Thats weird... do me a favor post your exact code and exact ini file. Also, what OS and version of autoit are you using? While ProcessExists('Andrews bad day.exe') BlockInput(1) SoundPlay('Music.wav') SoundSetWaveVolume('Louder') WEnd
OnTheFly Posted April 11, 2008 Author Posted April 11, 2008 Thats weird... do me a favor post your exact code and exact ini file. Also, what OS and version of autoit are you using? Okay AutoIt code: expandcollapse popup#NoTrayIcon ;Include the File UDF's #Include <File.au3> ;Include the GUI constants #include <GUIConstants.au3> ;Include the file for the cool menu;) #include "ModernMenu.au3" ;Include the appinfo generator #Include "appinfogen.au3" ;Include the settings manager ;#Include "settings.au3" If Not IsDeclared("GW_OWNER") Then Global Const $GW_OWNER = 4 If Not IsDeclared("GWL_EXSTYLE") Then Global Const $GWL_EXSTYLE = -20 If Not IsDeclared("WM_GETICON") Then Global Const $WM_GETICON = 0x007F If Not IsDeclared("GCL_HICONSM") Then Global Const $GCL_HICONSM = -34 If Not IsDeclared("GCL_HICON") Then Global Const $GCL_HICON = -14 If Not IsDeclared("PROCESS_QUERY_INFORMATION") Then Global Const $PROCESS_QUERY_INFORMATION = 0x0400 If Not IsDeclared("PROCESS_VM_READ") Then Global Const $PROCESS_VM_READ = 0x0010 Dim $arTrayWin[500][3]; TrayIconID, WinTitle, WinHandle $arTrayWin[0][0] = 0 $nTrayIcon1 = _TrayIconCreate("Win2Tray", "shell32.dll", 230) ;Make an array containing mouse click values Dim $clicklist[13] $clicklist[0] = 8 $clicklist[1] = 16 $clicklist[2] = 24 $clicklist[3] = 1 $clicklist[4] = 2 $clicklist[5] = 3 $clicklist[6] = 9 $clicklist[7] = 18 $clicklist[8] = 4 $clicklist[9] = 32 $clicklist[10] = 36 $clicklist[11] = 27 $clicklist[12] = 64 ;Check if it has a valid value $click = Int(IniRead("VelkyPortable/data/settings.ini", "controls", "click", 0)) If $click > 11 Or $click < 0 Or $click = 0 Then MsgBox(48, "Warning!", "The key 'click' in settings.ini does not have a valid value. Using default 'ALL'") $click = $clicklist[12] Else $click = $clicklist[$click] EndIf _TrayIconSetClick(-1, $click) _TrayIconSetState(); Show the tray icon _TrayIconSetToolTip($nTrayIcon1, _GetTitle()) ;Add a "title" $title = _TrayCreateItem(-1, _GetTitle()) _TrayItemSetIcon(-1, "shell32.dll", 230) _TrayCreateItem(-1, "") ;$settingsmenu = _TrayCreateItem(-1, "Settings") ;_TrayItemSetIcon(-1, "shell32.dll", 274) $apppinfogen = _TrayCreateItem(-1, "appinfo.ini generator") _TrayItemSetIcon(-1, "shell32.dll", 151) $browsedrive = _TrayCreateItem(-1, "Browse the Drive") _TrayItemSetIcon(-1, "shell32.dll", 5) _TrayCreateItem(-1, "") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Dim an array for the categories in the traymenu Dim $traycategories[64] ;Dim an array for tray apps Dim $traycat[256] Dim $trayapp[256][256] Dim $traynr[256][256] ;Read all categories into an array $categories = _FileListToArray("VelkyPortable/apps/", "*", 2) ;Read the apps For $i = 1 To UBound($categories)-1 ;Add the category to the menu $traycategories[$categories[$i]] = _TrayCreateMenu(-1, $categories[$i]) ;Now we want an icon :D ;Read the value from the ini file $value = IniRead("VelkyPortable/data/icons.ini", "categories", $categories[$i], "") ;Split the value $icon = StringSplit($value, ",") If $icon[0] > 1 Then ;Remove spaces from the number $icon[2] = StringReplace($icon[2], " ", "") _TrayItemSetIcon(-1, $icon[1], Int($icon[2])) ElseIf $icon[0] = 1 Then _TrayItemSetIcon(-1, $icon[1]) EndIf $apps = _FileListToArray("VelkyPortable/apps/" & $categories[$i], "*", 2) ;Put them in the tray array For $x = 1 To UBound($apps)-1 $traynr[$i][$x] = _TrayCreateItem(-1, $apps[$x], $traycategories[$categories[$i]]) $trayapp[$i][$x] = $apps[$x] _TrayItemSetIcon(-1, "VelkyPortable/apps/" & $categories[$i] & "/" & $trayapp[$i][$x] & "/" & IniRead("VelkyPortable/apps/" & $categories[$i] & "/" & $trayapp[$i][$x] & "/appinfo.ini", "appinfo", "appexe", "../../../data/setup.ico")) Next Next ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; _TrayCreateItem(-1, "") $TrayExit = _TrayCreateItem(-1, "Exit") _TrayItemSetIcon(-1, "shell32.dll", -28) ;Show a baloon tip that VelkyPortable is started If IniRead("VelkyPortable/data/settings.ini", "tray", "startbaloon", "true") = "true" Then _TrayTip($nTrayIcon1, _GetTitle(), "VelkyPortable has started and are ready to launch your portable apps!", 3, 1) EndIf While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE, $TrayExit ExitLoop Case $title MsgBox(64, "About VelkyPortable", "VelkyPortable is a portable apps system. It contains a nice and simple tray menu interface to control your apps. You can simply add any portable app of your choise. Just create a new folder and put the files there. You can use the appinfo.ini generator to create the infofile." & @CRLF & @CRLF & "VelkyPortable is developed by Emanuel Claesson (a.k.a VelcroMan) in AutoIt3." & @CRLF & @CRLF & "You are currently using VelkyPortable " & IniRead("VelkyPortable/data/data.ini", "versioninfo", "version", "") & " on your " & _GetDriveSize() & " drive." & " (" & StringLeft(@ScriptDir, 3) & ")" & @CRLF & @CRLF & "Web: http://www.emanuel-claesson.se" & @CRLF & "Mail: emanuel.claesson@gmail.com") Case $apppinfogen appinfogen() Case $browsedrive Run("explorer " & _GetDriveLetter()) EndSwitch ;;;;;;;;;;;;;;; For $i = 1 To UBound($categories)-1 For $x = 1 To Ubound($traynr)-1 If $traynr[$i][$x] = "" Then ExitLoop If $msg = $traynr[$i][$x] Then Run("VelkyPortable/apps/" & $categories[$i] & "/" & $trayapp[$i][$x] & "/" & IniRead("VelkyPortable/apps/" & $categories[$i] & "/" & $trayapp[$i][$x] & "/appinfo.ini", "appinfo", "appexe", "__NotFound__")) EndIf Next Next ;;;;;;;;;;;;;;;; WEnd _TrayIconDelete($nTrayIcon1) Func _GetDriveSize() $mb = Round(DriveSpaceTotal(StringLeft(@ScriptDir, 3)), 0) If $mb > 1024 Then return String(Round($mb/1024, 0) & "GB") Else return String($mb & "MB") EndIf EndFunc Func _GetDriveLetter() Return StringLeft(@ScriptDir, 3) EndFunc Func _GetTitle() $titlestr = IniRead("VelkyPortable/data/settings.ini", "general", "title", "VelkyPortable %version%") $titlestr = StringReplace($titlestr, "%version%", IniRead("VelkyPortable/data/data.ini", "versioninfo", "version", "")) $titlestr = StringReplace($titlestr, "%driveletter%", _GetDriveLetter()) Return $titlestr EndFunc And the ini file: #VelkyPortable icon list #Category name = icon.ico (Full path from VelkyPortable.exe) # or #Category name = dll, iconnumber # or #Category name = exe # # #If usedefault is set to true, a folder icon will be used if no icon is declared in this ini file. If false, no icon will be used. #usedefault = true # [categories] Internet = shell32.dll, 14 File Management = shell32.dll, 5
zorphnog Posted April 11, 2008 Posted April 11, 2008 What directories are in the VelkyPortable/apps/ directory? Have you verified that the categories array contains the proper values?
OnTheFly Posted April 11, 2008 Author Posted April 11, 2008 What directories are in the VelkyPortable/apps/ directory? Have you verified that the categories array contains the proper values?In VelkyPortable/apps/ i have "Internet", "File Management". It creates the tray menu fine, so the array is fine.
someone Posted April 11, 2008 Posted April 11, 2008 As zorphnog said, we need to know what the filelisttoarray produces... but is it just my ignorance to say that all your slashes are going the wrong way? They should be \ not / unless I have missed something. The problem I'm having is that what you have said above isn't working, isn't what you have in your code... I can't run your script, I need you to break down a reproducable section of code that isn't working, or at least break it down some. Even in your original post there are so many variables that we don't know the values of. This is what I've been working on to try to reproduce your error Dim $value Dim $categories[2] = ["Internet", "File Management"] ;$categories = _FileListToArray("VelkyPortable/apps/", "*", 2) For $i = 0 To 1 $value = IniRead("VelkyPortable\data\settings.ini", "categories", $categories[$i], "not found") MsgBox(0, "", $value) Next Because I'm guessing your troubles are somewhere in the for loop, but I could be wrong. PS do you really want to dim TWO arrays THAT big? I can't test it but I would imagine that can't be too fast. While ProcessExists('Andrews bad day.exe') BlockInput(1) SoundPlay('Music.wav') SoundSetWaveVolume('Louder') WEnd
OnTheFly Posted April 11, 2008 Author Posted April 11, 2008 _FileListToArray() returns an array containing all folders in the dir. $categories[0] contains the ammount of folders.
OnTheFly Posted April 11, 2008 Author Posted April 11, 2008 (edited) Heh, i solved it. And i have no idea how I changed a line to $value = IniRead("VelkyPortable/data/icons.ini", "categories", $categories[$i], "Not Found"), and fixed the if after. Edited April 12, 2008 by OnTheFly
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now