Sub Class_Globals
Private lm As Long
Private tmrHook As Timer
Private threadName As String
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize()
tmrHook.Initialize("t",2000)
tmrHook.Enabled = True
threadName = getcurrentThreadName
Main.filewatcher1 = Me
writelog($"Thread Initialized, Watching ${Main.SettingsFile}"$)
StartMessageLoop
End Sub
Public Sub Stop
writelog($"Thread Stopped"$)
tmrHook.Enabled = False
StopMessageLoop
End Sub
Sub t_Tick
Dim d As Long
If Main.restartingServer Then
Return
End If
If File.Exists(Main.appPath, Main.SettingsFile) Then
If lm = 0 Then
lm = File.LastModified(Main.appPath, Main.SettingsFile)
End If
d = File.LastModified(Main.appPath, Main.SettingsFile)
If lm <> d Then
lm = d
writelog(Main.SettingsFile & " has been modified, reload settings.")
mod_settings.load_settings
' // do we have the restart key
If Main.SettingsMap.ContainsKey("restart_server") Then
Dim v As Int = Main.SettingsMap.GetDefault("restart_server",0)
If v = 1 Then
writelog("Restarting Server ... ")
' // reset the value
Main.SettingsMap.Put("restart_server",0)
' // update the settings file
File.WriteMap(Main.appPath, Main.SettingsFile, Main.SettingsMap)
' // call the restart
CallSubDelayed2(Main,"RestartServer",True)
End If
End If
End If
End If
End Sub
Sub getcurrentThreadName As String
Dim t As JavaObject
Return t.InitializeStatic("java.lang.Thread").RunMethodJO("currentThread", Null).RunMethod("getName", Null)
End Sub
Sub writelog(pData As String)
Try
CallSubDelayed3(Main.logger1,"writelog",DateTime.Now,threadName & ":INFO:filewatcher│" & pData)
Catch
Log(threadName & ":INFO:filewatcher│" & pData)
End Try
End Sub