public EmulatorDto GetEmulatorPaths() { var programFilesPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86); var commonDocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments); var emulatorPathValues = new EmulatorDto(); if (Directory.Exists(Path.Combine(programFilesPath, "WinUAE"))) { // WinUAE was found in Program Files, check if Configurations exists under Public Documents or the WinUAE folder emulatorPathValues.EmulatorPath = Path.Combine(programFilesPath, "WinUAE\\WinUAE.exe"); if (Directory.Exists(Path.Combine(commonDocumentsPath, "Amiga Files\\WinUAE\\Configurations"))) emulatorPathValues.ConfigurationFilesPath = Path.Combine(commonDocumentsPath, "Amiga Files\\WinUAE\\Configurations"); else if (Directory.Exists(Path.Combine(programFilesPath, "WinUAE\\Configurations"))) emulatorPathValues.ConfigurationFilesPath = Path.Combine(programFilesPath, "WinUAE\\Configurations"); } else // Do a secondary check in case our operating system is Windows XP 32-bit (and WinUAE is under Program Files) { var programFilesPath32 = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); if (!Directory.Exists(Path.Combine(programFilesPath32, "WinUAE"))) return emulatorPathValues; // WinUAE was found in Program Files, check if Configurations exists under Public Documents or the WinUAE folder emulatorPathValues.EmulatorPath = Path.Combine(programFilesPath32, "WinUAE\\WinUAE.exe"); if (Directory.Exists(Path.Combine(commonDocumentsPath, "Amiga Files\\WinUAE\\Configurations"))) emulatorPathValues.ConfigurationFilesPath = Path.Combine(commonDocumentsPath, "Amiga Files\\WinUAE\\Configurations"); else if (Directory.Exists(Path.Combine(programFilesPath32, "WinUAE\\Configurations"))) emulatorPathValues.ConfigurationFilesPath = Path.Combine(programFilesPath32, "WinUAE\\Configurations"); } return emulatorPathValues; }
private static EmulatorDto ReadKeysFromRegistry(string rootKey, string[] afKeys) { var emulatorPathValues = new EmulatorDto(); var patRegistry = Registry.LocalMachine.OpenSubKey(rootKey); if (patRegistry != null) foreach (var subKeyName in patRegistry.GetSubKeyNames()) { patRegistry = Registry.LocalMachine.OpenSubKey(rootKey + "\\" + subKeyName); foreach (var afKey in afKeys) { if (patRegistry != null && (afKey == "AmigaFiles" && patRegistry.GetValue(afKey) != null)) { emulatorPathValues.ConfigurationFilesPath = Path.Combine(patRegistry.GetValue(afKey).ToString(), "WinUAE\\Configurations"); } if (patRegistry == null || (afKey != "Path" || patRegistry.GetValue(afKey) == null)) continue; emulatorPathValues.EmulatorPath = Path.Combine(patRegistry.GetValue(afKey).ToString(), "WinUAE\\winuae.exe"); } } patRegistry?.Close(); return emulatorPathValues; }