Exemple #1
0
        public MyLyricsSetup()
        {
            LyricDiagnostics.OpenLog(MediaPortal.Configuration.Config.GetFile(MediaPortal.Configuration.Config.Dir.Log, MyLyricsSettings.LogName));
            //LyricDiagnostics.OpenLog(MediaPortal.Configuration.Config.GetFile(MediaPortal.Configuration.Config.Dir.Log));

            #region Initialize GUI and class
            InitializeComponent();
            lyricsLibraryUC = new MyLyricsSetup_LyricsLibrary(this);
            this.tabPageLyricsDatabase.Controls.Add(lyricsLibraryUC);

            // initialize delegates
            m_DelegateLyricFound      = new DelegateLyricFound(this.lyricFoundMethod);
            m_DelegateLyricNotFound   = new DelegateLyricNotFound(this.lyricNotFoundMethod);
            m_DelegateThreadFinished  = new DelegateThreadFinished(this.ThreadFinishedMethod);
            m_DelegateThreadException = new DelegateThreadException(this.ThreadExceptionMethod);

            // Grab music database
            MusicDatabase dbs = new MusicDatabase();
            m_TotalTitles = dbs.GetNumOfSongs();
            #endregion

            #region Get settings from in MediaPortal.xml
            using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.Settings("MediaPortal.xml"))
            {
                try
                {
                    tbLimit.Text      = xmlreader.GetValueAsString("myLyrics", "limit", m_TotalTitles.ToString());
                    tbPluginName.Text = xmlreader.GetValueAsString("myLyrics", "pluginsName", "My Lyrics");

                    cbAutoFetch.Checked       = xmlreader.GetValueAsBool("myLyrics", "automaticFetch", true);
                    cbAutomaticUpdate.Checked = xmlreader.GetValueAsBool("myLyrics", "automaticUpdateWhenFirstFound", false);
                    cbMoveSongFrom.Checked    = xmlreader.GetValueAsBool("myLyrics", "moveLyricFromMarkedDatabase", true);

                    lbSongsLimitNote.Text = ("(You have currently " + m_TotalTitles.ToString() + " titles in your music database)");

                    rdDefault.Checked = ((string)xmlreader.GetValueAsString("myLyrics", "useDefaultSitesMode", "True")).ToString().Equals("True") ? true : false;
                    trackBar.Value    = ((int)xmlreader.GetValueAsInt("myLyrics", "defaultSitesModeValue", 2));
                    trackBar_Scroll(null, null);

                    if (!rdDefault.Checked)
                    {
                        trackBar.Enabled      = false;
                        rbUserDefined.Checked = true;

                        cbLyricWiki.Checked      = ((string)xmlreader.GetValueAsString("myLyrics", "useLyricWiki", "True")).ToString().Equals("True") ? true : false;
                        cbEvilLabs.Checked       = ((string)xmlreader.GetValueAsString("myLyrics", "useEvilLabs", "True")).ToString().Equals("True") ? true : false;
                        cbLyrics007.Checked      = ((string)xmlreader.GetValueAsString("myLyrics", "useLyrics007", "True")).ToString().Equals("True") ? true : false;
                        cbLyricsOnDemand.Checked = ((string)xmlreader.GetValueAsString("myLyrics", "useLyricsOnDemand", "True")).ToString().Equals("True") ? true : false;
                        cbSeekLyrics.Checked     = ((string)xmlreader.GetValueAsString("myLyrics", "useSeekLyrics", "True")).ToString().Equals("True") ? true : false;
                        cbHotLyrics.Checked      = ((string)xmlreader.GetValueAsString("myLyrics", "useHotLyrics", "True")).ToString().Equals("True") ? true : false;
                    }
                }
                catch {
                    MessageBox.Show("Something has gone wrong when reading Mediaportal.xml");
                }
            }
            #endregion

            #region Serialzie/deserialize lyricsdatabases
            string   lyricsXMLpath     = MediaPortal.Configuration.Config.GetFile(MediaPortal.Configuration.Config.Dir.Base, MyLyricsSettings.LyricsXMLName);
            FileInfo lyricsXMLfileInfo = new FileInfo(lyricsXMLpath);


            // If lyrics.xml present, then convert database to new format...
            if (lyricsXMLfileInfo.Exists)
            {
                string   path     = MediaPortal.Configuration.Config.GetFile(MediaPortal.Configuration.Config.Dir.Database, MyLyricsSettings.LyricsDBName);
                FileInfo fileInfo = new FileInfo(path);

                // .. but only if it hasn't already been converted
                if (fileInfo.Exists == false)
                {
                    if (MessageBox.Show(this, "Your database will have to be upgraded to work with this version\r\nUpgrade now?", "Upgrade lyricsdatabase", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        ConvertFromXMLtoLyricsDatabase convertFromXMLtoLyricsDatabase = new ConvertFromXMLtoLyricsDatabase();
                        MyLyricsSettings.LyricsDB = convertFromXMLtoLyricsDatabase.Convert(lyricsXMLpath);

                        // Create file to save the database to
                        FileStream fs = new FileStream(path, FileMode.Create);

                        // Create a BinaryFormatter object to perform the serialization
                        BinaryFormatter bf = new BinaryFormatter();

                        // Use the BinaryFormatter object to serialize the database to the file
                        bf.Serialize(fs, MyLyricsSettings.LyricsDB);
                        fs.Close();

                        // Create likewise a database for the remainingLyrics
                        path = MediaPortal.Configuration.Config.GetFile(MediaPortal.Configuration.Config.Dir.Database, MyLyricsSettings.LyricsMarkedDBName);
                        fs   = new FileStream(path, FileMode.Create);
                        MyLyricsSettings.LyricsMarkedDB = new LyricsDatabase();
                        bf.Serialize(fs, MyLyricsSettings.LyricsMarkedDB);

                        // Close the file
                        fs.Close();
                    }
                }

                // ... else deserialize the databases and save reference in LyricsDB and LyricsMarkedDB
                else
                {
                    DeserializeBothDB();
                }
            }

            // If no Lyrics.xml present in base, then create new serialized databases
            else
            {
                string   path     = MediaPortal.Configuration.Config.GetFile(MediaPortal.Configuration.Config.Dir.Database, MyLyricsSettings.LyricsDBName);
                FileInfo fileInfo = new FileInfo(path);

                // .. but only if the databases hasn't been created
                if (fileInfo.Exists == false)
                {
                    path = MediaPortal.Configuration.Config.GetFile(MediaPortal.Configuration.Config.Dir.Database, MyLyricsSettings.LyricsDBName);

                    // Serialize empty LyricsDatabase if no lyrics.xml present
                    FileStream      fs = new FileStream(path, FileMode.Create);
                    BinaryFormatter bf = new BinaryFormatter();
                    MyLyricsSettings.LyricsDB = new LyricsDatabase();
                    bf.Serialize(fs, MyLyricsSettings.LyricsDB);
                    fs.Close();

                    // Serialize empty LyricsMarkedDatabase
                    path = MediaPortal.Configuration.Config.GetFile(MediaPortal.Configuration.Config.Dir.Database, MyLyricsSettings.LyricsMarkedDBName);
                    fs   = new FileStream(path, FileMode.Create);
                    MyLyricsSettings.LyricsMarkedDB = new LyricsDatabase();
                    bf.Serialize(fs, MyLyricsSettings.LyricsMarkedDB);
                    fs.Close();
                }
                else
                {
                    DeserializeBothDB();
                }
            }

            MyLyricsSetup_LyricsLibrary.CurrentDB = MyLyricsSettings.LyricsDB;
            #endregion

            lyricsLibraryUC.updateLyricsTree();
        }
Exemple #2
0
 private void MyLyricsSetup_FormClosing(object sender, FormClosingEventArgs e)
 {
     LyricDiagnostics.Dispose();
 }
        public EvilLabs(string artist, string title, ManualResetEvent m_EventStop_SiteSearches, int timeLimit)
        {
            this.timeLimit = timeLimit;
            timer          = new System.Timers.Timer();

            if (LyricDiagnostics.TraceSource != null)
            {
                LyricDiagnostics.TraceSource.TraceEvent(TraceEventType.Information, 0, LyricDiagnostics.ElapsedTimeString() + "EvilLabs(" + artist + ", " + title + ")");
            }

            artist = LyricUtil.RemoveFeatComment(artist);
            artist = LyricUtil.TrimForParenthesis(artist);
            artist = artist.Replace(" ", "+");
            title  = LyricUtil.RemoveFeatComment(title);
            title  = LyricUtil.TrimForParenthesis(title);
            title  = title.Replace(" ", "+");
            string urlString = "http://www.evillabs.sk/lyrics/" + artist + "+-+" + title;

            WebClient client = new WebClient();

            timer.Enabled  = true;
            timer.Interval = timeLimit;
            timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
            timer.Start();

            Uri uri = new Uri(urlString);

            client.OpenReadCompleted += new System.Net.OpenReadCompletedEventHandler(callbackMethod);
            client.OpenReadAsync(uri);

            while (complete == false)
            {
                if (m_EventStop_SiteSearches.WaitOne(1, true))
                {
                    complete = true;
                }
                else
                {
                    System.Threading.Thread.Sleep(100);
                }
            }
        }