Replace remaining usages of CXmlSerializer

(Old theme loading remaining)
This commit is contained in:
Flamefire committed 2014-10-30 17:54:59 +01:00
1 parent 12e48d0446
commit a318ce12fa
9 files changed
+228 -317

No files matched your search

+28 -82
View File
@@ -17,16 +17,14 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Xml;
using System.Xml.Serialization; using System.Linq;
using VocaluxeLib; using VocaluxeLib;
using VocaluxeLib.Draw; using VocaluxeLib.Draw;
using VocaluxeLib.Menu;
using VocaluxeLib.Songs; using VocaluxeLib.Songs;
using VocaluxeLib.Xml; using VocaluxeLib.Xml;
@@ -61,14 +59,7 @@ namespace Vocaluxe.Base
/// </summary> /// </summary>
public static string[] CoverThemes public static string[] CoverThemes
{ {
get get { return _CoverThemes.Select(th => th.Info.Name).ToArray(); }
{
var coverThemes = new List<string>();
for (int i = 0; i < _CoverThemes.Count; i++)
coverThemes.Add(_CoverThemes[i].Name);
return coverThemes.ToArray();
}
} }
/// <summary> /// <summary>
@@ -79,7 +70,7 @@ namespace Vocaluxe.Base
{ {
for (int i = 0; i < _CoverThemes.Count; i++) for (int i = 0; i < _CoverThemes.Count; i++)
{ {
if (_CoverThemes[i].Name == CConfig.Config.Theme.CoverTheme) if (_CoverThemes[i].Info.Name == CConfig.Config.Theme.CoverTheme)
return i; return i;
} }
return -1; return -1;
@@ -164,48 +155,12 @@ namespace Vocaluxe.Base
{ {
for (int i = 0; i < _CoverThemes.Count; i++) for (int i = 0; i < _CoverThemes.Count; i++)
{ {
if (_CoverThemes[i].Name == coverThemeName) if (_CoverThemes[i].Info.Name == coverThemeName)
return _CoverThemes[i]; return _CoverThemes[i];
} }
return new SThemeCover(); return new SThemeCover();
} }
private static void Foo(SThemeScreen a, SThemeScreen b)
{
a = b;
}
private static void _TestNewLoad(string path)
{
SThemeCover themeCover;
var xml = new CXmlSerializer();
themeCover = xml.Deserialize<SThemeCover>(path);
string cover = themeCover.Info.Author;
SThemeScreen theme = new SThemeScreen();
SThemeScreen theme2 = new SThemeScreen();
Stopwatch watch = new Stopwatch();
watch.Start();
for (int i = 0; i < 1; i++)
theme = xml.Deserialize<SThemeScreen>(Path.Combine(CBase.Themes.GetThemeScreensPath(-1), "ScreenMain.xml"));
watch.Stop();
xml.Serialize(Path.Combine(CBase.Themes.GetThemeScreensPath(-1), "ScreenMain2.xml"), theme);
return;
Stopwatch watch2 = new Stopwatch();
watch2.Start();
for (int i = 0; i < 100; i++)
{
using (TextReader textReader = new StreamReader(Path.Combine(CBase.Themes.GetThemeScreensPath(-1), "ScreenMain.xml")))
{
XmlSerializer deserializer = new XmlSerializer(typeof(STheme));
theme2 = (SThemeScreen)deserializer.Deserialize(textReader);
}
}
watch2.Stop();
Foo(theme, theme2);
MessageBox.Show(watch.ElapsedMilliseconds + "ms/5000=" + watch.ElapsedMilliseconds / 1000 + "ms vs " + watch2.ElapsedMilliseconds / 100);
}
/// <summary> /// <summary>
/// Loads all cover-themes to list. /// Loads all cover-themes to list.
/// </summary> /// </summary>
@@ -213,27 +168,27 @@ namespace Vocaluxe.Base
{ {
_CoverThemes.Clear(); _CoverThemes.Clear();
string path = Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameCover); string folderPath = Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameCover);
List<string> files = CHelper.ListFiles(path, "*.xml"); List<string> files = CHelper.ListFiles(folderPath, "*.xml");
var xml = new CXmlDeserializer();
foreach (string file in files) foreach (string file in files)
{ {
_TestNewLoad(Path.Combine(path, file)); SThemeCover theme;
CXMLReader xmlReader = CXMLReader.OpenFile(Path.Combine(path, file)); try
if (xmlReader != null)
{ {
var coverTheme = new SThemeCover(); theme = xml.Deserialize<SThemeCover>(Path.Combine(folderPath, file));
}
catch (XmlException e)
{
CLog.LogError("Error loading cover theme " + file + ": " + e.Message);
continue;
}
xmlReader.GetValue("//root/Info/Name", out coverTheme.Name, String.Empty); if (theme.Info.Folder != "" && theme.Info.Name != "")
xmlReader.GetValue("//root/Info/Folder", out coverTheme.Folder, String.Empty); {
theme.FolderPath = Path.Combine(folderPath, theme.Info.Folder);
if (coverTheme.Folder != "" && coverTheme.Name != "") _CoverThemes.Add(theme);
{
coverTheme.FilePath = xmlReader.FilePath;
_CoverThemes.Add(coverTheme);
}
} }
} }
} }
@@ -245,11 +200,10 @@ namespace Vocaluxe.Base
{ {
SThemeCover coverTheme = _CoverTheme(coverThemeName); SThemeCover coverTheme = _CoverTheme(coverThemeName);
if (String.IsNullOrEmpty(coverTheme.Name)) if (String.IsNullOrEmpty(coverTheme.Info.Name))
return; return;
string coverPath = Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameCover, coverTheme.Folder); List<string> files = CHelper.ListImageFiles(coverTheme.FolderPath, true, true);
List<string> files = CHelper.ListImageFiles(coverPath, true, true);
lock (_Covers) lock (_Covers)
{ {
@@ -297,22 +251,14 @@ namespace Vocaluxe.Base
private static void _LoadCoverGenerators(SThemeCover coverTheme) private static void _LoadCoverGenerators(SThemeCover coverTheme)
{ {
CXMLReader xmlReader = CXMLReader.OpenFile(coverTheme.FilePath);
string coverPath = Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameCover, coverTheme.Folder);
lock (_CoverGenerators) lock (_CoverGenerators)
{ {
int i = 1; foreach (SThemeCoverGenerator theme in coverTheme.CoverGenerators)
while (xmlReader.ItemExists("//root/CoverGenerator" + i))
{ {
SThemeCoverGenerator theme; if (_CoverGenerators.ContainsKey(theme.Type))
if (xmlReader.Read("//root/CoverGenerator" + i, out theme)) continue;
{ CCoverGenerator el = new CCoverGenerator(theme, coverTheme.FolderPath);
if (_CoverGenerators.ContainsKey(theme.Type)) _CoverGenerators.Add(theme.Type, el);
continue;
CCoverGenerator el = new CCoverGenerator(theme, coverPath);
_CoverGenerators.Add(theme.Type, el);
}
i++;
} }
} }
} }
+78 -115
View File
@@ -27,7 +27,7 @@ namespace Vocaluxe.Base
struct SLanguage struct SLanguage
{ {
public string Name; public string Name;
public string LanguageFilePath; public string FilePath;
public Dictionary<string, string> Texts; public Dictionary<string, string> Texts;
public List<SPartyLanguage> PartyModeTexts; public List<SPartyLanguage> PartyModeTexts;
@@ -41,7 +41,7 @@ namespace Vocaluxe.Base
static class CLanguage static class CLanguage
{ {
private static List<SLanguage> _Languages; private static readonly List<SLanguage> _Languages = new List<SLanguage>();
private static int _CurrentLanguage = -1; private static int _CurrentLanguage = -1;
private static int _FallbackLanguage; private static int _FallbackLanguage;
@@ -55,11 +55,6 @@ namespace Vocaluxe.Base
} }
} }
public static string GetLanguageName(int lang)
{
return _Languages[lang].Name;
}
public static IEnumerable<string> GetLanguageNames() public static IEnumerable<string> GetLanguageNames()
{ {
var languages = new string[_Languages.Count]; var languages = new string[_Languages.Count];
@@ -72,8 +67,6 @@ namespace Vocaluxe.Base
public static bool Init() public static bool Init()
{ {
_Languages = new List<SLanguage>();
var files = new List<string>(); var files = new List<string>();
files.AddRange(CHelper.ListFiles(CSettings.FolderNameLanguages, "*.xml", true, true)); files.AddRange(CHelper.ListFiles(CSettings.FolderNameLanguages, "*.xml", true, true));
@@ -84,7 +77,7 @@ namespace Vocaluxe.Base
public static bool SetLanguage(string language) public static bool SetLanguage(string language)
{ {
int nr = GetLanguageNr(language); int nr = _GetLanguageNr(language);
if (nr != -1) if (nr != -1)
{ {
_CurrentLanguage = nr; _CurrentLanguage = nr;
@@ -93,7 +86,7 @@ namespace Vocaluxe.Base
return false; return false;
} }
public static int GetLanguageNr(string language) private static int _GetLanguageNr(string language)
{ {
for (int i = 0; i < _Languages.Count; i++) for (int i = 0; i < _Languages.Count; i++)
{ {
@@ -103,59 +96,58 @@ namespace Vocaluxe.Base
return -1; return -1;
} }
public static string Translate(string keyWord, int partyModeID = -1) /// <summary>
/// Checks if a translation exists and returns it
/// </summary>
/// <param name="keyWord">Word to translate</param>
/// <param name="partyModeID"></param>
/// <param name="translation">Translated word or keyWord if translation does not exist</param>
/// <returns>True if word was translated</returns>
private static bool _GetTranslation(string keyWord, int partyModeID, out string translation)
{ {
if (keyWord == null) if (keyWord == null)
return "Error";
if (keyWord.Length < 3 || keyWord.Substring(0, 3) != "TR_")
return keyWord;
string result;
if (partyModeID != -1)
{ {
int partyModeNr = _GetPartyModeNr(partyModeID, _CurrentLanguage); translation = "Error";
if (partyModeNr != -1 && _Languages[_CurrentLanguage].PartyModeTexts[partyModeNr].Texts.TryGetValue(keyWord, out result)) return false;
return result;
partyModeNr = _GetPartyModeNr(partyModeID, _FallbackLanguage);
if (partyModeNr != -1 && _Languages[_CurrentLanguage].PartyModeTexts[partyModeNr].Texts.TryGetValue(keyWord, out result))
return result;
} }
if (_Languages[_CurrentLanguage].Texts.TryGetValue(keyWord, out result)) if (keyWord.Length < 3 || keyWord.Substring(0, 3) != "TR_")
return result; {
if (_Languages[_FallbackLanguage].Texts.TryGetValue(keyWord, out result)) translation = keyWord;
return result; return false;
}
return keyWord; if (partyModeID != -1)
{
Dictionary<string, string> partyModeTexts = _GetPartyModeTexts(_CurrentLanguage, partyModeID);
if (partyModeTexts != null && partyModeTexts.TryGetValue(keyWord, out translation))
return true;
partyModeTexts = _GetPartyModeTexts(_FallbackLanguage, partyModeID);
if (partyModeTexts != null && partyModeTexts.TryGetValue(keyWord, out translation))
return true;
}
if (_Languages[_CurrentLanguage].Texts.TryGetValue(keyWord, out translation))
return true;
if (_Languages[_FallbackLanguage].Texts.TryGetValue(keyWord, out translation))
return true;
translation = keyWord;
return false;
}
public static string Translate(string keyWord, int partyModeID = -1)
{
string translation;
_GetTranslation(keyWord, partyModeID, out translation);
return translation;
} }
public static bool TranslationExists(string keyWord, int partyModeID = -1) public static bool TranslationExists(string keyWord, int partyModeID = -1)
{ {
if (keyWord == null) string translation;
return false; return _GetTranslation(keyWord, partyModeID, out translation);
if (keyWord.Length < 3 || keyWord.Substring(0, 3) != "TR_")
return false;
if (partyModeID != -1)
{
int partyModeNr = _GetPartyModeNr(partyModeID, _CurrentLanguage);
if (partyModeNr != -1 && _Languages[_CurrentLanguage].PartyModeTexts[partyModeNr].Texts.ContainsKey(keyWord))
return true;
partyModeNr = _GetPartyModeNr(partyModeID, _FallbackLanguage);
if (partyModeNr != -1 && _Languages[_CurrentLanguage].PartyModeTexts[partyModeNr].Texts.ContainsKey(keyWord))
return true;
}
if (_Languages[_CurrentLanguage].Texts.ContainsKey(keyWord))
return true;
if (_Languages[_FallbackLanguage].Texts.ContainsKey(keyWord))
return true;
return false;
} }
public static bool LoadPartyLanguageFiles(int partyModeID, string path) public static bool LoadPartyLanguageFiles(int partyModeID, string path)
@@ -166,89 +158,60 @@ namespace Vocaluxe.Base
return files.All(file => _LoadPartyLanguageFile(partyModeID, file)); return files.All(file => _LoadPartyLanguageFile(partyModeID, file));
} }
private static bool _LoadLanguageEntries(CXMLReader xmlReader, out Dictionary<string, string> texts) private static bool _LoadLanguageEntries(string filePath, out Dictionary<string, string> texts)
{ {
texts = new Dictionary<string, string>(); var deser = new CXmlDeserializer();
IEnumerable<string> names = xmlReader.GetAttributes("//resources/string", "name"); try
foreach (string name in names)
{ {
string value; texts = deser.Deserialize<Dictionary<string, string>>(filePath);
if (!xmlReader.GetValue("//resources/string[@name='" + name + "']", out value, "")) string language;
continue; if (!texts.TryGetValue("language", out language))
try throw new Exception("'language' entry is missing");
{ }
texts.Add(name, value); catch (Exception e)
} {
catch (Exception e) CLog.LogError("Error reading language file " + filePath + ": " + e.Message);
{ texts = null;
CLog.LogError("Error reading language file " + xmlReader.FilePath + ": " + e.Message); return false;
return false;
}
} }
return true; return true;
} }
private static bool _LoadPartyLanguageFile(int partyModeID, string file) private static bool _LoadPartyLanguageFile(int partyModeID, string filePath)
{ {
CXMLReader xmlReader = CXMLReader.OpenFile(file); var lang = new SPartyLanguage {PartyModeID = partyModeID};
if (xmlReader == null)
if (!_LoadLanguageEntries(filePath, out lang.Texts))
return false; return false;
string value = string.Empty; int nr = _GetLanguageNr(lang.Texts["language"]);
if (xmlReader.GetValue("//resources/string[@name='language']", out value, value))
{
int nr = GetLanguageNr(value);
if (nr == -1)
return true;
var lang = new SPartyLanguage {PartyModeID = partyModeID};
if (!_LoadLanguageEntries(xmlReader, out lang.Texts))
return false;
if (nr >= 0)
_Languages[nr].PartyModeTexts.Add(lang); _Languages[nr].PartyModeTexts.Add(lang);
return true; return true;
}
CLog.LogError("Error reading Party Language File " + file);
return false;
} }
private static void _LoadLanguageFile(string fileName) private static void _LoadLanguageFile(string fileName)
{ {
var lang = new SLanguage {LanguageFilePath = Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameLanguages, fileName)}; var lang = new SLanguage {FilePath = Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameLanguages, fileName), PartyModeTexts = new List<SPartyLanguage>()};
if (!_LoadLanguageEntries(lang.FilePath, out lang.Texts))
CXMLReader xmlReader = CXMLReader.OpenFile(lang.LanguageFilePath);
if (xmlReader == null)
return; return;
string value = string.Empty; lang.Name = lang.Texts["language"];
if (xmlReader.GetValue("//resources/string[@name='language']", out value, value)) if (lang.Name == CSettings.FallbackLanguage)
{ {
lang.Name = value; _FallbackLanguage = _Languages.Count;
if (_CurrentLanguage < 0)
if (lang.Name == CSettings.FallbackLanguage) _CurrentLanguage = _FallbackLanguage;
{
_FallbackLanguage = _Languages.Count;
if (_CurrentLanguage < 0)
_CurrentLanguage = _FallbackLanguage;
}
lang.PartyModeTexts = new List<SPartyLanguage>();
_LoadLanguageEntries(xmlReader, out lang.Texts);
_Languages.Add(lang);
} }
_Languages.Add(lang);
} }
private static int _GetPartyModeNr(int partyModeID, int language) private static Dictionary<string, string> _GetPartyModeTexts(int language, int partyModeID)
{ {
for (int i = 0; i < _Languages[language].PartyModeTexts.Count; i++) return
{ _Languages[language].PartyModeTexts.Where(partyLanguage => partyLanguage.PartyModeID == partyModeID).Select(partyLanguage => partyLanguage.Texts).FirstOrDefault();
if (_Languages[language].PartyModeTexts[i].PartyModeID == partyModeID)
return i;
}
return -1;
} }
} }
} }
+22 -81
View File
@@ -28,24 +28,6 @@ using VocaluxeLib.Xml;
namespace Vocaluxe.Base namespace Vocaluxe.Base
{ {
#region Structs
struct SPartyMode
{
public int PartyModeSystemVersion;
public string Name;
public string Description;
public string Author;
public string Folder;
public string PartyModeFile;
public List<string> ScreenFiles;
public int PartyModeVersionMajor;
public int PartyModeVersionMinor;
public string TargetAudience;
public IPartyMode PartyMode;
}
#endregion Structs
static class CParty static class CParty
{ {
private const int _PartyModeSystemVersion = 1; private const int _PartyModeSystemVersion = 1;
@@ -113,26 +95,7 @@ namespace Vocaluxe.Base
foreach (KeyValuePair<int, SPartyMode> kvp in _PartyModes) foreach (KeyValuePair<int, SPartyMode> kvp in _PartyModes)
{ {
if (kvp.Key != _NormalGameModeID) if (kvp.Key != _NormalGameModeID)
{ infos.Add(kvp.Value.Info);
SPartyMode mode = kvp.Value;
var info = new SPartyModeInfos
{
Author = mode.Author,
Description = mode.Description,
Name = mode.Name,
PartyModeID = mode.PartyMode.ID,
VersionMajor = mode.PartyModeVersionMajor,
VersionMinor = mode.PartyModeVersionMinor,
TargetAudience = mode.TargetAudience,
MaxPlayers = mode.PartyMode.GetMaxPlayer(),
MinPlayers = mode.PartyMode.GetMinPlayer(),
MaxTeams = mode.PartyMode.GetMaxTeams(),
MinTeams = mode.PartyMode.GetMinTeams()
};
infos.Add(info);
}
} }
return infos; return infos;
} }
@@ -233,48 +196,26 @@ namespace Vocaluxe.Base
} }
} }
private static bool _LoadPartyMode(string file, out SPartyMode pm) private static bool _LoadPartyMode(string filePath, out SPartyMode pm)
{ {
pm = new SPartyMode {ScreenFiles = new List<string>()}; CXmlDeserializer deser = new CXmlDeserializer();
try
CXMLReader xmlReader = CXMLReader.OpenFile(file);
//Error...
if (xmlReader == null)
return false;
bool loaded = true;
loaded &= xmlReader.TryGetIntValue("//root/PartyModeSystemVersion", ref pm.PartyModeSystemVersion);
loaded &= xmlReader.GetValue("//root/Info/Name", out pm.Name);
loaded &= xmlReader.GetValue("//root/Info/Description", out pm.Description);
loaded &= xmlReader.GetValue("//root/Info/Author", out pm.Author);
loaded &= xmlReader.GetValue("//root/Info/Folder", out pm.Folder);
loaded &= xmlReader.GetValue("//root/Info/PartyModeFile", out pm.PartyModeFile);
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);
loaded &= xmlReader.GetValues("//root/PartyScreens/*", ref pm.ScreenFiles);
if (!loaded)
{ {
CLog.LogError("Error loading PartyMode file: " + file); pm = deser.Deserialize<SPartyMode>(filePath);
if (pm.PartyModeSystemVersion != _PartyModeSystemVersion)
throw new Exception("Wrong PartyModeSystemVersion " + pm.PartyModeSystemVersion + " expected: " + _PartyModeSystemVersion);
if (pm.ScreenFiles.Count == 0)
throw new Exception("No ScreenFiles found");
}
catch (Exception e)
{
pm = new SPartyMode();
CLog.LogError("Error loading PartyMode file " + filePath + ": " + e.Message);
return false; return false;
} }
if (pm.PartyModeSystemVersion != _PartyModeSystemVersion) string pathToPm = Path.Combine(CSettings.ProgramFolder, CSettings.FolderNamePartyModes, pm.Info.Folder);
{
CLog.LogError("Error loading PartyMode file (wrong PartyModeSystemVersion): " + file);
return false;
}
if (pm.ScreenFiles.Count == 0)
{
CLog.LogError("Error loading PartyMode file (no ScreenFiles found): " + file);
return false;
}
string pathToPm = Path.Combine(CSettings.ProgramFolder, CSettings.FolderNamePartyModes, pm.Folder);
string pathToCode = Path.Combine(pathToPm, CSettings.FolderNamePartyModeCode); string pathToCode = Path.Combine(pathToPm, CSettings.FolderNamePartyModeCode);
var filesToCompile = new List<string>(); var filesToCompile = new List<string>();
@@ -284,11 +225,11 @@ namespace Vocaluxe.Base
if (output == null) if (output == null)
return false; return false;
object instance = output.CreateInstance(typeof(IPartyMode).Namespace + "." + pm.Folder + "." + pm.PartyModeFile, false, object instance = output.CreateInstance(typeof(IPartyMode).Namespace + "." + pm.Info.Folder + "." + pm.Info.PartyModeFile, false,
BindingFlags.Public | BindingFlags.Instance, null, new object[] {_NextID++, pathToPm}, null, null); BindingFlags.Public | BindingFlags.Instance, null, new object[] {_NextID++, pathToPm}, null, null);
if (instance == null) if (instance == null)
{ {
CLog.LogError("Error creating Instance of PartyMode file: " + file); CLog.LogError("Error creating Instance of PartyMode file: " + filePath);
return false; return false;
} }
@@ -298,13 +239,13 @@ namespace Vocaluxe.Base
} }
catch (Exception e) catch (Exception e)
{ {
CLog.LogError("Error casting PartyMode file: " + file + "; " + e.Message); CLog.LogError("Error casting PartyMode file: " + filePath + "; " + e.Message);
return false; return false;
} }
if (!CLanguage.LoadPartyLanguageFiles(pm.PartyMode.ID, Path.Combine(pathToPm, CSettings.FolderNamePartyModeLanguages))) if (!CLanguage.LoadPartyLanguageFiles(pm.PartyMode.ID, Path.Combine(pathToPm, CSettings.FolderNamePartyModeLanguages)))
{ {
CLog.LogError("Error loading language files for PartyMode: " + file); CLog.LogError("Error loading language files for PartyMode: " + filePath);
return false; return false;
} }
@@ -316,7 +257,7 @@ namespace Vocaluxe.Base
foreach (string screenfile in pm.ScreenFiles) foreach (string screenfile in pm.ScreenFiles)
{ {
CMenuParty screen = _GetPartyScreenInstance(output, screenfile, pm.Folder); CMenuParty screen = _GetPartyScreenInstance(output, screenfile, pm.Info.Folder);
if (screen != null) if (screen != null)
{ {
@@ -327,7 +268,7 @@ namespace Vocaluxe.Base
return false; return false;
} }
pm.PartyMode.LoadTheme(); pm.PartyMode.LoadTheme();
pm.Info.LoadData(pm.PartyMode);
return true; return true;
} }
+3 -3
View File
@@ -40,9 +40,9 @@ namespace Vocaluxe.Base.ThemeSystem
private bool _CheckRequiredElements() private bool _CheckRequiredElements()
{ {
List<string> missingTextures = _RequiredTextures.FindAll(name => !_Textures.ContainsKey(name)); List<string> missingTextures = _Required.Textures.FindAll(name => !_Textures.ContainsKey(name));
List<string> missingVideos = _RequiredVideos.FindAll(name => !_Videos.ContainsKey(name)); List<string> missingVideos = _Required.Videos.FindAll(name => !_Videos.ContainsKey(name));
List<string> missingColors = _RequiredColors.FindAll(name => !_Data.Colors.ContainsKey(name)); List<string> missingColors = _Required.Colors.FindAll(name => !_Data.Colors.ContainsKey(name));
if (missingTextures.Count + missingVideos.Count + missingColors.Count == 0) if (missingTextures.Count + missingVideos.Count + missingColors.Count == 0)
return true; return true;
string msg = "The skin \"" + this + "\" is missing the following elements: "; string msg = "The skin \"" + this + "\" is missing the following elements: ";
+3 -3
View File
@@ -43,21 +43,21 @@ namespace Vocaluxe.Base.ThemeSystem
public override bool GetColor(string name, out SColorF color) public override bool GetColor(string name, out SColorF color)
{ {
if (_Parent.Name == "Default" && !_RequiredColors.Contains(name)) if (_Parent.Name == "Default" && !_Required.Colors.Contains(name))
CLog.LogDebug("Non-Default color: " + name); CLog.LogDebug("Non-Default color: " + name);
return base.GetColor(name, out color) || _BaseSkin.GetColor(name, out color); return base.GetColor(name, out color) || _BaseSkin.GetColor(name, out color);
} }
public override CVideoStream GetVideo(string name, bool loop) public override CVideoStream GetVideo(string name, bool loop)
{ {
if (_Parent.Name == "Default" && !_RequiredVideos.Contains(name)) if (_Parent.Name == "Default" && !_Required.Videos.Contains(name))
CLog.LogDebug("Non-Default color: " + name); CLog.LogDebug("Non-Default color: " + name);
return base.GetVideo(name, loop) ?? _BaseSkin.GetVideo(name, loop); return base.GetVideo(name, loop) ?? _BaseSkin.GetVideo(name, loop);
} }
public override CTextureRef GetTexture(string name) public override CTextureRef GetTexture(string name)
{ {
if (_Parent.Name == "Default" && !_RequiredTextures.Contains(name)) if (_Parent.Name == "Default" && !_Required.Textures.Contains(name))
CLog.LogDebug("Non-Default color: " + name); CLog.LogDebug("Non-Default color: " + name);
return base.GetTexture(name) ?? _BaseSkin.GetTexture(name); return base.GetTexture(name) ?? _BaseSkin.GetTexture(name);
} }
+58 -15
View File
@@ -19,9 +19,12 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Xml;
using System.Xml.Serialization;
using VocaluxeLib; using VocaluxeLib;
using VocaluxeLib.Draw; using VocaluxeLib.Draw;
using VocaluxeLib.Xml; using VocaluxeLib.Xml;
using System.Linq;
namespace Vocaluxe.Base.ThemeSystem namespace Vocaluxe.Base.ThemeSystem
{ {
@@ -34,9 +37,43 @@ namespace Vocaluxe.Base.ThemeSystem
abstract class CSkin abstract class CSkin
{ {
private const int _SkinSystemVersion = 4; private const int _SkinSystemVersion = 4;
protected static readonly List<string> _RequiredTextures = new List<string>();
protected static readonly List<string> _RequiredVideos = new List<string>(); protected struct SRequiredElements
protected static readonly List<string> _RequiredColors = new List<string>(); {
[XmlIgnore] public List<string> Textures, Videos, Colors;
[XmlElement("Textures")]
public string TexturesStr
{
get { return string.Join("\r\n", Textures); }
set
{
string[] entries = value.Split(new string[] {"\r\n", "\n"}, StringSplitOptions.RemoveEmptyEntries);
Textures = entries.Select(s => s.Trim()).Where(s => !string.IsNullOrEmpty(s)).ToList();
}
}
[XmlElement("Videos")]
public string VideosStr
{
get { return string.Join("\r\n", Videos); }
set
{
string[] entries = value.Split(new string[] {"\r\n", "\n"}, StringSplitOptions.RemoveEmptyEntries);
Videos = entries.Select(s => s.Trim()).Where(s => !string.IsNullOrEmpty(s)).ToList();
}
}
[XmlElement("Colors")]
public string ColorsStr
{
get { return string.Join("\r\n", Colors); }
set
{
string[] entries = value.Split(new string[] {"\r\n", "\n"}, StringSplitOptions.RemoveEmptyEntries);
Colors = entries.Select(s => s.Trim()).Where(s => !string.IsNullOrEmpty(s)).ToList();
}
}
}
protected static SRequiredElements _Required;
private readonly string _Folder; private readonly string _Folder;
private readonly string _FileName; private readonly string _FileName;
@@ -56,26 +93,32 @@ namespace Vocaluxe.Base.ThemeSystem
public static bool InitRequiredElements() public static bool InitRequiredElements()
{ {
string path = Path.Combine(CSettings.ProgramFolder, CSettings.FileNameRequiredSkinElements); string path = Path.Combine(CSettings.ProgramFolder, CSettings.FileNameRequiredSkinElements);
CXMLReader xmlReader = CXMLReader.OpenFile(path); var xml = new CXmlDeserializer();
if (xmlReader == null) try
{
_Required = xml.Deserialize<SRequiredElements>(path);
}
catch (XmlException e)
{
CLog.LogError("Error reading required elements: " + e.Message);
return false; return false;
bool ok = xmlReader.Read("//root/Textures", _RequiredTextures); }
ok &= xmlReader.Read("//root/Videos", _RequiredVideos);
ok &= xmlReader.Read("//root/Colors", _RequiredColors);
for (int i = 1; i <= CSettings.MaxNumPlayer; i++) for (int i = 1; i <= CSettings.MaxNumPlayer; i++)
{ {
string name = "Player" + i; string name = "Player" + i;
if (!_RequiredColors.Contains(name)) if (!_Required.Colors.Contains(name))
_RequiredColors.Add(name); _Required.Colors.Add(name);
} }
return ok; return true;
} }
public static void Close() public static void Close()
{ {
_RequiredTextures.Clear(); if (_Required.Textures == null)
_RequiredVideos.Clear(); return;
_RequiredColors.Clear(); _Required.Textures.Clear();
_Required.Videos.Clear();
_Required.Colors.Clear();
} }
protected CSkin(string folder, string file, CTheme parent) protected CSkin(string folder, string file, CTheme parent)
@@ -94,7 +137,7 @@ namespace Vocaluxe.Base.ThemeSystem
{ {
try try
{ {
var xml = new CXmlSerializer(); var xml = new CXmlDeserializer();
_Data = xml.Deserialize<SSkin>(Path.Combine(_Folder, _FileName)); _Data = xml.Deserialize<SSkin>(Path.Combine(_Folder, _FileName));
if (_Data.SkinSystemVersion != _SkinSystemVersion) if (_Data.SkinSystemVersion != _SkinSystemVersion)
{ {
+34
View File
@@ -20,6 +20,7 @@ using System.ComponentModel;
using System.Xml.Serialization; using System.Xml.Serialization;
using Vocaluxe.Base.Fonts; using Vocaluxe.Base.Fonts;
using VocaluxeLib; using VocaluxeLib;
using VocaluxeLib.PartyModes;
using VocaluxeLib.Xml; using VocaluxeLib.Xml;
namespace Vocaluxe.Base namespace Vocaluxe.Base
@@ -108,4 +109,37 @@ namespace Vocaluxe.Base
public SPlaylistInfo Info; public SPlaylistInfo Info;
[XmlArray] public SPlaylistSong[] Songs; [XmlArray] public SPlaylistSong[] Songs;
} }
#region Partymode
struct SPartyModeInfos
{
public string Name;
public string Description;
public string Author;
public string Folder;
public string PartyModeFile;
[XmlAltName("PartyModeVersionMajor")] public int VersionMajor;
[XmlAltName("PartyModeVersionMinor")] public int VersionMinor;
public string TargetAudience;
[XmlIgnore] public int MaxPlayers, MinPlayers, MaxTeams, MinTeams;
[XmlIgnore] public int PartyModeID;
public void LoadData(IPartyMode pm)
{
MaxPlayers = pm.GetMaxPlayer();
MinPlayers = pm.GetMinPlayer();
MaxTeams = pm.GetMaxTeams();
MinTeams = pm.GetMinTeams();
PartyModeID = pm.ID;
}
}
struct SPartyMode
{
public int PartyModeSystemVersion;
[XmlArray("PartyScreens"), XmlArrayItem("ScreenFile")] public List<string> ScreenFiles;
[XmlIgnore] public IPartyMode PartyMode;
public SPartyModeInfos Info;
}
#endregion Partymode
} }
+1 -1
View File
@@ -134,7 +134,7 @@ namespace Vocaluxe.Screens
private void _SaveConfig() private void _SaveConfig()
{ {
CLanguage.LanguageId = _SelectSlides[_SelectSlideLanguage].Selection; CLanguage.LanguageId = _SelectSlides[_SelectSlideLanguage].Selection;
CConfig.Config.Game.Language = CLanguage.GetLanguageName(CLanguage.LanguageId); CConfig.Config.Game.Language = _SelectSlides[_SelectSlideLanguage].Value;
CConfig.Config.Debug.DebugLevel = (EDebugLevel)_SelectSlides[_SelectSlideDebugLevel].Selection; CConfig.Config.Debug.DebugLevel = (EDebugLevel)_SelectSlides[_SelectSlideDebugLevel].Selection;
CConfig.Config.Game.SongMenu = (ESongMenu)_SelectSlides[_SelectSlideSongMenu].Selection; CConfig.Config.Game.SongMenu = (ESongMenu)_SelectSlides[_SelectSlideSongMenu].Selection;
CConfig.Config.Game.SongSorting = (ESongSorting)_SelectSlides[_SelectSlideSongSorting].Selection; CConfig.Config.Game.SongSorting = (ESongSorting)_SelectSlides[_SelectSlideSongSorting].Selection;
+1 -17
View File
@@ -67,7 +67,7 @@ namespace VocaluxeLib
[XmlRoot("root")] [XmlRoot("root")]
public struct SThemeCover public struct SThemeCover
{ {
[XmlIgnore] public string Name, Folder, FilePath; [XmlIgnore] public string FolderPath;
public SThemeCoverInfo Info; public SThemeCoverInfo Info;
[XmlElement("CoverGenerator", IsNullable = false)] public List<SThemeCoverGenerator> CoverGenerators; [XmlElement("CoverGenerator", IsNullable = false)] public List<SThemeCoverGenerator> CoverGenerators;
} }
@@ -366,21 +366,5 @@ namespace VocaluxeLib
public int VoiceNr; public int VoiceNr;
public int ID; public int ID;
} }
public struct SPartyModeInfos
{
public int PartyModeID;
public string Name;
public string Description;
public string TargetAudience;
public int MaxPlayers;
public int MinPlayers;
public int MaxTeams;
public int MinTeams;
public string Author;
public int VersionMajor;
public int VersionMinor;
}
#endregion Game #endregion Game
} }