-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppSetupStateStore.cs
More file actions
53 lines (45 loc) · 1.46 KB
/
Copy pathAppSetupStateStore.cs
File metadata and controls
53 lines (45 loc) · 1.46 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
using System.IO;
namespace SimpleMusicPlayer;
public sealed class AppSetupStateStore
{
private readonly JsonFileStore<AppSetupState> _store;
public AppSetupStateStore()
{
var stateDirectory = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"SimpleMusicPlayer");
_store = new JsonFileStore<AppSetupState>(Path.Combine(stateDirectory, "setup-state.json"));
}
public AppSetupState Load() => _store.Load();
public void Save(AppSetupState state) => _store.Save(state);
public void MarkCompleted(string installPath)
{
Save(new AppSetupState
{
CompletedInstallPath = NormalizePath(installPath),
CompletedAt = DateTimeOffset.Now
});
}
public void MarkDismissed(string installPath)
{
var currentState = Load();
Save(new AppSetupState
{
CompletedInstallPath = currentState.CompletedInstallPath,
CompletedAt = currentState.CompletedAt,
DismissedInstallPath = NormalizePath(installPath),
DismissedAt = DateTimeOffset.Now
});
}
public static string NormalizePath(string path)
{
try
{
return Path.TrimEndingDirectorySeparator(Path.GetFullPath(path));
}
catch
{
return path.Trim().TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
}
}
}