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 />
|
||||||
</Text>
|
</Text>
|
||||||
</ButtonPlaylistSing>
|
</ButtonPlaylistSing>
|
||||||
<SelectSlideGameMode>
|
<SelectSlideGameMode Name="SelectSlideGameMode">
|
||||||
<Skin>Button</Skin>
|
<Skin>Button</Skin>
|
||||||
<SkinArrowLeft>SelectSlideArrowLeft</SkinArrowLeft>
|
<SkinArrowLeft>SelectSlideArrowLeft</SkinArrowLeft>
|
||||||
<SkinArrowRight>SelectSlideArrowRight</SkinArrowRight>
|
<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)
|
public virtual void LoadTheme(string xmlPath)
|
||||||
{
|
{
|
||||||
if (CBase.Config.GetLoadOldThemeFiles())
|
if (CBase.Config.GetLoadOldThemeFiles())
|
||||||
@@ -149,26 +169,10 @@ namespace VocaluxeLib.Menu
|
|||||||
|
|
||||||
string file = Path.Combine(xmlPath, ThemeName + ".xml");
|
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
|
try
|
||||||
{
|
{
|
||||||
TextReader textReader = new StreamReader(file);
|
CXmlDeserializer deserializer = new CXmlDeserializer(new CLoadThemeErrorHandler());
|
||||||
XmlSerializer deserializer = new XmlSerializer(typeof(SThemeScreen));
|
Theme = deserializer.Deserialize<SThemeScreen>(file);
|
||||||
Theme = (SThemeScreen)deserializer.Deserialize(textReader);
|
|
||||||
|
|
||||||
foreach (SThemeBackground bg in Theme.Backgrounds)
|
foreach (SThemeBackground bg in Theme.Backgrounds)
|
||||||
_AddBackground(new CBackground(bg, PartyModeID), bg.Name);
|
_AddBackground(new CBackground(bg, PartyModeID), bg.Name);
|
||||||
@@ -227,6 +231,10 @@ namespace VocaluxeLib.Menu
|
|||||||
{
|
{
|
||||||
CBase.Log.LogError("Error while reading " + ThemeName + ".xml", true, true);
|
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)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
CBase.Log.LogError(e.Message + e.StackTrace, true, true);
|
CBase.Log.LogError(e.Message + e.StackTrace, true, true);
|
||||||
@@ -308,12 +316,8 @@ namespace VocaluxeLib.Menu
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
TextWriter textWriter = new StreamWriter(Path.Combine(ThemePath, ThemeName + ".xml"));
|
CXmlSerializer serializer = new CXmlSerializer();
|
||||||
|
serializer.Serialize(Path.Combine(ThemePath, ThemeName + ".xml"), Theme);
|
||||||
XmlSerializer serializer = new XmlSerializer(typeof(SThemeScreen));
|
|
||||||
serializer.Serialize(textWriter, Theme);
|
|
||||||
|
|
||||||
textWriter.Close();
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
@@ -52,8 +53,8 @@ namespace VocaluxeLib.Menu
|
|||||||
public SThemeColor TextSelColor;
|
public SThemeColor TextSelColor;
|
||||||
|
|
||||||
public float TextH;
|
public float TextH;
|
||||||
public float TextRelativeX;
|
[DefaultValue(0.0f)] public float TextRelativeX;
|
||||||
public float TextRelativeY;
|
[DefaultValue(0.0f)] public float TextRelativeY;
|
||||||
public float TextMaxW;
|
public float TextMaxW;
|
||||||
|
|
||||||
public string TextFont;
|
public string TextFont;
|
||||||
|
|||||||
@@ -186,6 +186,7 @@ namespace VocaluxeLib
|
|||||||
public float Z;
|
public float Z;
|
||||||
[XmlIgnore] public float Rotation; //0..360°
|
[XmlIgnore] public float Rotation; //0..360°
|
||||||
|
|
||||||
|
[XmlIgnore]
|
||||||
public float Right
|
public float Right
|
||||||
{
|
{
|
||||||
get { return X + W; }
|
get { return X + W; }
|
||||||
@@ -195,6 +196,8 @@ namespace VocaluxeLib
|
|||||||
Debug.Assert(W >= 0);
|
Debug.Assert(W >= 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[XmlIgnore]
|
||||||
public float Bottom
|
public float Bottom
|
||||||
{
|
{
|
||||||
get { return Y + H; }
|
get { return Y + H; }
|
||||||
@@ -204,10 +207,14 @@ namespace VocaluxeLib
|
|||||||
Debug.Assert(H >= 0);
|
Debug.Assert(H >= 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[XmlIgnore]
|
||||||
public Size SizeI
|
public Size SizeI
|
||||||
{
|
{
|
||||||
get { return new Size((int)W, (int)H); }
|
get { return new Size((int)W, (int)H); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[XmlIgnore]
|
||||||
public SizeF Size
|
public SizeF Size
|
||||||
{
|
{
|
||||||
get { return new SizeF(W, H); }
|
get { return new SizeF(W, H); }
|
||||||
|
|||||||
@@ -86,14 +86,14 @@ namespace VocaluxeLib.Xml
|
|||||||
}
|
}
|
||||||
#endregion Debug Helpers
|
#endregion Debug Helpers
|
||||||
|
|
||||||
private readonly XmlNode _Node;
|
public readonly XmlNode Node;
|
||||||
public readonly bool IsError;
|
public readonly bool IsError;
|
||||||
|
|
||||||
public CXmlException(string msg, XmlNode node, bool isError = true)
|
public CXmlException(string msg, XmlNode node, bool isError = true)
|
||||||
: base(msg)
|
: base(msg)
|
||||||
{
|
{
|
||||||
IsError = isError;
|
IsError = isError;
|
||||||
_Node = node;
|
Node = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Message
|
public override string Message
|
||||||
@@ -103,12 +103,22 @@ namespace VocaluxeLib.Xml
|
|||||||
|
|
||||||
public override String ToString()
|
public override String ToString()
|
||||||
{
|
{
|
||||||
string xPath = _Node == null ? "" : _GetXPath(_Node);
|
string xPath = Node == null ? "" : _GetXPath(Node);
|
||||||
string type = IsError ? "Error" : "Warning";
|
string type = IsError ? "Error" : "Warning";
|
||||||
return type + ": " + base.Message.Replace("%n", xPath);
|
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
|
public class CXmlInvalidValueException : CXmlException
|
||||||
{
|
{
|
||||||
private readonly string _Value;
|
private readonly string _Value;
|
||||||
@@ -157,9 +167,9 @@ namespace VocaluxeLib.Xml
|
|||||||
|
|
||||||
public class CXmlDeserializer
|
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)
|
if (e.IsError)
|
||||||
throw e;
|
throw e;
|
||||||
@@ -421,7 +431,7 @@ namespace VocaluxeLib.Xml
|
|||||||
Dictionary<string, Tuple<SFieldInfo, List<object>>> embLists = new Dictionary<string, Tuple<SFieldInfo, List<object>>>();
|
Dictionary<string, Tuple<SFieldInfo, List<object>>> embLists = new Dictionary<string, Tuple<SFieldInfo, List<object>>>();
|
||||||
foreach (XmlNode node in nodes)
|
foreach (XmlNode node in nodes)
|
||||||
{
|
{
|
||||||
if (node is XmlComment)
|
if (node is XmlComment || node.LocalName == "xsd" || node.LocalName == "xsi")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
SFieldInfo field = new SFieldInfo();
|
SFieldInfo field = new SFieldInfo();
|
||||||
@@ -505,7 +515,7 @@ namespace VocaluxeLib.Xml
|
|||||||
if (!_CheckAndSetDefaultValue(o, field))
|
if (!_CheckAndSetDefaultValue(o, field))
|
||||||
{
|
{
|
||||||
if (parent != null)
|
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));
|
object value = _GetValue(null, field.Type, field.ArrayItemName, field.GetValue(o));
|
||||||
if (value != null)
|
if (value != null)
|
||||||
field.SetValue(o, value);
|
field.SetValue(o, value);
|
||||||
|
|||||||
Reference in new issue
Block a user