/// <summary> /// Loads skirmish settings from an INI file on the file system. /// </summary> private void LoadSettings() { if (!File.Exists(ProgramConstants.GamePath + SETTINGS_PATH)) { InitDefaultSettings(); return; } var skirmishSettingsIni = new IniFile(ProgramConstants.GamePath + SETTINGS_PATH); string gameModeName = skirmishSettingsIni.GetStringValue("Settings", "GameMode", string.Empty); int gameModeIndex = GameModes.FindIndex(g => g.Name == gameModeName); if (gameModeIndex > -1) { GameMode = GameModes[gameModeIndex]; ddGameMode.SelectedIndex = gameModeIndex; string mapSHA1 = skirmishSettingsIni.GetStringValue("Settings", "Map", string.Empty); int mapIndex = GameMode.Maps.FindIndex(m => m.SHA1 == mapSHA1); if (mapIndex > -1) { lbMapList.SelectedIndex = mapIndex; while (mapIndex > lbMapList.LastIndex) { lbMapList.TopIndex++; } } } else { LoadDefaultMap(); } var player = PlayerInfo.FromString(skirmishSettingsIni.GetStringValue("Player", "Info", string.Empty)); if (player == null) { Logger.Log("Failed to load human player information from skirmish settings!"); InitDefaultSettings(); return; } CheckLoadedPlayerVariableBounds(player); player.Name = ProgramConstants.PLAYERNAME; Players.Add(player); List <string> keys = skirmishSettingsIni.GetSectionKeys("AIPlayers"); if (keys == null) { keys = new List <string>(); // No point skip parsing all settings if only AI info is missing. //Logger.Log("AI player information doesn't exist in skirmish settings!"); //InitDefaultSettings(); //return; } bool AIAllowed = !(Map.MultiplayerOnly || GameMode.MultiplayerOnly) || !(Map.HumanPlayersOnly || GameMode.HumanPlayersOnly); foreach (string key in keys) { if (!AIAllowed) { break; } var aiPlayer = PlayerInfo.FromString(skirmishSettingsIni.GetStringValue("AIPlayers", key, string.Empty)); CheckLoadedPlayerVariableBounds(aiPlayer, true); if (aiPlayer == null) { Logger.Log("Failed to load AI player information from skirmish settings!"); InitDefaultSettings(); return; } if (AIPlayers.Count < MAX_PLAYER_COUNT - 1) { AIPlayers.Add(aiPlayer); } } if (ClientConfiguration.Instance.SaveSkirmishGameOptions) { foreach (GameLobbyDropDown dd in DropDowns) { // Maybe we should build an union of the game mode and map // forced options, we'd have less repetitive code that way if (GameMode != null) { int gameModeMatchIndex = GameMode.ForcedDropDownValues.FindIndex(p => p.Key.Equals(dd.Name)); if (gameModeMatchIndex > -1) { Logger.Log("Dropdown '" + dd.Name + "' has forced value in gamemode - saved settings ignored."); continue; } } if (Map != null) { int gameModeMatchIndex = Map.ForcedDropDownValues.FindIndex(p => p.Key.Equals(dd.Name)); if (gameModeMatchIndex > -1) { Logger.Log("Dropdown '" + dd.Name + "' has forced value in map - saved settings ignored."); continue; } } dd.UserSelectedIndex = skirmishSettingsIni.GetIntValue("GameOptions", dd.Name, dd.UserSelectedIndex); if (dd.UserSelectedIndex > -1 && dd.UserSelectedIndex < dd.Items.Count) { dd.SelectedIndex = dd.UserSelectedIndex; } } foreach (GameLobbyCheckBox cb in CheckBoxes) { if (GameMode != null) { int gameModeMatchIndex = GameMode.ForcedCheckBoxValues.FindIndex(p => p.Key.Equals(cb.Name)); if (gameModeMatchIndex > -1) { Logger.Log("Checkbox '" + cb.Name + "' has forced value in gamemode - saved settings ignored."); continue; } } if (Map != null) { int gameModeMatchIndex = Map.ForcedCheckBoxValues.FindIndex(p => p.Key.Equals(cb.Name)); if (gameModeMatchIndex > -1) { Logger.Log("Checkbox '" + cb.Name + "' has forced value in map - saved settings ignored."); continue; } } cb.Checked = skirmishSettingsIni.GetBooleanValue("GameOptions", cb.Name, cb.Checked); } } }
private void LoadSettings() { if (!File.Exists(ProgramConstants.GamePath + SETTINGS_PATH)) { InitDefaultSettings(); return; } var skirmishSettingsIni = new IniFile(ProgramConstants.GamePath + SETTINGS_PATH); var player = PlayerInfo.FromString(skirmishSettingsIni.GetStringValue("Player", "Info", string.Empty)); if (player == null) { Logger.Log("Failed to load human player information from skirmish settings!"); InitDefaultSettings(); return; } CheckLoadedPlayerVariableBounds(player); player.Name = ProgramConstants.PLAYERNAME; Players.Add(player); List <string> keys = skirmishSettingsIni.GetSectionKeys("AIPlayers"); if (keys == null) { Logger.Log("AI player information doesn't exist in skirmish settings!"); InitDefaultSettings(); return; } foreach (string key in keys) { var aiPlayer = PlayerInfo.FromString(skirmishSettingsIni.GetStringValue("AIPlayers", key, string.Empty)); CheckLoadedPlayerVariableBounds(aiPlayer); if (aiPlayer == null) { Logger.Log("Failed to load AI player information from skirmish settings!"); InitDefaultSettings(); return; } if (AIPlayers.Count < MAX_PLAYER_COUNT - 1) { AIPlayers.Add(aiPlayer); } } string gameModeName = skirmishSettingsIni.GetStringValue("Settings", "GameMode", string.Empty); int gameModeIndex = GameModes.FindIndex(g => g.Name == gameModeName); if (gameModeIndex > -1) { GameMode gm = GameModes[gameModeIndex]; string mapSHA1 = skirmishSettingsIni.GetStringValue("Settings", "Map", string.Empty); int mapIndex = gm.Maps.FindIndex(m => m.SHA1 == mapSHA1); if (mapIndex > -1) { ddGameMode.SelectedIndex = gameModeIndex; lbMapList.SelectedIndex = mapIndex; while (mapIndex > lbMapList.LastIndex) { lbMapList.TopIndex++; } return; } } LoadDefaultMap(); }