From d4c3d94d1a86f6d67d56f1b6eaecb827d6b311a7 Mon Sep 17 00:00:00 2001 From: amazing-username Date: Tue, 21 May 2019 22:03:34 -0400 Subject: [PATCH] Able to update the song's metadata and move the old song file to a new path and delete the old song path. Need to imlement functionality to revert changes incase something goes wrong. #37 --- Controllers/Managers/DirectoryManager.cs | 2 +- Controllers/Managers/SongManager.cs | 31 +++++++++++++++++------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/Controllers/Managers/DirectoryManager.cs b/Controllers/Managers/DirectoryManager.cs index 567349d..2d11c5e 100644 --- a/Controllers/Managers/DirectoryManager.cs +++ b/Controllers/Managers/DirectoryManager.cs @@ -113,7 +113,7 @@ namespace Icarus.Controllers.Managers _logger.Info("Created album path"); } - songPath = $@"{albumPath}{song.Filename}"; + songPath = albumPath; return songPath; } diff --git a/Controllers/Managers/SongManager.cs b/Controllers/Managers/SongManager.cs index cddb08d..9cbdb39 100644 --- a/Controllers/Managers/SongManager.cs +++ b/Controllers/Managers/SongManager.cs @@ -1018,27 +1018,40 @@ namespace Icarus.Controllers.Managers _logger.Info("Change to song's album or artist"); DirectoryManager dirMgr = new DirectoryManager(_config); + var oldSongPath = updatedSongRecord.SongPath; var newSongPath = dirMgr.GenerateSongPath(updatedSongRecord); + var filename = updatedSongRecord.Filename; - Console.WriteLine($"Old song path {updatedSongRecord.SongPath}"); + Console.WriteLine($"Old song path {oldSongPath}"); Console.WriteLine($"New song path {newSongPath}"); - System.IO.File.Copy(updatedSongRecord.SongPath, newSongPath, true); + _logger.Info("Copying song to the new path"); - if (!System.IO.File.Exists(newSongPath)) + System.IO.File.Copy(oldSongPath, newSongPath + filename, true); + + _logger.Info("Checking to see if song successfully copied"); + + if (!System.IO.File.Exists(newSongPath + filename)) { + _logger.Info("Song did not successfully copy"); + Console.WriteLine("New path does not exist when it should"); } - if (System.IO.File.Exists(updatedSongRecord.SongPath)) - { - Console.WriteLine("Old path exists when it should"); - } - updatedSongRecord.SongPath = newSongPath; + updatedSongRecord.SongPath = newSongPath + filename; - System.IO.File.Delete(updatedSongRecord.SongPath); + _logger.Info("Deleting old song path"); + + System.IO.File.Delete(oldSongPath); + + if (System.IO.File.Exists(oldSongPath)) + { + Console.WriteLine("Old path exists when it should not"); + } } + _logger.Info("Saving song metadata to the database"); + if (songStore.DoesSongExist(newSongRecord)) { songStore.UpdateSong(updatedSongRecord);