Use new serializer for theme loading
Fix some bugs during load
This commit is contained in:
1 parent
6d494b64b3
commit
3344a3562f
5 files changed
+56
-34
No files matched your search
@@ -1232,7 +1232,7 @@
|
||||
<Text />
|
||||
</Text>
|
||||
</ButtonPlaylistSing>
|
||||
<SelectSlideGameMode>
|
||||
<SelectSlideGameMode Name="SelectSlideGameMode">
|
||||
<Skin>Button</Skin>
|
||||
<SkinArrowLeft>SelectSlideArrowLeft</SkinArrowLeft>
|
||||
<SkinArrowRight>SelectSlideArrowRight</SkinArrowRight>
|
||||
|
||||
+28
-24
@@ -137,6 +137,26 @@ namespace VocaluxeLib.Menu
|
||||
}
|
||||
}
|
||||
|
||||
private class CLoadThemeErrorHandler : CXmlDeserializer.CXmlDefaultErrorHandler
|
||||
{
|
||||
private static readonly string[] _AllowedMissing = new string[]
|
||||
{
|
||||
"Backgrounds", "Statics", "Texts", "Buttons", "SongMenus", "Lyrics", "SelectSlides", "SingNotes",
|
||||
"NameSelections", "Equalizers", "Playlists", "ParticleEffects", "ScreenSettings"
|
||||
};
|
||||
|
||||
public override void HandleError(CXmlException e)
|
||||
{
|
||||
CXmlMissingElementException missingEx = e as CXmlMissingElementException;
|
||||
if (missingEx != null)
|
||||
{
|
||||
if (_AllowedMissing.Contains(missingEx.Field.Name))
|
||||
return;
|
||||
}
|
||||
base.HandleError(e);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void LoadTheme(string xmlPath)
|
||||
{
|
||||
if (CBase.Config.GetLoadOldThemeFiles())
|
||||
@@ -149,26 +169,10 @@ namespace VocaluxeLib.Menu
|
||||
|
||||
string file = Path.Combine(xmlPath, ThemeName + ".xml");
|
||||
|
||||
Theme.Informations = new SScreenInformation();
|
||||
Theme.Backgrounds = new List<SThemeBackground>();
|
||||
Theme.Statics = new List<SThemeStatic>();
|
||||
Theme.Texts = new List<SThemeText>();
|
||||
Theme.Buttons = new List<SThemeButton>();
|
||||
Theme.SongMenus = new List<SThemeSongMenu>();
|
||||
Theme.Lyrics = new List<SThemeLyrics>();
|
||||
Theme.SelectSlides = new List<SThemeSelectSlide>();
|
||||
Theme.SingNotes = new List<SThemeSingBar>();
|
||||
Theme.NameSelections = new List<SThemeNameSelection>();
|
||||
Theme.Equalizers = new List<SThemeEqualizer>();
|
||||
Theme.Playlists = new List<SThemePlaylist>();
|
||||
Theme.ParticleEffects = new List<SThemeParticleEffect>();
|
||||
Theme.ScreenSettings = new List<SThemeScreenSetting>();
|
||||
|
||||
try
|
||||
{
|
||||
TextReader textReader = new StreamReader(file);
|
||||
XmlSerializer deserializer = new XmlSerializer(typeof(SThemeScreen));
|
||||
Theme = (SThemeScreen)deserializer.Deserialize(textReader);
|
||||
CXmlDeserializer deserializer = new CXmlDeserializer(new CLoadThemeErrorHandler());
|
||||
Theme = deserializer.Deserialize<SThemeScreen>(file);
|
||||
|
||||
foreach (SThemeBackground bg in Theme.Backgrounds)
|
||||
_AddBackground(new CBackground(bg, PartyModeID), bg.Name);
|
||||
@@ -227,6 +231,10 @@ namespace VocaluxeLib.Menu
|
||||
{
|
||||
CBase.Log.LogError("Error while reading " + ThemeName + ".xml", true, true);
|
||||
}
|
||||
catch (CXmlException e)
|
||||
{
|
||||
CBase.Log.LogError("Error while reading " + ThemeName + ".xml: " + e, true, true);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
CBase.Log.LogError(e.Message + e.StackTrace, true, true);
|
||||
@@ -308,12 +316,8 @@ namespace VocaluxeLib.Menu
|
||||
|
||||
try
|
||||
{
|
||||
TextWriter textWriter = new StreamWriter(Path.Combine(ThemePath, ThemeName + ".xml"));
|
||||
|
||||
XmlSerializer serializer = new XmlSerializer(typeof(SThemeScreen));
|
||||
serializer.Serialize(textWriter, Theme);
|
||||
|
||||
textWriter.Close();
|
||||
CXmlSerializer serializer = new CXmlSerializer();
|
||||
serializer.Serialize(Path.Combine(ThemePath, ThemeName + ".xml"), Theme);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Xml.Serialization;
|
||||
@@ -52,8 +53,8 @@ namespace VocaluxeLib.Menu
|
||||
public SThemeColor TextSelColor;
|
||||
|
||||
public float TextH;
|
||||
public float TextRelativeX;
|
||||
public float TextRelativeY;
|
||||
[DefaultValue(0.0f)] public float TextRelativeX;
|
||||
[DefaultValue(0.0f)] public float TextRelativeY;
|
||||
public float TextMaxW;
|
||||
|
||||
public string TextFont;
|
||||
|
||||
@@ -186,6 +186,7 @@ namespace VocaluxeLib
|
||||
public float Z;
|
||||
[XmlIgnore] public float Rotation; //0..360°
|
||||
|
||||
[XmlIgnore]
|
||||
public float Right
|
||||
{
|
||||
get { return X + W; }
|
||||
@@ -195,6 +196,8 @@ namespace VocaluxeLib
|
||||
Debug.Assert(W >= 0);
|
||||
}
|
||||
}
|
||||
|
||||
[XmlIgnore]
|
||||
public float Bottom
|
||||
{
|
||||
get { return Y + H; }
|
||||
@@ -204,10 +207,14 @@ namespace VocaluxeLib
|
||||
Debug.Assert(H >= 0);
|
||||
}
|
||||
}
|
||||
|
||||
[XmlIgnore]
|
||||
public Size SizeI
|
||||
{
|
||||
get { return new Size((int)W, (int)H); }
|
||||
}
|
||||
|
||||
[XmlIgnore]
|
||||
public SizeF Size
|
||||
{
|
||||
get { return new SizeF(W, H); }
|
||||
|
||||
@@ -86,14 +86,14 @@ namespace VocaluxeLib.Xml
|
||||
}
|
||||
#endregion Debug Helpers
|
||||
|
||||
private readonly XmlNode _Node;
|
||||
public readonly XmlNode Node;
|
||||
public readonly bool IsError;
|
||||
|
||||
public CXmlException(string msg, XmlNode node, bool isError = true)
|
||||
: base(msg)
|
||||
{
|
||||
IsError = isError;
|
||||
_Node = node;
|
||||
Node = node;
|
||||
}
|
||||
|
||||
public override string Message
|
||||
@@ -103,12 +103,22 @@ namespace VocaluxeLib.Xml
|
||||
|
||||
public override String ToString()
|
||||
{
|
||||
string xPath = _Node == null ? "" : _GetXPath(_Node);
|
||||
string xPath = Node == null ? "" : _GetXPath(Node);
|
||||
string type = IsError ? "Error" : "Warning";
|
||||
return type + ": " + base.Message.Replace("%n", xPath);
|
||||
}
|
||||
}
|
||||
|
||||
public class CXmlMissingElementException : CXmlException
|
||||
{
|
||||
public readonly SFieldInfo Field;
|
||||
|
||||
public CXmlMissingElementException(XmlNode parent, SFieldInfo field, bool isError = true) : base("Element: " + field.Name + " is missing in %n", parent, isError)
|
||||
{
|
||||
Field = field;
|
||||
}
|
||||
}
|
||||
|
||||
public class CXmlInvalidValueException : CXmlException
|
||||
{
|
||||
private readonly string _Value;
|
||||
@@ -157,9 +167,9 @@ namespace VocaluxeLib.Xml
|
||||
|
||||
public class CXmlDeserializer
|
||||
{
|
||||
private class CXmlDefaultErrorHandler : IXmlErrorHandler
|
||||
public class CXmlDefaultErrorHandler : IXmlErrorHandler
|
||||
{
|
||||
public void HandleError(CXmlException e)
|
||||
public virtual void HandleError(CXmlException e)
|
||||
{
|
||||
if (e.IsError)
|
||||
throw e;
|
||||
@@ -421,7 +431,7 @@ namespace VocaluxeLib.Xml
|
||||
Dictionary<string, Tuple<SFieldInfo, List<object>>> embLists = new Dictionary<string, Tuple<SFieldInfo, List<object>>>();
|
||||
foreach (XmlNode node in nodes)
|
||||
{
|
||||
if (node is XmlComment)
|
||||
if (node is XmlComment || node.LocalName == "xsd" || node.LocalName == "xsi")
|
||||
continue;
|
||||
|
||||
SFieldInfo field = new SFieldInfo();
|
||||
@@ -505,7 +515,7 @@ namespace VocaluxeLib.Xml
|
||||
if (!_CheckAndSetDefaultValue(o, field))
|
||||
{
|
||||
if (parent != null)
|
||||
_ErrorHandler.HandleError(new CXmlException("element: " + field.Name + " is missing in %n", parent));
|
||||
_ErrorHandler.HandleError(new CXmlMissingElementException(parent, field));
|
||||
object value = _GetValue(null, field.Type, field.ArrayItemName, field.GetValue(o));
|
||||
if (value != null)
|
||||
field.SetValue(o, value);
|
||||
|
||||
Reference in new issue
Block a user