public void Process(object obj) { var album = obj as AlbumExplorer.AlbumResult; DirectoryInfo srcDir = album.Directory; if (!VirtualDrive.ExistsDirectory(srcDir.FullName)) { throw new Exception("Source directory not found: \"" + srcDir.FullName + "\""); } DirectoryNameGenerator generator = new DirectoryNameGenerator(Pattern); if (!generator.CanBuildName(album.Album.Words)) { Logger.WriteLine(Tokens.Warning, "Can not build name for directory \"" + srcDir + "\" with pattern \"" + generator.ToString() + "\""); return; } renamer.ProcessMessage(new FileOperationProcessor.Message( Path.Combine(srcDir.Parent.FullName, generator.Name(album.Album.Words)), FileOperationProcessor.FileOperation.Move)); try { renamer.Process(srcDir); } catch (IOException exception) { Logger.WriteLine(Tokens.Exception, exception + "\n" + exception.StackTrace); } }
private void RenameFile(DirectoryInfo dir, FileInfo file, FileNameGenerator p) { Tag tag = ID3.TagUtils.ReadTag(file); if (!p.CanBuildName(tag)) { Logger.WriteLine(Tokens.Warning, "Can not build name for file \"" + file.Name + "\" with pattern \"" + p.ToString() + "\""); return; } string pathString = dir.FullName + Path.DirectorySeparatorChar; string newName = p.Name(tag); string dst = pathString + newName; string src = file.FullName; int maxLength = 240; if (dst.Length >= maxLength) { newName = p.NameLimited(tag, maxLength - pathString.Length); dst = pathString + newName; } renamer.ProcessMessage(new FileOperationProcessor.Message( newName, FileOperationProcessor.FileOperation.Move)); renamer.Process(file); }