/// <summary> /// Checks if the database is OK /// </summary> public static void CheckDatabaseIntegrity() { try { Logger.LogInfo("CheckDatabaseIntegrity", "Checking database integrity"); var _s = new SettingsRepo().Load().Result; var _w = new WatchFolderRepo().Load().Result; var _m = new MusicFileRepo().LoadAll(true).Result; var _p = new PlaylistFileRepo().LoadAll().Result; var _l = new LogsRepo().LoadSpecific("3").Result; Logger.LogInfo("CheckDatabaseIntegrity", "Database integrity check complete - No issues"); } catch (Exception e) { if ( MessageBox.Show( $"Unfortunately the database integrity check has failed ({e.Message}). YT Music Uploader cannot continue in this state. " + $"If you click 'OK', YT Music Uploader will reset the database to its original state. You'll lose any uploaded file states but the program" + $" should then work. Otherwise click cancel to attempt to rectify the database yourself located in: %localappdata%\\YTMusicUploader", "Database Integrity Check Fail", MessageBoxButton.OKCancel, MessageBoxImage.Error) == MessageBoxResult.OK) { ResetDatabase(); Logger.LogInfo("CheckDatabaseIntegrity", "Database has been reset due to integrity check failure. Comfirmed by user."); } } }
private async Task LoadDb() { Settings = SettingsRepo.Load().Result; SetThrottleSpeed( Settings.ThrottleSpeed == 0 || Settings.ThrottleSpeed == -1 ? "-1" : (Convert.ToDouble(Settings.ThrottleSpeed) / 1000000).ToString()); var initialFilesCount = await MusicFileRepo.CountAll(); var issueCount = await MusicFileRepo.CountIssues(); var uploadsCount = await MusicFileRepo.CountUploaded(); await RegistrySettings.SetStartWithWindows(Settings.StartWithWindows); SetStartWithWindows(Settings.StartWithWindows); SetDiscoveredFilesLabel(InitialFilesCount.ToString()); await BindWatchFoldersList(); await InitialiseFolderWatchers(); InitialFilesCount = Task.FromResult(initialFilesCount).Result; SetIssuesLabel(Task.FromResult(issueCount).Result.ToString()); SetUploadedLabel(Task.FromResult(uploadsCount).Result.ToString()); RunDebugCommands(); }
public void SetAmountLabelsToZero() { MusicFileRepo.DeleteAll().Wait(); SetDiscoveredFilesLabel("0"); SetIssuesLabel("0"); SetUploadedLabel("0"); InitialFilesCount = 0; }
public void RepopulateAmountLables(bool includeDiscoveredFiles = false) { SetIssuesLabel(MusicFileRepo.CountIssues().Result.ToString()); SetUploadedLabel(MusicFileRepo.CountUploaded().Result.ToString()); if (includeDiscoveredFiles) { InitialFilesCount = MusicFileRepo.CountAll().Result; SetDiscoveredFilesLabel(InitialFilesCount.ToString()); } }
public void StartMainProcess(bool restarting = false) { IdleProcessor.Paused = true; // Only perform at start up if (!DatabaseIntegrityCheckDone) { SetStatusMessage("Checking database integrity", "Checking database integrity"); Database.Maintenance.CheckAndCopyDatabaseFile(); DatabaseIntegrityCheckDone = true; } Logger.LogInfo("StartMainProcess", "Main process thread starting"); _scanAndUploadThread = new Thread((ThreadStart) delegate { if (restarting) { if (WatchFolders.Count == 0) { MusicFileRepo.DeleteAll().Wait(); SetDiscoveredFilesLabel("0"); SetIssuesLabel("0"); SetUploadedLabel("0"); } } MainProcess(restarting); int retryIssuesCount = 0; while (MusicFileRepo.CountIssues().Result > 0) { ThreadHelper.SafeSleep(10000); retryIssuesCount++; if (retryIssuesCount < Global.YTMusicIssuesMainProcessRetry) { MainProcess(); } else { break; } } }) { IsBackground = true }; _scanAndUploadThread.Start(); }
private async Task RemoveWachFolder() { try { if ((WatchFolder)lbWatchFolders.SelectedItem != null) { await WatchFolderRepo.Delete(((WatchFolder)lbWatchFolders.SelectedItem).Id); await MusicFileRepo.DeleteWatchFolder(((WatchFolder)lbWatchFolders.SelectedItem).Path); RepopulateAmountLables(); } } catch { } await BindWatchFoldersList(); QueueChecker.Queue = true; }
private async Task LoadDb() { Settings = SettingsRepo.Load().Result; SetThrottleSpeed( Settings.ThrottleSpeed == 0 || Settings.ThrottleSpeed == -1 ? "-1" : (Convert.ToDouble(Settings.ThrottleSpeed) / 1000000).ToString()); await RegistrySettings.SetStartWithWindows(Settings.StartWithWindows); SetStartWithWindows(Settings.StartWithWindows); SetAlsoUploadPlaylists(Settings.UploadPlaylists); await BindWatchFoldersList(); await InitialiseFolderWatchers(); if (WatchFolders.Count == 0) { SetAmountLabelsToZero(); } int initialFilesCount = await MusicFileRepo.CountAll(); int issueCount = await MusicFileRepo.CountIssues(); int uploadsCount = await MusicFileRepo.CountUploaded(); InitialFilesCount = Task.FromResult(initialFilesCount).Result; SetDiscoveredFilesLabel(InitialFilesCount.ToString()); SetIssuesLabel(Task.FromResult(issueCount).Result.ToString()); SetUploadedLabel(Task.FromResult(uploadsCount).Result.ToString()); Logger.ClearHistoricLogs(); RunDebugCommands(); EnableOptionButtons(true); }
private async Task RemoveWachFolder() { try { if ((WatchFolder)lbWatchFolders.SelectedItem != null) { Logger.LogInfo("RemoveWachFolder", "Watch folder removed: " + ((WatchFolder)lbWatchFolders.SelectedItem).Path); await WatchFolderRepo.Delete(((WatchFolder)lbWatchFolders.SelectedItem).Id); await MusicFileRepo.DeleteWatchFolder(((WatchFolder)lbWatchFolders.SelectedItem).Path); RepopulateAmountLables(); } } catch (Exception e) { Logger.Log(e, "RemoveWachFolder"); } await BindWatchFoldersList(); Restart(); }
/// <summary> /// Read a playlist file from a give path and returns a PlaylistFile (Data Model) complete with absolute paths /// well as reading the meta /// </summary> /// <param name="path">Path to playlist file</param> /// <returns>PlaylistFile (Data Model)</returns> public static PlaylistFile ReadPlaylistFile(string path) { var playlistFile = new PlaylistFile(); try { string playlistExtension = Path.GetExtension(path).ToLower(); var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read); using (var sr = new StreamReader(fs)) { switch (playlistExtension) { case ".wpl": var content_wpl = new WplContent(); var playlist_wpl = content_wpl.GetFromStream(sr.BaseStream); playlistFile.Title = playlist_wpl.Title.Trim(); break; case ".zpl": var content_zpl = new ZplContent(); var playlist_zpl = content_zpl.GetFromStream(sr.BaseStream); playlistFile.Title = playlist_zpl.Title.Trim(); break; default: playlistFile.Title = Path.GetFileNameWithoutExtension(path).Trim(); break; } if (string.IsNullOrEmpty(playlistFile.Title)) { playlistFile.Title = Path.GetFileNameWithoutExtension(path).Trim(); } sr.BaseStream.Position = 0; var parser = PlaylistParserFactory.GetPlaylistParser(playlistExtension); if (sr.BaseStream.Length == 0) // empty playlist { throw new ApplicationException("Empty Playlist"); } var playlist = parser.GetFromStream(sr.BaseStream); var paths = playlist.GetTracksPaths(); if ((paths == null || paths.Count == 0) && playlistExtension.In(".m3u", ".m3u8")) { paths = M3uPlaylist.GetPlaylistFromCorruptM3u(path); } playlistFile.Path = path; playlistFile.LastModifiedDate = new FileInfo(path).LastWriteTime; var musicFileRepo = new MusicFileRepo(); foreach (string musicFilePath in paths) { try { string absolutePath = Utils.IsAbsolutePath(musicFilePath) ? musicFilePath : Utils.MakeAbsolutePath(Path.GetDirectoryName(path), musicFilePath); if (absolutePath.StartsWith("file://")) { absolutePath = new Uri(absolutePath).LocalPath; } if (Path.GetExtension(absolutePath).ToLower().In(Global.SupportedMusicFiles) && File.Exists(absolutePath)) { playlistFile.PlaylistItems.Add(new PlaylistFile.PlaylistFileItem { Path = absolutePath }); } } catch (Exception e) { // Invalid path - Ignore - Don't add var _ = e; Logger.LogWarning( "ReadPlaylistFile", "Invalid path detected in playlist file and will be ignored: " + path); } } } } catch (Exception e) { Logger.LogError( "ReadPlaylistFile", "Error reading playlist file: " + path + ": " + e.Message); } return(playlistFile); }
/// <summary> /// Read a playlist file from a give path and returns a PlaylistFile (Data Model) complete with absolute paths /// well as reading the meta /// </summary> /// <param name="path">Path to playlist file</param> /// <returns>PlaylistFile (Data Model)</returns> public static PlaylistFile ReadPlaylistFile(string path) { var playlistFile = new PlaylistFile(); string playlistExtension = Path.GetExtension(path).ToLower(); var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); using (var sr = new StreamReader(fs)) { switch (playlistExtension) { case ".wpl": var content_wpl = new WplContent(); var playlist_wpl = content_wpl.GetFromStream(sr.BaseStream); playlistFile.Title = playlist_wpl.Title.Trim(); break; case ".zpl": var content_zpl = new ZplContent(); var playlist_zpl = content_zpl.GetFromStream(sr.BaseStream); playlistFile.Title = playlist_zpl.Title.Trim(); break; default: playlistFile.Title = Path.GetFileNameWithoutExtension(path).Trim(); break; } if (string.IsNullOrEmpty(playlistFile.Title)) { playlistFile.Title = Path.GetFileNameWithoutExtension(path).Trim(); } sr.BaseStream.Position = 0; var parser = PlaylistParserFactory.GetPlaylistParser(playlistExtension); var playlist = parser.GetFromStream(sr.BaseStream); var paths = playlist.GetTracksPaths(); if ((paths == null || paths.Count == 0) && playlistExtension.In(".m3u", ".m3u8")) { paths = M3uPlaylist.GetPlaylistFromCorruptM3u(path); } playlistFile.Path = path; playlistFile.LastModifiedDate = new FileInfo(path).LastWriteTime; var musicFileRepo = new MusicFileRepo(); foreach (string musicFilePath in paths) { string absolutePath = Utils.IsAbsolutePath(musicFilePath) ? musicFilePath : Utils.MakeAbsolutePath(Path.GetDirectoryName(path), musicFilePath); if (absolutePath.StartsWith("file://")) { absolutePath = new Uri(absolutePath).LocalPath; } if (Path.GetExtension(absolutePath).ToLower().In(Global.SupportedMusicFiles) && File.Exists(absolutePath)) { playlistFile.PlaylistItems.Add(new PlaylistFile.PlaylistFileItem { Path = absolutePath }); } } } return(playlistFile); }