diff --git a/Output/PartyModes/Challenge.xml b/Output/PartyModes/Challenge.xml new file mode 100644 index 00000000..cccb8168 --- /dev/null +++ b/Output/PartyModes/Challenge.xml @@ -0,0 +1,12 @@ + + + 1 + + Challenge + brunzel + Challenge + CPartyModeChallenge.cs + 0 + 1 + + \ No newline at end of file diff --git a/Output/PartyModes/Challenge/Code/CPartyModeChallenge.cs b/Output/PartyModes/Challenge/Code/CPartyModeChallenge.cs new file mode 100644 index 00000000..f2780760 --- /dev/null +++ b/Output/PartyModes/Challenge/Code/CPartyModeChallenge.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Vocaluxe.PartyModes +{ + public class CPartyModeChallenge : CPartyMode + { + public CPartyModeChallenge() + { + _ScreenSongOptions.Selection.RandomOnly = false; + _ScreenSongOptions.Selection.PartyMode = false; + _ScreenSongOptions.Selection.CategoryChangeAllowed = true; + _ScreenSongOptions.Selection.NumJokers = null; + + _ScreenSongOptions.Sorting.SearchString = String.Empty; + _ScreenSongOptions.Sorting.SearchStringVisible = false; + } + + public override ScreenSongOptions GetScreenSongOptions() + { + _ScreenSongOptions.Sorting.SongSorting = _Base.Config.GetSongSorting(); + _ScreenSongOptions.Sorting.Tabs = _Base.Config.GetTabs(); + _ScreenSongOptions.Sorting.IgnoreArticles = _Base.Config.GetIgnoreArticles(); + + return _ScreenSongOptions; + } + + public override void SetSearchString(string SearchString, bool Visible) + { + _ScreenSongOptions.Sorting.SearchString = SearchString; + _ScreenSongOptions.Sorting.SearchStringVisible = Visible; + } + + } +} \ No newline at end of file diff --git a/Vocaluxe/Base/CParty.cs b/Vocaluxe/Base/CParty.cs index 9ad1c933..3f6d5ae9 100644 --- a/Vocaluxe/Base/CParty.cs +++ b/Vocaluxe/Base/CParty.cs @@ -1,5 +1,8 @@ using System; +using System.CodeDom.Compiler; using System.Collections.Generic; +using System.IO; +using System.Reflection; using System.Text; using System.Xml; using System.Xml.XPath; @@ -16,6 +19,7 @@ namespace Vocaluxe.Base public string Name; public string Author; public string Folder; + public string PartyModeFile; public int PartyModeVersionMajor; public int PartyModeVersionMinor; public bool NoErrors; @@ -151,12 +155,13 @@ namespace Vocaluxe.Base if (loaded) { - loaded &= CHelper.TryGetIntValueFromXML("//root/Info/PartyModeSystemVersion", navigator, ref pm.PartyModeSystemVersion); + loaded &= CHelper.TryGetIntValueFromXML("//root/PartyModeSystemVersion", navigator, ref pm.PartyModeSystemVersion); loaded &= CHelper.GetValueFromXML("//root/Info/Name", navigator, ref pm.Name, "ERROR Name"); loaded &= CHelper.GetValueFromXML("//root/Info/Author", navigator, ref pm.Author, "ERROR Author"); loaded &= CHelper.GetValueFromXML("//root/Info/Folder", navigator, ref pm.Folder, "ERROR Folder"); - loaded &= CHelper.TryGetIntValueFromXML("//root/Info/PartyModeSystemVersion", navigator, ref pm.PartyModeVersionMajor); - loaded &= CHelper.TryGetIntValueFromXML("//root/Info/PartyModeSystemVersion", navigator, ref pm.PartyModeVersionMinor); + loaded &= CHelper.GetValueFromXML("//root/Info/PartyModeFile", navigator, ref pm.PartyModeFile, "ERROR PartyModeFile"); + loaded &= CHelper.TryGetIntValueFromXML("//root/Info/PartyModeVersionMajor", navigator, ref pm.PartyModeVersionMajor); + loaded &= CHelper.TryGetIntValueFromXML("//root/Info/PartyModeVersionMinor", navigator, ref pm.PartyModeVersionMinor); if (pm.PartyModeSystemVersion != PartyModeSystemVersion) { @@ -171,10 +176,65 @@ namespace Vocaluxe.Base return pm; } - + Assembly Output = CompileFile(Path.Combine(Path.Combine(Path.Combine(CSettings.sFolderPartyModes, pm.Folder), CSettings.sFolderPartyModeCode), pm.PartyModeFile + ".cs")); + if (Output == null) + return pm; + + object Instance = Output.CreateInstance("Vocaluxe.PartyModes." + pm.PartyModeFile); + if (Instance == null) + { + CLog.LogError("Error creating Instance of PartyMode file: " + file); + return pm; + } + + try + { + pm.PartyMode = (IPartyMode)Instance; + } + catch (Exception e) + { + CLog.LogError("Error casting PartyMode file: " + file + "; " + e.Message); + return pm; + } + + pm.PartyMode.Initialize(CMain.Base); + pm.NoErrors = true; return pm; } + + private static Assembly CompileFile(string file) + { + CompilerParameters Params = new CompilerParameters(); + Params.ReferencedAssemblies.Add("VocaluxeLib.dll"); + Params.GenerateInMemory = true; +#if DEBUG + Params.IncludeDebugInformation = true; +#endif + + CodeDomProvider CDP = CodeDomProvider.CreateProvider("CSharp"); + CompilerResults CompileResult = null; + try + { + CompileResult = CDP.CompileAssemblyFromFile(Params, file); + } + catch (Exception e) + { + CLog.LogError("Error Compiling Source (" + file + "): " + e.Message); + return null; + } + + if (CompileResult.Errors.Count > 0) + { + for (int i = 0; i < CompileResult.Errors.Count; i++) + { + CLog.LogError("Error Compiling Source (" + file + "): " + CompileResult.Errors[i].ErrorText); + } + return null; + } + return CompileResult.CompiledAssembly; + } + #endregion private stuff } } diff --git a/Vocaluxe/Base/CSettings.cs b/Vocaluxe/Base/CSettings.cs index 3cf5209b..af45f0ae 100644 --- a/Vocaluxe/Base/CSettings.cs +++ b/Vocaluxe/Base/CSettings.cs @@ -90,7 +90,10 @@ namespace Vocaluxe.Base public const string sFolderScreenshots = "Screenshots"; public const string sFolderBackgroundMusic = "BackgroundMusic"; public static string sFolderPlaylists = "Playlists"; + + public static string sFolderPartyModes = "PartyModes"; + public const string sFolderPartyModeCode = "Code"; //public const String[] ToneStrings = new String[]{ "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" }; public const int ToneMin = -36;