コード例 #1
0
ファイル: CCover.cs プロジェクト: JanK118/Vocaluxe
        /// <summary>
        ///     Loads all cover-themes to list.
        /// </summary>
        private static void _LoadCoverThemes()
        {
            _CoverThemes.Clear();

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

            var xml = new CXmlDeserializer();

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

                if (!String.IsNullOrEmpty(theme.Info.Folder) && !String.IsNullOrEmpty(theme.Info.Name))
                {
                    theme.FolderPath = Path.Combine(folderPath, theme.Info.Folder);
                    _CoverThemes.Add(theme);
                }
            }
        }
コード例 #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.Error("Error creating Instance of PartyScreen: " + screenName);
                return(null);
            }

            CMenuParty screen;

            try
            {
                screen = (CMenuParty)instance;
            }
            catch (Exception e)
            {
                CLog.Error("Error casting PartyScreen: " + screenName + "; " + e.Message);
                return(null);
            }
            return(screen);
        }
コード例 #3
0
ファイル: CPlaylists.cs プロジェクト: da-ka/Vocaluxe
        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.Error("Can't find song '" + title + "' from '" + artist + "' in playlist file: " + file);
                            }
                        }
                    }
                }
                File.Delete(file);
            }
            catch
            {
                return(null);
            }

            return(pl);
        }
コード例 #4
0
ファイル: CMain.cs プロジェクト: da-ka/Vocaluxe
 public void Resume(CVideoStream stream)
 {
     try
     {
         CVideo.Resume(stream);
     }
     catch (NotSupportedException e)
     {
         CLog.Error($"Clould not resume the background video: {e.Message}");
     }
 }
コード例 #5
0
ファイル: CMain.cs プロジェクト: da-ka/Vocaluxe
 public void Close(ref CVideoStream stream)
 {
     try
     {
         CVideo.Close(ref stream);
     }
     catch (NotSupportedException e)
     {
         CLog.Error($"Clould not close the background video: {e.Message}");
     }
 }
コード例 #6
0
 private static void _CreateFolder(string path)
 {
     if (path != "" && !Directory.Exists(path))
     {
         try
         {
             Directory.CreateDirectory(path);
         }
         catch (Exception e)
         {
             CLog.Error("Cannot create directory \"" + path + "\": " + e.Message);
         }
     }
 }
コード例 #7
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.Error("Error Compiling Source (" + CHelper.ListStrings(files) + "): " + e.Message);
                    return(null);
                }

                if (compileResult.Errors.Count > 0)
                {
                    foreach (CompilerError e in compileResult.Errors)
                    {
                        CLog.Error("Error Compiling Source (" + CHelper.ListStrings(files) + "): " + e.ErrorText + " in '" + e.FileName + "' (" + e.Line + ")");
                    }
                    return(null);
                }
                return(compileResult.CompiledAssembly);
            }
        }
コード例 #8
0
        private static void _DeleteProfile(Guid 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 = Guid.Empty;
                    }
                }
            }
            catch (Exception)
            {
                CLog.Error("Can't delete Profile File " + _Profiles[profileID].FilePath);
            }
            _ProfilesChanged = true;
        }
コード例 #9
0
ファイル: CPlaylists.cs プロジェクト: da-ka/Vocaluxe
        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.Error("Can't delete Playlist File " + _Playlists[playlistID].File + ".xml");
                }
            }
            _Playlists.Remove(pl);
        }
コード例 #10
0
ファイル: CLanguage.cs プロジェクト: da-ka/Vocaluxe
        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.Error("Error reading language file " + filePath + ": " + e.Message);
                texts = null;
                return(false);
            }
            return(true);
        }
コード例 #11
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.Error("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.Error("Error creating Instance of PartyMode file: " + filePath);
                return(false);
            }

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

            if (!CLanguage.LoadPartyLanguageFiles(pm.PartyMode.ID, Path.Combine(pathToPm, CSettings.FolderNamePartyModeLanguages)))
            {
                CLog.Error("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);
        }