alielie
2026-09-10 f3889f2d36c50cf99468594854def9b7ed069fb5
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
using Microsoft.Win32;
 
namespace OpenTap.Addin.Util
{
    public interface IRegGetter
    {
        string GetAppPath(string keyPath);
    }
 
    public class RegUtil
    {
        public static IRegGetter Getter { get; private set; }
 
        public static void Register(IRegGetter getter)
        {
            Getter = getter;
        }
 
        public static string GetAppPath()
        {
            string Company = "JingCe", Program = "SeqEditor";
 
            string registryPath = $@"SOFTWARE\{Company}\{Program}";
 
            if (Getter != null)
            {
                return Getter.GetAppPath(registryPath);
            }
 
            // 尝试打开注册表键
            using (RegistryKey key = Registry.CurrentUser.OpenSubKey(registryPath))
            {
                if (key == null)
                {
                    // throw new Exception("注册表不存在,请先运行一次编辑器");
                    return ExecutorClient.ExeDir;
                }
 
                string value = key.GetValue("Location")?.ToString();
                if (string.IsNullOrEmpty(value))
                {
                    // throw new Exception("注册表不存在,请先运行一次编辑器");
                    return ExecutorClient.ExeDir;
                }
                return value;
            }
        }
    }
}