diff --git a/TGServerService/App.config b/TGServerService/App.config
index 6b4ecc1601..6a7a0786db 100644
--- a/TGServerService/App.config
+++ b/TGServerService/App.config
@@ -56,7 +56,7 @@
0
- 4
+ 5
@@ -73,6 +73,9 @@
+
+ 0
+
diff --git a/TGServerService/Properties/Settings.Designer.cs b/TGServerService/Properties/Settings.Designer.cs
index 7a76d2a5ae..34304772d5 100644
--- a/TGServerService/Properties/Settings.Designer.cs
+++ b/TGServerService/Properties/Settings.Designer.cs
@@ -205,7 +205,7 @@ namespace TGServerService.Properties {
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("4")]
+ [global::System.Configuration.DefaultSettingValueAttribute("5")]
public int SettingsVersion {
get {
return ((int)(this["SettingsVersion"]));
@@ -274,5 +274,17 @@ namespace TGServerService.Properties {
this["ReattachAPIVersion"] = value;
}
}
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("0")]
+ public ulong AutoUpdateInterval {
+ get {
+ return ((ulong)(this["AutoUpdateInterval"]));
+ }
+ set {
+ this["AutoUpdateInterval"] = value;
+ }
+ }
}
}
diff --git a/TGServerService/Properties/Settings.settings b/TGServerService/Properties/Settings.settings
index 5618f8cd97..a417d94fbd 100644
--- a/TGServerService/Properties/Settings.settings
+++ b/TGServerService/Properties/Settings.settings
@@ -48,7 +48,7 @@
0
- 4
+ 5
@@ -65,5 +65,8 @@
+
+ 0
+
\ No newline at end of file
diff --git a/TGServerService/Repository.cs b/TGServerService/Repository.cs
index 2b6bf6a3b5..4ec88a7370 100644
--- a/TGServerService/Repository.cs
+++ b/TGServerService/Repository.cs
@@ -30,6 +30,11 @@ namespace TGServerService
Repository Repo;
int currentProgress = -1;
+ System.Timers.Timer autoUpdateTimer = new System.Timers.Timer()
+ {
+ AutoReset = true
+ };
+
///
/// Repo specific information about the installation
/// Requires RepoLock and !RepoBusy to be instantiated
@@ -143,6 +148,9 @@ namespace TGServerService
UpdateInterfaceDll(false);
if(LoadRepo() == null)
DisableGarbageCollectionNoLock();
+ //start the autoupdate timer
+ autoUpdateTimer.Elapsed += AutoUpdateTimer_Elapsed;
+ SetAutoUpdateInterval(Properties.Settings.Default.AutoUpdateInterval);
}
bool RepoConfigsMatch()
@@ -556,13 +564,17 @@ namespace TGServerService
//public api
public string Update(bool reset)
+ {
+ return UpdateImpl(reset, true);
+ }
+
+ string UpdateImpl(bool reset, bool successOnUpToDate)
{
lock (RepoLock)
{
var result = LoadRepo();
if (result != null)
return result;
- SendMessage(String.Format("REPO: Updating origin branch...({0})", reset ? "Hard Reset" : "Merge"), ChatMessageType.DeveloperInfo);
try
{
if (Repo.Head == null || !Repo.Head.IsTracking)
@@ -573,6 +585,11 @@ namespace TGServerService
return res;
var originBranch = Repo.Head.TrackedBranch;
+ if (!successOnUpToDate && Repo.Head.Tip.Sha == originBranch.Tip.Sha)
+ return RepoErrorUpToDate;
+
+ SendMessage(String.Format("REPO: Updating origin branch...({0})", reset ? "Hard Reset" : "Merge"), ChatMessageType.DeveloperInfo);
+
if (reset)
{
var error = ResetNoLock(Repo.Head.TrackedBranch);
@@ -1179,6 +1196,33 @@ namespace TGServerService
}
}
+ ///
+ public void SetAutoUpdateInterval(ulong newInterval)
+ {
+ lock (autoUpdateTimer)
+ {
+ autoUpdateTimer.Stop();
+ if (newInterval > 0) {
+ autoUpdateTimer.Interval = newInterval * 60 * 1000; //convert from minutes to ms
+ autoUpdateTimer.Start();
+ }
+ }
+ Properties.Settings.Default.AutoUpdateInterval = newInterval;
+ }
+
+ public ulong AutoUpdateInterval()
+ {
+ return Properties.Settings.Default.AutoUpdateInterval;
+ }
+
+ private void AutoUpdateTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
+ {
+ if (UpdateImpl(true, false) == null)
+ {
+ Compile(true);
+ }
+ }
+
//public api
public bool SetPythonPath(string path)
{
diff --git a/TGServiceInterface/Repository.cs b/TGServiceInterface/Repository.cs
index da0ef9d8c5..eab2a89a8d 100644
--- a/TGServiceInterface/Repository.cs
+++ b/TGServiceInterface/Repository.cs
@@ -225,5 +225,19 @@ namespace TGServiceInterface
/// null on success, error message on failure
[OperationContract]
string UpdateTGS3Json();
+
+ ///
+ /// (De)Activate and set the interval for the automatic server updater
+ ///
+ /// Interval to check for updates in minutes, disables if zero
+ [OperationContract]
+ void SetAutoUpdateInterval(ulong newInterval);
+
+ ///
+ /// Get the current autoupdate interval
+ ///
+ /// The current auto update interval or zero if it's disabled
+ [OperationContract]
+ ulong AutoUpdateInterval();
}
}