From f61f8fa46e465199f964b588922a33b30a8edc3d Mon Sep 17 00:00:00 2001 From: jwallet Date: Tue, 5 Jan 2021 00:11:43 -0500 Subject: [PATCH] 310 throw before attempting to create unknown track / ignore empty track close issue #310 --- EspionSpotify/Models/OutputFile.cs | 2 ++ EspionSpotify/Native/FileManager.cs | 10 ++++++++++ EspionSpotify/Recorder.cs | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/EspionSpotify/Models/OutputFile.cs b/EspionSpotify/Models/OutputFile.cs index 634b203d..58d6cd00 100644 --- a/EspionSpotify/Models/OutputFile.cs +++ b/EspionSpotify/Models/OutputFile.cs @@ -25,11 +25,13 @@ internal void Increment() public override string ToString() { + if (string.IsNullOrWhiteSpace(_file)) return null; return $@"{Path}\{_file}{GetAddedCount()}.{Extension}"; } public string ToPendingFileString() { + if (string.IsNullOrWhiteSpace(_file)) return null; return $@"{Path}\{_file}{GetAddedCount()}.{SPYTIFY}"; } diff --git a/EspionSpotify/Native/FileManager.cs b/EspionSpotify/Native/FileManager.cs index 283cb729..c7237a82 100644 --- a/EspionSpotify/Native/FileManager.cs +++ b/EspionSpotify/Native/FileManager.cs @@ -70,6 +70,10 @@ public OutputFile UpdateOutputFileWithLatestTrackInfo(OutputFile outputFile, Tra public void DeleteFile(string currentFile) { + if (string.IsNullOrWhiteSpace(currentFile)) + { + throw new Exception($"Current file cannot be null."); + } try { if (_fileSystem.File.Exists(currentFile)) @@ -90,6 +94,10 @@ public void DeleteFile(string currentFile) public void RenameFile(string source, string destination) { + if (string.IsNullOrWhiteSpace(source) || string.IsNullOrWhiteSpace(destination)) + { + throw new Exception($"Source / Destination paths cannot be null."); + } try { if (_fileSystem.File.Exists(source)) @@ -121,6 +129,8 @@ public static string GetFolderPath(Track track, UserSettings userSettings) var artistDir = GetArtistFolderPath(track, userSettings.TrackTitleSeparator); var albumDir = GetAlbumFolderPath(track, userSettings.TrackTitleSeparator); + if (string.IsNullOrEmpty(artistDir) || string.IsNullOrEmpty(albumDir)) throw new Exception("Artist / Album cannot be null."); + return $@"\{artistDir}\{albumDir}"; } diff --git a/EspionSpotify/Recorder.cs b/EspionSpotify/Recorder.cs index 5d6c09a8..a83eaaa1 100644 --- a/EspionSpotify/Recorder.cs +++ b/EspionSpotify/Recorder.cs @@ -175,7 +175,7 @@ private async void WaveIn_RecordingStopped(object sender, StoppedEventArgs e) } var length = TimeSpan.FromSeconds(CountSeconds).ToString(@"mm\:ss"); - _form.WriteIntoConsole(I18nKeys.LogRecorded, _track.ToString(), length); + _form.WriteIntoConsole(I18nKeys.LogRecorded, _currentOutputFile.File, length); _fileManager.UpdateOutputFileWithLatestTrackInfo(_currentOutputFile, _track, _userSettings); _fileManager.RenameFile(_currentOutputFile.ToPendingFileString(), _currentOutputFile.ToString());