d3k/func.ahk

120 lines
3.1 KiB
AutoHotkey
Raw Normal View History

2019-12-17 10:57:15 -06:00
#SingleInstance force ; Only one instance at a time
SendMode, Input
FileEncoding, UTF-8 ; Makes sure the special characters dont break stuff
SetWorkingDir, %A_MyDocuments%\D3K ; Make sure we can find the .ahks linked below
d3k_version = 2.9 ; The current version
2019-12-17 10:57:15 -06:00
2020-01-14 09:16:37 -06:00
ini = %A_MyDocuments%\D3Ksettings.ini ; Where the settings ini is
2019-12-17 10:57:15 -06:00
GetDateTime(lang)
{
UTCTimestamp := A_NowUTC ; Grab the current time and date
2020-02-03 02:54:31 -06:00
UTCFormatStr := "yyyy-MM-dd" ; The Date
2019-12-17 10:57:15 -06:00
FormatTime, DateStr, %UTCTimestamp%, %UTCFormatStr% ; format it to make it look like the Date we want
2022-03-29 14:32:47 -05:00
UTCFormatStr := "H:mm'Z'" ; The time
2019-12-17 10:57:15 -06:00
FormatTime, TimeStr, %UTCTimestamp%, %UTCFormatStr% ; Format the string to be better
if (lang = "en")
{
Return DateStr " at " TimeStr
}
if (lang = "de")
{
Return DateStr " um " TimeStr
}
2022-03-29 14:32:47 -05:00
if (lang = "ISO8601")
{
Return DateStr "T" TimeStr
}
if (lang = "date")
{
Return DateStr
}
2019-12-17 10:57:15 -06:00
}
2020-02-03 02:54:31 -06:00
GetInfo(xID)
2019-12-17 10:57:15 -06:00
{
if (xID)
{
2020-02-07 03:29:43 -06:00
File := FileOpen(A_MyDocuments "\emails.csv", "r")
2020-02-03 02:54:31 -06:00
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
2020-01-24 03:24:06 -06:00
{
2020-02-03 02:54:31 -06:00
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
2020-01-24 03:24:06 -06:00
}
2020-02-03 02:54:31 -06:00
} Until (File.AtEOF)
File.Close()
Return false
2020-01-23 08:46:40 -06:00
}
if !(xID)
{
2020-02-03 02:54:31 -06:00
Return false
2020-01-23 08:46:40 -06:00
}
2019-12-17 10:57:15 -06:00
}
;------------------------------------------------------------------------------
; INI Manipulation that supports UTF-8
;------------------------------------------------------------------------------
ini_load(location)
{
2020-01-24 03:24:06 -06:00
File := FileOpen(location, "r")
2019-12-17 10:57:15 -06:00
out := {}
2020-01-24 03:24:06 -06:00
Loop
2019-12-17 10:57:15 -06:00
{
2020-01-24 03:24:06 -06:00
Line := File.ReadLine()
RegExMatch(Line, "(?<=\[).*(?=\])", _RESection) ; Matches section name
RegExMatch(Line, "(?<Key>.*)=(?<Value>.*)", _) ; Key = _Key, Value = _Value
2019-12-17 10:57:15 -06:00
If (_RESection)
{
_RESection := StrReplace(_RESection, " ", "_")
out[_RESection]:={}
currentSection := _RESection
} Else {
If (_Value)
{
_Key := StrReplace(_Key, " ", "_")
out[currentSection][_Key] := _Value
}
}
2020-01-24 03:24:06 -06:00
} Until (File.AtEOF)
File.Close()
2019-12-17 10:57:15 -06:00
Return out
}
2020-02-03 02:54:31 -06:00
ini_get(location, inSec, inKey)
2019-12-17 10:57:15 -06:00
{
ini_loaded := {}
ini_loaded := ini_load(location)
inSec := StrReplace(inSec, " ", "_")
inKey := StrReplace(inKey, " ", "_")
2020-02-03 02:54:31 -06:00
needed := ini_loaded[inSec][inKey]
if (needed) ; Without this it doesn't know what to return and gets stuck
{
Return needed
} Else Return false
2019-12-17 10:57:15 -06:00
}
2020-02-03 02:54:31 -06:00
ini_write(location, inKey, inValue)
2019-12-17 10:57:15 -06:00
{
FileRead, tempini, %location%
needle := inKey . "=.*"
replacement := inKey . "=" . inValue
tempini := RegExReplace(tempini, needle, replacement,, 1)
tempini := RegExReplace(tempini, "\R+\R", "`r`n")
2019-12-17 10:57:15 -06:00
FileAppend, %tempini%, tempini ; Append the fixed ini to a new file
FileCopy, tempini, %location%, 1 ; Copy the file over, overwriting existing contents
2020-01-09 06:16:22 -06:00
FileDelete, tempini ; Delete the fixed temporary ini
2022-03-29 14:32:47 -05:00
}