update to AHK v2

This commit is contained in:
2026-07-08 11:54:28 -05:00
parent 9e8ed05b4e
commit 748e3ab321
+44 -109
View File
@@ -1,62 +1,11 @@
#SingleInstance force ; Only one instance at a time #Requires AutoHotkey v2 ; v2 only
SendMode, Input #SingleInstance force ; Only one instance at a time
FileEncoding, UTF-8 ; Makes sure the special characters dont break stuff FileEncoding("UTF-8") ; Makes sure the special characters dont break stuff
SetWorkingDir, %A_MyDocuments%\D3K ; Make sure we can find the .ahks linked below SetWorkingDir(A_MyDocuments "\D3K") ; Make sure we can find the .ahks linked below
SetTitleMatchMode, 2 SetTitleMatchMode(2)
d3k_version := 3 ; The current version global d3k_version := 3 ; The current version
GetDateTime(lang)
{
FormatStr := "yyyy-MM-dd" ; The Date
FormatTime, DateStr, %A_NowUTC%, %FormatStr% ; format it to make it look like the Date we want
FormatStr := "H:mm'Z'" ; The time
FormatTime, TimeStr, %A_NowUTC%, %FormatStr% ; Format the string to be better
if (lang = "en")
{
Return DateStr " at " TimeStr
}
if (lang = "de")
{
Return DateStr " um " TimeStr
}
if (lang = "ISO8601")
{
Return DateStr "T" TimeStr
}
if (lang = "date")
{
Return DateStr
}
}
GetInfo(xID)
{
if (xID)
{
File := FileOpen(A_MyDocuments "\emails.csv", "r")
Loop
{
Line := File.ReadLine()
Array := StrSplit(Line,",") ; split the line at its separating commas to get separate "columns" AKA elements
if InStr(Array[1], xID) ; if at the specified element (1) the specified content (dealers xID) has been found
{
Test := {xid: Array[1], email: Array[2], name: Array[3], user: Array[4], org: Array[5]} ; Return the array so we can do {variable}.email and so on
File.Close() ; Close the file
Return Test ; Return the array with the deets that we found
}
} Until (File.AtEOF)
File.Close()
Return false
}
if !(xID)
{
Return false
}
}
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
; INI Manipulation that supports UTF-8 ; INI Manipulation that supports UTF-8
@@ -64,49 +13,48 @@ GetInfo(xID)
ini_load(location) ini_load(location)
{ {
out := {} temp := FileOpen(location, "r")
File := FileOpen(location, "r") cleaner := temp.Read()
cleaner := File.Read() temp.Close()
File.Close()
cleaner := RegExReplace(cleaner, "`am)^[\s\R]*") ; Remove empty lines 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) cleaner := RegExReplace(cleaner, "m)[ \t]+$") ; Get rid of extra space at the end of values (NEEDS FIXED)
File := FileOpen(location, "w") temp := FileOpen(location, "w")
File.Write(cleaner) temp.Write(cleaner)
File.Close() temp.Close()
File := FileOpen(location, "r") temp := FileOpen(location, "r")
out := Object()
Loop Loop
{ {
Line := File.ReadLine() Line := temp.ReadLine()
RegExMatch(Line, "(?<Section>(?<=\[).*(?=\]))|(?<Key>.*)=(?<Value>.*)", r) ; Key = rKey, Value = rValue, Section = rSection RegExMatch(Line, "(?<Section>(?<=\[).*(?=\]))|(?<Key>.*)=(?<Value>.*)", &r) ; Key = r.Key, Value = r.Value, Section = r.Section
If (rSection) If (r.Section)
{ {
rSection := Trim(rSection, " `t`r`n") ; Remove pesky newlines and extra space out.%r.Section% := Map()
rSection := StrReplace(rSection, " ", "§") ; AHK can't handle spaces in nested array names, so they're substituted with § current_Section := r.Section
out[rSection]:={}
c_Section := rSection
} Else } Else
{ {
rKey := Trim(rKey, " `t`r`n") trimKey := Trim(r.Key, " `t`r`n")
rValue := Trim(rValue, " `t`r`n") trimValue := Trim(r.Value, " `t`r`n")
out[c_Section, rKey] := rValue out.%current_Section%[trimKey] := trimValue
} }
} Until (File.AtEOF) } Until (temp.AtEOF)
File.Close() temp.Close()
Return out Return out
} }
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 Critical("On")
file := FileOpen(location, "r") ini := FileOpen(location, "r")
temp := file.Read() temp := ini.Read()
file.Close() ini.Close()
inKeyReg := "(?<=^" inKey "=)\S*" ; Regex to make sure we're matching only the value for the requested key inKeyReg := "(?<=" inKey "=)\S*" ; Regex to make sure we're matching only the value for the requested key
temp := RegExReplace(temp, inKeyReg, inValue) temp := RegExReplace(temp, inKeyReg, inValue)
file := FileOpen(location, "w") ini := FileOpen(location, "w")
file.Write(temp) ini.Write(temp)
file.Close() ini.Close()
Critical("Off")
} }
@@ -117,52 +65,39 @@ sett_ini := A_MyDocuments "\D3Ksettings.ini" ; Where the settings ini is
If !FileExist(sett_ini) ; Check if the sett_ini doesn't exist If !FileExist(sett_ini) ; Check if the sett_ini doesn't exist
{ {
file := FileOpen(sett_ini, "w") ini := FileOpen(sett_ini, "w")
writethis := " writethis := "
( LTrim ( LTrim
[USpec] [USpec]
Email=LastnameFirstname@JohnDeere.com Email=LastnameFirstname@JohnDeere.com
Name=Firstname
DocFile=Select File DocFile=Select File
[Main] [Main]
Mansol=1
MJDPaste=1 MJDPaste=1
CaseFormatter=1
CFmail=0
[Replacement]
JDProductNames=1 JDProductNames=1
GloVar=0 GloVar=0
[Language] [Language]
German=0 German=0
)" )"
file.Write(writethis) ini.Write(writethis)
file.Close() file.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)
} }
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
; Read the sett_ini ; Read the sett_ini
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
; This is the part that reads the file to see what your settings are. Variables in the sett_ini file are in all CamelCase, variables here are lowercase for more distinction ; This is the part that reads the file to see what your settings are.
settings := {} global settings := ini_load(sett_ini)
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: ; User Specific things:
email := settings["USpec", "Email"] ;global email := settings.USpec["Email"]
name := settings["USpec", "Name"] ;global docfile := settings.USpec["DocFile"]
docfile := settings["USpec", "DocFile"]
; General Settings
mansol := settings["Main", "Mansol"]
supadmin := settings["Main", "Supadmin"]
mjdpaste := settings["Main", "MJDPaste"]
caseformatter := settings["Main", "CaseFormatter"]
cfmail := settings["Main", "CFmail"]
; Replacement ; Replacement
jdpn := settings["Replacement", "JDProductNames"] ;global jdpn := settings.Replacement["JDProductNames"]
glovar := settings["Replacement", "GloVar"] ;global glovar := settings.Replacement["GloVar"]
; Language ; Language
ger := settings["Language", "German"] ;global ger := settings.Language["German"]