-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppConfig.cs
More file actions
97 lines (76 loc) · 3.53 KB
/
Copy pathAppConfig.cs
File metadata and controls
97 lines (76 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.Win32;
namespace WinScrobb;
public class AppConfig
{
public string ApiKey { get; set; } = "";
public string ApiSecret { get; set; } = "";
public string SessionKey { get; set; } = "";
public string Username { get; set; } = "";
public int PollIntervalSeconds { get; set; } = 3;
public bool RunAtStartup { get; set; } = true;
// ── Ghost mode (private listening) ────────────────────────────────────────
public DateTime? GhostUntilUtc { get; set; }
[JsonIgnore]
public bool IsGhostActive =>
GhostUntilUtc.HasValue && GhostUntilUtc.Value > DateTime.UtcNow;
// ── Easter egg / icon style ───────────────────────────────────────────────
public int LogoClicks { get; set; } = 0;
public bool RetroIconUnlocked { get; set; } = false;
public bool UseRetroIcon { get; set; } = false;
// ── iPod sync ─────────────────────────────────────────────────────────────
public bool IPodSyncEnabled { get; set; } = true;
public bool IPodAutoSyncOnConnect { get; set; } = false;
/// <summary>Per-device watermark (mount path → last-synced timestamp UTC).</summary>
public Dictionary<string, DateTime> IPodLastSync { get; set; } = new();
public DateTime GetLastIPodSync(string deviceId) =>
IPodLastSync.TryGetValue(deviceId, out var t) ? t : DateTime.MinValue;
public void SetLastIPodSync(string deviceId, DateTime utc) =>
IPodLastSync[deviceId] = utc;
private const string StartupKey = @"Software\Microsoft\Windows\CurrentVersion\Run";
private const string StartupName = "WinScrobb";
public void ApplyStartup()
{
using var key = Registry.CurrentUser.OpenSubKey(StartupKey, writable: true);
if (key is null) return;
if (RunAtStartup)
{
var exe = Environment.ProcessPath ?? "";
if (!string.IsNullOrEmpty(exe))
key.SetValue(StartupName, $"\"{exe}\"");
}
else
{
key.DeleteValue(StartupName, throwOnMissingValue: false);
}
}
// -------------------------------------------------------------------------
private static readonly string ConfigDir =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "WinScrobb");
private static readonly string ConfigPath = Path.Combine(ConfigDir, "config.json");
private static readonly JsonSerializerOptions JsonOpts = new() { WriteIndented = true };
public static AppConfig Load()
{
if (!File.Exists(ConfigPath))
return new AppConfig();
try
{
var json = File.ReadAllText(ConfigPath);
return JsonSerializer.Deserialize<AppConfig>(json, JsonOpts) ?? new AppConfig();
}
catch
{
return new AppConfig();
}
}
public void Save()
{
Directory.CreateDirectory(ConfigDir);
File.WriteAllText(ConfigPath, JsonSerializer.Serialize(this, JsonOpts));
}
[JsonIgnore]
public bool IsConfigured => !string.IsNullOrEmpty(ApiKey) && !string.IsNullOrEmpty(ApiSecret);
[JsonIgnore]
public bool IsAuthenticated => !string.IsNullOrEmpty(SessionKey);
}