コード例 #1
0
        public int DoReorg()
        {
            /// Todo: move this statement to the GUI.
            /// Database Reorg now fully in music.database
            ///

            GUIDialogProgress pDlgProgress =
                (GUIDialogProgress)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_PROGRESS);

            if (null == pDlgProgress)
            {
                return((int)Errors.ERROR_REORG_SONGS);
            }

            pDlgProgress.SetHeading(313);
            pDlgProgress.SetLine(2, "");
            pDlgProgress.SetLine(3, "");
            pDlgProgress.SetPercentage(0);
            pDlgProgress.Progress();
            pDlgProgress.SetLine(1, 316);
            pDlgProgress.ShowProgressBar(true);

            ///TFRO71 4 june 2005
            ///Connect the event to a method that knows what to do with the event.
            MusicDatabase.DatabaseReorgChanged += new MusicDBReorgEventHandler(SetPercentDonebyEvent);
            ///Execute the reorganisation
            int appel = m_dbs.MusicDatabaseReorg(null);

            ///Tfro Disconnect the event from the method.
            MusicDatabase.DatabaseReorgChanged -= new MusicDBReorgEventHandler(SetPercentDonebyEvent);

            pDlgProgress.SetLine(2, "Klaar");

            return((int)Errors.ERROR_OK);
        }
コード例 #2
0
        /// <summary>
        /// Run the MusicDBReorg, when it's schedule is due.
        /// </summary>
        private void Run()
        {
            Log.Debug("MusicDBReorg.Run: thread started");
            while (_run)
            {
                if (ShouldRunSchedule())
                {
                    // Start the Music DB Reorganization
                    _reorgRunning = true;
                    Log.Info("MusicDBReorg.Run: schedule is due:{0}", DateTime.Now.ToString());

                    try
                    {
                        LoadShares();
                        mDB.MusicDatabaseReorg(m_Shares);
                    }
                    catch (Exception ex)
                    {
                        Log.Error("MusicDBReorg.Run: Reorg failed:{0}", ex.Message);
                    }

                    // store last run
                    using (Settings writer = new MPSettings())
                    {
                        writer.SetValue("musicdbreorg", "lastrun", DateTime.Now.Day);
                    }
                    Log.Info("MusicDBReorg.Run: Reorg finished:{0}", DateTime.Now.ToString());
                    _reorgRunning = false;
                }
                else
                {
                    // stay Idle for a minute checking if we have to stop every second
                    int timeout = 60000;
                    while (_run && timeout > 0)
                    {
                        Thread.Sleep(1000);
                        timeout -= 1000;
                    }
                }
            }
            Log.Debug("MusicDBReorg.Run: thread stopped");
        }
コード例 #3
0
        private void FolderScanThread()
        {
            _scanRunning = true;
            ArrayList shares     = new ArrayList();
            ArrayList scanShares = new ArrayList();

            foreach (GUIListItem item in lcFolders.ListItems)
            {
                if (item.IsPlayed)
                {
                    scanShares.Add(item);
                }
            }

            for (int index = 0; index < _scanShare; index++)
            {
                GUIListItem item = (GUIListItem)scanShares[index];
                string      path = item.Path;
                if (Directory.Exists(path))
                {
                    try
                    {
                        string driveName = path.Substring(0, 1);
                        if (path.StartsWith(@"\\"))
                        {
                            // we have the path in unc notation
                            driveName = path;
                        }

                        ulong freeBytesAvailable = Util.Utils.GetFreeDiskSpace(driveName);

                        if (freeBytesAvailable > 0)
                        {
                            ulong diskSpace = freeBytesAvailable / 1048576;
                            if (diskSpace > 100) // > 100MB left for creation of thumbs, etc
                            {
                                Log.Info("MusicDatabase: adding share {0} for scanning - available disk space: {1} MB", path,
                                         diskSpace.ToString());
                                shares.Add(path);
                            }
                            else
                            {
                                Log.Warn("MusicDatabase: NOT scanning share {0} because of low disk space: {1} MB", path,
                                         diskSpace.ToString());
                            }
                        }
                    }
                    catch (Exception)
                    {
                        // Drive not ready, etc
                    }
                }
            }
            MusicDatabase.DatabaseReorgChanged += new MusicDBReorgEventHandler(SetStatus);
            EnableControls(false);
            // Now create a Settings Object with the Settings checked to pass to the Import
            MusicDatabaseSettings setting = new MusicDatabaseSettings();

            setting.CreateMissingFolderThumb = btnCreateMissingFolderThumbs.Selected;
            setting.ExtractEmbeddedCoverArt  = btnExtractthumbs.Selected;
            setting.StripArtistPrefixes      = btnStripartistprefixes.Selected;
            setting.TreatFolderAsAlbum       = btnTreatFolderAsAlbum.Selected;
            setting.UseFolderThumbs          = btnUseFolderThumbs.Selected;
            setting.UseAllImages             = btnUseAllImages.Selected;
            setting.CreateArtistPreviews     = btnCreateartistthumbs.Selected;
            setting.CreateGenrePreviews      = btnCreategenrethumbs.Selected;
            setting.UseLastImportDate        = btnUpdateSinceLastImport.Selected;
            setting.ExcludeHiddenFiles       = false;
            setting.DateAddedValue           = _dateAddedSelectedIndex;

            try
            {
                m_dbs.MusicDatabaseReorg(shares, setting);
            }
            catch (Exception ex)
            {
                Log.Error("Folder Scan: Exception during processing: ", ex.Message);
                _scanRunning = false;
            }

            using (Profile.Settings xmlreader = new Profile.MPSettings())
            {
                _updateSinceLastImport = String.Format("Only update files after {0}",
                                                       xmlreader.GetValueAsString("musicfiles", "lastImport",
                                                                                  "1900-01-01 00:00:00"));
            }

            _scanRunning = false;
            EnableControls(true);
            SetProperties();

            GUIDialogNotify dlgNotify =
                (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY);

            if (null != dlgNotify)
            {
                dlgNotify.SetHeading(GUILocalizeStrings.Get(1020)); // Information
                dlgNotify.SetText(GUILocalizeStrings.Get(300024));  // Scan finished
                dlgNotify.DoModal(GetID);
            }
        }
コード例 #4
0
        private void FolderScanThread()
        {
            ArrayList shares     = new ArrayList();
            ArrayList scanShares = new ArrayList();

            foreach (GUIListItem item in lcFolders.ListItems)
            {
                if (item.IsPlayed)
                {
                    scanShares.Add(item);
                }
            }

            for (int index = 0; index < _scanShare; index++)
            {
                GUIListItem item = (GUIListItem)scanShares[index];
                string      path = item.Path;
                if (Directory.Exists(path))
                {
                    try
                    {
                        string driveName = path.Substring(0, 1);
                        if (path.StartsWith(@"\\"))
                        {
                            // we have the path in unc notation
                            driveName = path;
                        }

                        ulong freeBytesAvailable = Util.Utils.GetFreeDiskSpace(driveName);

                        if (freeBytesAvailable > 0)
                        {
                            ulong diskSpace = freeBytesAvailable / 1048576;
                            if (diskSpace > 100) // > 100MB left for creation of thumbs, etc
                            {
                                Log.Info("MusicDatabase: adding share {0} for scanning - available disk space: {1} MB", path,
                                         diskSpace.ToString());
                                shares.Add(path);
                            }
                            else
                            {
                                Log.Warn("MusicDatabase: NOT scanning share {0} because of low disk space: {1} MB", path,
                                         diskSpace.ToString());
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error("FolderScanThread exception {0}", ex.Message);
                        // Drive not ready, etc
                    }
                }
            }
            MusicDatabase.DatabaseReorgChanged += new MusicDBReorgEventHandler(SetStatus);
            EnableControls(false);
            // Now create a Settings Object with the Settings checked to pass to the Import
            MusicDatabaseSettings setting = new MusicDatabaseSettings();

            setting.CreateMissingFolderThumb = btnCreateMissingFolderThumbs.Selected;
            setting.ExtractEmbeddedCoverArt  = btnExtractthumbs.Selected;
            setting.StripArtistPrefixes      = btnStripartistprefixes.Selected;
            setting.TreatFolderAsAlbum       = btnTreatFolderAsAlbum.Selected;
            setting.UseFolderThumbs          = btnUseFolderThumbs.Selected;
            setting.UseAllImages             = btnUseAllImages.Selected;
            setting.CreateArtistPreviews     = btnCreateartistthumbs.Selected;
            setting.CreateGenrePreviews      = btnCreategenrethumbs.Selected;
            setting.UseLastImportDate        = btnUpdateSinceLastImport.Selected;
            setting.ExcludeHiddenFiles       = false;
            setting.DateAddedValue           = _dateAddedSelectedIndex;

            try
            {
                m_dbs.MusicDatabaseReorg(shares, setting);
            }
            catch (Exception ex)
            {
                Log.Error("Folder Scan: Exception during processing: ", ex.Message);
            }

            using (Profile.Settings xmlreader = new Profile.MPSettings())
            {
                _updateSinceLastImport = String.Format(GUILocalizeStrings.Get(300232),
                                                       xmlreader.GetValueAsString("musicfiles", "lastImport",
                                                                                  "1900-01-01 00:00:00"));
            }

            EnableControls(true);
            SetProperties();

            // We can't send the message from here as this will result to run the dislog in a wrong thread
            GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_DATABASE_SCAN_ENDED, 0, 0, 0, 0, 0, null);

            GUIWindowManager.SendThreadMessage(msg);
        }