private RenamingEventArgs FireRenamingEvent(Id3Tag tag, string oldName, string newName) { EventHandler <RenamingEventArgs> renaming = Renaming; var args = new RenamingEventArgs(tag, oldName) { NewName = newName }; renaming?.Invoke(this, args); return(args); }
private RenameSuggestion GetRenameSuggestion(string filePath) { if (string.IsNullOrWhiteSpace(filePath)) { return(new RenameSuggestion(filePath, filePath, FileNamerMessages.InvalidFilePath)); } if (!File.Exists(filePath)) { return(new RenameSuggestion(filePath, filePath, FileNamerMessages.MissingFile)); } string directory = Path.GetDirectoryName(filePath); string originalName = Path.GetFileName(filePath); using (var mp3 = new Mp3(filePath)) { Id3Tag tag = mp3.GetTag(Id3Version.V23); if (tag == null) { return(new RenameSuggestion(directory, originalName, FileNamerMessages.MissingId3v23TagInFile)); } //TODO: Get ID3v1 tag as well and merge with the v2 tag string newName = GetNewName(tag, originalName, out string missingFrameName); if (missingFrameName != null) { return(new RenameSuggestion(directory, originalName, string.Format(FileNamerMessages.MissingDataForFrame, missingFrameName))); } newName += ".mp3"; RenamingEventArgs renamingEventResult = FireRenamingEvent(tag, originalName, newName); if (renamingEventResult.Cancel) { return(new RenameSuggestion(directory, originalName, RenameStatus.Cancelled)); } newName = renamingEventResult.NewName; RenameStatus status = originalName.Equals(newName, StringComparison.Ordinal) ? RenameStatus.CorrectlyNamed : RenameStatus.Rename; return(new RenameSuggestion(directory, originalName, newName, status)); } }