private static void LoadProfile(string FileName) { bool loaded = false; XPathDocument xPathDoc = null; XPathNavigator navigator = null; SProfile profile = new SProfile(); profile.ProfileFile = Path.Combine(CSettings.sFolderProfiles, FileName); try { xPathDoc = new XPathDocument(profile.ProfileFile); navigator = xPathDoc.CreateNavigator(); loaded = true; } catch (Exception e) { loaded = false; if (navigator != null) { navigator = null; } if (xPathDoc != null) { xPathDoc = null; } CLog.LogError("Error opening Profile File " + FileName + ": " + e.Message); } if (loaded) { string value = String.Empty; if (CHelper.GetValueFromXML("//root/Info/PlayerName", navigator, ref value, value)) { profile.PlayerName = value; profile.Difficulty = EGameDifficulty.TR_CONFIG_EASY; CHelper.TryGetEnumValueFromXML <EGameDifficulty>("//root/Info/Difficulty", navigator, ref profile.Difficulty); profile.Avatar = new SAvatar(-1); if (CHelper.GetValueFromXML("//root/Info/Avatar", navigator, ref value, value)) { profile.Avatar = GetAvatar(value); } profile.GuestProfile = EOffOn.TR_CONFIG_OFF; CHelper.TryGetEnumValueFromXML <EOffOn>("//root/Info/GuestProfile", navigator, ref profile.GuestProfile); profile.Active = EOffOn.TR_CONFIG_ON; CHelper.TryGetEnumValueFromXML <EOffOn>("//root/Info/Active", navigator, ref profile.Active); _Profiles.Add(profile); } else { CLog.LogError("Can't find PlayerName in Profile File: " + FileName); } } }
public static bool LoadConfig() { #region Inits bool loaded = false; XPathDocument xPathDoc = null; XPathNavigator navigator = null; try { xPathDoc = new XPathDocument(CSettings.sFileConfig); navigator = xPathDoc.CreateNavigator(); loaded = true; } catch (Exception) { CLog.LogError("Error opening Config.xml (FileName: " + CSettings.sFileConfig); loaded = false; if (navigator != null) { navigator = null; } if (xPathDoc != null) { xPathDoc = null; } } #endregion Inits if (loaded) { string value = string.Empty; #region Debug CHelper.TryGetEnumValueFromXML <EDebugLevel>("//root/Debug/DebugLevel", navigator, ref DebugLevel); #endregion Debug #region Graphics CHelper.TryGetEnumValueFromXML <ERenderer>("//root/Graphics/Renderer", navigator, ref Renderer); CHelper.TryGetEnumValueFromXML <ETextureQuality>("//root/Graphics/TextureQuality", navigator, ref TextureQuality); CHelper.TryGetIntValueFromXML("//root/Graphics/CoverSize", navigator, ref CoverSize); if (CoverSize > 1024) { CoverSize = 1024; } if (CoverSize < 32) { CoverSize = 32; } CHelper.TryGetIntValueFromXML("//root/Graphics/ScreenW", navigator, ref ScreenW); CHelper.TryGetIntValueFromXML("//root/Graphics/ScreenH", navigator, ref ScreenH); CHelper.TryGetEnumValueFromXML <EAntiAliasingModes>("//root/Graphics/AAMode", navigator, ref AAMode); CHelper.TryGetEnumValueFromXML <EColorDeep>("//root/Graphics/Colors", navigator, ref Colors); CHelper.TryGetFloatValueFromXML("//root/Graphics/MaxFPS", navigator, ref MaxFPS); CHelper.TryGetEnumValueFromXML <EOffOn>("//root/Graphics/VSync", navigator, ref VSync); CHelper.TryGetEnumValueFromXML <EOffOn>("//root/Graphics/FullScreen", navigator, ref FullScreen); CHelper.TryGetFloatValueFromXML("//root/Graphics/FadeTime", navigator, ref FadeTime); #endregion Graphics #region Theme CHelper.GetValueFromXML("//root/Theme/Name", navigator, ref Theme, Theme); CHelper.GetValueFromXML("//root/Theme/Skin", navigator, ref Skin, Skin); CHelper.GetValueFromXML("//root/Theme/Cover", navigator, ref CoverTheme, CoverTheme); CHelper.TryGetEnumValueFromXML("//root/Theme/DrawNoteLines", navigator, ref DrawNoteLines); CHelper.TryGetEnumValueFromXML("//root/Theme/DrawToneHelper", navigator, ref DrawToneHelper); CHelper.TryGetEnumValueFromXML("//root/Theme/TimerLook", navigator, ref TimerLook); CHelper.TryGetEnumValueFromXML("//root/Theme/CoverLoading", navigator, ref CoverLoading); #endregion Theme #region Sound CHelper.TryGetEnumValueFromXML <EPlaybackLib>("//root/Sound/PlayBackLib", navigator, ref PlayBackLib); CHelper.TryGetEnumValueFromXML <ERecordLib>("//root/Sound/RecordLib", navigator, ref RecordLib); CHelper.TryGetEnumValueFromXML <EBufferSize>("//root/Sound/AudioBufferSize", navigator, ref AudioBufferSize); CHelper.TryGetIntValueFromXML("//root/Sound/AudioLatency", navigator, ref AudioLatency); if (AudioLatency < -500) { AudioLatency = -500; } if (AudioLatency > 500) { AudioLatency = 500; } CHelper.TryGetEnumValueFromXML("//root/Sound/BackgroundMusic", navigator, ref BackgroundMusic); CHelper.TryGetIntValueFromXML("//root/Sound/BackgroundMusicVolume", navigator, ref BackgroundMusicVolume); CHelper.TryGetEnumValueFromXML("//root/Sound/BackgroundMusicSource", navigator, ref BackgroundMusicSource); #endregion Sound #region Game // Songfolder value = string.Empty; int i = 1; while (CHelper.GetValueFromXML("//root/Game/SongFolder" + i.ToString(), navigator, ref value, value)) { if (i == 1) { SongFolder.Clear(); } SongFolder.Add(value); value = string.Empty; i++; } CHelper.TryGetEnumValueFromXML <ESongMenu>("//root/Game/SongMenu", navigator, ref SongMenu); CHelper.TryGetEnumValueFromXML <ESongSorting>("//root/Game/SongSorting", navigator, ref SongSorting); CHelper.TryGetFloatValueFromXML("//root/Game/ScoreAnimationTime", navigator, ref ScoreAnimationTime); CHelper.TryGetEnumValueFromXML <ETimerMode>("//root/Game/TimerMode", navigator, ref TimerMode); CHelper.TryGetIntValueFromXML("//root/Game/NumPlayer", navigator, ref NumPlayer); CHelper.TryGetEnumValueFromXML("//root/Game/Tabs", navigator, ref Tabs); CHelper.GetValueFromXML("//root/Game/Language", navigator, ref Language, Language); CHelper.TryGetEnumValueFromXML <EOffOn>("//root/Game/LyricsOnTop", navigator, ref LyricsOnTop); if ((ScoreAnimationTime > 0 && ScoreAnimationTime < 1) || ScoreAnimationTime < 0) { ScoreAnimationTime = 1; } if (NumPlayer < 1 || NumPlayer > CSettings.MaxNumPlayer) { NumPlayer = 2; } List <string> _Languages = new List <string>(); _Languages = CLanguage.GetLanguages(); bool _LangExists = false; for (i = 0; i < _Languages.Count; i++) { if (_Languages[i] == Language) { _LangExists = true; } } //TODO: What should we do, if English not exists? if (_LangExists == false) { Language = "English"; } CLanguage.SetLanguage(Language); #endregion Game #region Video CHelper.TryGetEnumValueFromXML <EVideoDecoder>("//root/Video/VideoDecoder", navigator, ref VideoDecoder); CHelper.TryGetEnumValueFromXML <EOffOn>("//root/Video/VideoBackgrounds", navigator, ref VideoBackgrounds); CHelper.TryGetEnumValueFromXML <EOffOn>("//root/Video/VideoPreview", navigator, ref VideoPreview); CHelper.TryGetEnumValueFromXML <EOffOn>("//root/Video/VideosInSongs", navigator, ref VideosInSongs); #endregion Video #region Record MicConfig = new SMicConfig[CSettings.MaxNumPlayer]; value = string.Empty; for (int p = 1; p <= CSettings.MaxNumPlayer; p++) { MicConfig[p - 1] = new SMicConfig(0); CHelper.GetValueFromXML("//root/Record/MicConfig" + p.ToString() + "/DeviceName", navigator, ref MicConfig[p - 1].DeviceName, String.Empty); CHelper.GetValueFromXML("//root/Record/MicConfig" + p.ToString() + "/DeviceDriver", navigator, ref MicConfig[p - 1].DeviceDriver, String.Empty); CHelper.GetValueFromXML("//root/Record/MicConfig" + p.ToString() + "/InputName", navigator, ref MicConfig[p - 1].InputName, String.Empty); CHelper.TryGetIntValueFromXML("//root/Record/MicConfig" + p.ToString() + "/Channel", navigator, ref MicConfig[p - 1].Channel); } CHelper.TryGetIntValueFromXML("//root/Record/MicDelay", navigator, ref MicDelay); MicDelay = (int)(20 * Math.Round(MicDelay / 20.0)); if (MicDelay < 0) { MicDelay = 0; } if (MicDelay > 500) { MicDelay = 500; } #endregion Record return(true); } else { return(false); } }