uploader.json (server, user, DPAPI CurrentUser-protected token, trusted fingerprints, options, watch folders) written atomically; command line (paths, --tray, --capture); named mutex plus a current-user named pipe that hands a second launch's paths to the running instance; HKCU Run key for "Start with Windows"; coalescing background writer for state files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
78 lines
3.0 KiB
C#
78 lines
3.0 KiB
C#
using System.IO;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
using Titano.Core.Diagnostics;
|
|
using Titano.Core.IO;
|
|
using Titano.Ui.Theming;
|
|
using Titano.Uploader.Uploads;
|
|
|
|
namespace Titano.Uploader.Infrastructure;
|
|
|
|
/// <summary>
|
|
/// <c>uploader.json</c>. The bearer token is stored only DPAPI-protected for the current Windows user
|
|
/// (<see cref="TokenProtector"/>); "Start with Windows" lives in the registry, which stays the source of truth.
|
|
/// </summary>
|
|
public sealed class UploaderSettings
|
|
{
|
|
public string? ServerUrl { get; set; }
|
|
public string? Username { get; set; }
|
|
|
|
/// <summary>Base64 of the DPAPI (CurrentUser) blob of the bearer token.</summary>
|
|
public string? ProtectedToken { get; set; }
|
|
|
|
/// <summary>SHA-256 fingerprints (XX:XX:…) of self-signed certificates the user trusted (TOFU).</summary>
|
|
public List<string> TrustedFingerprints { get; set; } = [];
|
|
|
|
/// <summary>Upload limit in MB/s (decimal megabytes); 0 = unlimited.</summary>
|
|
public int BandwidthLimit { get; set; }
|
|
|
|
public bool MinimizeToTray { get; set; } = true;
|
|
public bool DeleteAfterUpload { get; set; }
|
|
public UploadTargetMode Target { get; set; } = UploadTargetMode.Sessions;
|
|
public Guid? TargetSequenceId { get; set; }
|
|
public string? NewSequenceTitle { get; set; }
|
|
public List<WatchFolderSettings> WatchFolders { get; set; } = [];
|
|
public string? Language { get; set; }
|
|
public AppTheme Theme { get; set; } = AppTheme.Dark;
|
|
public WindowPlacement? Window { get; set; }
|
|
|
|
public sealed class WatchFolderSettings
|
|
{
|
|
public string Path { get; set; } = string.Empty;
|
|
public int IntervalSeconds { get; set; } = 60;
|
|
}
|
|
|
|
public sealed class WindowPlacement
|
|
{
|
|
public double Left { get; set; }
|
|
public double Top { get; set; }
|
|
public double Width { get; set; }
|
|
public double Height { get; set; }
|
|
}
|
|
|
|
public static UploaderSettings Load(string path)
|
|
{
|
|
try
|
|
{
|
|
if (File.Exists(path))
|
|
return JsonSerializer.Deserialize(File.ReadAllBytes(path), UploaderSettingsJson.Default.UploaderSettings) ?? new UploaderSettings();
|
|
}
|
|
catch (JsonException ex)
|
|
{
|
|
// A corrupt settings file must never block startup; defaults apply.
|
|
Log.Warning("settings", "uploader.json unreadable; using defaults", ex);
|
|
}
|
|
catch (IOException ex)
|
|
{
|
|
Log.Warning("settings", "uploader.json unreadable; using defaults", ex);
|
|
}
|
|
return new UploaderSettings();
|
|
}
|
|
|
|
public void Save(string path) => AtomicFile.WriteAllBytes(path, JsonSerializer.SerializeToUtf8Bytes(this, UploaderSettingsJson.Default.UploaderSettings));
|
|
}
|
|
|
|
[JsonSourceGenerationOptions(WriteIndented = true, PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase, UseStringEnumConverter = true)]
|
|
[JsonSerializable(typeof(UploaderSettings))]
|
|
internal sealed partial class UploaderSettingsJson : JsonSerializerContext;
|