99 lines
3.2 KiB
AutoHotkey
99 lines
3.2 KiB
AutoHotkey
#Requires AutoHotkey v2 ; v2 only
|
|
#SingleInstance force ; Only one instance at a time
|
|
FileEncoding("UTF-8") ; Makes sure the special characters dont break stuff
|
|
SetWorkingDir(A_MyDocuments "\D3K") ; Make sure we can find the .ahks linked below
|
|
SetTitleMatchMode(2)
|
|
|
|
global d3k_version := 3 ; The current version
|
|
|
|
|
|
;------------------------------------------------------------------------------
|
|
; INI Manipulation that supports UTF-8
|
|
;------------------------------------------------------------------------------
|
|
|
|
ini_load(location)
|
|
{
|
|
temp := FileOpen(location, "r")
|
|
cleaner := temp.Read()
|
|
temp.Close()
|
|
cleaner := RegExReplace(cleaner, "`m)[ \t]+$|^[\s\R]*$") ; Remove empty lines, spaces, tabs
|
|
temp := FileOpen(location, "w")
|
|
temp.Write(cleaner)
|
|
temp.Close()
|
|
temp := FileOpen(location, "r")
|
|
out := Map() ; I tried an object, it was too complicated for what I'm doing. Nested map is good enough
|
|
curr_section := 0 ; v2 won't evaluate a true/false to false if a variable isn't set to false
|
|
r := Object() ; bruh why do I have to set up variables now suddenly
|
|
Loop
|
|
{
|
|
Line := temp.ReadLine()
|
|
RegExMatch(Line, "(?<Section>(?<=\[).*(?=\]))|(?<Key>.*)=(?<Value>.*)", &r) ; Key = r.Key, Value = r.Value, Section = r.Section
|
|
If (r.Section)
|
|
{
|
|
out[r.Section] := Map()
|
|
curr_section := r.Section
|
|
} Else
|
|
{
|
|
If (curr_section)
|
|
{
|
|
out[curr_section].Set(Trim(r.Key, " `t`r`n"), Trim(r.Value, " `t`r`n"))
|
|
} Else
|
|
{
|
|
out.Set(Trim(r.Key, " `t`r`n"), Trim(r.Value, " `t`r`n")) ; this handles things with no section
|
|
}
|
|
}
|
|
} Until (temp.AtEOF)
|
|
temp.Close()
|
|
Return out
|
|
}
|
|
|
|
|
|
ini_write(location, inKey, inValue) ; Don't need to specify section because you can only have one hotstring anyway
|
|
{
|
|
ini := FileOpen(location, "r")
|
|
temp := ini.Read()
|
|
ini.Close()
|
|
temp := RegExReplace(temp, "(?<=" inKey "=).*", inValue)
|
|
ini := FileOpen(location, "w")
|
|
ini.Write(temp)
|
|
ini.Close()
|
|
}
|
|
|
|
|
|
;------------------------------------------------------------------------------
|
|
; Make sure the settings file exists, if not, create it
|
|
;------------------------------------------------------------------------------
|
|
sett_ini := A_MyDocuments "\D3Ksettings.ini" ; Where the settings ini is
|
|
|
|
If !FileExist(sett_ini) ; Check if the sett_ini doesn't exist
|
|
{
|
|
ini := FileOpen(sett_ini, "w")
|
|
writethis := "
|
|
( LTrim
|
|
[email protected]
|
|
DocFile=0
|
|
JDProductNames=1
|
|
GloVar=0
|
|
German=0
|
|
msmv=always
|
|
msmv_status=stopped
|
|
)"
|
|
ini.Write(writethis)
|
|
ini.Close()
|
|
Run("Settings.ahk") ; Runs the GUI for changing the settings, accessible with Alt+Shift+\ (also easy way to restart this script)
|
|
}
|
|
|
|
;------------------------------------------------------------------------------
|
|
; Read the sett_ini
|
|
;------------------------------------------------------------------------------
|
|
; This is the part that reads the file to see what your settings are.
|
|
|
|
global settings := ini_load(sett_ini)
|
|
|
|
; started as global variables, keeping this commented out in case there's some old script where I need to replace something
|
|
; User Specific things:
|
|
;global email := settings["Email"]
|
|
;global docfile := settings["DocFile"]
|
|
;global jdpn := settings["JDProductNames"]
|
|
;global glovar := settings["GloVar"]
|
|
;global ger := settings["German"] |