thnx for the reference
btw how does this script handle with the adding or removing of a script from the folder
cause i played more with the old release and discovered a way to keep all data together incase of new scripts but didn't find a way to reuse the keys of the files that are removed from the folder
Code:
IniRead, IniFilecount, Master Script Settings.ini, Filecount, Filecount, 0
Loop, %IniFilecount% ; Inireads all needed values
{
Iniread, Scriptname%A_Index%, Master Script Settings.ini, Scriptname, Script%A_Index%,0
Iniread, Autostart%A_Index%, Master Script Settings.ini, Autostart, Script%A_Index%,0
Iniread, Hotkey%A_Index%, Master Script Settings.ini, Hotkey, Script%A_Index%
Iniread, Winkey%A_Index%, Master Script Settings.ini, Winkey, Script%A_Index%,0
IniRead, Deactivate%A_Index%, Master Script Settings.ini, Deactivate, Script%A_Index%,0
IniRead, ScriptDir%A_Index%, Master Script Settings.ini, Directory, Script%A_Index%, %A_ScriptDir%
; File%A_Index% := Scriptname%A_Index% <--- Commented out since there was a conflict
}
Loop,%IniFilecount%
{
Search:= ScriptDir%A_Index% Scriptname%A_Index%
;MsgBox,%Search%
IfNotExist,%Search%
{
;Msgbox,file not found
;Msgbox
IniDelete, Master Script Settings.ini, Scriptname, Script%A_Index%
IniDelete, Master Script Settings.ini, Autostart, Script%A_Index%
IniDelete, Master Script Settings.ini, Hotkey, Script%A_Index%
IniDelete, Master Script Settings.ini, Winkey, Script%A_Index%
IniDelete, Master Script Settings.ini, Deactivate, Script%A_Index%
IniDelete, Master Script Settings.ini, Directory, Script%A_Index%
}
}
Loop, *.ahk,0,1
{
If(A_LoopFileDir = "Inactive Scripts")
Continue
Else
{
Loop,%IniFilecount%
{
FileEntryExist=0
;Msgbox,%A_Index%
SplitPath,A_LoopFileFullPath,FileCheck,DirCheck
If(DirCheck ="")
DirCheck = %A_ScriptDir%\
Else
DirCheck=%A_ScriptDir%\%A_LoopFileDir%\
FileChecker:=Scriptname%A_Index%
DirChecker:=ScriptDir%A_Index%
foundnotdir=0
;Msgbox,%FileCheck% = %FileChecker% and %DirCheck% = %DirChecker%
If(FileCheck <> FileChecker)
{
;Msgbox, File Doesn't match
Continue
}
Else
{
;Msgbox,File Exists
If(DirCheck == DirChecker )
{
;Msgbox,File Exists in Directory
FileEntryExist=1
num:=A_Index-foundnotdir
;MsgBox,%num%
Break
}
Else
{
foundnotdir++
;Msgbox,File doesn't Exist in Directory
}
}
}
;Msgbox, File Existance is %FileEntryExist%
If(FileEntryExist = 1)
{
Iniread, Autostart%num%, Master Script Settings.ini, Autostart, Script%num%,0
Iniread, Hotkey%num%, Master Script Settings.ini, Hotkey, Script%num%
Iniread, Winkey%num%, Master Script Settings.ini, Winkey, Script%num%,0
IniRead, Deactivate%num%, Master Script Settings.ini, Deactivate, Script%num%,0
;Msgbox, Autostart%num% "|" Hotkey%num%"|"Winkey%num%"|"Deactivate%num% ":" Scriptname%num%
Continue
}
Else
{
;Msgbox,%A_LoopFileName% doesn't exist in the records
FileList = %FileList%%A_LoopFileName%`n
If(A_LoopFileDir ="")
FileDir = %FileDir%%A_ScriptDir%\`n
Else
FileDir = %FileDir%%A_ScriptDir%\%A_LoopFileDir%\`n
}
}
}
FileCount=0
Loop, parse, FileList, `n
{
if A_LoopField = ; Ignore the blank item at the end of the list.
{
FileCount := A_Index-1 ; To also ignore the blank item in future Filecounts
continue
}
addfile:= IniFilecount + FileCount
msgbox,%addfile% file is %A_LoopField%
Scriptname%addfile% = %A_LoopField%
/*
MsgBox, 4,, File number %A_Index% is %A_LoopField%. Continue?
IfMsgBox, No
break
*/
}
FileCount=0
Loop, parse, FileDir, `n
{
if A_LoopField = ; Ignore the blank item at the end of the list.
{
FileCount := A_Index-1 ; To also ignore the blank item in future Filecounts
continue
}
msgbox,%addfile% file is %A_LoopField%
ScriptDir%addfile% = %A_LoopField%
/*
MsgBox, 4,, File number %A_Index% is %A_LoopField%. Continue?
IfMsgBox, No
break
*/
}
FileCount:=IniFilecount+FileCount
Msgbox,%FileCount%
IniWrite, %Filecount%, Master Script Settings.ini, Filecount, Filecount
IniRead, Filecount, Master Script Settings.ini, Filecount, Filecount, 0
Loop, %addfile% ;adds the files to the Master Script Settings.ini file
{
DirIni := ScriptDir%addfile%
IniWrite, %DirIni%, Master Script Settings.ini, Directory, Script%addfile%
ScriptnameIni := Scriptname%addfile%
IniWrite, %ScriptnameIni%, Master Script Settings.ini, Scriptname, Script%addfile%
}
Loop, %Filecount% ; Inireads all needed values
{
Iniread, Scriptname%A_Index%, Master Script Settings.ini, Scriptname, Script%A_Index%,0
Iniread, Autostart%A_Index%, Master Script Settings.ini, Autostart, Script%A_Index%,0
Iniread, Hotkey%A_Index%, Master Script Settings.ini, Hotkey, Script%A_Index%
Iniread, Winkey%A_Index%, Master Script Settings.ini, Winkey, Script%A_Index%,0
IniRead, Deactivate%A_Index%, Master Script Settings.ini, Deactivate, Script%A_Index%,0
IniRead, ScriptDir%A_Index%, Master Script Settings.ini, Directory, Script%A_Index%, %A_ScriptDir%
; File%A_Index% := Scriptname%A_Index% <--- Commented out since there was a conflict
}
CreateGUI_Stage1:
;the first peice doesn't have to reside in this area but it is added here for easier editing as it is part of the gui creation process
Files:= FileCount
GuiMaxCount = 1
Loop ;dicovering how many gui windows are required to show the whole file list
{
If(Files > 15) ;15 choosen as the limit of programs per gui
{
GuiMaxCount++
Files -= 15
Continue
}
Else ;if there is less than 15 files no extra guis required
{
Break
}
}
window = 0 ;set to blank to allow for incrimental counting
CreateGUI_Stage2:
window ++ ;add 1 to window to keeptrack of what gui window we are editing
If (window > GuiMaxCount) ; if script tries to make uneeded windows this if will prevent it
Gosub,Exit
Else ;create the gui
{
Low_Lim:= 15*(window-1)+1 ;calculating for the text of the gui
if(window = GuiMaxCount) ;deciphering wether the gui is a full gui or a partial one and calculating the appropriate High_Lim
High_Lim:= FileCount
Else
High_Lim:= 15*window
;add the controls of the current gui
Gui, %window%:Default
Gui, %window%: Add, Text,, ... %FileCount% files found showing results %Low_Lim% to %High_Lim% ; text to show the user what files of the filecount are showed on the gui
Gui, %window%: Add, Button, gSubmit, Save && Exit
Gui, %window%: Add, Button, xp+70 yp gReset, Reset
Gui, %window%: Add, Button, xp+55 yp w25 gHelp, ?
Gui, %window%: Add, Button, xp+35 yp gExit, Exit
Gui, %window%: Add, Text, y+15 xp-150, Run script | Autostart | Hotkey | +Win key? | Deactivate
Loop, 15 ;add the controls for each program shown in the gui
{
instance :=(15*(window - 1)) + A_Index ;becuase of multiple windows a_Index is unable to be used thus current program has to be calculated
;MsgBox, %instance%
If(instance > FileCount) ;since it repeats 15 times must ensure that only the amount of files is added not any extras usually blanks
Break
Else ;same process as in orignial script except %instance% used instead of %A_Index%
{
FileText := ScriptName%instance%
Gui, %window%: Add, GroupBox, xs0 w350, %FileText%
Gui, %window%: Add, Button, xp+10 yp+20 h20 r1 gLaunchFileSelect, %instance% ;set to the file number to allow the "LaunchFileSelect" subroutine to be able to function correctly
LaunchindexN = Launchindex%instance% ; ?
n := Autostart%instance%
Gui, %window%: Add, Checkbox, xp+70 yp+5 r1 vAutostartN%instance% checked%n%
n := Hotkey%instance%
Gui, %window%: Add, Hotkey, xp+50 yp-5 w70 vHotkeyN%instance%, %n%
n := Winkey%instance%
Gui, %window%: Add, Checkbox, xp+75 yp+5 r1 vWinkeyN%instance% checked%n%
n:= Deactivate%instance%
Gui, %window%: Add, Checkbox, xp+75 yp vDeactivateN%instance% checked%n%
}
}
Gui, %window%:Show, Autosize, Master Script settings (window %window% of %GuiMaxCount%) ;title showing which window of the series it is
Return
}
return
reset:
Run,%A_ScriptFullPath%
return
Submit:
Gui,Submit
Loop, 15
{
instance :=(15*(window - 1)) + A_Index
If(instance > FileCount) ;since it repeats 15 times must ensure that only the amount of files is added not any extras usually blanks
Break
Else ;same process as in orignial script except %instance% used instead of %A_Index%
{
DirIni := ScriptDir%instance%
;MsgBox, ScriptDir%instance% is %DirIni%
IniWrite, %DirIni%, Master Script Settings.ini, Directory, Script%instance%
ScriptnameIni := Scriptname%instance%
IniWrite, %ScriptnameIni%, Master Script Settings.ini, Scriptname, Script%instance%
AutostartIni := AutostartN%instance%
IniWrite, %AutostartINI%, Master Script Settings.ini, Autostart, Script%instance%
HotkeyINI := HotkeyN%instance%
IniWrite, %HotkeyINI%, Master Script Settings.ini, Hotkey, Script%instance%
WinkeyINI := WinkeyN%instance%
IniWrite, %WinkeyINI%, Master Script Settings.ini, Winkey, Script%instance%
DeactivateINI := DeactivateN%instance% ; Yes, I know the this INI value won't be used, but can be good to have if someone wants to change the script
IniWrite, %DeactivateIni%, Master Script Settings.ini, Deactivate, Script%instance%
Filemovetext := File%instance%
FileCreateDir, Inactive Scripts
If (DeactivateN%instance% = 1)
{
MsgBox, 4, ,Do you want to move %FileMoveText% to %Inactive_Dir%
IfMsgBox Yes
FileMove, %Filemovetext%, %Inactive_Dir%
Else
Continue
}
}
}
Gui,Destroy
Goto,CreateGUI_Stage2
return
Exit:
ExitApp
return
reload:
Reload
return
Masterstartup:
MsgBox FAIL
return
Help:
MsgBox Run script - Runs the chosen script `nAutostart - The chosen script will always start when you start your computer `nHotkey & Win key - Assign a hotkey to launch the selected script, if you want to combine it with the Left Windows key: Also tick the "Win key?" button `nDeactivate - Moves the designated script to a subfolder called "Inactive scripts", so it will not appear in this list
return
Launch:
SoundPlay, *64
Run, %FiletoLaunch%
return
; THE FOLLOWING "LaunchFileSelect" subroutine uses the name of the button to decipher what file the user wants to run, collects it respectable directory, colaborates these together to give a path to the file to be sent to the Launch subroutine
LaunchFileSelect:
Selected_File:= File%A_GuiControl%
Selected_File_Dir:= Dir%A_GuiControl%
FiletoLaunch = %Selected_File_Dir%%Selected_File%
;Msgbox, %FiletoLaunch%
Gosub, Launch
Return