public override async Task <(bool Changed, SongData song)> Execute(SongData song) { if (CaseConversion.CaseConvert(ref song)) { return(true, song); } return(false, song); }
/// <summary> /// Does the actual save of the Song /// </summary> /// <param name = "song"></param> /// <returns></returns> private bool SaveTrack(ref SongData song) { log.Trace(">>>"); try { if (song.Changed) { Util.StatusCurrentFile($"Saving file {song.FullFileName}"); log.Debug($"Save: Saving song: {song.FullFileName}"); // The track to be saved, may be currently playing. If this is the case stop playback to free the file //if (track.FullFileName == TracksGrid.MainForm.Player.CurrentSongPlaying) //{ // Log.Debug("Save: Song is played in Player. Stop playback to free the file"); // TracksGrid.MainForm.Player.Stop(); //} if (options.MainSettings.CopyArtist && song.AlbumArtist == "") { song.AlbumArtist = song.Artist; } if (options.MainSettings.UseCaseConversion) { CaseConversion.CaseConvert(ref song); } var originalFileName = song.FullFileName; // Need the original filename for database update, in case a rename happens // Save the file var errorMessage = ""; if (Song.SaveFile(song, ref errorMessage)) { if (RenameFile(song, out var newFileName)) { // Read the Song with the new Information song = Song.Create(newFileName); } // Check, if we need to create a folder.jpg var fileName = Path.Combine(Path.GetDirectoryName(song.FullFileName), "folder.jpg"); if (!File.Exists(fileName) && options.MainSettings.CreateFolderThumb) { if (song.Pictures.Count > 0) { int indexFrontCover = song.Pictures .Select((pic, i) => new { Pic = pic, Position = i }).First(m => m.Pic.Type == PictureType.FrontCover) .Position; if (indexFrontCover < 0) { indexFrontCover = 0; } Util.SavePicture(song.Pictures[indexFrontCover], fileName); var miscfileevt = new GenericEvent { Action = "miscfileschanged" }; EventSystem.Publish(miscfileevt); } } // TODO: Update the Music Database //ServiceScope.Get<IMusicDatabase>().UpdateTrack(track, originalFileName); song.Status = 0; song.Changed = false; } else { song.Status = 2; song.StatusMsg = errorMessage; } } } catch (Exception ex) { song.Status = 2; song.StatusMsg = ex.Message; log.Error($"Save: Error Saving data for song {song.FileName}: {ex.Message} {ex.StackTrace}"); return(false); } log.Trace("<<<"); return(true); }