Пример #1
0
        /// <summary>
        ///     Loads all cover-themes to list.
        /// </summary>
        private static void _LoadCoverThemes()
        {
            _CoverThemes.Clear();

            string        folderPath = Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameCover);
            List <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.LogError("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);
                }
            }
        }
Пример #2
0
        private static CMenuParty _GetPartyScreenInstance(Assembly assembly, string screenName, string partyModeName)
        {
            if (assembly == null)
            {
                return(null);
            }

            object instance = assembly.CreateInstance(typeof(IPartyMode).Namespace + "." + partyModeName + "." + screenName);

            if (instance == null)
            {
                CLog.LogError("Error creating Instance of PartyScreen: " + screenName);
                return(null);
            }

            CMenuParty screen;

            try
            {
                screen = (CMenuParty)instance;
            }
            catch (Exception e)
            {
                CLog.LogError("Error casting PartyScreen: " + screenName + "; " + e.Message);
                return(null);
            }
            return(screen);
        }
Пример #3
0
        private static CPlaylistFile _ConvertUSDXPlaylist(string file)
        {
            var pl = new CPlaylistFile();
            ReadOnlyCollection <CSong> allSongs = CSongs.AllSongs;

            if (!File.Exists(file))
            {
                return(null);
            }
            try
            {
                StreamReader sr;
                using (sr = new StreamReader(file, Encoding.Default, true))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        int pos = line.IndexOf(":", StringComparison.Ordinal);
                        if (pos <= 0)
                        {
                            continue;
                        }
                        if (line[0] == '#')
                        {
                            //Name or comment
                            string identifier = line.Substring(1, pos - 1).Trim();
                            string value      = line.Substring(pos + 1, line.Length - pos - 1).Trim();
                            if (identifier.ToUpper() == "NAME")
                            {
                                pl.Name = value;
                            }
                        }
                        else
                        {
                            //Song
                            string artist = line.Substring(0, pos - 1).Trim();
                            string title  = line.Substring(pos + 1, line.Length - pos - 1).Trim();
                            CSong  plSong = allSongs.FirstOrDefault(song => song.Artist == artist && song.Title == title);
                            if (plSong != null)
                            {
                                pl.AddSong(plSong.ID);
                            }
                            else
                            {
                                CLog.LogError("Can't find song '" + title + "' from '" + artist + "' in playlist file: " + file);
                            }
                        }
                    }
                }
                File.Delete(file);
            }
            catch
            {
                return(null);
            }

            return(pl);
        }
Пример #4
0
 public void Close(ref CVideoStream stream)
 {
     try
     {
         CVideo.Close(ref stream);
     }
     catch (NotSupportedException e)
     {
         CLog.LogError($"Clould not close the background video: {e.Message}");
     }
 }
Пример #5
0
 public void Resume(CVideoStream stream)
 {
     try
     {
         CVideo.Resume(stream);
     }
     catch (NotSupportedException e)
     {
         CLog.LogError($"Clould not resume the background video: {e.Message}");
     }
 }
Пример #6
0
        public static void LoadTheme()
        {
            bool           loaded    = false;
            XPathDocument  xPathDoc  = null;
            XPathNavigator navigator = null;
            int            index     = 0;

            for (int i = 0; i < _Themes.Count; i++)
            {
                if (_Themes[i].Name == CConfig.Theme)
                {
                    index = i;
                }
            }

            try
            {
                xPathDoc  = new XPathDocument(Path.Combine(_Themes[index].Path, _Themes[index].FileName));
                navigator = xPathDoc.CreateNavigator();
                loaded    = true;
            }
            catch (Exception e)
            {
                CLog.LogError("Error loading theme " + _Themes[index].FileName + ": " + e.Message);
                loaded = false;
                if (navigator != null)
                {
                    navigator = null;
                }

                if (xPathDoc != null)
                {
                    xPathDoc = null;
                }
            }

            if (loaded)
            {
                int skinIndex = GetSkinIndex();

                // Load Cursor
                LoadCursor(navigator, skinIndex);

                // load fonts
                CFonts.LoadThemeFonts(
                    _Themes[index].Name,
                    Path.Combine(Path.Combine(_Themes[index].Path, _Themes[index].SkinFolder), CSettings.sFolderThemeFonts),
                    navigator);
            }
        }
Пример #7
0
 private static void _CreateFolder(string path)
 {
     if (path != "" && !Directory.Exists(path))
     {
         try
         {
             Directory.CreateDirectory(path);
         }
         catch (Exception e)
         {
             CLog.LogError("Cannot create directory \"" + path + "\": " + e.Message);
         }
     }
 }
Пример #8
0
        public static void InitDraw()
        {
            switch (CConfig.Renderer)
            {
            case ERenderer.TR_CONFIG_SOFTWARE:
                _Draw = new CDrawWinForm();
                break;

            case ERenderer.TR_CONFIG_OPENGL:
                try
                {
                    _Draw = new COpenGL();
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message + " - Error in initializing of OpenGL. Please check whether" +
                                    " your graphic card drivers are up to date.");
                    CLog.LogError(e.Message + " - Error in initializing of OpenGL. Please check whether" +
                                  " your graphic card drivers are up to date.");
                    Environment.Exit(Environment.ExitCode);
                }
                break;

#if WIN
            case ERenderer.TR_CONFIG_DIRECT3D:
                try
                {
                    _Draw = new CDirect3D();
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message + " - Error in initializing of Direct3D. Please check if " +
                                    "your DirectX redistributables and graphic card drivers are up to date. You can " +
                                    "download the DirectX runtimes at http://www.microsoft.com/download/en/details.aspx?id=8109",
                                    CSettings.sProgramName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    CLog.LogError(e.Message + " - Error in initializing of Direct3D. Please check if " +
                                  "your DirectX redistributables and graphic card drivers are up to date. You can " +
                                  "download the DirectX runtimes at http://www.microsoft.com/download/en/details.aspx?id=8109");
                    Environment.Exit(Environment.ExitCode);
                }
                break;
#endif

            default:
                _Draw = new CDrawWinForm();
                break;
            }
            _Draw.Init();
        }
Пример #9
0
        /// <summary>
        ///     Initializes the Driver selected in the config
        /// </summary>
        /// <returns></returns>
        public static bool Init()
        {
            if (_Draw != null)
            {
                return(false);
            }
            switch (CConfig.Config.Graphics.Renderer)
            {
            case ERenderer.TR_CONFIG_SOFTWARE:
                _Draw = new CDrawWinForm();
                break;

            case ERenderer.TR_CONFIG_OPENGL:
                try
                {
                    _Draw = new COpenGL();
                }
                catch (Exception e)
                {
                    CLog.LogError(e.Message + " - Error in initializing of OpenGL. Please check whether" +
                                  " your graphic card drivers are up to date.", true, true);
                    return(false);
                }
                break;

#if WIN
            case ERenderer.TR_CONFIG_DIRECT3D:
                try
                {
                    _Draw = new CDirect3D();
                }
                catch (Exception e)
                {
                    CLog.LogError(e.Message + " - Error in initializing of Direct3D. Please check if " +
                                  "your DirectX redistributables and graphic card drivers are up to date. You can " +
                                  "download the DirectX runtimes at http://www.microsoft.com/download/en/details.aspx?id=8109", true, true);
                    return(false);
                }
                break;
#endif

            default:
                _Draw = new CDrawWinForm();
                break;
            }
            return(_Draw.Init());
        }
Пример #10
0
        private static void _DeleteProfile(int profileID)
        {
            if (!IsProfileIDValid(profileID))
            {
                return;
            }

            if (string.IsNullOrEmpty(_Profiles[profileID].FilePath))
            {
                _RemoveProfile(profileID);
                return;
            }

            try
            {
                //Check if profile saved in config
                for (int i = 0; i < CSettings.MaxNumPlayer; i++)
                {
                    if (CConfig.Config.Game.Players[i] == GetProfileFileName(profileID))
                    {
                        CConfig.Config.Game.Players[i] = string.Empty;
                        CConfig.SaveConfig();
                    }
                }
                File.Delete(_Profiles[profileID].FilePath);
                _RemoveProfile(profileID);

                //Check if profile is selected in game
                for (int i = 0; i < CGame.Players.Length; i++)
                {
                    if (CGame.Players[i].ProfileID > profileID)
                    {
                        CGame.Players[i].ProfileID--;
                    }
                    else if (CGame.Players[i].ProfileID == profileID)
                    {
                        CGame.Players[i].ProfileID = -1;
                    }
                }
            }
            catch (Exception)
            {
                CLog.LogError("Can't delete Profile File " + _Profiles[profileID].FilePath);
            }
            _ProfilesChanged = true;
        }
Пример #11
0
        public static string GetThemeScreensPath()
        {
            string path = String.Empty;

            int themeIndex = GetThemeIndex();

            if (themeIndex != -1)
            {
                path = Path.Combine(_Themes[themeIndex].Path, _Themes[themeIndex].SkinFolder);
                path = Path.Combine(path, CSettings.sFolderScreens);
            }
            else
            {
                CLog.LogError("Can't find current Theme");
            }

            return(path);
        }
Пример #12
0
        public Font GetFont()
        {
            if (fonts == null)
            {
                fonts = new PrivateFontCollection();
                try
                {
                    fonts.AddFontFile(FilePath);
                    family = fonts.Families[0];
                }
                catch (Exception e)
                {
                    CLog.LogError("Error opening font file " + FilePath + ": " + e.Message);
                }
            }

            return(new Font(family, CFonts.Height, CFonts.GetFontStyle(), GraphicsUnit.Pixel));
        }
Пример #13
0
 public static void DeleteProfile(int ProfileID)
 {
     if (ProfileID < 0 || ProfileID >= _Profiles.Count)
     {
         return;
     }
     if (_Profiles[ProfileID].ProfileFile != String.Empty)
     {
         try
         {
             File.Delete(_Profiles[ProfileID].ProfileFile);
             _Profiles.RemoveAt(ProfileID);
         }
         catch (Exception)
         {
             CLog.LogError("Can't delete Profile File " + _Profiles[ProfileID].ProfileFile + ".xml");
         }
     }
 }
Пример #14
0
 public static void DeletePlaylist(int PlaylistID)
 {
     if (PlaylistID < 0 || PlaylistID >= _Playlists.Count)
     {
         return;
     }
     if (_Playlists[PlaylistID].PlaylistFile != String.Empty)
     {
         try
         {
             File.Delete(_Playlists[PlaylistID].PlaylistFile);
         }
         catch (Exception)
         {
             CLog.LogError("Can't delete Playlist File " + _Playlists[PlaylistID].PlaylistFile + ".xml");
         }
     }
     _Playlists.RemoveAt(PlaylistID);
 }
Пример #15
0
        private static Assembly _CompileFiles(string[] files)
        {
            if (files == null || files.Length == 0)
            {
                return(null);
            }

            var compilerParams = new CompilerParameters();

            compilerParams.ReferencedAssemblies.Add("System.Windows.Forms.dll");
            compilerParams.ReferencedAssemblies.Add("System.dll");
            compilerParams.ReferencedAssemblies.Add("System.Core.dll");
            compilerParams.ReferencedAssemblies.Add(Path.Combine("libs", "managed", "VocaluxeLib.dll"));
            compilerParams.GenerateInMemory = true;
#if DEBUG
            compilerParams.IncludeDebugInformation = true;
#endif

            using (CodeDomProvider cdp = CodeDomProvider.CreateProvider("CSharp"))
            {
                CompilerResults compileResult;

                try
                {
                    compileResult = cdp.CompileAssemblyFromFile(compilerParams, files);
                }
                catch (Exception e)
                {
                    CLog.LogError("Error Compiling Source (" + CHelper.ListStrings(files) + "): " + e.Message);
                    return(null);
                }

                if (compileResult.Errors.Count > 0)
                {
                    foreach (CompilerError e in compileResult.Errors)
                    {
                        CLog.LogError("Error Compiling Source (" + CHelper.ListStrings(files) + "): " + e.ErrorText + " in '" + e.FileName + "' (" + e.Line + ")");
                    }
                    return(null);
                }
                return(compileResult.CompiledAssembly);
            }
        }
Пример #16
0
        private static string GetVideoFileName(string VideoName, int SkinIndex, bool ReturnPath)
        {
            foreach (SkinElement sk in _Skins[SkinIndex].VideoList)
            {
                if (sk.Name == VideoName)
                {
                    if (!ReturnPath)
                    {
                        return(sk.Value);
                    }
                    else
                    {
                        return(Path.Combine(_Skins[SkinIndex].Path, sk.Value));
                    }
                }
            }

            CLog.LogError("Can't find Video Element \"" + VideoName);
            return(VideoName);
        }
Пример #17
0
        private static string GetSkinFileName(string SkinName, int SkinIndex, bool ReturnPath)
        {
            foreach (SkinElement sk in _Skins[SkinIndex].SkinList.Values)
            {
                if (sk.Name == SkinName)
                {
                    if (!ReturnPath)
                    {
                        return(sk.Value);
                    }
                    else
                    {
                        return(Path.Combine(_Skins[SkinIndex].Path, sk.Value));
                    }
                }
            }

            CLog.LogError("Can't find Skin Element \"" + SkinName);
            return(SkinName);
        }
Пример #18
0
        public static void Delete(int playlistID)
        {
            CPlaylistFile pl = Get(playlistID);

            if (pl == null)
            {
                return;
            }
            if (pl.File != "" && File.Exists(pl.File))
            {
                try
                {
                    File.Delete(pl.File);
                }
                catch (Exception)
                {
                    CLog.LogError("Can't delete Playlist File " + _Playlists[playlistID].File + ".xml");
                }
            }
            _Playlists.Remove(pl);
        }
Пример #19
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);
        }
Пример #20
0
        public static bool Init()
        {
            _HighscoreDB = new CHighscoreDB(CConfig.FileHighscoreDB);
            _CoverDB     = new CCoverDB(Path.Combine(CSettings.DataFolder, CSettings.FileNameCoverDB));
            _ResourceDB  = new CResourceDB(Path.Combine(CSettings.ProgramFolder, CSettings.FileNameCreditsRessourcesDB));

            if (!_HighscoreDB.Init())
            {
                CLog.LogError("Error initializing Highscore-DB", true, true);
                return(false);
            }
            if (!_CoverDB.Init())
            {
                CLog.LogError("Error initializing Cover-DB", true, true);
                return(false);
            }
            if (!_ResourceDB.Init())
            {
                CLog.LogError("Error initializing Credits-DB", true, true);
                return(false);
            }
            return(true);
        }
Пример #21
0
        private static void SaveProfile(int ProfileID)
        {
            if (ProfileID < 0 || ProfileID >= _Profiles.Count)
            {
                return;
            }

            if (_Profiles[ProfileID].ProfileFile == String.Empty)
            {
                string filename = string.Empty;
                foreach (char chr in _Profiles[ProfileID].PlayerName)
                {
                    if (char.IsLetter(chr))
                    {
                        filename += chr.ToString();
                    }
                }

                if (filename == String.Empty)
                {
                    filename = "1";
                }

                int i = 0;
                while (File.Exists(Path.Combine(CSettings.sFolderProfiles, filename + ".xml")))
                {
                    i++;
                    if (!File.Exists(Path.Combine(CSettings.sFolderProfiles, filename + i + ".xml")))
                    {
                        filename += i;
                    }
                }

                SProfile profile = _Profiles[ProfileID];
                profile.ProfileFile  = Path.Combine(CSettings.sFolderProfiles, filename + ".xml");
                _Profiles[ProfileID] = profile;
            }

            XmlWriter writer;

            try
            {
                writer = XmlWriter.Create(_Profiles[ProfileID].ProfileFile, _settings);
            }
            catch (Exception e)
            {
                CLog.LogError("Error creating/opening Profile File " + _Profiles[ProfileID].ProfileFile + ": " + e.Message);
                return;
            }

            if (writer == null)
            {
                CLog.LogError("Error creating/opening Profile File " + _Profiles[ProfileID].ProfileFile);
                return;
            }

            writer.WriteStartDocument();
            writer.WriteStartElement("root");

            writer.WriteStartElement("Info");
            writer.WriteElementString("PlayerName", _Profiles[ProfileID].PlayerName);
            writer.WriteElementString("Difficulty", Enum.GetName(typeof(EGameDifficulty), _Profiles[ProfileID].Difficulty));
            writer.WriteElementString("Avatar", _Profiles[ProfileID].Avatar.FileName);
            writer.WriteElementString("GuestProfile", Enum.GetName(typeof(EOffOn), _Profiles[ProfileID].GuestProfile));
            writer.WriteElementString("Active", Enum.GetName(typeof(EOffOn), _Profiles[ProfileID].Active));
            writer.WriteEndElement();

            writer.WriteEndElement(); //end of root
            writer.WriteEndDocument();

            writer.Flush();
            writer.Close();
        }
Пример #22
0
        public static void ListSkins()
        {
            CHelper Helper     = new CHelper();
            int     themeIndex = GetThemeIndex();

            _Skins.Clear();

            if (themeIndex < 0)
            {
                CLog.LogError("Error List Skins. Can't find Theme: " + CConfig.Theme);
                return;
            }

            Theme theme = _Themes[themeIndex];

            string        path  = Path.Combine(theme.Path, theme.SkinFolder);
            List <string> files = Helper.ListFiles(path, "*.xml", false);

            foreach (string file in files)
            {
                bool           loaded    = false;
                XPathDocument  xPathDoc  = null;
                XPathNavigator navigator = null;

                try
                {
                    xPathDoc  = new XPathDocument(Path.Combine(path, file));
                    navigator = xPathDoc.CreateNavigator();
                    loaded    = true;
                }
                catch (Exception e)
                {
                    CLog.LogError("Error loading skin " + file + ": " + e.Message);
                    loaded = false;
                    if (navigator != null)
                    {
                        navigator = null;
                    }

                    if (xPathDoc != null)
                    {
                        xPathDoc = null;
                    }
                }

                if (loaded)
                {
                    Skin skin = new Skin();

                    int version = 0;
                    CHelper.TryGetIntValueFromXML("//root/SkinSystemVersion", navigator, ref version);

                    if (version == SkinSystemVersion)
                    {
                        CHelper.GetValueFromXML("//root/Info/Name", navigator, ref skin.Name, String.Empty);
                        if (skin.Name != String.Empty)
                        {
                            CHelper.GetValueFromXML("//root/Info/Author", navigator, ref skin.Author, String.Empty);
                            CHelper.TryGetIntValueFromXML("//root/Info/SkinVersionMajor", navigator, ref skin.SkinVersionMajor);
                            CHelper.TryGetIntValueFromXML("//root/Info/SkinVersionMinor", navigator, ref skin.SkinVersionMinor);


                            skin.Path     = path;
                            skin.FileName = file;

                            skin.SkinList = new Dictionary <string, SkinElement>();
                            List <string> names = CHelper.GetValuesFromXML("Skins", navigator);
                            foreach (string str in names)
                            {
                                SkinElement sk = new SkinElement();
                                sk.Name            = str;
                                sk.Value           = String.Empty;
                                skin.SkinList[str] = sk;
                            }

                            skin.VideoList = new List <SkinElement>();
                            names          = CHelper.GetValuesFromXML("Videos", navigator);
                            foreach (string str in names)
                            {
                                SkinElement sk = new SkinElement();
                                sk.Name  = str;
                                sk.Value = String.Empty;
                                skin.VideoList.Add(sk);
                            }
                            _Skins.Add(skin);
                        }
                    }
                    else
                    {
                        string msg = "Can't load Skin \"" + file + "\", ";
                        if (version < SkinSystemVersion)
                        {
                            msg += "the file ist outdated! ";
                        }
                        else
                        {
                            msg += "the file is for newer program versions! ";
                        }

                        msg += "Current SkinSystemVersion is " + SkinSystemVersion.ToString();
                        CLog.LogError(msg);
                    }
                }
            }
        }
Пример #23
0
 public void LogError(string errorText, bool showMsg = false, bool exit = false)
 {
     CLog.LogError(errorText, showMsg, exit);
 }
Пример #24
0
        private static void ListThemes()
        {
            CHelper Helper = new CHelper();

            _Themes.Clear();

            string        path  = Path.Combine(Directory.GetCurrentDirectory(), CSettings.sFolderThemes);
            List <string> files = Helper.ListFiles(path, "*.xml", false);

            foreach (string file in files)
            {
                bool           loaded    = false;
                XPathDocument  xPathDoc  = null;
                XPathNavigator navigator = null;

                try
                {
                    xPathDoc  = new XPathDocument(Path.Combine(path, file));
                    navigator = xPathDoc.CreateNavigator();
                    loaded    = true;
                }
                catch (Exception e)
                {
                    CLog.LogError("Error loading theme " + file + ": " + e.Message);
                    loaded = false;
                    if (navigator != null)
                    {
                        navigator = null;
                    }

                    if (xPathDoc != null)
                    {
                        xPathDoc = null;
                    }
                }

                if (loaded)
                {
                    Theme theme = new Theme();

                    int version = 0;
                    CHelper.TryGetIntValueFromXML("//root/ThemeSystemVersion", navigator, ref version);

                    if (version == ThemeSystemVersion)
                    {
                        CHelper.GetValueFromXML("//root/Info/Name", navigator, ref theme.Name, String.Empty);
                        if (theme.Name != String.Empty)
                        {
                            CHelper.GetValueFromXML("//root/Info/Author", navigator, ref theme.Author, String.Empty);
                            CHelper.GetValueFromXML("//root/Info/SkinFolder", navigator, ref theme.SkinFolder, String.Empty);
                            CHelper.TryGetIntValueFromXML("//root/Info/ThemeVersionMajor", navigator, ref theme.ThemeVersionMajor);
                            CHelper.TryGetIntValueFromXML("//root/Info/ThemeVersionMinor", navigator, ref theme.ThemeVersionMinor);
                            theme.Path     = path;
                            theme.FileName = file;

                            _Themes.Add(theme);
                        }
                    }
                    else
                    {
                        string msg = "Can't load Theme \"" + file + "\", ";
                        if (version < ThemeSystemVersion)
                        {
                            msg += "the file ist outdated! ";
                        }
                        else
                        {
                            msg += "the file is for newer program versions! ";
                        }

                        msg += "Current ThemeSystemVersion is " + ThemeSystemVersion.ToString();
                        CLog.LogError(msg);
                    }
                }
            }
        }
Пример #25
0
        /// <summary>
        /// Loads theme fonts from skin file
        /// </summary>
        public static void LoadThemeFonts(string ThemeName, string FontFolder, XPathNavigator navigator)
        {
            string value = string.Empty;
            int    i     = 1;

            while (CHelper.GetValueFromXML("//root/Fonts/Font" + i.ToString() + "/Folder", navigator, ref value, value))
            {
                SFont sf = new SFont();
                sf.Folder = value;

                sf.IsThemeFont = true;
                sf.ThemeName   = ThemeName;

                bool ok = true;

                ok           &= CHelper.GetValueFromXML("//root/Fonts/Font" + i.ToString() + "/FileNormal", navigator, ref value, value);
                sf.FileNormal = value;
                value         = Path.Combine(FontFolder, Path.Combine(sf.Folder, value));
                CFont f = new CFont(value);
                sf.Normal = f;

                string name = String.Empty;
                ok     &= CHelper.GetValueFromXML("//root/Fonts/Font" + i.ToString() + "/Name", navigator, ref name, value);
                sf.Name = name;

                ok           &= CHelper.GetValueFromXML("//root/Fonts/Font" + i.ToString() + "/FileItalic", navigator, ref value, value);
                sf.FileItalic = value;
                value         = Path.Combine(FontFolder, Path.Combine(sf.Folder, value));
                f             = new CFont(value);
                sf.Italic     = f;

                ok         &= CHelper.GetValueFromXML("//root/Fonts/Font" + i.ToString() + "/FileBold", navigator, ref value, value);
                sf.FileBold = value;
                value       = Path.Combine(FontFolder, Path.Combine(sf.Folder, value));
                f           = new CFont(value);
                sf.Bold     = f;

                ok &= CHelper.GetValueFromXML("//root/Fonts/Font" + i.ToString() + "/FileBoldItalic", navigator, ref value, value);
                sf.FileBoldItalic = value;
                value             = Path.Combine(FontFolder, Path.Combine(sf.Folder, value));
                f             = new CFont(value);
                sf.BoldItalic = f;

                sf.Outline = 0f;
                ok        &= CHelper.TryGetFloatValueFromXML("//root/Fonts/Font" + i.ToString() + "/Outline", navigator, ref sf.Outline);

                sf.OutlineColor = new SColorF(0f, 0f, 0f, 1f);
                ok &= CHelper.TryGetFloatValueFromXML("//root/Fonts/Font" + i.ToString() + "/OutlineColorR", navigator, ref sf.OutlineColor.R);
                ok &= CHelper.TryGetFloatValueFromXML("//root/Fonts/Font" + i.ToString() + "/OutlineColorG", navigator, ref sf.OutlineColor.G);
                ok &= CHelper.TryGetFloatValueFromXML("//root/Fonts/Font" + i.ToString() + "/OutlineColorB", navigator, ref sf.OutlineColor.B);
                ok &= CHelper.TryGetFloatValueFromXML("//root/Fonts/Font" + i.ToString() + "/OutlineColorA", navigator, ref sf.OutlineColor.A);

                if (ok)
                {
                    _Fonts.Add(sf);
                }
                else
                {
                    CLog.LogError("Error loading theme fonts for theme \"" + ThemeName + "\": Error in Font" + i.ToString());
                }
                i++;
            }

            CLog.StartBenchmark(1, "BuildGlyphs");
            BuildGlyphs();
            CLog.StopBenchmark(1, "BuildGlyphs");
        }
Пример #26
0
        /// <summary>
        /// Load default fonts
        /// </summary>
        /// <returns></returns>
        private static bool LoadFontList()
        {
            bool           loaded    = false;
            XPathDocument  xPathDoc  = null;
            XPathNavigator navigator = null;

            try
            {
                xPathDoc  = new XPathDocument(System.IO.Path.Combine(CSettings.sFolderFonts, CSettings.sFileFonts));
                navigator = xPathDoc.CreateNavigator();
                loaded    = true;
            }
            catch (Exception e)
            {
                CLog.LogError("Error loading default fonts: " + e.Message);
                loaded = false;
                if (navigator != null)
                {
                    navigator = null;
                }

                if (xPathDoc != null)
                {
                    xPathDoc = null;
                }
            }
            _Fonts.Clear();

            if (loaded)
            {
                string value = string.Empty;
                int    i     = 1;
                while (CHelper.GetValueFromXML("//root/Font" + i.ToString() + "/Folder", navigator, ref value, value))
                {
                    string Folder = value;

                    CHelper.GetValueFromXML("//root/Font" + i.ToString() + "/FileNormal", navigator, ref value, value);
                    value = Path.Combine(Directory.GetCurrentDirectory(),
                                         Path.Combine(CSettings.sFolderFonts, Path.Combine(Folder, value)));
                    CFont f  = new CFont(value);
                    SFont sf = new SFont();
                    sf.Normal = f;

                    string name = String.Empty;
                    CHelper.GetValueFromXML("//root/Font" + i.ToString() + "/Name", navigator, ref name, value);
                    sf.Name        = name;
                    sf.IsThemeFont = false;
                    sf.ThemeName   = String.Empty;

                    CHelper.GetValueFromXML("//root/Font" + i.ToString() + "/FileItalic", navigator, ref value, value);
                    value = Path.Combine(Directory.GetCurrentDirectory(),
                                         Path.Combine(CSettings.sFolderFonts, Path.Combine(Folder, value)));
                    f         = new CFont(value);
                    sf.Italic = f;

                    CHelper.GetValueFromXML("//root/Font" + i.ToString() + "/FileBold", navigator, ref value, value);
                    value = Path.Combine(Directory.GetCurrentDirectory(),
                                         Path.Combine(CSettings.sFolderFonts, Path.Combine(Folder, value)));
                    f       = new CFont(value);
                    sf.Bold = f;

                    CHelper.GetValueFromXML("//root/Font" + i.ToString() + "/FileBoldItalic", navigator, ref value, value);
                    value = Path.Combine(Directory.GetCurrentDirectory(),
                                         Path.Combine(CSettings.sFolderFonts, Path.Combine(Folder, value)));
                    f             = new CFont(value);
                    sf.BoldItalic = f;

                    sf.Outline = 0f;
                    CHelper.TryGetFloatValueFromXML("//root/Font" + i.ToString() + "/Outline", navigator, ref sf.Outline);

                    sf.OutlineColor = new SColorF(0f, 0f, 0f, 1f);
                    CHelper.TryGetFloatValueFromXML("//root/Font" + i.ToString() + "/OutlineColorR", navigator, ref sf.OutlineColor.R);
                    CHelper.TryGetFloatValueFromXML("//root/Font" + i.ToString() + "/OutlineColorG", navigator, ref sf.OutlineColor.G);
                    CHelper.TryGetFloatValueFromXML("//root/Font" + i.ToString() + "/OutlineColorB", navigator, ref sf.OutlineColor.B);
                    CHelper.TryGetFloatValueFromXML("//root/Font" + i.ToString() + "/OutlineColorA", navigator, ref sf.OutlineColor.A);

                    _Fonts.Add(sf);
                    i++;
                }
            }
            return(loaded);
        }
Пример #27
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);
        }
Пример #28
0
        private static void LoadProfile(string FileName)
        {
            bool           loaded    = false;
            XPathDocument  xPathDoc  = null;
            XPathNavigator navigator = null;

            SProfile profile = new SProfile();

            profile.ProfileFile = Path.Combine(CSettings.sFolderProfiles, FileName);

            try
            {
                xPathDoc  = new XPathDocument(profile.ProfileFile);
                navigator = xPathDoc.CreateNavigator();
                loaded    = true;
            }
            catch (Exception e)
            {
                loaded = false;
                if (navigator != null)
                {
                    navigator = null;
                }

                if (xPathDoc != null)
                {
                    xPathDoc = null;
                }

                CLog.LogError("Error opening Profile File " + FileName + ": " + e.Message);
            }

            if (loaded)
            {
                string value = String.Empty;
                if (CHelper.GetValueFromXML("//root/Info/PlayerName", navigator, ref value, value))
                {
                    profile.PlayerName = value;

                    profile.Difficulty = EGameDifficulty.TR_CONFIG_EASY;
                    CHelper.TryGetEnumValueFromXML <EGameDifficulty>("//root/Info/Difficulty", navigator, ref profile.Difficulty);

                    profile.Avatar = new SAvatar(-1);
                    if (CHelper.GetValueFromXML("//root/Info/Avatar", navigator, ref value, value))
                    {
                        profile.Avatar = GetAvatar(value);
                    }

                    profile.GuestProfile = EOffOn.TR_CONFIG_OFF;
                    CHelper.TryGetEnumValueFromXML <EOffOn>("//root/Info/GuestProfile", navigator, ref profile.GuestProfile);

                    profile.Active = EOffOn.TR_CONFIG_ON;
                    CHelper.TryGetEnumValueFromXML <EOffOn>("//root/Info/Active", navigator, ref profile.Active);

                    _Profiles.Add(profile);
                }
                else
                {
                    CLog.LogError("Can't find PlayerName in Profile File: " + FileName);
                }
            }
        }
Пример #29
0
        private static void LoadLanguageFile(string FileName)
        {
            bool           loaded    = false;
            XPathDocument  xPathDoc  = null;
            XPathNavigator navigator = null;
            SLanguage      lang      = new SLanguage();

            lang.LanguageFilePath = Path.Combine(CSettings.sFolderLanguages, FileName);

            try
            {
                xPathDoc  = new XPathDocument(lang.LanguageFilePath);
                navigator = xPathDoc.CreateNavigator();
                loaded    = true;
            }
            catch (Exception e)
            {
                loaded = false;
                if (navigator != null)
                {
                    navigator = null;
                }

                if (xPathDoc != null)
                {
                    xPathDoc = null;
                }

                CLog.LogError("Error opening Language File " + FileName + ": " + e.Message);
            }

            if (loaded)
            {
                string value = string.Empty;
                if (CHelper.GetValueFromXML("//root/Info/Name", navigator, ref value, value))
                {
                    lang.Name = value;

                    if (lang.Name == CSettings.FallbackLanguage)
                    {
                        _FallbackLanguage = _Languages.Count;
                    }

                    lang.Texts = new Hashtable();

                    List <string> texts = CHelper.GetValuesFromXML("Texts", navigator);
                    for (int i = 0; i < texts.Count; i++)
                    {
                        if (CHelper.GetValueFromXML("//root/Texts/" + texts[i], navigator, ref value, value))
                        {
                            try
                            {
                                lang.Texts.Add(texts[i], value);
                            }
                            catch (Exception e)
                            {
                                CLog.LogError("Error reading Language File " + FileName + ": " + e.Message);
                            }
                        }
                    }

                    _Languages.Add(lang);
                }
            }
        }
Пример #30
0
        public static bool LoadConfig()
        {
            #region Inits
            bool           loaded    = false;
            XPathDocument  xPathDoc  = null;
            XPathNavigator navigator = null;

            try
            {
                xPathDoc  = new XPathDocument(CSettings.sFileConfig);
                navigator = xPathDoc.CreateNavigator();
                loaded    = true;
            }
            catch (Exception)
            {
                CLog.LogError("Error opening Config.xml (FileName: " + CSettings.sFileConfig);
                loaded = false;
                if (navigator != null)
                {
                    navigator = null;
                }

                if (xPathDoc != null)
                {
                    xPathDoc = null;
                }
            }
            #endregion Inits

            if (loaded)
            {
                string value = string.Empty;

                #region Debug
                CHelper.TryGetEnumValueFromXML <EDebugLevel>("//root/Debug/DebugLevel", navigator, ref DebugLevel);
                #endregion Debug

                #region Graphics
                CHelper.TryGetEnumValueFromXML <ERenderer>("//root/Graphics/Renderer", navigator, ref Renderer);
                CHelper.TryGetEnumValueFromXML <ETextureQuality>("//root/Graphics/TextureQuality", navigator, ref TextureQuality);
                CHelper.TryGetIntValueFromXML("//root/Graphics/CoverSize", navigator, ref CoverSize);
                if (CoverSize > 1024)
                {
                    CoverSize = 1024;
                }
                if (CoverSize < 32)
                {
                    CoverSize = 32;
                }

                CHelper.TryGetIntValueFromXML("//root/Graphics/ScreenW", navigator, ref ScreenW);
                CHelper.TryGetIntValueFromXML("//root/Graphics/ScreenH", navigator, ref ScreenH);
                CHelper.TryGetEnumValueFromXML <EAntiAliasingModes>("//root/Graphics/AAMode", navigator, ref AAMode);
                CHelper.TryGetEnumValueFromXML <EColorDeep>("//root/Graphics/Colors", navigator, ref Colors);
                CHelper.TryGetFloatValueFromXML("//root/Graphics/MaxFPS", navigator, ref MaxFPS);
                CHelper.TryGetEnumValueFromXML <EOffOn>("//root/Graphics/VSync", navigator, ref VSync);
                CHelper.TryGetEnumValueFromXML <EOffOn>("//root/Graphics/FullScreen", navigator, ref FullScreen);
                CHelper.TryGetFloatValueFromXML("//root/Graphics/FadeTime", navigator, ref FadeTime);
                #endregion Graphics

                #region Theme
                CHelper.GetValueFromXML("//root/Theme/Name", navigator, ref Theme, Theme);
                CHelper.GetValueFromXML("//root/Theme/Skin", navigator, ref Skin, Skin);
                CHelper.GetValueFromXML("//root/Theme/Cover", navigator, ref CoverTheme, CoverTheme);
                CHelper.TryGetEnumValueFromXML("//root/Theme/DrawNoteLines", navigator, ref DrawNoteLines);
                CHelper.TryGetEnumValueFromXML("//root/Theme/DrawToneHelper", navigator, ref DrawToneHelper);
                CHelper.TryGetEnumValueFromXML("//root/Theme/TimerLook", navigator, ref TimerLook);
                CHelper.TryGetEnumValueFromXML("//root/Theme/CoverLoading", navigator, ref CoverLoading);
                #endregion Theme

                #region Sound
                CHelper.TryGetEnumValueFromXML <EPlaybackLib>("//root/Sound/PlayBackLib", navigator, ref PlayBackLib);
                CHelper.TryGetEnumValueFromXML <ERecordLib>("//root/Sound/RecordLib", navigator, ref RecordLib);
                CHelper.TryGetEnumValueFromXML <EBufferSize>("//root/Sound/AudioBufferSize", navigator, ref AudioBufferSize);

                CHelper.TryGetIntValueFromXML("//root/Sound/AudioLatency", navigator, ref AudioLatency);
                if (AudioLatency < -500)
                {
                    AudioLatency = -500;
                }
                if (AudioLatency > 500)
                {
                    AudioLatency = 500;
                }

                CHelper.TryGetEnumValueFromXML("//root/Sound/BackgroundMusic", navigator, ref BackgroundMusic);
                CHelper.TryGetIntValueFromXML("//root/Sound/BackgroundMusicVolume", navigator, ref BackgroundMusicVolume);
                CHelper.TryGetEnumValueFromXML("//root/Sound/BackgroundMusicSource", navigator, ref BackgroundMusicSource);
                #endregion Sound

                #region Game
                // Songfolder
                value = string.Empty;
                int i = 1;
                while (CHelper.GetValueFromXML("//root/Game/SongFolder" + i.ToString(), navigator, ref value, value))
                {
                    if (i == 1)
                    {
                        SongFolder.Clear();
                    }

                    SongFolder.Add(value);
                    value = string.Empty;
                    i++;
                }

                CHelper.TryGetEnumValueFromXML <ESongMenu>("//root/Game/SongMenu", navigator, ref SongMenu);
                CHelper.TryGetEnumValueFromXML <ESongSorting>("//root/Game/SongSorting", navigator, ref SongSorting);
                CHelper.TryGetFloatValueFromXML("//root/Game/ScoreAnimationTime", navigator, ref ScoreAnimationTime);
                CHelper.TryGetEnumValueFromXML <ETimerMode>("//root/Game/TimerMode", navigator, ref TimerMode);
                CHelper.TryGetIntValueFromXML("//root/Game/NumPlayer", navigator, ref NumPlayer);
                CHelper.TryGetEnumValueFromXML("//root/Game/Tabs", navigator, ref Tabs);
                CHelper.GetValueFromXML("//root/Game/Language", navigator, ref Language, Language);
                CHelper.TryGetEnumValueFromXML <EOffOn>("//root/Game/LyricsOnTop", navigator, ref LyricsOnTop);

                if ((ScoreAnimationTime > 0 && ScoreAnimationTime < 1) || ScoreAnimationTime < 0)
                {
                    ScoreAnimationTime = 1;
                }

                if (NumPlayer < 1 || NumPlayer > CSettings.MaxNumPlayer)
                {
                    NumPlayer = 2;
                }

                List <string> _Languages = new List <string>();
                _Languages = CLanguage.GetLanguages();

                bool _LangExists = false;

                for (i = 0; i < _Languages.Count; i++)
                {
                    if (_Languages[i] == Language)
                    {
                        _LangExists = true;
                    }
                }

                //TODO: What should we do, if English not exists?
                if (_LangExists == false)
                {
                    Language = "English";
                }
                CLanguage.SetLanguage(Language);

                #endregion Game

                #region Video
                CHelper.TryGetEnumValueFromXML <EVideoDecoder>("//root/Video/VideoDecoder", navigator, ref VideoDecoder);
                CHelper.TryGetEnumValueFromXML <EOffOn>("//root/Video/VideoBackgrounds", navigator, ref VideoBackgrounds);
                CHelper.TryGetEnumValueFromXML <EOffOn>("//root/Video/VideoPreview", navigator, ref VideoPreview);
                CHelper.TryGetEnumValueFromXML <EOffOn>("//root/Video/VideosInSongs", navigator, ref VideosInSongs);
                #endregion Video

                #region Record
                MicConfig = new SMicConfig[CSettings.MaxNumPlayer];
                value     = string.Empty;
                for (int p = 1; p <= CSettings.MaxNumPlayer; p++)
                {
                    MicConfig[p - 1] = new SMicConfig(0);
                    CHelper.GetValueFromXML("//root/Record/MicConfig" + p.ToString() + "/DeviceName", navigator, ref MicConfig[p - 1].DeviceName, String.Empty);
                    CHelper.GetValueFromXML("//root/Record/MicConfig" + p.ToString() + "/DeviceDriver", navigator, ref MicConfig[p - 1].DeviceDriver, String.Empty);
                    CHelper.GetValueFromXML("//root/Record/MicConfig" + p.ToString() + "/InputName", navigator, ref MicConfig[p - 1].InputName, String.Empty);
                    CHelper.TryGetIntValueFromXML("//root/Record/MicConfig" + p.ToString() + "/Channel", navigator, ref MicConfig[p - 1].Channel);
                }

                CHelper.TryGetIntValueFromXML("//root/Record/MicDelay", navigator, ref MicDelay);
                MicDelay = (int)(20 * Math.Round(MicDelay / 20.0));
                if (MicDelay < 0)
                {
                    MicDelay = 0;
                }
                if (MicDelay > 500)
                {
                    MicDelay = 500;
                }

                #endregion Record

                return(true);
            }
            else
            {
                return(false);
            }
        }