diff --git a/UnityProject/Assets/Scripts/Core/Database/ServerData.ServerStatus.cs b/UnityProject/Assets/Scripts/Core/Database/ServerData.ServerStatus.cs index 3ef286bd9f4..50da869b842 100644 --- a/UnityProject/Assets/Scripts/Core/Database/ServerData.ServerStatus.cs +++ b/UnityProject/Assets/Scripts/Core/Database/ServerData.ServerStatus.cs @@ -130,6 +130,8 @@ private async Task SendServerStatus() status.ForkName = buildInfo.ForkName; status.BuildVersion = buildInfo.BuildNumber; + status.GoodFileVersion = buildInfo.GoodFileVersion; + if (SubSceneManager.Instance == null) { status.CurrentMap = "loading"; @@ -294,6 +296,7 @@ public class ServerStatus public string OSXDownload; public string LinuxDownload; public int fps; + public string GoodFileVersion; } //Read from Streaming Assets/config/config.json on the server @@ -364,5 +367,8 @@ public class BuildInfo public int BuildNumber; //I.E. Unitystation, ColonialMarines, BeeStation public string ForkName; + + //What good file version does this build use + public string GoodFileVersion; } } diff --git a/UnityProject/Assets/Scripts/Core/Editor/GrabGoodFileVersion.cs b/UnityProject/Assets/Scripts/Core/Editor/GrabGoodFileVersion.cs new file mode 100644 index 00000000000..288d53e8298 --- /dev/null +++ b/UnityProject/Assets/Scripts/Core/Editor/GrabGoodFileVersion.cs @@ -0,0 +1,90 @@ +using System; +using System.Diagnostics; +using DatabaseAPI; +using Logs; +using Newtonsoft.Json; +using SecureStuff; +using UnityEditor; +using UnityEditor.Build; +using UnityEngine; + +public class GrabGoodFileVersion : IPreprocessBuild +{ + public int callbackOrder + { + get { return 9; } + } + + public void OnPreprocessBuild(BuildTarget target, string path) + { + var Gamedata = AssetDatabase.LoadAssetAtPath( + "Assets/Prefabs/SceneConstruction/NestedManagers/GameData.prefab"); + if (Gamedata.GetComponent().DevBuild) + { + return; + } + + try + { + // Get the latest good-file version tag + string latestTag = GetLatestGoodFileVersion(); + + var BuildInfo = JsonConvert.DeserializeObject(AccessFile.Load("buildinfo.json")); + BuildInfo.GoodFileVersion = latestTag.Replace("good-file-", ""); + AccessFile.Save("buildinfo.json", JsonConvert.SerializeObject(BuildInfo)); + } + catch ( Exception ex) + { + Loggy.Warning( "Not able to set good file version " + ex.ToString()); + + } + } + + private string GetLatestGoodFileVersion() + { + try + { + // Set up the Git process to get tags + Process gitProcess = new Process + { + StartInfo = new ProcessStartInfo + { + FileName = "git", + Arguments = "tag --list good-file-* --sort=-v:refname", + RedirectStandardOutput = true, + RedirectStandardError = true, + UseShellExecute = false, + CreateNoWindow = true + } + }; + + UnityEngine.Debug.Log("[GrabGoodFileVersion] Running Git command to fetch tags..."); + UnityEngine.Debug.Log($"[GrabGoodFileVersion] Command: git {gitProcess.StartInfo.Arguments}"); + + // Start the process and capture the output + gitProcess.Start(); + string output = gitProcess.StandardOutput.ReadToEnd().Trim(); + string error = gitProcess.StandardError.ReadToEnd(); + gitProcess.WaitForExit(); + + UnityEngine.Debug.Log($"[GrabGoodFileVersion] Git process exited with code {gitProcess.ExitCode}."); + UnityEngine.Debug.Log($"[GrabGoodFileVersion] Standard Output:\n{output}"); + UnityEngine.Debug.Log($"[GrabGoodFileVersion] Standard Error:\n{error}"); + + if (gitProcess.ExitCode != 0) + { + UnityEngine.Debug.LogError($"[GrabGoodFileVersion] Git process failed with exit code {gitProcess.ExitCode}."); + return null; + } + + // Split the output into lines and take the first line as the latest tag + string[] tags = output.Split('\n'); + return tags.Length > 0 ? tags[0] : null;; + } + catch (System.Exception ex) + { + UnityEngine.Debug.LogError($"An error occurred while retrieving the Git tag: {ex.Message}"); + return null; + } + } +} diff --git a/UnityProject/Assets/Scripts/Core/Editor/GrabGoodFileVersion.cs.meta b/UnityProject/Assets/Scripts/Core/Editor/GrabGoodFileVersion.cs.meta new file mode 100644 index 00000000000..e550ed9bc8d --- /dev/null +++ b/UnityProject/Assets/Scripts/Core/Editor/GrabGoodFileVersion.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: d2a1b37e7284f174a9fea3b8a023856b \ No newline at end of file diff --git a/UnityProject/Assets/StreamingAssets/Config/buildinfo.json b/UnityProject/Assets/StreamingAssets/Config/buildinfo.json index ddffff17247..e8a09b983b6 100644 --- a/UnityProject/Assets/StreamingAssets/Config/buildinfo.json +++ b/UnityProject/Assets/StreamingAssets/Config/buildinfo.json @@ -1 +1 @@ -{"BuildNumber": 3921,"ForkName":"Unitystation"} \ No newline at end of file +{"BuildNumber":3921,"ForkName":"Unitystation","GoodFileVersion":"good-file-0.1.0"} \ No newline at end of file