Example #1
0
        private static void _LoadCovers()
        {
            CLog.StartBenchmark("Load Covers");
            int            songCount = _Songs.Count;
            AutoResetEvent ev        = new AutoResetEvent(songCount == 0);

            NumSongsWithCoverLoaded = 0;
            foreach (CSong song in _Songs)
            {
                CSong tmp = song;
                Task.Factory.StartNew(() =>
                {
                    tmp.LoadSmallCover();
                    if (Interlocked.Increment(ref _NumSongsWithCoverLoaded) >= songCount)
                    {
                        ev.Set();
                    }
                });
            }
            ev.WaitOne();
            _CoverLoaded = true;
            CDataBase.CommitCovers();
            CLog.StopBenchmark("Load Covers");
        }
Example #2
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);
        }
Example #3
0
        /// <summary>
        ///     Loads all covers from the theme
        /// </summary>
        private static bool _LoadCovers()
        {
            SThemeCover coverTheme = _GetCoverTheme();

            Debug.Assert(!String.IsNullOrEmpty(coverTheme.Info.Name));

            IEnumerable <string> files = CHelper.ListImageFiles(coverTheme.FolderPath, true, true);

            lock (_Covers)
            {
                foreach (string file in files)
                {
                    _AddCover(Path.GetFileNameWithoutExtension(file), file);
                }
                if (_CoverExists(_NoCoverName))
                {
                    NoCover = _Covers[_NoCoverName];
                }
                else if (_CoverExists(_NoCoverNameAlt))
                {
                    NoCover = _Covers[_NoCoverNameAlt];
                }
                else
                {
                    CLog.Fatal("Covertheme \"{ThemeName}\" does not include a cover file named \"{MissingFileName}\" and cannot be used!", CLog.Params(coverTheme.Info.Name, _NoCoverName));
                    _UnloadCovers();
                    // Remove current theme and recursively try the other themes
                    _CoverThemes.Remove(coverTheme);
                    return(_CoverThemes.Count > 0 && _LoadCovers());
                }
            }
            _LoadCoverGenerators(coverTheme);
            return(true);
        }
Example #4
0
        private static bool _HandleInputs(CKeys keys, CMouse mouse)
        {
            SKeyEvent   keyEvent        = new SKeyEvent();
            SMouseEvent mouseEvent      = new SMouseEvent();
            SKeyEvent   inputKeyEvent   = new SKeyEvent();
            SMouseEvent inputMouseEvent = new SMouseEvent();

            bool popupPlayerControlAllowed = CurrentScreen.CurrentMusicType == EMusicType.Background;
            bool popupVolumeControlAllowed = CurrentScreen.CurrentMusicType != EMusicType.None;

            //Hide volume control for bg-music if bg-music is disabled
            if (popupVolumeControlAllowed && (CurrentScreen.CurrentMusicType == EMusicType.Background || CurrentScreen.CurrentMusicType == EMusicType.BackgroundPreview) && CConfig.Config.Sound.BackgroundMusic == EBackgroundMusicOffOn.TR_CONFIG_OFF)
            {
                popupVolumeControlAllowed = false;
            }

            bool resume = true;
            bool eventsAvailable;
            bool inputEventsAvailable = CController.PollKeyEvent(ref inputKeyEvent);

            while ((eventsAvailable = keys.PollEvent(ref keyEvent)) || inputEventsAvailable)
            {
                if (!eventsAvailable)
                {
                    keyEvent = inputKeyEvent;
                }

                if (keyEvent.IsArrowKey() || keyEvent.Key == Keys.NumPad0 || keyEvent.Key == Keys.D0 || keyEvent.Key == Keys.Add)
                {
                    _Cursor.Deactivate();

                    if (keyEvent.ModAlt && keyEvent.ModCtrl)
                    {
                        switch (keyEvent.Key)
                        {
                        case Keys.Right:
                            if (keyEvent.ModShift)
                            {
                                CConfig.Config.Graphics.BorderLeft++;
                            }
                            else
                            {
                                CConfig.Config.Graphics.BorderRight--;
                            }
                            break;

                        case Keys.Left:
                            if (keyEvent.ModShift)
                            {
                                CConfig.Config.Graphics.BorderLeft--;
                            }
                            else
                            {
                                CConfig.Config.Graphics.BorderRight++;
                            }
                            break;

                        case Keys.Down:
                            if (keyEvent.ModShift)
                            {
                                CConfig.Config.Graphics.BorderTop++;
                            }
                            else
                            {
                                CConfig.Config.Graphics.BorderBottom--;
                            }
                            break;

                        case Keys.Up:
                            if (keyEvent.ModShift)
                            {
                                CConfig.Config.Graphics.BorderTop--;
                            }
                            else
                            {
                                CConfig.Config.Graphics.BorderBottom++;
                            }
                            break;

                        case Keys.D0:
                        case Keys.NumPad0:
                            CConfig.Config.Graphics.BorderLeft      =
                                CConfig.Config.Graphics.BorderRight = CConfig.Config.Graphics.BorderTop = CConfig.Config.Graphics.BorderBottom = 0;
                            break;

                        case Keys.Add:
                            switch (CConfig.Config.Graphics.ScreenAlignment)
                            {
                            case EGeneralAlignment.Middle:
                                CConfig.Config.Graphics.ScreenAlignment = EGeneralAlignment.End;
                                break;

                            case EGeneralAlignment.End:
                                CConfig.Config.Graphics.ScreenAlignment = EGeneralAlignment.Start;
                                break;

                            default:
                                CConfig.Config.Graphics.ScreenAlignment = EGeneralAlignment.Middle;
                                break;
                            }
                            break;
                        }
                        CConfig.SaveConfig();
                        break;
                    }
                }

                if (keyEvent.Key == Keys.F11)
                {
                    if (_CurrentPopupScreen == EPopupScreens.NoPopup)
                    {
                        ShowPopup(EPopupScreens.PopupServerQR);
                    }
                    else
                    {
                        HidePopup(EPopupScreens.PopupServerQR);
                    }
                }

                if (keyEvent.Key == Keys.F8)
                {
                    CLog.ShowLogAssistant("", null);
                }

                if (popupPlayerControlAllowed && keyEvent.Key == Keys.Tab)
                {
                    if (_CurrentPopupScreen == EPopupScreens.NoPopup && CConfig.Config.Sound.BackgroundMusic == EBackgroundMusicOffOn.TR_CONFIG_ON)
                    {
                        ShowPopup(EPopupScreens.PopupPlayerControl);
                    }
                    else
                    {
                        HidePopup(EPopupScreens.PopupPlayerControl);
                    }
                }

                if (popupPlayerControlAllowed && CConfig.Config.Sound.BackgroundMusic != EBackgroundMusicOffOn.TR_CONFIG_OFF)
                {
                    if (keyEvent.Key == Keys.MediaNextTrack)
                    {
                        CBackgroundMusic.Next();
                    }
                    else if (keyEvent.Key == Keys.MediaPreviousTrack)
                    {
                        CBackgroundMusic.Previous();
                    }
                    else if (keyEvent.Key == Keys.MediaPlayPause)
                    {
                        if (CBackgroundMusic.IsPlaying)
                        {
                            CBackgroundMusic.Pause();
                        }
                        else
                        {
                            CBackgroundMusic.Play();
                        }
                    }
                }

                if (keyEvent.ModShift && (keyEvent.Key == Keys.F1))
                {
                    CSettings.ProgramState = EProgramState.EditTheme;
                }
                else if (keyEvent.ModAlt && (keyEvent.Key == Keys.Enter))
                {
                    CConfig.Config.Graphics.FullScreen = (CConfig.Config.Graphics.FullScreen == EOffOn.TR_CONFIG_ON) ? EOffOn.TR_CONFIG_OFF : EOffOn.TR_CONFIG_ON;
                }
                else if (keyEvent.ModAlt && (keyEvent.Key == Keys.P))
                {
                    CDraw.MakeScreenShot();
                }
                else
                {
                    if (_Fading == null)
                    {
                        bool handled = false;
                        if (_CurrentPopupScreen != EPopupScreens.NoPopup)
                        {
                            handled = _PopupScreens[(int)_CurrentPopupScreen].HandleInput(keyEvent);
                            if (popupVolumeControlAllowed && _CurrentPopupScreen == EPopupScreens.PopupVolumeControl && handled)
                            {
                                _VolumePopupTimer.Restart();
                            }
                        }
                        else if (popupVolumeControlAllowed && _PopupScreens[(int)EPopupScreens.PopupVolumeControl].HandleInput(keyEvent))
                        {
                            ShowPopup(EPopupScreens.PopupVolumeControl);
                            _VolumePopupTimer.Restart();
                        }

                        if (!handled)
                        {
                            resume &= CurrentScreen.HandleInput(keyEvent);
                        }
                    }
                }

                if (!eventsAvailable)
                {
                    inputEventsAvailable = CController.PollKeyEvent(ref inputKeyEvent);
                }
            }

            inputEventsAvailable = CController.PollMouseEvent(ref inputMouseEvent);

            while ((eventsAvailable = mouse.PollEvent(ref mouseEvent)) || inputEventsAvailable)
            {
                if (!eventsAvailable)
                {
                    mouseEvent = inputMouseEvent;
                }

                if (mouseEvent.Wheel != 0)
                {
                    _Cursor.Activate();
                }

                _UpdateMousePosition(mouseEvent.X, mouseEvent.Y);

                bool isOverPopupPlayerControl = CHelper.IsInBounds(_PopupScreens[(int)EPopupScreens.PopupPlayerControl].ScreenArea, mouseEvent);
                if (popupPlayerControlAllowed && isOverPopupPlayerControl)
                {
                    if (_CurrentPopupScreen == EPopupScreens.NoPopup && CConfig.Config.Sound.BackgroundMusic == EBackgroundMusicOffOn.TR_CONFIG_ON)
                    {
                        ShowPopup(EPopupScreens.PopupPlayerControl);
                    }
                }

                if (!isOverPopupPlayerControl && _CurrentPopupScreen == EPopupScreens.PopupPlayerControl)
                {
                    HidePopup(EPopupScreens.PopupPlayerControl);
                }

                bool isOverPopupVolumeControl = CHelper.IsInBounds(_PopupScreens[(int)EPopupScreens.PopupVolumeControl].ScreenArea, mouseEvent);
                if (popupVolumeControlAllowed && isOverPopupVolumeControl)
                {
                    if (_CurrentPopupScreen == EPopupScreens.NoPopup)
                    {
                        ShowPopup(EPopupScreens.PopupVolumeControl);
                        _VolumePopupTimer.Reset();
                        _VolumePopupTimer.Start();
                    }
                }

                if (_CursorOverVolumeControl && !isOverPopupVolumeControl)
                {
                    if (_CurrentPopupScreen == EPopupScreens.PopupVolumeControl)
                    {
                        HidePopup(EPopupScreens.PopupVolumeControl);
                        _VolumePopupTimer.Reset();
                    }
                }
                _CursorOverVolumeControl = isOverPopupVolumeControl;


                bool handled = false;
                if (_CurrentPopupScreen != EPopupScreens.NoPopup)
                {
                    handled = _PopupScreens[(int)_CurrentPopupScreen].HandleMouse(mouseEvent);
                }

                if (!handled && _Fading == null && (_Cursor.IsActive || mouseEvent.LB || mouseEvent.RB || mouseEvent.MB))
                {
                    resume &= CurrentScreen.HandleMouse(mouseEvent);
                }

                if (!eventsAvailable)
                {
                    inputEventsAvailable = CController.PollMouseEvent(ref inputMouseEvent);
                }
            }
            return(resume);
        }
Example #5
0
 public void LogSongInfo(string text)
 {
     CLog.LogSongInfo(text);
 }
Example #6
0
 public void LogDebug(string text)
 {
     CLog.LogDebug(text);
 }
Example #7
0
 public void LogError(string errorText, bool showMsg = false, bool exit = false)
 {
     CLog.LogError(errorText, showMsg, exit);
 }
Example #8
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);
                }
            }
        }
Example #9
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);
                }
            }
        }
Example #10
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();
        }
Example #11
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");
        }
Example #12
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);
        }
Example #13
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);
            }
        }
Example #14
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);
                    }
                }
            }
        }
Example #15
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);
                    }
                }
            }
        }
Example #16
0
        public static void LoadSkins()
        {
            for (int index = 0; index < _Skins.Count; index++)
            {
                bool           loaded    = false;
                XPathDocument  xPathDoc  = null;
                XPathNavigator navigator = null;

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

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

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


                    // load skins/textures
                    List <string> keys = new List <string>(_Skins[index].SkinList.Keys);

                    foreach (string name in keys)
                    {
                        try
                        {
                            CHelper.GetValueFromXML("//root/Skins/" + name, navigator, ref value, String.Empty);
                            SkinElement sk = _Skins[index].SkinList[name];
                            sk.Value      = value;
                            sk.VideoIndex = -1;
                            sk.Texture    = CDraw.AddTexture(Path.Combine(_Skins[index].Path, sk.Value));
                            _Skins[index].SkinList[name] = sk;
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show("Error on loading texture \"" + name + "\": " + e.Message + e.StackTrace);
                            CLog.LogError("Error on loading texture \"" + name + "\": " + e.Message + e.StackTrace);
                        }
                    }


                    // load videos
                    for (int i = 0; i < _Skins[index].VideoList.Count; i++)
                    {
                        try
                        {
                            CHelper.GetValueFromXML("//root/Videos/" + _Skins[index].VideoList[i].Name, navigator, ref value, String.Empty);
                            SkinElement sk = new SkinElement();
                            sk.Name       = _Skins[index].VideoList[i].Name;
                            sk.Value      = value;
                            sk.VideoIndex = CVideo.VdLoad(Path.Combine(_Skins[index].Path, sk.Value));
                            CVideo.VdSetLoop(sk.VideoIndex, true);
                            CVideo.VdPause(sk.VideoIndex);
                            sk.Texture = new STexture(-1);
                            _Skins[index].VideoList[i] = sk;
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show("Error on loading video \"" + _Skins[index].VideoList[i].Name + "\": " + e.Message + e.StackTrace);
                            CLog.LogError("Error on loading video \"" + _Skins[index].VideoList[i].Name + "\": " + e.Message + e.StackTrace);
                        }
                    }

                    // load colors
                    LoadColors(navigator, index);
                }
            }
        }