Files
Triforce-Source/launcher/Logic/Log.cs
ruckus7382sfgsgdf fb26495475 Triforce v0.5.2
The new launcher (Windows and Linux: the game's own look, music and settings, saves and mods pages, smaller updates in parts), benchmark mode (Find my best settings: the game tours four places by itself and writes its results), Quit and Restart in the pause menu under Mods, Squadala! in the Mods menu, battle music above 60 fps, menu text, the controller in the menus with the game in the background, the whole GameBanana list, RX 580 and RX 5000/6000 shader fixes, the pipeline cache kept through an update, async present black flashes, and faster builds.
2026-11-19 10:52:50 -06:00

40 lines
1.6 KiB
C#

namespace Triforce.Logic;
/// <summary>setup.log: what the launcher checked, downloaded and ran, for bug reports (old Setup.cs Program.Log). Windows: beside
/// the installed launcher (&lt;install&gt;\setup.log, the old place); Linux: ${XDG_STATE_HOME}/triforce/setup.log. A line is
/// "yyyy-MM-dd HH:mm:ss &lt;text&gt;"; the file is deleted once it is over 2 MiB. Nothing is written under NoWrites.</summary>
public sealed class Log
{
readonly TriforceContext ctx;
readonly object gate = new();
internal Log(TriforceContext ctx) { this.ctx = ctx; }
/// <summary>Every line as it is written (the App may show them; a test reads them).</summary>
public event Action<string>? Written;
public string FilePath => Path.Combine(ctx.Platform.LogFolder(ctx.Home), "setup.log");
public void Write(string line)
{
Written?.Invoke(line);
if (ctx.NoWrites) return;
try
{
lock (gate)
{
var file = FilePath;
Directory.CreateDirectory(Path.GetDirectoryName(file)!);
if (File.Exists(file) && new FileInfo(file).Length > (2 << 20)) File.Delete(file);
File.AppendAllText(file, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + line + Environment.NewLine);
}
}
catch (Exception) { }
}
/// <summary>The whole log, "" when there is none.</summary>
public string ReadAll()
{
try { lock (gate) return File.Exists(FilePath) ? File.ReadAllText(FilePath) : ""; } catch (Exception) { return ""; }
}
}