Exemple #1
0
        /// <summary>
        /// Backgroundworker to scan folders
        /// </summary>
        private void FolderScan(object sender, DoWorkEventArgs e)
        {
            _scanRunning = true;

            // Get the arguments
            object[] args    = e.Argument as object[];
            var      shares  = args[0] as ArrayList;
            var      setting = args[1] as MusicDatabaseSettings;

            MediaPortal.Music.Database.MusicDatabase.DatabaseReorgChanged += SetStatus;

            try
            {
                m_dbs.MusicDatabaseReorg(shares, setting);
            }
            catch (Exception ex)
            {
                Log.Error("Folder Scan: Exception during processing: ", ex.Message);
                _scanRunning = false;
            }
        }
        /// <summary>
        /// Thread to scan the Shares
        /// </summary>
        private void FolderScanThread()
        {
            _scanRunning = true;
            ArrayList shares = new ArrayList();

            for (int index = 0; index < sharesListBox.CheckedIndices.Count; index++)
            {
                string path = sharesListBox.Items[(int)sharesListBox.CheckedIndices[index]].ToString();
                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
                    }
                }
            }
            MediaPortal.Music.Database.MusicDatabase.DatabaseReorgChanged +=
                new MusicDBReorgEventHandler(SetStatus);
            groupBox1.Enabled = false;
            groupBox2.Enabled = true;
            // Now create a Settings Object with the Settings checked to pass to the Import
            MusicDatabaseSettings setting = new MusicDatabaseSettings();

            setting.CreateMissingFolderThumb = checkBoxCreateFolderThumb.Checked;
            setting.ExtractEmbeddedCoverArt  = buildThumbsCheckBox.Checked;
            setting.StripArtistPrefixes      = checkBoxStripArtistPrefix.Checked;
            setting.TreatFolderAsAlbum       = folderAsAlbumCheckBox.Checked;
            setting.UseFolderThumbs          = checkBoxUseFolderThumb.Checked;
            setting.UseAllImages             = checkBoxAllImages.Checked;
            setting.CreateArtistPreviews     = checkBoxCreateArtist.Checked;
            setting.CreateGenrePreviews      = checkBoxCreateGenre.Checked;
            setting.UseLastImportDate        = checkBoxUpdateSinceLastImport.Checked;
            setting.ExcludeHiddenFiles       = false;
            setting.DateAddedValue           = comboBoxDateAdded.SelectedIndex;

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

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

            _scanRunning      = false;
            groupBox1.Enabled = true;
            groupBox2.Enabled = false;
        }