Local-mode composition root (SQLite index, one JobEngine fed by a single handler registration list), keyset-paged library with thumbnail cache and hover scrub, live job list with throttled updates and the shell job bar, settings with live template validation and encoder self-test, server connection with trust-on-first-use and DPAPI token, first-run welcome, About with update check, and --capture screenshots with synthetic data. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
63 lines
2.5 KiB
C#
63 lines
2.5 KiB
C#
using System.IO;
|
|
|
|
namespace Titano.App.Infrastructure;
|
|
|
|
/// <summary>
|
|
/// Where the client keeps its data (BRIEF §6.2): <c>%LOCALAPPDATA%\Titano</c>, or <c>.\data</c> next to the
|
|
/// executable when <c>portable.txt</c> exists. Never inside Documents/OneDrive (SQLite corrupts in synced folders).
|
|
/// </summary>
|
|
public sealed class AppEnvironment
|
|
{
|
|
private AppEnvironment(string dataDirectory, bool portable, bool isCapture)
|
|
{
|
|
DataDirectory = dataDirectory;
|
|
IsPortable = portable;
|
|
IsCapture = isCapture;
|
|
Directory.CreateDirectory(DataDirectory);
|
|
Directory.CreateDirectory(LogDirectory);
|
|
Directory.CreateDirectory(CacheDirectory);
|
|
}
|
|
|
|
public string DataDirectory { get; }
|
|
public bool IsPortable { get; }
|
|
|
|
/// <summary>A throw-away environment for <c>--capture</c>: nothing of the user's data is read or written.</summary>
|
|
public bool IsCapture { get; }
|
|
|
|
public string LogDirectory => Path.Combine(DataDirectory, "logs");
|
|
public string CacheDirectory => Path.Combine(DataDirectory, "cache");
|
|
public string BackupDirectory => Path.Combine(DataDirectory, "backups");
|
|
public string DatabasePath => Path.Combine(DataDirectory, "titano.db");
|
|
public string SettingsPath => Path.Combine(DataDirectory, "settings.json");
|
|
|
|
public static AppEnvironment Detect()
|
|
{
|
|
var exeDir = AppContext.BaseDirectory;
|
|
if (File.Exists(Path.Combine(exeDir, "portable.txt")))
|
|
return new AppEnvironment(Path.Combine(exeDir, "data"), portable: true, isCapture: false);
|
|
var local = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
|
return new AppEnvironment(Path.Combine(local, "Titano"), portable: false, isCapture: false);
|
|
}
|
|
|
|
/// <summary>A fresh temporary data folder for screenshots and smoke tests; delete it with <see cref="DeleteCaptureData"/>.</summary>
|
|
public static AppEnvironment ForCapture() =>
|
|
new(Path.Combine(Path.GetTempPath(), "titano-capture-" + Guid.CreateVersion7().ToString("N")), portable: false, isCapture: true);
|
|
|
|
/// <summary>Removes the temporary data folder of a capture environment (never a real one).</summary>
|
|
public void DeleteCaptureData()
|
|
{
|
|
if (!IsCapture) return;
|
|
try
|
|
{
|
|
Directory.Delete(DataDirectory, recursive: true);
|
|
}
|
|
catch (IOException)
|
|
{
|
|
// Files still open (log, database) are left to the OS temp cleanup.
|
|
}
|
|
catch (UnauthorizedAccessException)
|
|
{
|
|
}
|
|
}
|
|
}
|