-
Notifications
You must be signed in to change notification settings - Fork 21
/
UserSettings.cs
78 lines (68 loc) · 2.7 KB
/
UserSettings.cs
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
using System;
using System.IO.IsolatedStorage;
using System.Windows.Forms;
namespace CabMaker
{
[Serializable]
public class UserSettings
{
static readonly string _settingsFileName = $"{Application.ProductName}.dat";
public string SourcePath { get; set; }
public bool IncludeSubfolders { get; set; }
public string TargetPath { get; set; }
public string FileName { get; set; }
public CompressionType CompressionType { get; set; }
public int CompressionWindowSize { get; set; }
public UserSettings()
{
SourcePath = "";
IncludeSubfolders = true;
TargetPath = "";
FileName = "";
CompressionType = Constants.DefaultCompressionType;
CompressionWindowSize = Constants.DefaultCompressionWindowSize.Exponent;
}
public static void Clear()
{
// HACK:
// For whatever reason, deleting files from isolated storage never seems to work (throws an exception every time).
// So... as a workaround, we'll simply save the default settings to "clear out" user-saved settings. If anyone
// out there has more time than me to investigate/fix this, please feel free. I'd love to find a better solution.
var defaultSettings = new UserSettings();
Save(defaultSettings);
}
public static UserSettings FetchWithDefaults()
{
using (var storage = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null))
{
return storage.LoadObject<UserSettings>(_settingsFileName) ?? new UserSettings();
}
}
public static void Save(
string sourceFolder,
bool isRecursive,
string targetFolder,
string targetFileName,
CompressionType compressionType,
CompressionWindowSize compressionWindowSize)
{
UserSettings settings = new UserSettings()
{
SourcePath = sourceFolder,
IncludeSubfolders = isRecursive,
TargetPath = targetFolder,
FileName = targetFileName,
CompressionType = compressionType,
CompressionWindowSize = compressionWindowSize.Exponent
};
Save(settings);
}
public static void Save(UserSettings settings)
{
using (var storage = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null))
{
storage.SaveObject(settings, _settingsFileName);
}
}
}
}