Update 'func.ahk'

This commit is contained in:
David Daily 2020-01-24 03:24:06 -06:00
parent 03cfca5549
commit 7adfefb670
1 changed files with 16 additions and 56 deletions

View File

@ -29,75 +29,34 @@ GetInfo(xID) ; Accept what is passed here as the variable "xID" in the script
{
if (xID)
{
csv := FileOpen(A_MyDocuments "\Work_Docs\emails.csv", "r")
if RegExMatch(csv.Read, xID)
{
Loop {
ReadLine := csv.ReadLine()
Array := StrSplit(ReadLine,",")
} Until InStr(Array[1], xID)
csv.Close()
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
Return Test
} Else
{
Return Test.xid := "0"
}
Loop, Read, %A_MyDocuments%\Work_Docs\emails.csv ; read every line of "emails.csv"
{
Array := StrSplit(A_LoopReadLine,",") ; 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,
Break ; stop searching
}
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
Return Test
}
if !(xID)
{
Return Test.xid := "0"
Return
}
}
SetInfo(xID, column, value)
{
StringUpper, xID, xID ;just to make sure
if (xID)
{
csv := FileOpen(A_MyDocuments "\Work_Docs\emails.csv", "r")
Array := []
Dealinfo := []
Loop {
ReadLine := csv.ReadLine()
Array := StrSplit(ReadLine,",")
usrid := Array[1]
Dealinfo[usrid] := {xid: Array[1], email: Array[2], name: Array[3], user: Array[4], org: Array[5]}
} Until (csv.AtEOF)
csv.Close()
Switch column
{
Case "email": Dealinfo[xID].email := value
Case "name": Dealinfo[xID].name := value
Case "user": Dealinfo[xID].user := value
Case "org": Dealinfo[xID].org := value
}
for k in Dealinfo
{
tempcsv .= Dealinfo[k].xid . "," . Dealinfo[k].email . "," . Dealinfo[k].name . "," . Dealinfo[k].user . "," . Dealinfo[k].org
}
csv := A_MyDocuments . "\Work_Docs\emails.csv"
FileAppend, %tempcsv%, tempcsv
FileCopy, tempcsv, %csv%, 1
FileDelete, tempcsv
Return true
} Else Return false
}
;------------------------------------------------------------------------------
; INI Manipulation that supports UTF-8
;------------------------------------------------------------------------------
ini_load(location)
{
File := FileOpen(location, "r")
out := {}
Loop, Read, %location%
Loop
{
RegExMatch(A_LoopReadLine, "(?<=\[).*(?=\])", _RESection) ; Matches section name
RegExMatch(A_LoopReadLine, "(?<Key>.*)=(?<Value>.*)", _) ; Key = _Key, Value = _Value
Line := File.ReadLine()
RegExMatch(Line, "(?<=\[).*(?=\])", _RESection) ; Matches section name
RegExMatch(Line, "(?<Key>.*)=(?<Value>.*)", _) ; Key = _Key, Value = _Value
If (_RESection)
{
@ -111,7 +70,8 @@ ini_load(location)
out[currentSection][_Key] := _Value
}
}
}
} Until (File.AtEOF)
File.Close()
Return out
}