mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-25 05:56:58 +01:00
Adds automatic updating
This commit is contained in:
@@ -56,7 +56,7 @@
|
||||
<value>0</value>
|
||||
</setting>
|
||||
<setting name="SettingsVersion" serializeAs="String">
|
||||
<value>4</value>
|
||||
<value>5</value>
|
||||
</setting>
|
||||
<setting name="ReattachCommsKey" serializeAs="String">
|
||||
<value />
|
||||
@@ -73,6 +73,9 @@
|
||||
<setting name="ReattachAPIVersion" serializeAs="String">
|
||||
<value />
|
||||
</setting>
|
||||
<setting name="AutoUpdateInterval" serializeAs="String">
|
||||
<value>0</value>
|
||||
</setting>
|
||||
</TGServerService.Properties.Settings>
|
||||
</userSettings>
|
||||
</configuration>
|
||||
|
||||
+13
-1
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
<Value Profile="(Default)">0</Value>
|
||||
</Setting>
|
||||
<Setting Name="SettingsVersion" Type="System.Int32" Scope="User">
|
||||
<Value Profile="(Default)">4</Value>
|
||||
<Value Profile="(Default)">5</Value>
|
||||
</Setting>
|
||||
<Setting Name="ReattachCommsKey" Type="System.String" Scope="User">
|
||||
<Value Profile="(Default)" />
|
||||
@@ -65,5 +65,8 @@
|
||||
<Setting Name="ReattachAPIVersion" Type="System.String" Scope="User">
|
||||
<Value Profile="(Default)" />
|
||||
</Setting>
|
||||
<Setting Name="AutoUpdateInterval" Type="System.UInt64" Scope="User">
|
||||
<Value Profile="(Default)">0</Value>
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
||||
@@ -30,6 +30,11 @@ namespace TGServerService
|
||||
Repository Repo;
|
||||
int currentProgress = -1;
|
||||
|
||||
System.Timers.Timer autoUpdateTimer = new System.Timers.Timer()
|
||||
{
|
||||
AutoReset = true
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -225,5 +225,19 @@ namespace TGServiceInterface
|
||||
/// <returns>null on success, error message on failure</returns>
|
||||
[OperationContract]
|
||||
string UpdateTGS3Json();
|
||||
|
||||
/// <summary>
|
||||
/// (De)Activate and set the interval for the automatic server updater
|
||||
/// </summary>
|
||||
/// <param name="newInterval">Interval to check for updates in minutes, disables if zero</param>
|
||||
[OperationContract]
|
||||
void SetAutoUpdateInterval(ulong newInterval);
|
||||
|
||||
/// <summary>
|
||||
/// Get the current autoupdate interval
|
||||
/// </summary>
|
||||
/// <returns>The current auto update interval or zero if it's disabled</returns>
|
||||
[OperationContract]
|
||||
ulong AutoUpdateInterval();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user