Skip to content

Commit 0a4e9e1

Browse files
author
Bish
committed
Migrate 'legacy' installs to new version
1 parent 224625b commit 0a4e9e1

2 files changed

Lines changed: 43 additions & 5 deletions

File tree

‎Torch.Server/Initializer.cs‎

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Threading.Tasks;
1212
using System.Windows;
1313
using System.Windows.Threading;
14+
using System.Xml.Linq;
1415
using NLog;
1516
using NLog.Targets;
1617
using Sandbox;
@@ -31,6 +32,7 @@ public class Initializer
3132
private static readonly Logger Log = LogManager.GetLogger(nameof(Initializer));
3233
private bool _init;
3334
private const string STEAMCMD_DIR = "steam/steamcmd";
35+
private const string STEAMCMD_LEGACY_DIR = "steamcmd";
3436
private const string STEAMCMD_ZIP = "temp.zip";
3537
private static readonly string STEAMCMD_PATH = $"{STEAMCMD_DIR}\\steamcmd.exe";
3638
private static readonly string RUNSCRIPT_PATH = $"{STEAMCMD_DIR}\\runscript.txt";
@@ -80,10 +82,10 @@ public bool Initialize(string[] args)
8082

8183
// This is what happens when Keen is bad and puts extensions into the System namespace.
8284
if (!Enumerable.Contains(args, "-noupdate"))
83-
RunSteamCmd();
85+
RunSteamCmd(PeekForceOverwriteRunscript());
8486

8587
var basePath = new FileInfo(typeof(Program).Assembly.Location).Directory.ToString();
86-
88+
8789

8890
InitConfig();
8991
if (!Config.Parse(args))
@@ -185,16 +187,25 @@ private void InitConfig()
185187
ConfigPersistent = Persistent<TorchConfig>.Load(configPath);
186188
}
187189

188-
public static void RunSteamCmd()
190+
public static void RunSteamCmd(bool forceOverwriteRunscript = true)
189191
{
190192
var log = LogManager.GetLogger("SteamCMD");
191193

194+
// Migrate from old layout (steamcmd/) to new layout (steam/steamcmd/)
195+
if (Directory.Exists(STEAMCMD_LEGACY_DIR) && !Directory.Exists(STEAMCMD_DIR))
196+
{
197+
log.Info("Migrating SteamCMD from legacy directory...");
198+
Directory.CreateDirectory("steam");
199+
Directory.Move(STEAMCMD_LEGACY_DIR, STEAMCMD_DIR);
200+
log.Info("SteamCMD migrated to steam/steamcmd.");
201+
}
202+
192203
if (!Directory.Exists(STEAMCMD_DIR))
193204
{
194205
Directory.CreateDirectory(STEAMCMD_DIR);
195206
}
196207

197-
if (!File.Exists(RUNSCRIPT_PATH))
208+
if (forceOverwriteRunscript || !File.Exists(RUNSCRIPT_PATH))
198209
File.WriteAllText(RUNSCRIPT_PATH, RUNSCRIPT);
199210

200211
if (!File.Exists(STEAMCMD_PATH))
@@ -253,7 +264,31 @@ public static void RunSteamCmd()
253264
}
254265
log.Info("SteamCMD update check complete.");
255266
}
256-
267+
268+
/// <summary>
269+
/// Peek at Torch.cfg XML to read ForceOverwriteRunscript before TorchConfig can be loaded.
270+
/// Returns true (default) if the config doesn't exist or the element is missing.
271+
/// </summary>
272+
private static bool PeekForceOverwriteRunscript()
273+
{
274+
var configPath = Path.Combine(Directory.GetCurrentDirectory(), "Torch.cfg");
275+
if (!File.Exists(configPath))
276+
return true;
277+
278+
try
279+
{
280+
var doc = System.Xml.Linq.XDocument.Load(configPath);
281+
var element = doc.Root?.Element("ForceOverwriteRunscript");
282+
if (element == null)
283+
return true;
284+
285+
return bool.TryParse(element.Value, out var value) ? value : true;
286+
}
287+
catch
288+
{
289+
return true;
290+
}
291+
}
257292

258293
private void LogException(Exception ex)
259294
{

‎Torch.Server/TorchConfig.cs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ public TorchBranchType BranchName
226226
[Display(Name = "Overwrite global NLog config on update.", Description = "This should ALWAYS be true UNLESS you know what you are doing. Breaking the default config may cause issues with logging. Just, no. Leave this alone.", GroupName = "Logging" )]
227227
public bool OverwriteGlobalNLogConfigOnUpdate { get; set; } = true;
228228

229+
[Display(Name = "Force Overwrite Runscript", Description = "Always overwrite the SteamCMD runscript on startup. Disable only if you have a custom runscript.", GroupName = "Server")]
230+
public bool ForceOverwriteRunscript { get; set; } = true;
231+
229232
public event PropertyChangedEventHandler PropertyChanged;
230233

231234
public TorchConfig() { }

0 commit comments

Comments
 (0)