;;; ;;; Establish concurrent checks to trigger intrinsic events (a programmable object) ;;; class Async { ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; instantiate ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; __New() { this.interval := 1000 ; one second (base metric) ; this.gofastest := 6 ; 1/10 minute (6 seconds) this.gofast := 60 ; 1 minute this.gonormal := 360 ; 1/10 hour (6 minutes) this.goslow := 3600 ; 1 hour this.goslowest := 43200 ; 1/2 day (6 hours * 2) ; this.dofastest := "DoTrace" ; task is most frequent this.dofast := "DoUpdate" ; task is frequent this.donormal := "DoDownload" ; task is normal this.doslow := "DoReload" ; task is infrequent this.doslowest := "DoUnload" ; task is least frequent FileGetTime, DiskDT, %A_ScriptFullPath% LoadDT := A_Now RegRead, PlaceIndex, HKEY_CURRENT_USER, Environment, AcePlace this.inmemory := DiskDT this.tomemory := LoadDT this.Place := PlaceIndex this.count := 0 this.ondisk := "" SplitPath, A_ScriptFullPath, sFile, sPath, sExt, sName, sDrive this.ScriptName := sName If (sName = "ACE" or sName = "FACE") { RegWrite, REG_SZ, HKEY_CURRENT_USER, Software\ACE, Async(%sName%).Path, %sPath% RegWrite, REG_SZ, HKEY_CURRENT_USER, Software\ACE, Async(%sName%).Load, %LoadDT% } this.timer := ObjBindMethod(this, "Tick") } ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; method ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DoTrace() { ; ; log AcePlace value if AcePlace has changed - see FacePath\FaceAbout\places.log ; If (AcePlace = "") ; only proper scripts may monitor 'place position' return PlaceWas := this.Place RegRead, PlaceIs, HKEY_CURRENT_USER, Environment, AcePlace this.DoMessage(PlaceIs . " ()", .5) If (PlaceIs = PlaceWas) ; place position has NOT changed Return ; EXIT, below code has to do with change in place Else this.Place := PlaceIs If (this.ScriptName <> "ACE") { ; only the proper ACE script writes to Trace log If (this.ScriptName = "PLACE") ; PLACE scripts disconnect when not at their place ExitApp ; so unload (remember... If (PlaceIs = this.Place) Else ; any other script Return ; simply does nothing regardless } FileName := FaceNotesPath . "\Where@.txt" ; 110317 from: FileName := AcePath . "\today.txt" File := FileOpen(FileName, "a") If !IsObject(File) { this.DoMessage("Can't write: " . FileName, 30) Return } Writing := A_Now . "`t" . FaceID . "`t" . PlaceIs . "`t" . AceID . "`tWORD`twas@" . PlaceWas . "`r`n" File.Write(Writing) File.Close() this.DoMessage("TravelLog(" . PlaceIs . ")", 3) return } DoDownload() { ; ; download and prompt to install the public release script (if newer release) ; this.DoMessage("DoDowload() is NOT finished", 5) } DoReload() { ; ; when bugs exist this reduces exposure - restart script ; this.DoMessage("DoReload() is NOT finished but reloading NOW.", 10) Reload } DoUnload() { ; ; time to die - prevents conflicts with a backup process ; this.DoMessage("ACE script (" . A_ScriptName . ") is unloading to avoid conflicts with backup procedures.", 15) ExitApp } ;;; Add(CheckItem, CheckSpeed) { ;;; ;;; If (CheckItem <> "Trace" and CheckItem <> "Unload" and CheckItem <> "Reload" and CheckItem <> "Update" and CheckItem <> "Download") ;;; Return "Item to check is not recognized (" . CheckItem . ")" . "`n" ;;; If (CheckSpeed <> "Fastest" and CheckSpeed <> "Fast" and CheckSpeed <> "Normal" and CheckSpeed <> "Slow" and CheckSpeed <> "Slowest") ;;; Return "Speed to check is not recognized (" . CheckSpeed . ")" . "`n" ;;; ;;; this.dofastest := "Do" . CheckItem ;;; msgbox Async.Add`n`nDo%CheckSpeed% := Do%CheckItem% ;;; Return ;;; } ;;; ;;; ;;; DoUpdate() { ; ; check if new release is in-place (on disk vs in memory) - if so, notify of restart ; FileGetTime, DiskDT, %A_ScriptFullPath% ; add ,C for Creation date this.ScriptDiskDT := DiskDT If (this.ScriptDiskDT = this.ScriptMemoryDT) Return ; this.CountDownFrom := 30 ; this.CountDownIn := 1 this.DoMessage("Update - restart in 30...", 30) ;;; MsgBox, 64, ACE Async, Just noticed you were pushed an update.`n`n■`t%A_ScriptName%`n`nwill now restart., 300 this.DoReload() } DoJunction(Destiny) { If (Destiny = "DoDownload") this.DoDownload() If (Destiny = "DoReload") this.DoReload() If (Destiny = "DoTrace") this.DoTrace() If (Destiny = "DoUnload") this.DoUnload() If (Destiny = "DoUpdate") this.DoUpdate() } Start() { timer := this.timer SetTimer % timer, % this.interval this.DoMessage(this.name . " has started...", 3) } Stop() { timer := this.timer SetTimer % timer, Off this.DoMessage(this.name . " was stopped", 3) } Tick() { this.count += 1 if (this.countdownfrom > 0) if (this.countdownin = 0) { Tooltip % this.countdownfrom this.countdownfrom -= 1 if (this.countdownfrom = 0) { sleep 1000 Tooltip % this.countdownfrom sleep 500 Tooltip } } else this.countdownin -= 1 if (Mod(this.count, this.gofastest) = 0) { this.DoJunction(this.dofastest) } if (Mod(this.count, this.gofast) = 0) { this.DoJunction(this.dofast) } if (Mod(this.count, this.gonormal) = 0) { this.DoJunction(this.donormal) } if (Mod(this.count, this.goslow) = 0) { this.DoJunction(this.doslow) } if (Mod(this.count, this.goslowest) = 0) { this.DoJunction(this.doslowest) } } DoMessage(Msg, Sec) { If (Msg > "") { HowLong := Sec * this.interval ThisCNT := this.count Msg := this.ScriptName . "." . Msg StringReplace, Msg, Msg, , %ThisCNT% SplashTextOn, , , % Msg Sleep, %HowLong% SplashTextOff } } ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; get/set ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Factor[] { get{ return this.interval } set{ this.interval := value }} Fastest[] { get{ return this.gofastest ; * this.interval } set{ this.gofastest := value }} Fast[] { get{ return this.gofast ; * this.interval } set{ this.gofast := value }} Normal[] { get{ return this.gonormal ; * this.interval } set{ this.gonormal := value }} Slow[] { get{ return this.goslow ; * this.interval } set{ this.goslow := value }} Slowest[] { get{ return this.goslowest ; * this.interval } set{ this.goslowest := value }} CountDownFrom[] { get{ return this.countfrom } set{ this.countfrom := value }} CountDownIn[] { get{ return this.counting } set{ this.counting := value }} ScriptDiskDT[] { get{ return this.ondisk } set{ this.ondisk := value }} ScriptMemoryDT[] { get{ return this.inmemory } set{ this.inmemory := value }} ScriptLoadDT[] { get{ return this.tomemory } set{ this.tomemory := value }} ScriptName[] { get{ return this.scriptfilename } set{ this.scriptfilename := value }} Place[] { get{ return this.placenum ; this must not remain static } set{ this.placenum := value }} }