forked from Buttys/DevProLauncher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRegEditor.cs
88 lines (82 loc) · 2.22 KB
/
RegEditor.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
79
80
81
82
83
84
85
86
87
88
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;
namespace YGOPro_Launcher
{
public static class RegEditor
{
public static bool Write(string path, string key, object value)
{
try
{
RegistryKey rk = Registry.CurrentUser;
RegistryKey sk1 = rk.CreateSubKey(path);
// Save the value
sk1.SetValue(key, value);
return true;
}
catch (Exception e)
{
Console.Write(e.Message);
//failed to write
return false;
}
}
public static bool CreateDirectory(string path)
{
try
{
RegistryKey rk = Registry.CurrentUser;
RegistryKey newpath = rk.CreateSubKey(path);
return true;
}
catch (Exception e)
{
Console.Write(e.Message);
return false;
}
}
public static bool DeleteRegTree(string path)
{
try
{
// Setting
RegistryKey rk = Registry.CurrentUser;
RegistryKey sk1 = rk.OpenSubKey(path);
// If the RegistryKey exists, I delete it
if (sk1 != null)
rk.DeleteSubKeyTree(path);
return true;
}
catch (Exception e)
{
Console.Write(e.Message);
return false;
}
}
public static string Read(string path, string key)
{
// Opening the registry key
RegistryKey rk = Registry.CurrentUser;
RegistryKey sk1 = rk.OpenSubKey(path);
if (sk1 == null)
{
return null;
}
else
{
try
{
return (string)sk1.GetValue(key);
}
catch (Exception e)
{
Console.Write(e.Message);
return null;
}
}
}
}
}