diff --git a/Vocaluxe/Base/CCover.cs b/Vocaluxe/Base/CCover.cs index 62527cd3..ac9cc10c 100644 --- a/Vocaluxe/Base/CCover.cs +++ b/Vocaluxe/Base/CCover.cs @@ -188,7 +188,7 @@ namespace Vocaluxe.Base if (xmlReader != null) { _Covers.Clear(); - List cover = xmlReader.GetValues("Cover"); + List cover = xmlReader.GetNames("//root/Cover/*"); foreach (string coverName in cover) { string name; diff --git a/Vocaluxe/Base/CLanguage.cs b/Vocaluxe/Base/CLanguage.cs index c78b3ed5..a86faf0f 100644 --- a/Vocaluxe/Base/CLanguage.cs +++ b/Vocaluxe/Base/CLanguage.cs @@ -168,7 +168,7 @@ namespace Vocaluxe.Base private static bool _LoadLanguageEntries(CXMLReader xmlReader, out Dictionary texts) { texts = new Dictionary(); - IEnumerable names = xmlReader.GetAttributes("resources", "name"); + IEnumerable names = xmlReader.GetAttributes("//resources/string", "name"); foreach (string name in names) { string value; diff --git a/Vocaluxe/Base/CParty.cs b/Vocaluxe/Base/CParty.cs index 1dada7f9..22bc3b33 100644 --- a/Vocaluxe/Base/CParty.cs +++ b/Vocaluxe/Base/CParty.cs @@ -246,10 +246,10 @@ namespace Vocaluxe.Base loaded &= xmlReader.GetValue("//root/Info/Author", out pm.Author, "ERROR Author"); loaded &= xmlReader.GetValue("//root/Info/Folder", out pm.Folder, "ERROR Folder"); loaded &= xmlReader.GetValue("//root/Info/PartyModeFile", out pm.PartyModeFile, "ERROR PartyModeFile"); - loaded &= xmlReader.GetInnerValues("PartyScreens", ref pm.ScreenFiles); loaded &= xmlReader.TryGetIntValue("//root/Info/PartyModeVersionMajor", ref pm.PartyModeVersionMajor); loaded &= xmlReader.TryGetIntValue("//root/Info/PartyModeVersionMinor", ref pm.PartyModeVersionMinor); loaded &= xmlReader.GetValue("//root/Info/TargetAudience", out pm.TargetAudience, "ERROR TargetAudience"); + loaded &= xmlReader.GetValues("//root/PartyScreens/*", ref pm.ScreenFiles); if (!loaded) { diff --git a/Vocaluxe/Base/CTheme.cs b/Vocaluxe/Base/CTheme.cs index e382191e..520353a4 100644 --- a/Vocaluxe/Base/CTheme.cs +++ b/Vocaluxe/Base/CTheme.cs @@ -485,12 +485,12 @@ namespace Vocaluxe.Base skin.PartyModeID = theme.PartyModeID; skin.SkinList = new Dictionary(); - List names = xmlReader.GetValues("Skins"); + List names = xmlReader.GetNames("//root/Skins/*"); foreach (string str in names) skin.SkinList[str] = new CSkinElement(); skin.VideoList = new Dictionary(); - names = xmlReader.GetValues("Videos"); + names = xmlReader.GetNames("//root/Videos/*"); foreach (string str in names) skin.VideoList[str] = new CVideoSkinElement(); _Skins.Add(skin); @@ -665,7 +665,7 @@ namespace Vocaluxe.Base } var colorScheme = new List(); - List names = xmlReader.GetValues("ColorSchemes"); + List names = xmlReader.GetNames("//root/ColorSchemes/*"); foreach (string str in names) { var scheme = new SColorScheme {Name = str}; diff --git a/Vocaluxe/Lib/Playlist/CPlaylistFile.cs b/Vocaluxe/Lib/Playlist/CPlaylistFile.cs index bdadd99b..ff86215f 100644 --- a/Vocaluxe/Lib/Playlist/CPlaylistFile.cs +++ b/Vocaluxe/Lib/Playlist/CPlaylistFile.cs @@ -122,7 +122,7 @@ namespace Vocaluxe.Lib.Playlist Songs = new List(); - List songs = xmlReader.GetValues("Songs"); + List songs = xmlReader.GetNames("//root/Songs/*"); foreach (string songEntry in songs) { diff --git a/VocaluxeLib/CXMLReader.cs b/VocaluxeLib/CXMLReader.cs index c35f12ef..1603af81 100644 --- a/VocaluxeLib/CXMLReader.cs +++ b/VocaluxeLib/CXMLReader.cs @@ -57,49 +57,44 @@ namespace VocaluxeLib } } - public bool TryGetEnumValue(string cast, ref T value) + public bool TryGetEnumValue(string xPath, ref T value) where T : struct { string val; - if (GetValue(cast, out val, Enum.GetName(typeof(T), value))) + if (GetValue(xPath, out val, Enum.GetName(typeof(T), value))) return CHelper.TryParse(val, out value, true); return false; } - public bool TryGetIntValue(string cast, ref int value) + public bool TryGetIntValue(string xPath, ref int value) { string val; - if (GetValue(cast, out val, value.ToString())) + if (GetValue(xPath, out val, value.ToString())) return int.TryParse(val, out value); return false; } - public bool TryGetIntValueRange(string cast, ref int value, int min = 0, int max = 100) + public bool TryGetIntValueRange(string xPath, ref int value, int min = 0, int max = 100) { - bool result = TryGetIntValue(cast, ref value); + bool result = TryGetIntValue(xPath, ref value); if (result) - { - if (value < min) - value = min; - else if (value > max) - value = max; - } + value = value.Clamp(min, max); return result; } - public bool TryGetFloatValue(string cast, ref float value) + public bool TryGetFloatValue(string xPath, ref float value) { string val; - return GetValue(cast, out val, value.ToString()) && CHelper.TryParse(val, out value); + return GetValue(xPath, out val, value.ToString()) && CHelper.TryParse(val, out value); } - public bool GetValue(string cast, out string value, string defaultValue) + public bool GetValue(string xPath, out string value, string defaultValue) { int resultCt = 0; string val = string.Empty; - _Navigator.MoveToFirstChild(); - XPathNodeIterator iterator = _Navigator.Select(cast); + _Navigator.MoveToRoot(); + XPathNodeIterator iterator = _Navigator.Select(xPath); while (iterator.MoveNext()) { @@ -116,77 +111,45 @@ namespace VocaluxeLib return true; } - public List GetValues(string cast) + public List GetNames(string xPath) { var values = new List(); _Navigator.MoveToRoot(); - _Navigator.MoveToFirstChild(); - _Navigator.MoveToFirstChild(); - - while (_Navigator.Name != cast) - _Navigator.MoveToNext(); - - _Navigator.MoveToFirstChild(); - - values.Add(_Navigator.LocalName); - while (_Navigator.MoveToNext()) - values.Add(_Navigator.LocalName); - - return values; - } - - public IEnumerable GetAttributes(string cast, string attribute) - { - var values = new List(); - - _Navigator.MoveToRoot(); - _Navigator.MoveToFirstChild(); - - while (_Navigator.Name != cast) - _Navigator.MoveToNext(); - - _Navigator.MoveToFirstChild(); - - values.Add(_Navigator.LocalName); - while (_Navigator.MoveToNext()) - values.Add(_Navigator.GetAttribute(attribute, "")); - - return values; - } - - public bool GetInnerValues(string cast, ref List values) - { - _Navigator.MoveToRoot(); - _Navigator.MoveToFirstChild(); - _Navigator.MoveToFirstChild(); - - while (_Navigator.Name != cast) - _Navigator.MoveToNext(); - - _Navigator.MoveToFirstChild(); - - values.Add(_Navigator.Value); - while (_Navigator.MoveToNext()) - values.Add(_Navigator.Value); - - return true; - } - - public bool ItemExists(string cast) - { - int results = 0; - - _Navigator.MoveToFirstChild(); - XPathNodeIterator iterator = _Navigator.Select(cast); - + XPathNodeIterator iterator = _Navigator.Select(xPath); while (iterator.MoveNext()) - results++; + values.Add(iterator.Current.LocalName); - if (results == 0) - return false; + return values; + } + + public IEnumerable GetAttributes(string xPath, string attribute) + { + var values = new List(); + + _Navigator.MoveToRoot(); + XPathNodeIterator iterator = _Navigator.Select(xPath); + while (iterator.MoveNext()) + values.Add(iterator.Current.GetAttribute(attribute, "")); + + return values; + } + + public bool GetValues(string xPath, ref List values) + { + _Navigator.MoveToRoot(); + XPathNodeIterator iterator = _Navigator.Select(xPath); + while (iterator.MoveNext()) + values.Add(iterator.Current.Value); return true; } + + public bool ItemExists(string xPath) + { + _Navigator.MoveToRoot(); + + return _Navigator.Select(xPath).MoveNext(); + } } } \ No newline at end of file