Пример #1
0
        public bool _Load(string file)
        {
            File = file;
            SPlaylist data;

            try
            {
                var xml = new CXmlDeserializer();
                data = xml.Deserialize <SPlaylist>(File);
            }
            catch (Exception e)
            {
                CLog.Error("Cannot load playlist from " + file + ": " + e.Message);
                return(false);
            }
            Name  = data.Info.Name;
            Songs = new List <CPlaylistSong>();
            foreach (SPlaylistSong songEntry in data.Songs)
            {
                CSong plSong = CSongs.AllSongs.FirstOrDefault(song => song.Artist == songEntry.Artist && song.Title == songEntry.Title);
                if (plSong == null)
                {
                    CLog.Error("Can't find song '" + songEntry.Title + "' from '" + songEntry.Artist + "' in playlist file: " + File);
                }
                else
                {
                    var playlistSong = new CPlaylistSong(plSong.ID, songEntry.GameMode);
                    Songs.Add(playlistSong);
                }
            }
            return(true);
        }
Пример #2
0
        public void TestRealFiles()
        {
            Type[] types = new Type[]
            { typeof(SThemeCover), typeof(CConfig.SConfig), typeof(SThemeScreen), typeof(SDefaultFonts), typeof(SSkin), typeof(STheme), typeof(Dictionary <string, string>) };
            string filePath = Path.Combine(new string[] { AppDomain.CurrentDomain.BaseDirectory, "..", "..", "..", "TestXmlFiles" });

            foreach (Type type in types)
            {
                string xmlPath = Path.Combine(filePath, type.Name + ".xml");
                var    deser   = new CXmlDeserializer();
                object foo     = null;
                try
                {
                    foo = deser.Deserialize(xmlPath, Activator.CreateInstance(type));
                }
                catch (Exception e)
                {
                    Assert.Fail("Exception with " + type.Name + ": {0}", new object[] { e.Message });
                }
                Assert.IsInstanceOfType(foo, type, "Wrong type with " + type.Name);
                var    ser    = new CXmlSerializer(type == typeof(CConfig.SConfig));
                string newXml = ser.Serialize(foo, type == typeof(Dictionary <string, string>) ? "resources" : null);
                // Typename will be uppercase but input is lowercase
                newXml = newXml.Replace("<String", "<string").Replace("</String", "</string");
                string oldXml = File.ReadAllText(xmlPath);
                Assert.AreEqual(oldXml, newXml, "Error with " + type.Name);
            }
        }
Пример #3
0
        /// <summary>
        ///     Loads all cover-themes to list.
        /// </summary>
        private static void _LoadCoverThemes()
        {
            _CoverThemes.Clear();

            string folderPath          = Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameCover);
            IEnumerable <string> files = CHelper.ListFiles(folderPath, "*.xml");

            var xml = new CXmlDeserializer();

            foreach (string file in files)
            {
                SThemeCover theme;
                try
                {
                    theme = xml.Deserialize <SThemeCover>(Path.Combine(folderPath, file));
                }
                catch (CXmlException e)
                {
                    CLog.Error("Error loading cover theme " + file + ": " + e);
                    continue;
                }

                if (!String.IsNullOrEmpty(theme.Info.Folder) && !String.IsNullOrEmpty(theme.Info.Name))
                {
                    theme.FolderPath = Path.Combine(folderPath, theme.Info.Folder);
                    _CoverThemes.Add(theme);
                }
            }
        }
Пример #4
0
        public bool LoadProfile()
        {
            var xml = new CXmlDeserializer();

            try
            {
                xml.Deserialize(FilePath, this);
                //If ID couldn't be loaded, generate a new one and save it
                if (ID == Guid.Empty)
                {
                    ID = Guid.NewGuid();
                    SaveProfile();
                }
            }
            catch (Exception e)
            {
                if (_ConvertProfile(ref e))
                {
                    return(true);
                }
                CLog.Error("Error loading profile file " + Path.GetFileName(FilePath) + ": " + e.Message);
                return(false);
            }
            return(true);
        }
Пример #5
0
        private bool _ConvertProfile(ref Exception e)
        {
            var xml = new CXmlDeserializer();
            var ser = new CXmlSerializer();

            try
            {
                var    old    = xml.Deserialize <SOldXmlProfile>(FilePath);
                string newXml = ser.Serialize(old.Info);
                xml.DeserializeString(newXml, this);
                if (ID == null)
                {
                    ID = Guid.NewGuid();
                }
                ser.Serialize(FilePath, this);
            }
            catch (Exception e2)
            {
                if (!(e2 is CXmlException))
                {
                    e = e2;
                }
                return(false);
            }
            return(true);
        }
Пример #6
0
        /// <summary>
        ///     Load default fonts
        /// </summary>
        /// <returns></returns>
        private static bool _LoadDefaultFonts()
        {
            SDefaultFonts defaultFonts;

            try
            {
                var xml = new CXmlDeserializer();
                defaultFonts = xml.Deserialize <SDefaultFonts>(Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameFonts, CSettings.FileNameFonts));
            }
            catch (Exception e)
            {
                CLog.Error(e, "Error loading default Fonts");
                return(false);
            }

            return(LoadThemeFonts(defaultFonts.Fonts, Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameFonts), "", -1));
        }
Пример #7
0
        public bool LoadProfile()
        {
            var xml = new CXmlDeserializer();

            try
            {
                xml.Deserialize(FilePath, this);
            }
            catch (Exception e)
            {
                if (_ConvertProfile(ref e))
                {
                    return(true);
                }
                CBase.Log.LogError("Error loading profile file " + Path.GetFileName(FilePath) + ": " + e.Message);
                return(false);
            }
            return(true);
        }
Пример #8
0
        public void TestRealFiles([Values(typeof(SThemeCover), typeof(CConfig.SConfig), /*typeof(SThemeScreen),*/ typeof(SDefaultFonts), typeof(SSkin), typeof(STheme), typeof(Dictionary <string, string>))] Type type)
        {
            string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "..", "VocaluxeLib", "XML", "TestFiles");

            string xmlPath = Path.Combine(filePath, type.Name + ".xml");
            var    deser   = new CXmlDeserializer();

            object foo = deser.Deserialize(xmlPath, Activator.CreateInstance(type));

            Assert.IsInstanceOf(type, foo, "Wrong type with " + type.Name);
            var    ser    = new CXmlSerializer(type == typeof(CConfig.SConfig));
            string newXml = ser.Serialize(foo, type == typeof(Dictionary <string, string>) ? "resources" : null);

            // Typename will be uppercase but input is lowercase
            newXml = newXml.Replace("<String", "<string").Replace("</String", "</string");
            string oldXml = File.ReadAllText(xmlPath);

            Assert.AreEqual(oldXml, newXml, "Recontructed XML has differences.");
        }
Пример #9
0
        public bool Init()
        {
            try
            {
                var xml = new CXmlDeserializer();
                _Data = xml.Deserialize <SSkin>(Path.Combine(_Folder, _FileName));
                if (_Data.SkinSystemVersion != _SkinSystemVersion)
                {
                    string errorMsg = _Data.SkinSystemVersion < _SkinSystemVersion ? "the file ist outdated!" : "the file is for newer program versions!";
                    errorMsg += " Current Version is " + _SkinSystemVersion;
                    throw new Exception(errorMsg);
                }
            }
            catch (Exception e)
            {
                CLog.Error(e, "Can't load skin file \"" + Path.Combine(_Folder, _FileName) + "\". Invalid file!");
                return(false);
            }

            return(true);
        }
Пример #10
0
        private static bool _LoadLanguageEntries(string filePath, out Dictionary <string, string> texts)
        {
            var deser = new CXmlDeserializer();

            try
            {
                texts = deser.Deserialize <Dictionary <string, string> >(filePath);
                string language;
                if (!texts.TryGetValue("language", out language))
                {
                    throw new Exception("'language' entry is missing");
                }
            }
            catch (Exception e)
            {
                CLog.LogError("Error reading language file " + filePath + ": " + e.Message);
                texts = null;
                return(false);
            }
            return(true);
        }
Пример #11
0
        public static bool InitRequiredElements()
        {
            string path = Path.Combine(CSettings.ProgramFolder, CSettings.FileNameRequiredSkinElements);
            var    xml  = new CXmlDeserializer();

            try
            {
                _Required = xml.Deserialize <SRequiredElements>(path);
            }
            catch (CXmlException e)
            {
                CLog.Error("Error reading required elements: " + e);
                return(false);
            }
            for (int i = 1; i <= CSettings.MaxNumPlayer; i++)
            {
                string name = "Player" + i;
                if (!_Required.Colors.Contains(name))
                {
                    _Required.Colors.Add(name);
                }
            }
            return(true);
        }
Пример #12
0
        public bool Init()
        {
            try
            {
                var xml = new CXmlDeserializer();
                _Data = xml.Deserialize <STheme>(Path.Combine(_Folder, _FileName));
                if (_Data.ThemeSystemVersion != _ThemeSystemVersion)
                {
                    string errorMsg = _Data.ThemeSystemVersion < _ThemeSystemVersion ? "the file ist outdated!" : "the file is for newer program versions!";
                    errorMsg += " Current Version is " + _ThemeSystemVersion;
                    throw new Exception(errorMsg);
                }
            }
            catch (Exception e)
            {
                CLog.LogError("Can't load theme \"" + _FileName + "\". Invalid file!", false, false, e);
                return(false);
            }

            string        path  = Path.Combine(_Folder, Name);
            List <string> files = CHelper.ListFiles(path, "*.xml");

            // Load skins, succeed if at least 1 skin was loaded
            bool ok = false;

            foreach (string file in files)
            {
                CSkin skin = _GetNewSkin(path, file);
                if (skin.Init())
                {
                    _Skins.Add(skin.Name, skin);
                    ok = true;
                }
            }
            return(ok);
        }
Пример #13
0
        private static bool _LoadPartyMode(string filePath, out SPartyMode pm)
        {
            CXmlDeserializer deser = new CXmlDeserializer();

            try
            {
                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);
            }

            string pathToPm   = Path.Combine(CSettings.ProgramFolder, CSettings.FolderNamePartyModes, pm.Info.Folder);
            string pathToCode = Path.Combine(pathToPm, CSettings.FolderNamePartyModeCode);

            var filesToCompile = new List <string>();

            filesToCompile.AddRange(CHelper.ListFiles(pathToCode, "*.cs", false, true));

            Assembly output = _CompileFiles(filesToCompile.ToArray());

            if (output == null)
            {
                return(false);
            }

            object instance = output.CreateInstance(typeof(IPartyMode).Namespace + "." + pm.Info.Folder + "." + pm.Info.PartyModeFile, false,
                                                    BindingFlags.Public | BindingFlags.Instance, null, new object[] { _NextID++ }, null, null);

            if (instance == null)
            {
                CLog.LogError("Error creating Instance of PartyMode file: " + filePath);
                return(false);
            }

            try
            {
                pm.PartyMode = (IPartyMode)instance;
            }
            catch (Exception e)
            {
                CLog.LogError("Error casting PartyMode file: " + filePath + "; " + e.Message);
                return(false);
            }

            if (!CLanguage.LoadPartyLanguageFiles(pm.PartyMode.ID, Path.Combine(pathToPm, CSettings.FolderNamePartyModeLanguages)))
            {
                CLog.LogError("Error loading language files for PartyMode: " + filePath);
                return(false);
            }

            if (!CThemes.ReadThemesFromFolder(Path.Combine(pathToPm, CSettings.FolderNameThemes), pm.PartyMode.ID))
            {
                return(false);
            }

            if (!CThemes.LoadPartymodeTheme(pm.PartyMode.ID))
            {
                return(false);
            }

            foreach (string screenfile in pm.ScreenFiles)
            {
                CMenuParty screen = _GetPartyScreenInstance(output, screenfile, pm.Info.Folder);

                if (screen != null)
                {
                    screen.AssignPartyMode(pm.PartyMode);
                    pm.PartyMode.AddScreen(screen, screenfile);
                }
                else
                {
                    return(false);
                }
            }
            pm.PartyMode.LoadTheme();
            pm.Info.ExtInfo = pm.PartyMode;
            return(true);
        }
Пример #14
0
        public virtual void LoadTheme(string xmlPath)
        {
            ThemePath = xmlPath;

            string file = Path.Combine(xmlPath, ThemeName + ".xml");

            try
            {
                CXmlDeserializer deserializer = new CXmlDeserializer(new CLoadThemeErrorHandler());
                Theme = deserializer.Deserialize <SThemeScreen>(file);

                foreach (SThemeBackground bg in Theme.Backgrounds)
                {
                    _AddBackground(new CBackground(bg, PartyModeID), bg.Name);
                }

                foreach (SThemeButton bt in Theme.Buttons)
                {
                    _AddButton(new CButton(bt, PartyModeID), bt.Name);
                }

                foreach (SThemeEqualizer eq in Theme.Equalizers)
                {
                    _AddEqualizer(new CEqualizer(eq, PartyModeID), eq.Name);
                }

                foreach (SThemeLyrics ly in Theme.Lyrics)
                {
                    _AddLyric(new CLyric(ly, PartyModeID), ly.Name);
                }

                foreach (SThemeNameSelection ns in Theme.NameSelections)
                {
                    _AddNameSelection(new CNameSelection(ns, PartyModeID), ns.Name);
                }

                foreach (SThemeParticleEffect pe in Theme.ParticleEffects)
                {
                    _AddParticleEffect(new CParticleEffect(pe, PartyModeID), pe.Name);
                }

                foreach (SThemePlaylist pl in Theme.Playlists)
                {
                    _AddPlaylist(new CPlaylist(pl, PartyModeID), pl.Name);
                }

                foreach (SThemeProgressBar pb in Theme.ProgressBars)
                {
                    _AddProgressBar(new CProgressBar(pb, PartyModeID), pb.Name);
                }

                foreach (SThemeScreenSetting ss in Theme.ScreenSettings)
                {
                    _AddScreenSetting(new CScreenSetting(ss, PartyModeID), ss.Name);
                }

                foreach (SThemeSelectSlide sl in Theme.SelectSlides)
                {
                    _AddSelectSlide(new CSelectSlide(sl, PartyModeID), sl.Name);
                }

                foreach (SThemeSingBar sb in Theme.SingNotes)
                {
                    _AddSingNote(new CSingNotes(sb, PartyModeID), sb.Name);
                }

                foreach (SThemeSongMenu sm in Theme.SongMenus)
                {
                    _AddSongMenu(CSongMenuFactory.CreateSongMenu(sm, PartyModeID), sm.Name);
                }

                foreach (SThemeStatic st in Theme.Statics)
                {
                    _AddStatic(new CStatic(st, PartyModeID), st.Name);
                }

                foreach (SThemeText te in Theme.Texts)
                {
                    _AddText(new CText(te, PartyModeID), te.Name);
                }

                if (_ScreenVersion != Theme.Informations.ScreenVersion)
                {
                    string msg = "Can't load screen file of screen \"" + ThemeName + "\", ";
                    if (Theme.Informations.ScreenVersion < _ScreenVersion)
                    {
                        msg += "the file ist outdated! ";
                    }
                    else
                    {
                        msg += "the file is for newer program versions! ";
                    }

                    msg += "Current screen version is " + _ScreenVersion;
                    CLog.Error(msg);
                }
                foreach (IThemeable el in _Elements.Select(_GetElement).OfType <IThemeable>())
                {
                    el.LoadSkin();
                }
            }
            catch (Exception e)
            {
                CLog.Fatal(e, "Error while reading {ThemeName}.xml", CLog.Params(ThemeName), true);
            }
        }