/// <summary> /// Deletes all files, related to album (tracks, images, text files,...) from directory. If no files left in directory, deletes it. Otherwise deletes all empty subdirectories. /// </summary> /// <param name="mDirInfo"></param> /// <returns></returns> public bool DeleteSourceMusicDirectoryFiles(IMusicDirInfo mDirInfo) { //delete audio files foreach (var trackInfo in mDirInfo.TrackList) { DeleteFile(trackInfo); } //delete separate images foreach (var imageFile in mDirInfo.ImageFiles) { DeleteFile(imageFile); } //delete images from image directories foreach (var imageDirectory in mDirInfo.ImageDirectories) { DeleteDirectory(imageDirectory.Path); } //delete text files foreach (var textFile in mDirInfo.TextFiles) { DeleteFile(textFile); } //delete unknown type files foreach (var unknownFile in mDirInfo.UnknownFiles) { DeleteFile(unknownFile); } return(DeleteSourceMusicDirectory(mDirInfo.Path)); }
//TODO: Refactor or delete /// <summary> /// Moves only music files and subdirectories, containing images or text files. /// </summary> /// <param name="sourcePath"></param> /// <param name="destPath"></param> //public void MoveMusicDirectory(string sourcePath, string destPath) //{ // var dirInfo = new DirectoryInfo(sourcePath); // var files = dirInfo.GetFiles(); // var directories = dirInfo.GetDirectories(); // //add more precise file check // if (files.Any(arg => arg.Length > MaxFileSize)) // { // return; // } // var directoriesToMove = new List<DirectoryInfo>(); // foreach (var dir in directories) // { // if (IsImageDirectory(dir)) // { // directoriesToMove.Add(dir); // } // } // CreateDirectory(destPath); // foreach (var file in files) // { // var destFilePath = Path.Combine(destPath, file.Name); // File.Move(file.FullName, destFilePath); // } // foreach (var dirToMove in directoriesToMove) // { // var destDirName = Path.Combine(destPath, dirToMove.Name); // MoveDirectory(dirToMove.FullName, destDirName); // } //} public bool CopyMusicDirectory(IMusicDirInfo mDirInfo, string albumStorageDir) { if (mDirInfo == null) { throw new ArgumentNullException(nameof(mDirInfo)); } if (string.IsNullOrEmpty(albumStorageDir)) { throw new ArgumentNullException(nameof(albumStorageDir)); } //copy audio files foreach (var trackInfo in mDirInfo.TrackList) { CopyFile(trackInfo, albumStorageDir); } //copy separate images var imgDirPath = Path.Combine(albumStorageDir, DefaultAlbumImagesDirectory); CreateDirectory(imgDirPath); foreach (var imageFile in mDirInfo.ImageFiles) { MoveFile(imageFile, imgDirPath); } //copy images from image directories foreach (var imageDirectory in mDirInfo.ImageDirectories) { var targetDirectoryFileNames = GetFileNamesFromDirectory(imgDirPath); foreach (var imageFile in imageDirectory.Children) { var fileNameWithExtension = Path.GetFileName(imageFile.Path); var targetFileName = GenerateUniqueName(targetDirectoryFileNames, fileNameWithExtension).Item1; targetDirectoryFileNames.Add(targetFileName); CopyFile(imageFile, imgDirPath, targetFileName); } } //copy text files if (mDirInfo.TextFiles.Any()) { var docDirPath = Path.Combine(albumStorageDir, DefaultAlbumDocsDirectory); CreateDirectory(docDirPath); foreach (var textFile in mDirInfo.TextFiles) { CopyFile(textFile, docDirPath); } } //copy unknown type files if (mDirInfo.UnknownFiles.Any()) { var unknownDirPath = Path.Combine(albumStorageDir, DefaultAlbumUnknownFilesDirectory); CreateDirectory(unknownDirPath); foreach (var unknownFile in mDirInfo.UnknownFiles) { CopyFile(unknownFile, unknownDirPath); } } //сигнал об успешном перемещении return(true); }
public bool CompareAlbums(IMusicDirInfo mDirInfo, DiscogsRelease dRelease) { if (mDirInfo.MusicFilesInDirectory != dRelease.tracklist.Length) { return(false); } var mDirTrackNames = new List <string>(); var dAlbumTrackNames = new List <string>(); foreach (var trackInfo in mDirInfo.TrackInfos) { mDirTrackNames.Add(trackInfo.TrackName); } foreach (var discogsTrack in dRelease.tracklist) { dAlbumTrackNames.Add(discogsTrack.title); } return(mDirTrackNames.OrderBy(t => t).SequenceEqual(dAlbumTrackNames.OrderBy(t => t))); }