private void FindGameInstallationPath(GameConfiguration gameConfiguration) { if (!gameConfiguration.IsInstalled) { return; } // If installed via Steam, find game installation path. // Easiest way I've found so far is to look at the uninstall settings. if (!string.IsNullOrEmpty(gameConfiguration.SteamId)) { RegistryKey regKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Steam App " + gameConfiguration.SteamId); if (regKey != null) { string steamInstallationPath = regKey.GetValue("InstallLocation").ToString(); if (!String.IsNullOrEmpty(steamInstallationPath)) { if (Directory.Exists(steamInstallationPath)) { gameConfiguration.InstallationPath = steamInstallationPath; ////this.LogItems.Add(new LogEntry("Located Steam game files: " + steamInstallationPath)); } } } } }
/// <summary> /// Attempts to figure out whether the game is installed. /// /// Currently, only steam installs are supported. /// </summary> /// <param name="gameConfiguration">The game configuration</param> /// <returns>True if found, false if not</returns> private void VerifyInstallation(GameConfiguration gameConfiguration) { // Check registry for steam id if (!string.IsNullOrEmpty(gameConfiguration.SteamId)) { string expectedRegistryPath = @"Software\Valve\Steam\Apps\" + gameConfiguration.SteamId; RegistryKey regKey = Registry.CurrentUser.OpenSubKey(expectedRegistryPath); if (regKey != null) { string value = regKey.GetValue("Installed").ToString(); gameConfiguration.IsInstalled = value.Equals("1"); //this.LogItems.Add(new LogEntry("Found Steam installation of " + gameConfiguration.FriendlyName)); } } }
/// <summary> /// Reads the game configuration for a particular xml node name. /// </summary> /// <param name="xmlNodeName">Name of the XML node.</param> /// <returns></returns> private IList<GameConfiguration> ReadGameConfig(string xmlNodeName) { IList<GameConfiguration> gameConfigurations = new List<GameConfiguration>(); // Read file to memory var config = XmlHelper.ReadXmlFile("Configuration.xml"); if (config == null) { return null; } // Read the games. Most likely only one (source or target), but the code here supports multiple var foundGames = config.Descendants(xmlNodeName); // For each game, read the various properties we need, and store the result in a new GameConfiguration object foreach (var game in foundGames) { // Save game related var saveGameFolderTypeAsString = XElementHelper.ReadStringValue(game, "defaultSaveGameLocationType"); var saveGameFolderType = saveGameFolderTypeAsString.Equals(RelativeFolderLocationRoot.SteamFolder.ToString()) ? RelativeFolderLocationRoot.SteamFolder : RelativeFolderLocationRoot.WindowsUsersFolder; var saveGameExtension = XElementHelper.ReadStringValue(game, "saveGameExtension"); // Installation directory related var steamId = XElementHelper.ReadStringValue(game, "steamId"); var nonsteamRegistryName = XElementHelper.ReadStringValue(game, "nonsteamRegistryName", false); var installationFolder = this.GetSteamInstallationFolder(steamId); if (String.IsNullOrEmpty(installationFolder)) { installationFolder = this.GetNonSteamInstallationFolder(nonsteamRegistryName); } var configurationFileDirectoryTagName = XElementHelper.ReadStringValue(game, "configurationFileDirectoryTagName"); // Mod related var defaultModFolderLocationTypeAsString = XElementHelper.ReadStringValue(game, "defaultModFolderLocationType", false); var defaultModFolderLocationType = defaultModFolderLocationTypeAsString.Equals(RelativeFolderLocationRoot.SteamFolder.ToString()) ? RelativeFolderLocationRoot.SteamFolder : RelativeFolderLocationRoot.WindowsUsersFolder; var configurationFileModDirectoryTagName = XElementHelper.ReadStringValue(game, "configurationFileModDirectoryTagName", false); var currentModTagName = XElementHelper.ReadStringValue(game, "currentModTagName", false); //if (defaultModFolderLocationType == RelativeFolderLocationRoot.SteamFolder) //{ // this.options.Logger.AddLogEntry(new LogEntry("The \"defaultModFolderLocationType\" tag cannot have the value \"SteamFolder\". This value isn't supported in the frontend yet.", LogEntrySeverity.Error, LogEntrySource.UI)); //} var supportedModsAsString = game.Descendants("supportedMod"); var gameConfig = new GameConfiguration() { Name = XElementHelper.ReadStringValue(game, "name"), FriendlyName = XElementHelper.ReadStringValue(game, "friendlyName"), SaveGamePath = (saveGameFolderType == RelativeFolderLocationRoot.SteamFolder ? installationFolder : this.GetUsersFolder()) + XElementHelper.ReadStringValue(game, "defaultSaveGameSubLocation"), SteamId = steamId, ConfigurationFileDirectoryTagName = configurationFileDirectoryTagName, SaveGameExtension = saveGameExtension, ConfigurationFileModDirectoryTagName = configurationFileModDirectoryTagName, CurrentModTagName = currentModTagName, ModPath = (defaultModFolderLocationType == RelativeFolderLocationRoot.SteamFolder ? installationFolder : GetUsersFolder()) + XElementHelper.ReadStringValue(game, "defaultModFolderLocation", false), InstallationPath = installationFolder }; // Dummy item so that the user can undo selecting a mod var dummyMod = new SupportedMod() { Name = "No mod", IsDummyItem = true }; gameConfig.SupportedMods.Add(dummyMod); gameConfig.CurrentMod = dummyMod; // Add proper mods if (supportedModsAsString.Count() > 0) { supportedModsAsString.ForEach(m => gameConfig.SupportedMods.Add(new SupportedMod() { Name = XElementHelper.ReadStringValue(m, "modName") })); } gameConfigurations.Add(gameConfig); } return gameConfigurations; }