Skip to content

Commit

Permalink
310 throw before attempting to create unknown track / ignore empty track
Browse files Browse the repository at this point in the history
close issue #310
  • Loading branch information
jwallet committed Jan 5, 2021
1 parent c5d4b30 commit f61f8fa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions EspionSpotify/Models/OutputFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
}

Expand Down
10 changes: 10 additions & 0 deletions EspionSpotify/Native/FileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
Expand Down Expand Up @@ -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}";
}

Expand Down
2 changes: 1 addition & 1 deletion EspionSpotify/Recorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit f61f8fa

Please sign in to comment.