Files
d3k/func.ahk
T

103 lines
3.1 KiB
AutoHotkey
Raw Normal View History

2026-07-08 11:54:28 -05:00
#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)
2019-12-17 10:57:15 -06:00
2026-07-08 11:54:28 -05:00
global d3k_version := 3 ; The current version
2019-12-17 10:57:15 -06:00
2022-03-29 14:33:19 -05:00
;------------------------------------------------------------------------------
2023-02-13 16:20:22 -06:00
; INI Manipulation that supports UTF-8
2022-03-29 14:33:19 -05:00
;------------------------------------------------------------------------------
2023-02-13 16:20:22 -06:00
ini_load(location)
{
2026-07-08 11:54:28 -05:00
temp := FileOpen(location, "r")
cleaner := temp.Read()
temp.Close()
2023-02-13 16:20:22 -06:00
cleaner := RegExReplace(cleaner, "`am)^[\s\R]*") ; Remove empty lines
cleaner := RegExReplace(cleaner, "m)[ \t]+$") ; Get rid of extra space at the end of values (NEEDS FIXED)
2026-07-08 11:54:28 -05:00
temp := FileOpen(location, "w")
temp.Write(cleaner)
temp.Close()
temp := FileOpen(location, "r")
out := Object()
2023-02-13 16:20:22 -06:00
Loop
{
2026-07-08 11:54:28 -05:00
Line := temp.ReadLine()
RegExMatch(Line, "(?<Section>(?<=\[).*(?=\]))|(?<Key>.*)=(?<Value>.*)", &r) ; Key = r.Key, Value = r.Value, Section = r.Section
If (r.Section)
2023-02-13 16:20:22 -06:00
{
2026-07-08 11:54:28 -05:00
out.%r.Section% := Map()
current_Section := r.Section
2023-02-13 16:20:22 -06:00
} Else
{
2026-07-08 11:54:28 -05:00
trimKey := Trim(r.Key, " `t`r`n")
trimValue := Trim(r.Value, " `t`r`n")
out.%current_Section%[trimKey] := trimValue
2023-02-13 16:20:22 -06:00
}
2026-07-08 11:54:28 -05:00
} Until (temp.AtEOF)
temp.Close()
2023-02-13 16:20:22 -06:00
Return out
}
2022-03-29 14:33:19 -05:00
2023-02-13 16:20:22 -06:00
ini_write(location, inKey, inValue) ; Don't need to specify section because you can only have one hotstring anyway
{
2026-07-08 11:54:28 -05:00
Critical("On")
ini := FileOpen(location, "r")
temp := ini.Read()
ini.Close()
inKeyReg := "(?<=" inKey "=)\S*" ; Regex to make sure we're matching only the value for the requested key
2023-07-14 11:10:18 -05:00
temp := RegExReplace(temp, inKeyReg, inValue)
2026-07-08 11:54:28 -05:00
ini := FileOpen(location, "w")
ini.Write(temp)
ini.Close()
Critical("Off")
2023-02-13 16:20:22 -06:00
}
2022-03-29 14:33:19 -05:00
;------------------------------------------------------------------------------
2023-02-13 16:20:22 -06:00
; Make sure the settings file exists, if not, create it
2022-03-29 14:33:19 -05:00
;------------------------------------------------------------------------------
2023-02-13 16:20:22 -06:00
sett_ini := A_MyDocuments "\D3Ksettings.ini" ; Where the settings ini is
2022-03-29 14:33:19 -05:00
2023-02-13 16:20:22 -06:00
If !FileExist(sett_ini) ; Check if the sett_ini doesn't exist
{
2026-07-08 11:54:28 -05:00
ini := FileOpen(sett_ini, "w")
2023-02-13 16:20:22 -06:00
writethis := "
( LTrim
[USpec]
Email=LastnameFirstname@JohnDeere.com
DocFile=Select File
[Main]
MJDPaste=1
JDProductNames=1
GloVar=0
[Language]
German=0
)"
2026-07-08 11:54:28 -05:00
ini.Write(writethis)
2023-02-13 16:20:22 -06:00
file.Close()
2026-07-08 11:54:28 -05:00
Run("Settings.ahk") ; Runs the GUI for changing the settings, accessible with Alt+Shift+\ (also easy way to restart this script)
2023-02-13 16:20:22 -06:00
}
2022-03-29 14:33:19 -05:00
;------------------------------------------------------------------------------
2023-02-13 16:20:22 -06:00
; Read the sett_ini
2022-03-29 14:33:19 -05:00
;------------------------------------------------------------------------------
2026-07-08 11:54:28 -05:00
; This is the part that reads the file to see what your settings are.
2022-03-29 14:33:19 -05:00
2026-07-08 11:54:28 -05:00
global settings := ini_load(sett_ini)
2022-03-29 14:33:19 -05:00
2026-07-08 11:54:28 -05:00
; started as global variables, keeping this commented out in case there's some old script where I need to replace something
2023-02-13 16:20:22 -06:00
; User Specific things:
2026-07-08 11:54:28 -05:00
;global email := settings.USpec["Email"]
;global docfile := settings.USpec["DocFile"]
2022-03-29 14:33:19 -05:00
2023-02-13 16:20:22 -06:00
; Replacement
2026-07-08 11:54:28 -05:00
;global jdpn := settings.Replacement["JDProductNames"]
;global glovar := settings.Replacement["GloVar"]
2022-03-29 14:33:19 -05:00
2023-02-13 16:20:22 -06:00
; Language
2026-07-08 11:54:28 -05:00
;global ger := settings.Language["German"]