Sign in to follow this  
Followers 0
Rex

Item Launcher (Launch Resources from USB/CD/DVD)

1 post in this topic

It's a simple Utility to add and launch Programs ect. from a media.

I made it with USB in mind, but as i scripted i ended up with a prog that can be used for both usb, cd and dvd...

The main window Contains a ListBox in where the items is been added, double clicking on an item launches the item with system default program for that file type. (Using ShellExecute)

In the menu one can Add/Edit or Remove an Item to/from the ListBox.

When Adding an item one can add a description about the Item, witch will be showed under the ListBox when the item is selected.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=..\..\Ikoner\Flotte Ikoner\Icon 110.ico
#AutoIt3Wrapper_Outfile=Launcher.exe
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0
#AutoIt3Wrapper_Add_Constants=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <GuiMenu.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <Array.au3>
#include <file.au3>
#include <String.au3>
#include <ListBoxConstants.au3>


Opt("GUIOnEventMode", 1)

$IniFile = @ScriptDir & "\Launcher.ini"

Global $sItemEditLaunchNameHex = "", $bAddItem = False, $bEditItem = False, $bAuto = False, $bReadOnly = False, $bFirstRun = True, $bAutoGUI = False, $bExeFile = False

; Checking if the launcher is runned from a read-only media
$sType = DriveGetType(@ScriptDir & "\") ; Find the status of dir the script is runned from

; Main GUI start --->
#Region ### START Koda GUI section ### Form=F:\AutoIT3 Scripts\GUI Forms\hUtility_Launcher(USB).kxf
$sGUITitle = "Utility Launcer"
$hUtility_Launcher = GUICreate($sGUITitle, 363, 369, -1, -1, -1, BitOR($WS_EX_TOPMOST, $WS_EX_ACCEPTFILES, $WS_EX_APPWINDOW, $WS_EX_TOOLWINDOW, $WS_EX_WINDOWEDGE))
$idMenuItems = GUICtrlCreateMenu("Items")
$idMenuItemAdd = GUICtrlCreateMenuItem("Add items", $idMenuItems)
GUICtrlSetOnEvent($idMenuItemAdd, "hMenuItemAddClick")
$idMenuItemRemove = GUICtrlCreateMenuItem("Remove items", $idMenuItems)
GUICtrlSetOnEvent($idMenuItemRemove, "hMenuItemRemoveClick")
$idMenuItemEdit = GUICtrlCreateMenuItem("Edit Item", $idMenuItems)
GUICtrlSetOnEvent($idMenuItemEdit, "hMenuItemEditClick")
$MenuItemConfig = GUICtrlCreateMenu("Config")
;$MenuItemConfigLan = GUICtrlCreateMenuItem("Language", $MenuItemConfig)
;GUICtrlSetOnEvent($MenuItemConfigLan, "MenuItemConfigLanClick")
$MenuItemConfigAutoRun = GUICtrlCreateMenuItem("Autorun", $MenuItemConfig)
GUICtrlSetOnEvent($MenuItemConfigAutoRun, "MenuItemConfigAutoRunClick")
$MenuItemConfigReadOnly = GUICtrlCreateMenuItem("Read only", $MenuItemConfig)
GUICtrlSetTip($MenuItemConfigReadOnly, "This will make the Launcher.ini file Read-Only")
GUICtrlSetOnEvent($MenuItemConfigReadOnly, "MenuItemConfigReadOnlyClick")
GUISetOnEvent($GUI_EVENT_CLOSE, "hUtility_LauncherClose")
$idLabelHeadLine = GUICtrlCreateLabel("Please choose utility to launch", 8, 16, 345, 28, $SS_CENTER)
GUICtrlSetFont($idLabelHeadLine, 14, 400, 0, "MS Sans Serif")
GUICtrlSetColor($idLabelHeadLine, 0x0000FF)
$idListApps = GUICtrlCreateList("", 8, 48, 345, 201)
GUICtrlSetTip($idListApps, "Double click to launch the selected App")
$idLabelInfo = GUICtrlCreateLabel("Description / Info", 8, 256, 86, 17)
$idEditItemDescription = GUICtrlCreateEdit("", 8, 272, 345, 65, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN, $WS_VSCROLL, $ES_READONLY))
GUISetState(@SW_HIDE)

#EndRegion ### END Koda GUI section ###
; <--- Main gui End

; Add Item GUI Start --->
#Region ### START Koda GUI section ### Form=f:\autoit3 scripts\gui forms\usb launcher\hadd.kxf
$hAddItem = GUICreate("Add item", 363, 209, -1, -1, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_APPWINDOW, $WS_EX_TOOLWINDOW, $WS_EX_WINDOWEDGE))
GUISetOnEvent($GUI_EVENT_CLOSE, "hAddItemClose")
$idLabelItem = GUICtrlCreateLabel("Item", 8, 8, 24, 16)
$idInputAddItemPath = GUICtrlCreateInput("", 8, 24, 233, 21)
GUICtrlSetState($idInputAddItemPath, $GUI_DROPACCEPTED)
GUICtrlSetTip($idInputAddItemPath, "You can drag an item to add it.")
$idLabelBrowse = GUICtrlCreateLabel("Browse", 248, 8, 39, 16)
$idAddRadioFile = GUICtrlCreateRadio("File", 248, 24, 35, 21)

GUICtrlSetState($idAddRadioFile, $GUI_UNCHECKED)
GUICtrlSetOnEvent($idAddRadioFile, "idRadioFileClick")
$idAddRadioFolder = GUICtrlCreateRadio("Folder", 288, 24, 49, 21)
GUICtrlSetState($idAddRadioFolder, $GUI_UNCHECKED)
GUICtrlSetOnEvent($idAddRadioFolder, "idRadioFolderClick")
$idLabelItemName = GUICtrlCreateLabel("Item Name to show in launch box", 8, 48, 161, 16)
$idInputAddItemLaunchName = GUICtrlCreateInput("", 8, 64, 345, 21)
GUICtrlSetTip($idInputAddItemLaunchName, "Item name to show in launchbox, if left blank item name will be used")
$idLabelAddItemDescription = GUICtrlCreateLabel("Item Description", 8, 88, 80, 16)
$idEditAddItemDescription = GUICtrlCreateEdit("", 8, 104, 345, 65, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN, $WS_VSCROLL))
$idButtonAdd = GUICtrlCreateButton("Add", 8, 176, 75, 25)
GUICtrlSetOnEvent($idButtonAdd, "idButtonAddClick")
$idButtonAddCancel = GUICtrlCreateButton("Cancel", 280, 176, 75, 25)
GUICtrlSetOnEvent($idButtonAddCancel, "idButtonAddCancelClick")
GUISetOnEvent($GUI_EVENT_DROPPED, "_Droppede")
GUISetState(@SW_HIDE)
#EndRegion ### END Koda GUI section ###

; <--- Add Item GUI End

; Edit Item GUI start --->
#Region ### START Koda GUI section ### Form=F:\AutoIT3 Scripts\GUI Forms\USB Launcher\hedit.kxf
$hEditItem = GUICreate("Edit item", 363, 209, -1, -1, -1, BitOR($WS_EX_APPWINDOW, $WS_EX_TOOLWINDOW, $WS_EX_WINDOWEDGE))
GUISetOnEvent($GUI_EVENT_CLOSE, "hEditItemClose")
$idLabelEditItem = GUICtrlCreateLabel("Item", 8, 8, 24, 16)
$idInputEditItemPath = GUICtrlCreateInput("", 8, 24, 233, 21)
GUICtrlSetState($idInputEditItemPath, $GUI_DROPACCEPTED)
GUICtrlSetTip($idInputEditItemPath, "You can drag an tiem to add it.")
$idLabelBrowse = GUICtrlCreateLabel("Browse", 248, 8, 39, 16)
$idEditRadioFile = GUICtrlCreateRadio("File", 248, 24, 35, 21)
GUICtrlSetOnEvent($idEditRadioFile, "idRadioFileClick")
$idEditRadioFolder = GUICtrlCreateRadio("Folder", 288, 24, 49, 21)
GUICtrlSetOnEvent($idEditRadioFolder, "idRadioFolderClick")
$idLabelEditItemName = GUICtrlCreateLabel("Item Name to show in launch box", 8, 48, 161, 16)
$idInputEditItemLaunchName = GUICtrlCreateInput("", 8, 64, 345, 21)
GUICtrlSetTip($idInputEditItemLaunchName, "Item name to show in launchbox, if left blank item name will be used")
$idLabelItemDescription = GUICtrlCreateLabel("Item Description", 8, 88, 80, 16)
$idEditEditItemDescription = GUICtrlCreateEdit("", 8, 104, 345, 65, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN, $WS_VSCROLL))
$idButtonEditSave = GUICtrlCreateButton("Save", 8, 176, 75, 25)
GUICtrlSetOnEvent($idButtonEditSave, "idButtonEditSaveClick")
$idButtonEditCancel = GUICtrlCreateButton("Cancel", 280, 176, 75, 25)
GUICtrlSetOnEvent($idButtonEditCancel, "idButtonEditCancelClick")
GUISetOnEvent($GUI_EVENT_DROPPED, "_Droppede")
GUISetState(@SW_HIDE)
#EndRegion ### END Koda GUI section ###
; <--- Edit Item GUI End

#Region ### START Koda GUI section ### Form=F:\AutoIT3 Scripts\GUI Forms\USB Launcher\hAutoRun.kxf
$hAutoRun = GUICreate("Autorun generator", 363, 209, -1, -1, -1, BitOR($WS_EX_APPWINDOW,$WS_EX_TOOLWINDOW,$WS_EX_WINDOWEDGE))
GUISetOnEvent($GUI_EVENT_CLOSE, "hAutoRunClose")
$idLabelExeFile = GUICtrlCreateLabel("Name of the executible file to be launched", 8, 8, 203, 17)
$idInputExeFile = GUICtrlCreateInput("", 8, 24, 297, 21)
$idLabelBrowseExeFile = GUICtrlCreateLabel("Browse", 312, 8, 39, 17)
$idRadioExeFile = GUICtrlCreateRadio("File", 312, 24, 35, 21, $BS_PUSHLIKE)
GUICtrlSetOnEvent($idRadioExeFile, "idRadioExeFileClick")
$idLabelIcon = GUICtrlCreateLabel("Icon Path", 8, 48, 50, 17)
$idInputIcon = GUICtrlCreateInput("", 8, 64, 297, 21)
GUICtrlSetTip($idInputIcon, "Icon to be showed in Explorer ect.")
$idRadioIcon = GUICtrlCreateRadio("File", 312, 64, 35, 21, $BS_PUSHLIKE)
GUICtrlSetOnEvent($idRadioIcon, "idRadioIconclick")
$idLabelBrowseIcon = GUICtrlCreateLabel("Browse", 312, 48, 39, 17)
$idLabelAction = GUICtrlCreateLabel("Action", 8, 88, 34, 17)
$idInputAction = GUICtrlCreateInput("", 8, 104, 345, 21)
$idLabelLabel = GUICtrlCreateLabel("Label", 8, 128, 36, 16)
$idInputLabel = GUICtrlCreateInput("", 8, 144, 345, 21)
$idButtonGenerate = GUICtrlCreateButton("Generate", 8, 176, 75, 25, $BS_DEFPUSHBUTTON)
GUICtrlSetOnEvent($idButtonGenerate, "idButtonGenerateClick")
$idButtonAutoCancle = GUICtrlCreateButton("Cancel", 280, 176, 75, 25)
GUICtrlSetOnEvent($idButtonAutoCancle, "idButtonAutoCancleClick")
GUISetState(@SW_HIDE)
#EndRegion ### END Koda GUI section ###


;Getting info when the user clicks an item in the ListBox
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
_Startup()
While 1
Sleep(100)
WEnd

Func _Startup()

; Checking if inifile is read-only
$sFile = FileGetAttrib($IniFile)
; Checking if Launcher is set in Read-Only mode by User
$iReadOnly = IniRead($IniFile, "Config", "Menu", "1")

; Using info from Read-Only checks at the script start
; If either the launcher is runned from a CDROM drive, if the inifile is made Read-only or Menu is Set to "0" in Ini file, we disable the menu
If $sType = "CDROM" Or StringInStr($sFile, "R") Or $iReadOnly = "0" Then
; Disabling Menu
GUICtrlSetState($idMenuItems, $GUI_DISABLE)
GUICtrlSetState($MenuItemConfig, $GUI_DISABLE)
; Setting Menu item test to Blank, Makes the menu look not ther...
GUICtrlSetData($idMenuItems, "")
GUICtrlSetData($MenuItemConfig, "")
EndIf
; If it the first time the Launcher launches we do a Splashimage thing
If $bFirstRun = True Then _Splash()
; Showind main menu
GUISetState(@SW_SHOW, $hUtility_Launcher)

; ListBox and Edit handling ===>

; Clearing existing entrys in listBox before updating (if any should exist)
_GUICtrlListBox_ResetContent($idListApps)

; Clearing description if any
GUICtrlSetData($idEditItemDescription, "")

; Reads inifile and updates ListBox
$asItems = IniReadSectionNames($IniFile) ; Reading all sections from the Launcher.ini
$sConfig = _ArraySearch($asItems, "Config") ; Searching for the Section [Config]
; Deliting the first entry in Array.
_ArrayDelete($asItems, 0); This is the entry who tells how many Items the array contains, if we keep it til will be loaded into the listbox as "0x5"
; Using the result of array search
If $sConfig <> -1 Then _ArrayDelete($asItems, $sConfig) ; If the [Config] section exsist, we delete it - if we keep it it will be loaded into the listbox

;Sorting array
_ArraySort($asItems) ; Sorting list array

; Adding Items to ListBox
; Using Ubound to get total items of Array, and running loop to add Items to listbox.
For $i = 0 To UBound($asItems) -1 ; Running loop until $i = the result of Ubound -1
; Dehexing and Adds Read Item Names to ListBox
_GUICtrlListBox_AddString($idListApps, _HexToString($asItems[$i])) ; Data writen to the ini file is writen in hex, so when loading the "list" we needs to dehex the entrys
Next
EndFunc

; Splash image
Func _Splash()

If $sType = "CDROM" Then
; Choosing SplashImage
; Fetching pic from Resurses
Local $destination = "CD-Rom.jpg"
SplashImageOn("", $destination, 300, 325, -1 ,-1 , 1)
Sleep(3000)
SplashOff()
Else
Local $destination = "USB.jpg"
SplashImageOn("", $destination, 200, 450, -1 ,-1 , 1)
Sleep(3000)
SplashOff()
EndIf
$bFirstRun = False ; Setting Firstlaunch to False
EndFunc


#region Main Functions
; Menu item add
Func hMenuItemAddClick()
; Getting pos of Launcher window
Local $size = WinGetPos($hUtility_Launcher)
; Moving Add Items windows to the pos of Launcer window
WinMove($hAddItem, "", $size[0], $size[1])
; Shows Add Item GUI
GUISetState(@SW_SHOW, $hAddItem)
$bAddItem = True
; Hides Launcher GUI
GUISetState(@SW_HIDE, $hUtility_Launcher)
EndFunc ;==>hMenuItemAddClick

; Editing previous added item
Func hMenuItemEditClick()

; Getting name of the selected item
$iIndex = _GUICtrlListBox_GetCurSel($idListApps) ; Getting Index of Item selected with the mouse
$sName = _GUICtrlListBox_GetText($idListApps, $iIndex) ; Getting txt for item selected with use of the result in $iIndex

If $sName <> "" Then ; Check for empyt string

$sItemEditLaunchNameHex = _StringToHex($sName) ; Hexing result of $sName, so we can search for it in the ini file
$sItems2Edit = IniReadSection($IniFile, $sItemEditLaunchNameHex) ; Reading section in ini file using the hexed name
If Not @error Then
Local $size = WinGetPos($hUtility_Launcher)
; Moving Add Items windows to the pos of Launcer window
GUICtrlSetData($idInputEditItemPath, _HexToString($sItems2Edit[1][1]))
GUICtrlSetData($idInputEditItemLaunchName, _HexToString($sItems2Edit[2][1]))
GUICtrlSetData($idEditEditItemDescription, _HexToString($sItems2Edit[3][1]))
WinMove($hEditItem, "", $size[0], $size[1])
WinActivate($hEditItem, "")
GUISetState(@SW_HIDE, $hUtility_Launcher)
GUISetState(@SW_SHOW,$hEditItem)
$bEditItem = True
GUISetState($GUI_FOCUS,$hEditItem)
else
Return
EndIf
EndIf
EndFunc ;==>hMenuItemEditClick

Func hMenuItemRemoveClick()

; Getting name of selected item
$iIndex = _GUICtrlListBox_GetCurSel($idListApps) ; Getting Index of selectet item
$sName = _GUICtrlListBox_GetText($idListApps, $iIndex) ; getting the name of the selected item, by using the result of $iIndex
; Removes the selectet item from ListBox and inifile
_GUICtrlListBox_DeleteString($idListApps, $iIndex) ; Removing the slelected item from ListBox
IniDelete($IniFile, _StringToHex($sName)) ; Removing item from ini file.
_Startup() ; refreshes Listbox by calling the Startup function
EndFunc ;==>hMenuItemRemoveClick

Func hUtility_LauncherClose()
Exit ; Closes program
EndFunc ;==>hUtility_LauncherClose

Func MenuItemConfigAutoRunClick()
; Getting Pos of Launcher window
Local $size = WinGetPos($hUtility_Launcher)
; Moving Add Items windows to the pos of Launcer window
WinMove($hAutoRun, "", $size[0], $size[1])
WinActivate($hAutoRun, "")
GUISetState(@SW_HIDE, $hUtility_Launcher)
GUISetState(@SW_SHOW,$hAutoRun)
GUISetState($GUI_FOCUS,$hAutoRun)
$bAutoGUI = True

EndFunc ;==>MenuItemConfigAutoRunClick

Func MenuItemConfigLanClick()

EndFunc ;==>MenuItemConfigLanClick

Func MenuItemConfigReadOnlyClick()
; Set Launcher.ini to Read-Only
#Region --- CodeWizard generated code Start ---
;MsgBox features: Title=Yes, Text=Yes, Buttons=Yes and No, Icon=Info, Miscellaneous=Top-most attribute
If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(262212,"Read-Only","This will set the Launcher.ini to Read-Only state!" & @CRLF & @CRLF & "When in Read-Only state the menus is dissabled," & @CRLF & "preventing the option to Add, Remove or Edit" & @CRLF & "Items in the Launch list." & @CRLF & @CRLF & "To enable the Menu Items, an the options to" & @CRLF & "Add, Remove And Edit Items in the Launcher List," & @CRLF & 'remove the "R" attrib from the Launcher.ini' & @CRLF & 'and change the value "Menu" in [Config] from 0 to 1' & @CRLF & "in the Launcher.ini file." & @CRLF & @CRLF & 'To enable Read-Only press "Yes", the efect will be immediately!')
Select
Case $iMsgBoxAnswer = 6 ;Yes
IniWrite($IniFile, "Config", "Menu", "0")
FileSetAttrib($IniFile, "R")
$bReadOnly = True
_Startup()
Case $iMsgBoxAnswer = 7 ;No
Return

EndSelect
#EndRegion --- CodeWizard generated code End ---

EndFunc ;==>MenuItemConfigReadOnlyClick

#endregion Main Functions


#region AddItem Functions
Func hAddItemClose()

GUICtrlSetData($idInputAddItemPath, "") ; Clearing the Item Input
GUICtrlSetData($idInputAddItemLaunchName, "") ; Clearing the Item Name Input (Name showed in the ListBox view)
GUICtrlSetData($idEditAddItemDescription, "") ; Clearing the Edit (Item Description)

GUICtrlSetState($idAddRadioFile, $GUI_UNCHECKED)
GUICtrlSetState($idAddRadioFolder, $GUI_UNCHECKED)
GUISetState(@SW_SHOW, $hUtility_Launcher)
$bAddItem = False
GUISetState(@SW_HIDE, $hAddItem) ; Hides the gui
EndFunc ;==>hAddItemClose

Func idButtonAddCancelClick()
hAddItemClose()
EndFunc ;==>idButtonAddCancelClick

Func idButtonAddClick()
; Getting info from Inputboxes
$sAddItemPath = GUICtrlRead($idInputAddItemPath)
If $sAddItemPath = "" Then
#Region --- CodeWizard generated code Start ---
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Critical, Miscellaneous=Top-most attribute
MsgBox(262160,"Item path","No item path was choosen!!" & @CRLF & "Please choose a Item or hit cancle" & @CRLF & "to get back to the Launcher window...")
#EndRegion --- CodeWizard generated code End ---
GUICtrlSetState($idInputAddItemPath, $GUI_FOCUS)
Return
EndIf
$sAddItemLaunchName = GUICtrlRead($idInputAddItemLaunchName)
If $sAddItemLaunchName = "" Then
#Region --- CodeWizard generated code Start ---
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Critical, Miscellaneous=Top-most attribute
MsgBox(262160,"Launch Name","No Launch name was choose!!" & @CRLF & "Please Write a name for the item, or hit" & @CRLF & "Cancel to get back to the Launcher window...")
#EndRegion --- CodeWizard generated code End ---
GUICtrlSetState($idInputAddItemLaunchName, $GUI_FOCUS)
Return
EndIf
$sAddItemDescription = GUICtrlRead($idEditAddItemDescription)
_AddItem($sAddItemPath, $sAddItemLaunchName, $sAddItemDescription)
EndFunc ;==>idButtonAddClick

#endregion AddItem Functions
; Radio clicks handling
; Radios is pressent in both add and edit gui.
Func idRadioFileClick()

; Browse for file to add
$sFilePath = FileOpenDialog("Choose File to add to launcer", @ScriptDir, "All files (*.*)", 1 + 2)
If $sFilePath = "" Then Return
If $bAddItem = True Then
GUICtrlSetState($idAddRadioFile, $GUI_UNCHECKED)
GUICtrlSetState($idInputAddItemLaunchName, $GUI_FOCUS)
Else
GUICtrlSetState($idEditRadioFile, $GUI_UNCHECKED)
GUICtrlSetState($idInputEditItemLaunchName, $GUI_FOCUS)
EndIf
_ItemPaths($sFilePath)

EndFunc ;==>idRadioFileClick

Func idRadioFolderClick()
; Browse for folder to add
$sFolderPath = FileSelectFolder("Choose a folder.", @ScriptDir)
; Caling the ItemPath function to get the realative path of the selected folder
If $bAddItem = True Then
GUICtrlSetState($idAddRadioFolder, $GUI_UNCHECKED)
GUICtrlSetState($idInputAddItemLaunchName, $GUI_FOCUS)
Else
GUICtrlSetState($idEditRadioFolder, $GUI_UNCHECKED)
GUICtrlSetState($idInputEditItemLaunchName, $GUI_FOCUS)
EndIf

_ItemPaths($sFolderPath)
EndFunc ;==>idRadioFolderClick

Func _ItemPaths($sPath)

Dim $szDrive, $szDir, $szFName, $szExt
$sRet = _PathSplit($sPath, $szDrive, $szDir, $szFName, $szExt); Retives only the file name (we do not need the path, course files must be inside the scriptDir)

; Checking Item path, if outside @ScriptDir we warn and clear searsh result
; getting the len of the @ScriptDir
$iScriptPath = StringLen(@ScriptDir)
; Geting the len of the selected item path
$iFileFullPath = StringLen($sPath)
$iFilePath = StringLen($sRet[1] & $sRet[2])
; getting the left most char form the item path, using the result of the len for @scriptDir
; We need this to check if the Item was selected inside the ROOT dir or a sub dir of the ROOT dir of the Launcher
$sStringTrim = StringLeft($sPath, $iScriptPath)
; Math thing :)
; The file path we adds to the input should be relative to the launcher path so we take the len og the fullpath and substracts the len of the scriptpath
$iFilePathAddTotal = $iFileFullPath - $iScriptPath
; The result of $iFilePathAddTotal we use to return the realitive path of the Item by doing a stringright, we substract -1 more the the result becourse @ScriptDir don't return a trailing \
$sFilePathAdd = StringRight($sPath, $iFilePathAddTotal - 1) ;

If $sStringTrim <> @ScriptDir Then
#Region --- CodeWizard generated code Start ---
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Critical
MsgBox(16, "Item not in Root dir", "The selected item needs to be in the same" & @CRLF & "root dir (" & @ScriptDir & ") of the launcer file or a subfolder of the" & @CRLF & "launcher root dir (" & @ScriptDir & "\My Folder),")
If $bAddItem = True Then
GUICtrlSetData($idInputAddItemPath, "")
GUICtrlSetState($idInputAddItemPath, $GUI_FOCUS)
Return
ElseIf $bEditItem = True Then
GUICtrlSetData($idInputEditItemPath, "")
GUICtrlSetState($idInputEditItemPath, $GUI_FOCUS)
Return
ElseIf $bExeFile = True Then
GUICtrlSetData($idInputExeFile, "")
GUICtrlSetState($idInputExeFile, $GUI_FOCUS)
Else
GUICtrlSetData($idInputIcon, "")
GUICtrlSetState($idInputIcon, $GUI_FOCUS)
EndIf
Else
If $bAddItem = True Then
GUICtrlSetData($idInputAddItemPath, $sFilePathAdd)
GUICtrlSetState($idInputAddItemLaunchName, $GUI_FOCUS)
ElseIf $bEditItem = True Then
GUICtrlSetData($idInputEditItemPath, $sFilePathAdd)
GUICtrlSetState($idInputEditItemLaunchName, $GUI_FOCUS)
ElseIf $bExeFile = True Then
GUICtrlSetData($idInputExeFile, $sFilePathAdd)
GUICtrlSetState($idInputIcon, $GUI_FOCUS)
Else
GUICtrlSetData($idInputIcon, $sFilePathAdd)
GUICtrlSetState($idInputAction, $GUI_FOCUS)
EndIf
EndIf
#EndRegion --- CodeWizard generated code Start ---
EndFunc

Func _Droppede()
$sPath = @GUI_DragFile
MsgBox(0, "Draged file ", "File draged = " & $sPath)
_ItemPaths($sPath)
EndFunc


#region Edit Item Functions
Func hEditItemClose()
GUISetState(@SW_HIDE, $hEditItem) ; Hides the gui
GUICtrlSetData($idInputEditItemPath, "") ; Clearing the Item Input
GUICtrlSetData($idInputEditItemLaunchName, "") ; Clearing the Item Name Input (Name showed in the ListBox view)
GUICtrlSetData($idEditItemDescription, "") ; Clearing the Edit (Item Description)
GUISetState(@SW_SHOW, $hUtility_Launcher)

EndFunc ;==>hEditItemClose

Func idButtonEditCancelClick()
hEditItemClose()
EndFunc ;==>idButtonEditCancelClick

Func idButtonEditSaveClick()
; Old entry
;$sItemEditLaunchNameHex

; Getting data from Inputs
$sEditInputPath = GUICtrlRead($idInputEditItemPath)
$sEditInputName = GUICtrlRead($idInputEditItemLaunchName)
$sEditInputDesc = GUICtrlRead($idEditEditItemDescription)

If _StringToHex($sEditInputName) <> $sItemEditLaunchNameHex Then
; If string is updated we delete the old one
IniDelete($IniFile, $sItemEditLaunchNameHex)
EndIf
; Writing Edited Item info to inifile
IniWrite($IniFile, _StringToHex($sEditInputName), "1", _StringToHex($sEditInputPath))
IniWrite($IniFile, _StringToHex($sEditInputName), "2", _StringToHex($sEditInputName))
IniWrite($IniFile, _StringToHex($sEditInputName), "3", _StringToHex($sEditInputDesc))
_Startup()
hEditItemClose()

EndFunc ;==>idButtonEditSaveClick
#endregion Edit Item Functions

#region Autorun Functions

Func hAutoRunClose()
GUISetState(@SW_HIDE, $hAutoRun)
GUISetState(@SW_SHOW, $hUtility_Launcher)
GUICtrlSetData($idInputExeFile, "")
GUICtrlSetData($idInputIcon, "")
GUICtrlSetData($idInputAction, "")
GUICtrlSetData($idInputLabel, "")
$bAutoGUI = False
EndFunc

Func idButtonAutoCancleClick()
hAutoRunClose()
EndFunc
Func idButtonGenerateClick()

; Reading inputs
$sExe = GUICtrlRead($idInputExeFile)
$sIcon = GUICtrlRead($idInputIcon)
$sAction = GUICtrlRead($idInputAction)
$sLabel = GUICtrlRead($idInputLabel)
If $sExe <> "" Then
IniWrite(@ScriptDir & "\Autorun.inf", "Autorun", "Open", $sExe)
Else
#Region --- CodeWizard generated code Start ---
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Critical, Miscellaneous=Top-most attribute
MsgBox(262160,"Autorun","No file to run selected!!" & @CRLF & "Please select a file, or use cancel" & @CRLF & "to get back to Launcher window!")
#EndRegion --- CodeWizard generated code End ---
Return
EndIf
IniWrite(@ScriptDir & "\Autorun.inf", "Autorun", "Icon", $sIcon)
IniWrite(@ScriptDir & "\Autorun.inf", "Autorun", "Action", $sAction)
IniWrite(@ScriptDir & "\Autorun.inf", "Autorun", "Lable", $sLabel)
#Region --- CodeWizard generated code Start ---
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Info, Miscellaneous=Top-most attribute
MsgBox(262208,"Autorun","Autorun.inf created with following info:" & @CRLF & @CRLF & "[Autorun]" & @CRLF & "Open = "& $sExe & @CRLF & "Icon = " & $sIcon & @CRLF & "Action = " &$sAction & @CRLF & "Label = " & $sLabel)
#EndRegion --- CodeWizard generated code End ---

hAutoRunClose()

EndFunc
Func idRadioExeFileClick()
$sFilePath = FileOpenDialog("Choose File to add to launcer", @ScriptDir, "Exe files (*.Exe)", 1 + 2)
If $sFilePath = "" Then Return
$bExeFile = True
_ItemPaths($sFilePath)
EndFunc
Func idRadioIconclick()
$sFilePath = FileOpenDialog("Choose File to add to launcer", @ScriptDir, "Exe files or Icons (*.Exe;*.Ico)", 1 + 2)
If $sFilePath = "" Then Return
$bExeFile = False
_ItemPaths($sFilePath)
EndFunc

#endregion
; Adding selected to INI file and updates the ListBox.
Func _AddItem($sItemPath, $sItemLaunchName, $sItemDescription)

; Converting Entrys to hex
$sItemPathHex = _StringToHex($sItemPath)
; Cleaning up the Launchname with a String Prob
$sItemLaunchNameHex = _StringToHex($sItemLaunchName)
$sItemDescriptionHex = _StringToHex($sItemDescription)

; Checking if added Item Already exists
$sCheckForDublets = IniReadSectionNames($IniFile)
$sDubletCheck = _ArraySearch($sCheckForDublets, $sItemLaunchNameHex)
if $sDubletCheck = -1 Then
; Writing Item info to inifile
IniWrite($IniFile, $sItemLaunchNameHex, "1", $sItemPathHex)
IniWrite($IniFile, $sItemLaunchNameHex, "2", $sItemLaunchNameHex)
IniWrite($IniFile, $sItemLaunchNameHex, "3", $sItemDescriptionHex)
_Startup()
hAddItemClose()
Else
#Region --- CodeWizard generated code Start ---
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Warning, Miscellaneous=Top-most attribute
MsgBox(262192,"Item Name","The typed item name: " & $sItemLaunchName & " is already in use!" & @CRLF & @CRLF & "Please choose another name for the item.")
#EndRegion --- CodeWizard generated code End ---
GUICtrlSetData($idInputAddItemLaunchName, "")
Return
EndIf
EndFunc ;==>_AddItem

Func _GetDescription($sItemName)
; Read inifile to get item description)
If $sItemName = "" Then Return
$sInfo = IniRead($IniFile, _StringToHex($sItemName), "3", "No info")
GUICtrlSetData($idEditItemDescription, _HexToString($sInfo))
EndFunc

Func _LaunchSelected($sApp2Launch)
; get Item path
$s2Hex = _StringToHex($sApp2Launch)
$sItemPath = IniRead($IniFile, $s2Hex, "1", "ERROR")
$sFromHex = _HexToString($sItemPath)
ShellExecute($sFromHex)
GUISetState(@SW_MINIMIZE, $hUtility_Launcher)
EndFunc


Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg
Local $hWndFrom, $iIDFrom, $iCode, $hWndListBox
If Not IsHWnd($idListApps) Then $hWndListBox = GUICtrlGetHandle($idListApps)
$hWndFrom = $ilParam
$iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
$iCode = BitShift($iwParam, 16) ; Hi Word

Switch $hWndFrom
Case $idListApps, $hWndListBox
Switch $iCode
Case $LBN_DBLCLK ; Sent when the user double-clicks a string in a list box
$iIndex = _GUICtrlListBox_GetCurSel($idListApps)
$sSelected = _GUICtrlListBox_GetText($idListApps, $iIndex)
_LaunchSelected($sSelected)

Case $LBN_ERRSPACE ; Sent when a list box cannot allocate enough memory to meet a specific request
; no return value
Case $LBN_KILLFOCUS ; Sent when a list box loses the keyboard focus

; no return value
Case $LBN_SELCANCEL ; Sent when the user cancels the selection in a list box

; no return value
Case $LBN_SELCHANGE ; Sent when the selection in a list box has changed

$iIndex = _GUICtrlListBox_GetCurSel($idListApps)
$sSelected = _GUICtrlListBox_GetText($idListApps, $iIndex)
_GetDescription($sSelected)

Case $LBN_SETFOCUS ; Sent when a list box receives the keyboard focus

; no return value
EndSwitch
EndSwitch
; Proceed the default AutoIt3 internal message commands.
; You also can complete let the line out.
; !!! But only 'Return' (without any value) will not proceed
; the default AutoIt3-message in the future !!!
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND

Only thing i missed was to add and Use the Splash Images from Recurses, never could found out how to that :(

c;") / Rex

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0