/// <summary> /// Gets all registry keys that exist in the given search base and path /// </summary> /// <param name="search">The RegistrySearch structure to specify where to search and where to base the search</param> /// <returns>The RegistryKey object of the folder in registry, or null if the search failed</returns> public static RegistryKey GetRegistryKeys(RegistrySearch search) { try { return(search.Root.OpenSubKey(search.Searchpath)); } catch (Exception ex) { Logging.Exception("Failed to get registry entry"); Logging.Exception(ex.ToString()); return(null); } }
/// <summary> /// Checks the registry to get the latest location of where WoT is installed, includes exe in the name /// </summary> /// <returns>A list of all unique valid game paths</returns> public static List <string> AutoFindWoTDirectoryList() { RegistryKey result; List <string> searchPathWoT = new List <string>(); //check replay link locations (the last game instance the user opened) //key is null, value is path //example value: "C:\TANKS\World_of_Tanks_NA\win64\WorldOfTanks.exe" "%1" RegistrySearch[] registryEntriesGroup1 = new RegistrySearch[] { new RegistrySearch() { Root = Registry.LocalMachine, Searchpath = @"SOFTWARE\Classes\.wotreplay\shell\open\command" }, new RegistrySearch() { Root = Registry.CurrentUser, Searchpath = @"Software\Classes\.wotreplay\shell\open\command" } }; foreach (RegistrySearch searchPath in registryEntriesGroup1) { Logging.Debug("Searching in registry root {0} with path {1}", searchPath.Root.Name, searchPath.Searchpath); result = GetRegistryKeys(searchPath); if (result != null) { foreach (string valueInKey in result.GetValueNames()) { string possiblePath = result.GetValue(valueInKey) as string; if (!string.IsNullOrWhiteSpace(possiblePath) && possiblePath.ToLower().Contains("worldoftanks.exe")) { string[] splitResult = possiblePath.Split('"'); //get index 1 option possiblePath = splitResult[1].Trim(); Logging.Debug("Possible path found: {0}", possiblePath); searchPathWoT.Add(possiblePath); } } result.Dispose(); result = null; } } //key is WoT path, don't care about value RegistrySearch[] registryEntriesGroup2 = new RegistrySearch[] { new RegistrySearch() { Root = Registry.CurrentUser, Searchpath = @"Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache" }, new RegistrySearch() { Root = Registry.CurrentUser, Searchpath = @"Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Store" } }; foreach (RegistrySearch searchPath in registryEntriesGroup2) { Logging.Debug("Searching in registry root {0} with path {1}", searchPath.Root.Name, searchPath.Searchpath); result = GetRegistryKeys(searchPath); if (result != null) { foreach (string possiblePath in result.GetValueNames()) { if (!string.IsNullOrWhiteSpace(possiblePath) && possiblePath.ToLower().Contains("worldoftanks.exe")) { Logging.Debug("Possible path found: {0}", possiblePath); searchPathWoT.Add(possiblePath); } } result.Dispose(); result = null; } } Logging.Debug("Filter out win32/64 options"); for (int i = 0; i < searchPathWoT.Count; i++) { string potentialResult = searchPathWoT[i]; //if it has win32 or win64, filter it out if (potentialResult.Contains(ApplicationConstants.WoT32bitFolderWithSlash) || potentialResult.Contains(ApplicationConstants.WoT64bitFolderWithSlash)) { potentialResult = potentialResult.Replace(ApplicationConstants.WoT32bitFolderWithSlash, string.Empty).Replace(ApplicationConstants.WoT64bitFolderWithSlash, string.Empty); } searchPathWoT[i] = potentialResult; } Logging.Debug("Filter out options to non existent locations"); searchPathWoT.RemoveAll(match => !File.Exists(match)); Logging.Debug("Filter out duplicates"); searchPathWoT = searchPathWoT.Distinct().ToList(); foreach (string path in searchPathWoT) { Logging.Info("Valid path found: {0}", path); } return(searchPathWoT); }
/// <summary> /// Checks the registry to get the latest location of where WoT is installed /// </summary> /// <returns>True if operation success</returns> public static string AutoFindWoTDirectory() { List <string> searchPathWoT = new List <string>(); RegistryKey result = null; //check replay link locations (the last game instance the user opened) //key is null, value is path RegistrySearch[] registryEntriesGroup1 = new RegistrySearch[] { new RegistrySearch() { Root = Registry.LocalMachine, Searchpath = @"SOFTWARE\Classes\.wotreplay\shell\open\command" }, new RegistrySearch() { Root = Registry.CurrentUser, Searchpath = @"Software\Classes\.wotreplay\shell\open\command" } }; foreach (RegistrySearch searchPath in registryEntriesGroup1) { Logging.Debug("Searching in registry root {0} with path {1}", searchPath.Root.Name, searchPath.Searchpath); result = GetRegistryKeys(searchPath); if (result != null) { foreach (string valueInKey in result.GetValueNames()) { string possiblePath = result.GetValue(valueInKey) as string; if (!string.IsNullOrWhiteSpace(possiblePath) && possiblePath.ToLower().Contains("worldoftanks.exe")) { //trim front possiblePath = possiblePath.Substring(1); //trim end possiblePath = possiblePath.Substring(0, possiblePath.Length - 6); Logging.Debug("Possible path found: {0}", possiblePath); searchPathWoT.Add(possiblePath); } } result.Dispose(); result = null; } } //key is WoT path, don't care about value RegistrySearch[] registryEntriesGroup2 = new RegistrySearch[] { new RegistrySearch() { Root = Registry.CurrentUser, Searchpath = @"Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache" }, new RegistrySearch() { Root = Registry.CurrentUser, Searchpath = @"Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Store" } }; foreach (RegistrySearch searchPath in registryEntriesGroup2) { Logging.Debug("Searching in registry root {0} with path {1}", searchPath.Root.Name, searchPath.Searchpath); result = GetRegistryKeys(searchPath); if (result != null) { foreach (string possiblePath in result.GetValueNames()) { if (!string.IsNullOrWhiteSpace(possiblePath) && possiblePath.ToLower().Contains("worldoftanks.exe")) { Logging.Debug("Possible path found: {0}", possiblePath); searchPathWoT.Add(possiblePath); } } result.Dispose(); result = null; } } foreach (string path in searchPathWoT) { string potentialResult = path; //if it has win32 or win64, filter it out if (potentialResult.Contains(Settings.WoT32bitFolderWithSlash) || potentialResult.Contains(Settings.WoT64bitFolderWithSlash)) { potentialResult = potentialResult.Replace(Settings.WoT32bitFolderWithSlash, string.Empty).Replace(Settings.WoT64bitFolderWithSlash, string.Empty); } if (File.Exists(potentialResult)) { Logging.Info("Valid game path found: {0}", potentialResult); return(potentialResult); } } //return false if nothing found return(null); }