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; } } } }