-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRegistryStorage.cs
39 lines (35 loc) · 1.34 KB
/
RegistryStorage.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
using Microsoft.Win32;
namespace Updater
{
public static class RegistryStorage
{
public static string DefaultSubKey => $@"Software\{Utils.SoftwareName}";
public static string Load(string subKey = null, string name = "ExecutePath")
{
if (subKey == null) subKey = DefaultSubKey;
var path = string.Empty;
// HKCU_CURRENT_USER\Software\
var registryKey = Registry.CurrentUser.OpenSubKey(subKey);
if (registryKey == null) return path;
path = (string)registryKey.GetValue(name);
registryKey.Close();
return path;
}
public static void Save(string value, string subKey = null, string name = "ExecutePath")
{
if (subKey == null) subKey = DefaultSubKey;
// HKCU_CURRENT_USER\Software\
var registryKey = Registry.CurrentUser.CreateSubKey(subKey);
registryKey?.SetValue(name, value);
registryKey?.Close();
}
public static int RegistryAddCount(string subKey, string name, int delta = 1)
{
var countS = Load(subKey, name);
var count = string.IsNullOrEmpty(countS) ? 0 : int.Parse(countS);
count += delta;
Save(count.ToString(), subKey, name);
return count - delta;
}
}
}