private void TryLoadData() { try { BsonReader reader = BsonReader.Create(File.ReadAllText(this.settingsFileLocation)); this.settings = BsonSerializer.Deserialize <MusicDatabaseSettings>(reader); } catch { this.settings = MusicDatabaseSettings.CreateDefault(); this.Save(); } }
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); } }
/// <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; }
public void Dispose() { this.settings = null; this.settingsFileLocation = null; }
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); }
private void startButton_Click(object sender, EventArgs e) { groupBox1.Enabled = false; groupBox2.Enabled = true; // Now create a Settings Object with the Settings checked to pass to the Import MusicDatabaseSettings setting = new MusicDatabaseSettings { CreateMissingFolderThumb = checkBoxCreateFolderThumb.Checked, ExtractEmbeddedCoverArt = buildThumbsCheckBox.Checked, StripArtistPrefixes = checkBoxStripArtistPrefix.Checked, TreatFolderAsAlbum = folderAsAlbumCheckBox.Checked, UseFolderThumbs = checkBoxUseFolderThumb.Checked, UseAllImages = checkBoxAllImages.Checked, CreateArtistPreviews = checkBoxCreateArtist.Checked, CreateGenrePreviews = checkBoxCreateGenre.Checked, UseLastImportDate = checkBoxUpdateSinceLastImport.Checked, ExcludeHiddenFiles = false, DateAddedValue = comboBoxDateAdded.SelectedIndex }; 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 } } } _scanThread = new BackgroundWorker(); _scanThread.WorkerReportsProgress = true; _scanThread.DoWork += FolderScan; _scanThread.RunWorkerCompleted += FolderScanCompleted; _scanThread.ProgressChanged += FolderScanProgress; _scanThread.RunWorkerAsync(new object[] { shares, setting }); }