Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
WindowsRegisterManager.cs
浏览该文件的文档.
1#if WINDOWS
2#pragma warning disable CA1416
3using Microsoft.Win32;
4
5namespace Game.Managers {
6 static class WindowsRegisterManager {
7 public static string SurvivalcraftPath => $"{ModsManager.ExternalPath}Survivalcraft.exe";
8
9 public static void RegisterFileType(string keyName, string keyValue, string extension) {
10 //keyName = "WPCFile";
11 //keyValue = "资源包文件";
12 //bool isCreateRegistry = true;
13 try {
14 // 检查 文件关联是否创建
15 RegistryKey isExCommand = Registry.ClassesRoot.OpenSubKey(keyName);
16 if (isExCommand == null) {
17 //isCreateRegistry = true;
18 }
19 else {
20 if (isExCommand.GetValue("Create")?.ToString() == SurvivalcraftPath) {
21 //isCreateRegistry = false;
22 }
23 else {
24 Registry.ClassesRoot.DeleteSubKeyTree(keyName);
25 //isCreateRegistry = true;
26 }
27 }
28 }
29 catch (Exception) {
30 //isCreateRegistry = true;
31 }
32
33 // 假如 文件关联 还没有创建,或是关联位置已被改变
34 //if (isCreateRegistry)
35 {
36 try {
37 if (SurvivalcraftPath == null) {
38 return;
39 }
40 RegistryKey key = Registry.ClassesRoot.CreateSubKey(keyName);
41 if (key == null) {
42 return;
43 }
44 key.SetValue("Create", SurvivalcraftPath);
45 RegistryKey keyico = key.CreateSubKey("DefaultIcon");
46 if (keyico == null) {
47 return;
48 }
49 keyico.SetValue("", $"{SurvivalcraftPath},0");
50 key.SetValue("", keyValue);
51 key = key.CreateSubKey("Shell");
52 if (key == null) {
53 return;
54 }
55 key = key.CreateSubKey("Open");
56 if (key == null) {
57 return;
58 }
59 key = key.CreateSubKey("Command");
60 if (key == null) {
61 return;
62 }
63
64 // 关联的位置
65 key.SetValue("", $@"{SurvivalcraftPath} %1/");
66
67 // 关联的文件扩展名,
68 keyName = extension;
69 key = Registry.ClassesRoot.CreateSubKey(keyName);
70 if (key == null) {
71 return;
72 }
73 key.SetValue("", keyValue);
74 }
75 catch (Exception) {
76 // ignored
77 }
78 }
79 }
80 }
81}
82#endif