Upgrade to AHK v2 #3

Open
david wants to merge 35 commits from tier2 into master
Showing only changes of commit 9fd247681a - Show all commits
+24 -28
View File
@@ -16,26 +16,31 @@ ini_load(location)
temp := FileOpen(location, "r") temp := FileOpen(location, "r")
cleaner := temp.Read() cleaner := temp.Read()
temp.Close() temp.Close()
cleaner := RegExReplace(cleaner, "`am)^[\s\R]*") ; Remove empty lines cleaner := RegExReplace(cleaner, "`m)[ \t]+$|^[\s\R]*$") ; Remove empty lines, spaces, tabs
cleaner := RegExReplace(cleaner, "m)[ \t]+$") ; Get rid of extra space at the end of values (NEEDS FIXED)
temp := FileOpen(location, "w") temp := FileOpen(location, "w")
temp.Write(cleaner) temp.Write(cleaner)
temp.Close() temp.Close()
temp := FileOpen(location, "r") temp := FileOpen(location, "r")
out := Object() 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 Loop
{ {
Line := temp.ReadLine() Line := temp.ReadLine()
RegExMatch(Line, "(?<Section>(?<=\[).*(?=\]))|(?<Key>.*)=(?<Value>.*)", &r) ; Key = r.Key, Value = r.Value, Section = r.Section RegExMatch(Line, "(?<Section>(?<=\[).*(?=\]))|(?<Key>.*)=(?<Value>.*)", &r) ; Key = r.Key, Value = r.Value, Section = r.Section
If (r.Section) If (r.Section)
{ {
out.%r.Section% := Map() out[r.Section] := Map()
current_Section := r.Section curr_section := r.Section
} Else } Else
{ {
trimKey := Trim(r.Key, " `t`r`n") If (curr_section)
trimValue := Trim(r.Value, " `t`r`n") {
out.%current_Section%[trimKey] := trimValue 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) } Until (temp.AtEOF)
temp.Close() temp.Close()
@@ -45,16 +50,13 @@ ini_load(location)
ini_write(location, inKey, inValue) ; Don't need to specify section because you can only have one hotstring anyway ini_write(location, inKey, inValue) ; Don't need to specify section because you can only have one hotstring anyway
{ {
Critical("On")
ini := FileOpen(location, "r") ini := FileOpen(location, "r")
temp := ini.Read() temp := ini.Read()
ini.Close() ini.Close()
inKeyReg := "(?<=" inKey "=)\S*" ; Regex to make sure we're matching only the value for the requested key temp := RegExReplace(temp, "(?<=" inKey "=).*", inValue)
temp := RegExReplace(temp, inKeyReg, inValue)
ini := FileOpen(location, "w") ini := FileOpen(location, "w")
ini.Write(temp) ini.Write(temp)
ini.Close() ini.Close()
Critical("Off")
} }
@@ -68,18 +70,16 @@ If !FileExist(sett_ini) ; Check if the sett_ini doesn't exist
ini := FileOpen(sett_ini, "w") ini := FileOpen(sett_ini, "w")
writethis := " writethis := "
( LTrim ( LTrim
[USpec]
Email=LastnameFirstname@JohnDeere.com Email=LastnameFirstname@JohnDeere.com
DocFile=Select File DocFile=0
[Main]
MJDPaste=1
JDProductNames=1 JDProductNames=1
GloVar=0 GloVar=0
[Language]
German=0 German=0
msmv=always
msmv_status=stopped
)" )"
ini.Write(writethis) ini.Write(writethis)
file.Close() ini.Close()
Run("Settings.ahk") ; Runs the GUI for changing the settings, accessible with Alt+Shift+\ (also easy way to restart this script) Run("Settings.ahk") ; Runs the GUI for changing the settings, accessible with Alt+Shift+\ (also easy way to restart this script)
} }
@@ -92,12 +92,8 @@ 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 ; started as global variables, keeping this commented out in case there's some old script where I need to replace something
; User Specific things: ; User Specific things:
;global email := settings.USpec["Email"] ;global email := settings["Email"]
;global docfile := settings.USpec["DocFile"] ;global docfile := settings["DocFile"]
;global jdpn := settings["JDProductNames"]
; Replacement ;global glovar := settings["GloVar"]
;global jdpn := settings.Replacement["JDProductNames"] ;global ger := settings["German"]
;global glovar := settings.Replacement["GloVar"]
; Language
;global ger := settings.Language["German"]