private static string moveFilesToBooksDir(Book product, string outputAudioFilename) { // create final directory. move each file into it. MOVE AUDIO FILE LAST // new dir: safetitle_limit50char + " [" + productId + "]" var destinationDir = AudibleFileStorage.Audio.GetDestDir(product.Title, product.AudibleProductId); Directory.CreateDirectory(destinationDir); var sortedFiles = getProductFilesSorted(product, outputAudioFilename); var musicFileExt = Path.GetExtension(outputAudioFilename).Trim('.'); // audio filename: safetitle_limit50char + " [" + productId + "]." + audio_ext var audioFileName = FileUtility.GetValidFilename(destinationDir, product.Title, musicFileExt, product.AudibleProductId); foreach (var f in sortedFiles) { var dest = AudibleFileStorage.Audio.IsFileTypeMatch(f) ? audioFileName // non-audio filename: safetitle_limit50char + " [" + productId + "][" + audio_ext +"]." + non_audio_ext : FileUtility.GetValidFilename(destinationDir, product.Title, f.Extension, product.AudibleProductId, musicFileExt); if (Path.GetExtension(dest).Trim('.').ToLower() == "cue") { Cue.UpdateFileName(f, audioFileName); } File.Move(f.FullName, dest); } return(destinationDir); }
/// <summary>Move new files to 'Books' directory</summary> /// <returns>True if audiobook file(s) were successfully created and can be located on disk. Else false.</returns> private static bool moveFilesToBooksDir(LibraryBook libraryBook, List <FilePathCache.CacheEntry> entries) { // create final directory. move each file into it var destinationDir = AudibleFileStorage.Audio.GetDestinationDirectory(libraryBook); Directory.CreateDirectory(destinationDir); FilePathCache.CacheEntry getFirstAudio() => entries.FirstOrDefault(f => f.FileType == FileType.Audio); if (getFirstAudio() == default) { return(false); } for (var i = 0; i < entries.Count; i++) { var entry = entries[i]; var realDest = FileUtility.SaferMoveToValidPath(entry.Path, Path.Combine(destinationDir, Path.GetFileName(entry.Path))); FilePathCache.Insert(libraryBook.Book.AudibleProductId, realDest); // propogate corrected path. Must update cache with corrected path. Also want updated path for cue file (after this for-loop) entries[i] = entry with { Path = realDest }; } var cue = entries.FirstOrDefault(f => f.FileType == FileType.Cue); if (cue != default) { Cue.UpdateFileName(cue.Path, getFirstAudio().Path); } AudibleFileStorage.Audio.Refresh(); return(true); } }