compressed code, improved some logic

This commit is contained in:
David Daily 2020-05-22 13:41:42 -05:00
parent b4637072a2
commit c7d3567790
1 changed files with 116 additions and 135 deletions

251
D3K.ahk
View File

@ -62,153 +62,134 @@ ger := ini_get(ini, "Language", "German")
If (glovar = 1)
{
glovarini := A_MyDocuments "\GloVar.ini" ; Location of the ini that the user modifies
glovarstart := "#SingleInstance force`n`n:*:$dorg::`n:*:$dus::`n:*:$dnm::`n:*:$dem::`n:*:$xid::`n"
SetTimer, GloVar, 2000 ; Check every 2 seconds
GloVar:
WinWaitNotActive, GloVar.ini ; So that we don't get any problems with the file on disk being out of date. I use VSCode with the "Save on lose focus" option on, YMMV
FileGetTime, gvModNew, %glovarini%
if !(gvModNew = gvMod) ; Those two lines mean the rest of this only executes if there were changes to the ini.
{
FileGetTime, gvModNew, %glovarini%
if !(gvModNew = gvMod) ; Those two lines mean the rest of this only executes if there were changes to the ini.
gvMod := gvModNew
FileDelete, glovar.ahk ; Start with a clean slate
FileAppend, %glovarstart%, glovar.ahk ; makes sure we only have one instance of the script running at a time
RESection := "" ; Make sure that its clear
file := FileOpen(glovarini, "r")
Loop ; Read one line at a time
{
gvMod := gvModNew
FileDelete, glovar.ahk ; Start with a clean slate
FileAppend, %glovarstart%, glovar.ahk ; makes sure we only have one instance of the script running at a time
Line := file.ReadLine()
RegExMatch(Line, "(?<=\[).*(?=\])", RESection) ; explained above
RegExMatch(Line, "^(?<Key>.*)=(?<Value>.*)", RE) ; Key = REKey, Value = REValue
RESection := "" ; Make sure that its clear
file := FileOpen(glovarini, "r")
Loop ; Read one line at a time
If (RESection && InStr(StoredSection := RESection, "clear")) ; Found a clear section
{
Line := file.ReadLine()
RegExMatch(Line, "(?<=\[).*(?=\])", RESection) ; explained above
RegExMatch(Line, "^(?<Key>.*)=(?<Value>.*)", RE) ; Key = REKey, Value = REValue
If !(RESection) ; If the RegEx doesn't find antything, its empty
; Will clear the ini and save its and the documentation file's contents to a log
FileRead, doctemp, %docfile% ; Read documentation file, set in settings
FileRead, initemp, %glovarini% ; Read the ini
initemp := RegExReplace(initemp, "(?<=\[)clear(?=\])", "Info") ; Replace the "clear" section we set with Info
CurrTime := GetDateTime("en") ; get the current date and time as "YYYY-MM-DD at HH:MM GMT"
writethis := "Case on " . CurrTime . "`n" . doctemp . "`n`n" . initemp ; Save the current time, what was in the doc file, and glovarini to a variable
FileAppend, % "`n`n`n`n" writethis "`n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", %A_MyDocuments%/D3KLog.txt ; Write a few new lines , the content, and a line underneath
FileAppend,, temptemp
FileCopy, glovarsource, %glovarini%, 1 ; Copies and replaces any text in glovar.ini with the template
FileCopy, temptemp, %docfile%, 1 ; These two this close together makes it look like they get cleared at the same time
FileDelete, temptemp
fileread, gvMod, %glovarini% ; Make sure that this script knows what the ini was changed to so it doesn't constantly run through the above code
FileDelete, glovar.ahk ; THE CLEAN SLATE
FileAppend, %glovarstart%, glovar.ahk
Sleep, 500
FileGetTime, gvMod, %glovarini% ; Make sure that this script knows what the ini was changed to so it doesn't constantly run through the above code
If FileExist("glovar.ahk")
{
If !(REValue) ; If there is no value for the key, skip it (Continue the loop at the next line)
{
Continue
}
If InStr(StoredSection, "Serial Numbers") ; If the section is "Serial Numbers", make everything uppercase
{
StringUpper, REValue, REValue ; Makes it uppercase
WinWaitNotActive, GloVar.ini ; Just to make sure
{
ini_write(glovarini, REKey, REValue)
FileGetTime, gvMod, %glovarini%
}
}
If InStr(StoredSection, "Operations Center") ; If the section is "Operations Center" and the Key "un", make it uppercase
{
If InStr(REKey, "usr")
{
StringUpper, REValue, REValue ; Makes it uppercase
WinWaitNotActive, GloVar.ini
{
ini_write(glovarini, REKey, REValue) ; Writes the properly formatted case number to glovar.ini
FileGetTime, gvMod, %glovarini%
}
}
}
If InStr(REKey, "case") ; If a key contains "case". Case numbers are all in the format "LETTERS-NUMBERS".
{
StringUpper, REValue, REValue ; Makes it uppercase
RegExMatch(REValue, "(?<=\().*(?=\))", REMatch) ; Match everything but the parenthesis. When the case numbers are shown they have parenthesis, and those are annoying.
If (REMatch) ; If there's anything there
{
WinWaitNotActive, GloVar.ini
{
ini_write(glovarini, REKey, REMatch) ; Writes the properly formatted case number to glovar.ini
FileGetTime, gvMod, %glovarini%
}
REValue := REMatch
} Else {
WinWaitNotActive, GloVar.ini
{
ini_write(glovarini, REKey, REValue) ; Writes the properly formatted case number to glovar.ini
FileGetTime, gvMod, %glovarini%
}
}
}
If InStr(REKey, "xid") ; If an xID is entered. Unique identifier for people
{
dealinfo := GetInfo(REValue) ; Gets information, see function for details
StringUpper, REValue, REValue ; Makes xID uppercase
if !(REValue = dealinfo.xid)
{
run addemail.ahk
Continue
}
; Replace the data in glovar.ahk with the data from the ini
FileRead, tempglovar, glovar.ahk
tempglovar := RegExReplace(tempglovar, "(?<=\$xid::).*", dealinfo.xid)
tempglovar := RegExReplace(tempglovar, "(?<=\$dem::).*", dealinfo.email)
tempglovar := RegExReplace(tempglovar, "(?<=\$dnm::).*", dealinfo.name)
tempglovar := RegExReplace(tempglovar, "(?<=\$dus::).*", dealinfo.user)
tempglovar := RegExReplace(tempglovar, "(?<=\$dorg::).*", dealinfo.org)
FileAppend, %tempglovar%, tempglovar
FileCopy, tempglovar, glovar.ahk,1
FileDelete, tempglovar
WinWaitNotActive, GloVar.ini
{
ini_write(glovarini, "xID", dealinfo.xid) ; Writes the xID
ini_write(glovarini, "dem", dealinfo.email) ; Writes email address (incredibly useful)
ini_write(glovarini, "dnm", dealinfo.name) ; Writes Name (useful for when referring to that person)
ini_write(glovarini, "dus", dealinfo.user) ; Writes demo account name (somewhat useful)
ini_write(glovarini, "dorg", dealinfo.org)
}
FileGetTime, gvMod, %glovarini% ; Make sure that this script knows what the ini was changed to so it doesn't constantly run through the above code
Continue
}
If (InStr(REKey, "dem") or InStr(REKey, "dnm") or InStr(REKey, "dus"))
{
; Do not process xID related info, that is done above
Continue
}
writethis := ":*:$" REKey "::" REValue "`n" ; Save the hotstring to a variable
FileAppend, %writethis%, glovar.ahk ; Write the variable to glovar.ahk
Run glovar.ahk
}
If (RESection) ; If we have a section
{
StoredSection := RESection
If InStr(RESection, "clear") ; Will clear the ini and save its and the documentation file's contents to a log
{
FileRead, doctemp, %docfile% ; Read documentation file, set in settings
FileRead, initemp, %glovarini% ; Read the ini
initemp := RegExReplace(initemp, "(?<=\[)clear(?=\])", "Info") ; Replace the "clear" section we set with Info
CurrTime := GetDateTime("en") ; get the current date and time as "YYYY-MM-DD at HH:MM GMT"
writethis := "Case on " . CurrTime . "`n" . doctemp . "`n`n" . initemp ; Save the current time, what was in the doc file, and glovarini to a variable
FileAppend, % "`n`n`n`n" writethis "`n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", %A_MyDocuments%/D3KLog.txt ; Write a few new lines , the content, and a line underneath
FileAppend,, temptemp
FileCopy, glovarsource, %glovarini%, 1 ; Copies and replaces any text in glovar.ini with the template
FileCopy, temptemp, %docfile%, 1 ; These two this close together makes it look like they get cleared at the same time
FileDelete, temptemp
fileread, gvMod, %glovarini% ; Make sure that this script knows what the ini was changed to so it doesn't constantly run through the above code
FileDelete, glovar.ahk ; THE CLEAN SLATE
FileAppend, %glovarstart%, glovar.ahk
Sleep, 500
FileGetTime, gvMod, %glovarini% ; Make sure that this script knows what the ini was changed to so it doesn't constantly run through the above code
If FileExist("glovar.ahk")
{
Run glovar.ahk
}
Return
}
}
} Until (file.AtEOF)
file.Close()
FileGetTime, gvMod, %glovarini% ; Make sure that this script knows what the ini was changed to so it doesn't constantly run through the above code
If FileExist("glovar.ahk")
{
Run glovar.ahk
Return
} else if (RESection) { ; found a different section
StoredSection := RESection
continue
}
If !(RESection) ; If the RegEx doesn't find antything, its empty
{
If !(REValue) ; If there is no value for the key, skip it (Continue the loop at the next line)
{
Continue
}
If InStr(StoredSection, "Serial Numbers") ; If the section is "Serial Numbers", make everything uppercase
{
StringUpper, REValue, REValue ; Makes it uppercase
WinWaitNotActive, GloVar.ini ; Just to make sure
ini_write(glovarini, REKey, REValue)
FileGetTime, gvMod, %glovarini%
MsgBox, test
}
If InStr(StoredSection, "Operations Center") ; If the section is "Operations Center" and the Key "un", make it uppercase
{
If InStr(REKey, "usr")
{
StringUpper, REValue, REValue ; Makes it uppercase
WinWaitNotActive, GloVar.ini
ini_write(glovarini, REKey, REValue) ; Writes the properly formatted case number to glovar.ini
FileGetTime, gvMod, %glovarini%
}
}
If InStr(REKey, "case") ; If a key contains "case". Case numbers are all in the format "LETTERS-NUMBERS".
{
StringUpper, REValue, REValue ; Makes it uppercase
RegExMatch(REValue, "(?<=\().*(?=\))", REMatch) ; Match everything but the parenthesis. When the case numbers are shown they have parenthesis, and those are annoying.
If (REMatch) ; If there's anything there
{
WinWaitNotActive, GloVar.ini
ini_write(glovarini, REKey, REMatch) ; Writes the properly formatted case number to glovar.ini
FileGetTime, gvMod, %glovarini%
REValue := REMatch
} Else {
WinWaitNotActive, GloVar.ini
ini_write(glovarini, REKey, REValue) ; Writes the properly formatted case number to glovar.ini
FileGetTime, gvMod, %glovarini%
}
}
If InStr(REKey, "xid") ; If an xID is entered. Unique identifier for people
{
dealinfo := GetInfo(REValue) ; Gets information, see function for details
StringUpper, REValue, REValue ; Makes xID uppercase
if !(REValue = dealinfo.xid)
{
run addemail.ahk
Continue
}
; Replace the data in glovar.ahk with the data from the ini
FileRead, tempglovar, glovar.ahk
tempglovar := RegExReplace(tempglovar, "(?<=\$xid::).*", dealinfo.xid)
tempglovar := RegExReplace(tempglovar, "(?<=\$dem::).*", dealinfo.email)
tempglovar := RegExReplace(tempglovar, "(?<=\$dnm::).*", dealinfo.name)
tempglovar := RegExReplace(tempglovar, "(?<=\$dus::).*", dealinfo.user)
tempglovar := RegExReplace(tempglovar, "(?<=\$dorg::).*", dealinfo.org)
FileAppend, %tempglovar%, tempglovar
FileCopy, tempglovar, glovar.ahk,1
FileDelete, tempglovar
WinWaitNotActive, GloVar.ini
ini_write(glovarini, "xID", dealinfo.xid) ; Writes the xID
ini_write(glovarini, "dem", dealinfo.email) ; Writes email address (incredibly useful)
ini_write(glovarini, "dnm", dealinfo.name) ; Writes Name (useful for when referring to that person)
ini_write(glovarini, "dus", dealinfo.user) ; Writes demo account name (somewhat useful)
ini_write(glovarini, "dorg", dealinfo.org)
FileGetTime, gvMod, %glovarini% ; Make sure that this script knows what the ini was changed to so it doesn't constantly run through the above code
Continue
}
If (InStr(REKey, "dem") or InStr(REKey, "dnm") or InStr(REKey, "dus"))
{
; Do not process xID related info, that is done above
Continue
}
writethis := ":*:$" REKey "::" REValue "`n" ; Save the hotstring to a variable
FileAppend, %writethis%, glovar.ahk ; Write the variable to glovar.ahk
}
} Until (file.AtEOF)
file.Close()
FileGetTime, gvMod, %glovarini% ; Make sure that this script knows what the ini was changed to so it doesn't constantly run through the above code
If FileExist("glovar.ahk")
{
Run glovar.ahk
}
}
Return