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); } }
private async static void _LoadProfiles() { _LoadAvatars(); var knownFiles = new List <string>(); if (_Profiles.Count > 0) { var ids = new Guid[_Profiles.Keys.Count]; _Profiles.Keys.CopyTo(ids, 0); foreach (Guid id in ids) { if (_Profiles[id].LoadProfile()) { knownFiles.Add(Path.GetFileName(_Profiles[id].FilePath)); } else { _Profiles.Remove(id); } } } if (CConfig.UseCloudServer) { string json = JsonConvert.SerializeObject(new { Key = CConfig.CloudServerKey }); var content = new StringContent(json, Encoding.UTF8, "application/json"); string responseString = ""; var response = await _Client.PostAsync(CConfig.CloudServerURL + "/api/getProfiles", content); responseString = await response.Content.ReadAsStringAsync(); CProfile[] CloudProfiles = JsonConvert.DeserializeObject <CProfile[]>(responseString); Console.Write(CloudProfiles); foreach (CProfile profile in CloudProfiles) { _Profiles.Add(profile.ID, profile); } } else { var files = new List <string>(); foreach (string path in CConfig.ProfileFolders) { files.AddRange(CHelper.ListFiles(path, "*.xml", true, true)); } foreach (string file in files) { if (knownFiles.Contains(Path.GetFileName(file))) { continue; } var profile = new CProfile(); if (profile.LoadProfile(file)) { _Profiles.Add(profile.ID, profile); } } } _ProfilesChanged = true; }
public static void ListSkins() { CHelper Helper = new CHelper(); int themeIndex = GetThemeIndex(); _Skins.Clear(); if (themeIndex < 0) { CLog.LogError("Error List Skins. Can't find Theme: " + CConfig.Theme); return; } Theme theme = _Themes[themeIndex]; string path = Path.Combine(theme.Path, theme.SkinFolder); List <string> files = Helper.ListFiles(path, "*.xml", false); foreach (string file in files) { bool loaded = false; XPathDocument xPathDoc = null; XPathNavigator navigator = null; try { xPathDoc = new XPathDocument(Path.Combine(path, file)); navigator = xPathDoc.CreateNavigator(); loaded = true; } catch (Exception e) { CLog.LogError("Error loading skin " + file + ": " + e.Message); loaded = false; if (navigator != null) { navigator = null; } if (xPathDoc != null) { xPathDoc = null; } } if (loaded) { Skin skin = new Skin(); int version = 0; CHelper.TryGetIntValueFromXML("//root/SkinSystemVersion", navigator, ref version); if (version == SkinSystemVersion) { CHelper.GetValueFromXML("//root/Info/Name", navigator, ref skin.Name, String.Empty); if (skin.Name != String.Empty) { CHelper.GetValueFromXML("//root/Info/Author", navigator, ref skin.Author, String.Empty); CHelper.TryGetIntValueFromXML("//root/Info/SkinVersionMajor", navigator, ref skin.SkinVersionMajor); CHelper.TryGetIntValueFromXML("//root/Info/SkinVersionMinor", navigator, ref skin.SkinVersionMinor); skin.Path = path; skin.FileName = file; skin.SkinList = new Dictionary <string, SkinElement>(); List <string> names = CHelper.GetValuesFromXML("Skins", navigator); foreach (string str in names) { SkinElement sk = new SkinElement(); sk.Name = str; sk.Value = String.Empty; skin.SkinList[str] = sk; } skin.VideoList = new List <SkinElement>(); names = CHelper.GetValuesFromXML("Videos", navigator); foreach (string str in names) { SkinElement sk = new SkinElement(); sk.Name = str; sk.Value = String.Empty; skin.VideoList.Add(sk); } _Skins.Add(skin); } } else { string msg = "Can't load Skin \"" + file + "\", "; if (version < SkinSystemVersion) { msg += "the file ist outdated! "; } else { msg += "the file is for newer program versions! "; } msg += "Current SkinSystemVersion is " + SkinSystemVersion.ToString(); CLog.LogError(msg); } } } }
private static void ListThemes() { CHelper Helper = new CHelper(); _Themes.Clear(); string path = Path.Combine(Directory.GetCurrentDirectory(), CSettings.sFolderThemes); List <string> files = Helper.ListFiles(path, "*.xml", false); foreach (string file in files) { bool loaded = false; XPathDocument xPathDoc = null; XPathNavigator navigator = null; try { xPathDoc = new XPathDocument(Path.Combine(path, file)); navigator = xPathDoc.CreateNavigator(); loaded = true; } catch (Exception e) { CLog.LogError("Error loading theme " + file + ": " + e.Message); loaded = false; if (navigator != null) { navigator = null; } if (xPathDoc != null) { xPathDoc = null; } } if (loaded) { Theme theme = new Theme(); int version = 0; CHelper.TryGetIntValueFromXML("//root/ThemeSystemVersion", navigator, ref version); if (version == ThemeSystemVersion) { CHelper.GetValueFromXML("//root/Info/Name", navigator, ref theme.Name, String.Empty); if (theme.Name != String.Empty) { CHelper.GetValueFromXML("//root/Info/Author", navigator, ref theme.Author, String.Empty); CHelper.GetValueFromXML("//root/Info/SkinFolder", navigator, ref theme.SkinFolder, String.Empty); CHelper.TryGetIntValueFromXML("//root/Info/ThemeVersionMajor", navigator, ref theme.ThemeVersionMajor); CHelper.TryGetIntValueFromXML("//root/Info/ThemeVersionMinor", navigator, ref theme.ThemeVersionMinor); theme.Path = path; theme.FileName = file; _Themes.Add(theme); } } else { string msg = "Can't load Theme \"" + file + "\", "; if (version < ThemeSystemVersion) { msg += "the file ist outdated! "; } else { msg += "the file is for newer program versions! "; } msg += "Current ThemeSystemVersion is " + ThemeSystemVersion.ToString(); CLog.LogError(msg); } } } }
public static void LoadSkins() { for (int index = 0; index < _Skins.Count; index++) { bool loaded = false; XPathDocument xPathDoc = null; XPathNavigator navigator = null; try { xPathDoc = new XPathDocument(Path.Combine(_Skins[index].Path, _Skins[index].FileName)); navigator = xPathDoc.CreateNavigator(); loaded = true; } catch (Exception e) { CLog.LogError("Error loading skin " + _Skins[index].FileName + ": " + e.Message); loaded = false; if (navigator != null) { navigator = null; } if (xPathDoc != null) { xPathDoc = null; } } if (loaded) { string value = String.Empty; // load skins/textures List <string> keys = new List <string>(_Skins[index].SkinList.Keys); foreach (string name in keys) { try { CHelper.GetValueFromXML("//root/Skins/" + name, navigator, ref value, String.Empty); SkinElement sk = _Skins[index].SkinList[name]; sk.Value = value; sk.VideoIndex = -1; sk.Texture = CDraw.AddTexture(Path.Combine(_Skins[index].Path, sk.Value)); _Skins[index].SkinList[name] = sk; } catch (Exception e) { MessageBox.Show("Error on loading texture \"" + name + "\": " + e.Message + e.StackTrace); CLog.LogError("Error on loading texture \"" + name + "\": " + e.Message + e.StackTrace); } } // load videos for (int i = 0; i < _Skins[index].VideoList.Count; i++) { try { CHelper.GetValueFromXML("//root/Videos/" + _Skins[index].VideoList[i].Name, navigator, ref value, String.Empty); SkinElement sk = new SkinElement(); sk.Name = _Skins[index].VideoList[i].Name; sk.Value = value; sk.VideoIndex = CVideo.VdLoad(Path.Combine(_Skins[index].Path, sk.Value)); CVideo.VdSetLoop(sk.VideoIndex, true); CVideo.VdPause(sk.VideoIndex); sk.Texture = new STexture(-1); _Skins[index].VideoList[i] = sk; } catch (Exception e) { MessageBox.Show("Error on loading video \"" + _Skins[index].VideoList[i].Name + "\": " + e.Message + e.StackTrace); CLog.LogError("Error on loading video \"" + _Skins[index].VideoList[i].Name + "\": " + e.Message + e.StackTrace); } } // load colors LoadColors(navigator, index); } } }
/// <summary> /// Loads theme fonts from skin file /// </summary> public static void LoadThemeFonts(string ThemeName, string SkinFolder, XPathNavigator navigator) { string value = string.Empty; int i = 1; while (CHelper.GetValueFromXML("//root/Fonts/Font" + i.ToString() + "/Folder", navigator, ref value, value)) { SFont sf = new SFont(); sf.Folder = value; sf.IsThemeFont = true; sf.ThemeName = ThemeName; bool ok = true; ok &= CHelper.GetValueFromXML("//root/Fonts/Font" + i.ToString() + "/FileNormal", navigator, ref value, value); sf.FileNormal = value; value = Path.Combine(SkinFolder, Path.Combine(sf.Folder, value)); CFont f = new CFont(value); sf.Normal = f; string name = String.Empty; ok &= CHelper.GetValueFromXML("//root/Fonts/Font" + i.ToString() + "/Name", navigator, ref name, value); sf.Name = name; ok &= CHelper.GetValueFromXML("//root/Fonts/Font" + i.ToString() + "/FileItalic", navigator, ref value, value); sf.FileItalic = value; value = Path.Combine(SkinFolder, Path.Combine(sf.Folder, value)); f = new CFont(value); sf.Italic = f; ok &= CHelper.GetValueFromXML("//root/Fonts/Font" + i.ToString() + "/FileBold", navigator, ref value, value); sf.FileBold = value; value = Path.Combine(SkinFolder, Path.Combine(sf.Folder, value)); f = new CFont(value); sf.Bold = f; ok &= CHelper.GetValueFromXML("//root/Fonts/Font" + i.ToString() + "/FileBoldItalic", navigator, ref value, value); sf.FileBoldItalic = value; value = Path.Combine(SkinFolder, Path.Combine(sf.Folder, value)); f = new CFont(value); sf.BoldItalic = f; sf.Outline = 0f; ok &= CHelper.TryGetFloatValueFromXML("//root/Fonts/Font" + i.ToString() + "/Outline", navigator, ref sf.Outline); sf.OutlineColor = new SColorF(0f, 0f, 0f, 1f); ok &= CHelper.TryGetFloatValueFromXML("//root/Fonts/Font" + i.ToString() + "/OutlineColorR", navigator, ref sf.OutlineColor.R); ok &= CHelper.TryGetFloatValueFromXML("//root/Fonts/Font" + i.ToString() + "/OutlineColorG", navigator, ref sf.OutlineColor.G); ok &= CHelper.TryGetFloatValueFromXML("//root/Fonts/Font" + i.ToString() + "/OutlineColorB", navigator, ref sf.OutlineColor.B); ok &= CHelper.TryGetFloatValueFromXML("//root/Fonts/Font" + i.ToString() + "/OutlineColorA", navigator, ref sf.OutlineColor.A); if (ok) { _Fonts.Add(sf); } else { CLog.LogError("Error loading theme fonts for theme \"" + ThemeName + "\": Error in Font" + i.ToString()); } i++; } CLog.StartBenchmark(1, "BuildGlyphs"); BuildGlyphs(); CLog.StopBenchmark(1, "BuildGlyphs"); }
/// <summary> /// Load default fonts /// </summary> /// <returns></returns> private static bool LoadFontList() { bool loaded = false; XPathDocument xPathDoc = null; XPathNavigator navigator = null; try { xPathDoc = new XPathDocument(System.IO.Path.Combine(CSettings.sFolderFonts, CSettings.sFileFonts)); navigator = xPathDoc.CreateNavigator(); loaded = true; } catch (Exception e) { CLog.LogError("Error loading default fonts: " + e.Message); loaded = false; if (navigator != null) { navigator = null; } if (xPathDoc != null) { xPathDoc = null; } } _Fonts.Clear(); if (loaded) { string value = string.Empty; int i = 1; while (CHelper.GetValueFromXML("//root/Font" + i.ToString() + "/Folder", navigator, ref value, value)) { string Folder = value; CHelper.GetValueFromXML("//root/Font" + i.ToString() + "/FileNormal", navigator, ref value, value); value = Path.Combine(Directory.GetCurrentDirectory(), Path.Combine(CSettings.sFolderFonts, Path.Combine(Folder, value))); CFont f = new CFont(value); SFont sf = new SFont(); sf.Normal = f; string name = String.Empty; CHelper.GetValueFromXML("//root/Font" + i.ToString() + "/Name", navigator, ref name, value); sf.Name = name; sf.IsThemeFont = false; sf.ThemeName = String.Empty; CHelper.GetValueFromXML("//root/Font" + i.ToString() + "/FileItalic", navigator, ref value, value); value = Path.Combine(Directory.GetCurrentDirectory(), Path.Combine(CSettings.sFolderFonts, Path.Combine(Folder, value))); f = new CFont(value); sf.Italic = f; CHelper.GetValueFromXML("//root/Font" + i.ToString() + "/FileBold", navigator, ref value, value); value = Path.Combine(Directory.GetCurrentDirectory(), Path.Combine(CSettings.sFolderFonts, Path.Combine(Folder, value))); f = new CFont(value); sf.Bold = f; CHelper.GetValueFromXML("//root/Font" + i.ToString() + "/FileBoldItalic", navigator, ref value, value); value = Path.Combine(Directory.GetCurrentDirectory(), Path.Combine(CSettings.sFolderFonts, Path.Combine(Folder, value))); f = new CFont(value); sf.BoldItalic = f; sf.Outline = 0f; CHelper.TryGetFloatValueFromXML("//root/Font" + i.ToString() + "/Outline", navigator, ref sf.Outline); sf.OutlineColor = new SColorF(0f, 0f, 0f, 1f); CHelper.TryGetFloatValueFromXML("//root/Font" + i.ToString() + "/OutlineColorR", navigator, ref sf.OutlineColor.R); CHelper.TryGetFloatValueFromXML("//root/Font" + i.ToString() + "/OutlineColorG", navigator, ref sf.OutlineColor.G); CHelper.TryGetFloatValueFromXML("//root/Font" + i.ToString() + "/OutlineColorB", navigator, ref sf.OutlineColor.B); CHelper.TryGetFloatValueFromXML("//root/Font" + i.ToString() + "/OutlineColorA", navigator, ref sf.OutlineColor.A); _Fonts.Add(sf); i++; } } return(loaded); }