fix looping bug

Changed to reading the time the file was last modified instead of its contents, much more reliable.
Thanks nou on the AHK discord for the help!
This commit is contained in:
David Daily 2020-01-02 05:31:40 -06:00
parent a3c9c9ed1b
commit 31751b4066

31
D3K.ahk
View File

@ -1,7 +1,5 @@
#Include, func.ahk
lastFileContent =
Menu, Tray, Icon, shell32.dll, 283 ; Set the tray icon to a keyboard
SetWorkingDir, %A_MyDocuments%\D3K ; Make sure we can find the .ahks linked below
@ -73,23 +71,17 @@ If (glovar = 1)
SetTimer, GloVar, 2000 ; Check every 2 seconds
GloVar:
If FileExist("glovar.ahk")
{
Run glovar.ahk
}
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
{
fileread, newFileContent, %glovarini%
if !(newFileContent = lastFileContent) ; 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.
{
lastFileContent := newFileContent
gvMod := gvModNew
FileDelete, glovar.ahk ; Start with a clean slate
FileAppend, #SingleInstance force`n`n, glovar.ahk ; makes sure we only have one instance of the script running at a time
RESection := "" ; Make sure that its clear
Loop, Read, %glovarini% ; Read one line at a time
{
RegExMatch(A_LoopReadLine, "(?<=\[).*(?=\])", RESection) ; explained above
@ -107,7 +99,7 @@ GloVar:
WinWaitNotActive, GloVar.ini ; Just to make sure
{
ini_writeValue(glovarini, REKey, REValue)
fileread, lastFileContent, %glovarini%
FileGetTime, gvMod, %glovarini%
}
}
If InStr(StoredSection, "Operations Center") ; If the section is "Operations Center" and the Key "un", make it uppercase
@ -118,7 +110,7 @@ GloVar:
WinWaitNotActive, GloVar.ini
{
ini_writeValue(glovarini, REKey, REValue) ; Writes the properly formatted case number to glovar.ini
fileread, lastFileContent, %glovarini%
FileGetTime, gvMod, %glovarini%
}
}
}
@ -131,14 +123,14 @@ GloVar:
WinWaitNotActive, GloVar.ini
{
ini_writeValue(glovarini, REKey, REMatch) ; Writes the properly formatted case number to glovar.ini
fileread, lastFileContent, %glovarini%
FileGetTime, gvMod, %glovarini%
}
REValue := REMatch
} Else {
WinWaitNotActive, GloVar.ini
{
ini_writeValue(glovarini, REKey, REValue) ; Writes the properly formatted case number to glovar.ini
fileread, lastFileContent, %glovarini%
FileGetTime, gvMod, %glovarini%
}
}
}
@ -155,8 +147,7 @@ GloVar:
ini_writeValue(glovarini, "dus", dealinfo.user) ; Writes demo account name (somewhat useful)
ini_writeValue(glovarini, "xID", REValue) ; Writes the xID entered, but uppercase
}
fileread, lastFileContent, %glovarini% ; Make sure that this script knows what the ini was changed to so it doesn't constantly run through the above code
Break
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 (RESection) ; If we have a section
@ -171,14 +162,14 @@ GloVar:
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
FileCopy, glovarsource, %glovarini%, 1 ; Copies and replaces any text in glovar.ini with the template
fileread, lastFileContent, %glovarini% ; Make sure that this script knows what the ini was changed to so it doesn't constantly run through the above code
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, #SingleInstance force`n`n, glovar.ahk
Sleep, 500
}
}
}
fileread, lastFileContent, %glovarini% ; Make sure that this script knows what the ini was changed to so it doesn't constantly run through the above code
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