public static async ValueTask <FileHandle> Mkdirp(this IFileService fs, Url url) { var pathParts = PathLib.Split(url.Path); var currentUrl = url with { Path = "/" }; var currentFileHandle = await fs.CreateFileHandle(currentUrl); foreach (var part in pathParts) { currentUrl = currentUrl with { Path = currentUrl.Path == "/" ? currentUrl.Path + part : currentUrl.Path + '/' + part }; try { currentFileHandle = await fs.CreateDirectory(currentFileHandle, part); } catch (FileExistsException) { currentFileHandle = await fs.CreateFileHandle(currentUrl); if (!(await fs.Stat(currentFileHandle)).Type.HasFlag(FileType.Directory)) { throw new FileNotADirectoryException(currentUrl); } } } return(currentFileHandle); }
public override async ValueTask <FileHandle> CreateDirectory(FileHandle parentFileHandle, string name) { var parentLocalFileHandle = new LocalFileHandle(parentFileHandle); var stats = StatRealPath(GetRealPath(parentLocalFileHandle.Path)); if (!parentLocalFileHandle.IsSameFile(stats)) { throw new FileNotFoundException(parentFileHandle); } if (!stats.Type.HasFlag(FileType.Directory)) { throw new FileNotADirectoryException(parentFileHandle); } var targetPath = PathLib.Join(parentLocalFileHandle.Path, name); var targetRealPath = GetRealPath(targetPath); var fileType = GetFileType(targetRealPath); if (fileType != null) { throw new FileExistsException($"The file '{targetPath}' existed."); } Directory.CreateDirectory(targetRealPath); var targetStat = StatRealPath(targetRealPath); var targetFileHandle = new LocalFileHandle(targetPath, targetStat).FileHandle; await IndexFile(targetPath, targetFileHandle, targetStat); return(targetFileHandle); }
private async ValueTask <long> CreateDirectory(IDbTransaction transaction, string path, FileChangeEventBuilder eventBuilder) { var pathPart = PathLib.Split(path); long?directoryId = null; int i; for (i = pathPart.Length; i >= 0; i--) { var currentPath = "/" + string.Join('/', pathPart.Take(i).ToArray()); var directory = await _databaseTable.SelectByPathAsync(transaction, currentPath); if (directory == null) { continue; } if (directory.IsDirectory) { directoryId = directory.Id; break; } await Delete(transaction, directory, eventBuilder); } for (i++; i <= pathPart.Length; i++) { var currentPath = "/" + string.Join('/', pathPart.Take(i).ToArray()); directoryId = await _databaseTable.InsertAsync(transaction, currentPath, directoryId, true, null, null); } return(directoryId !.Value); }
public void JoinTest() { var joinTests = new Dictionary <string[], string> { { new[] { ".", "x/b", "..", "/b/c.js" }, "x/b/c.js" }, { Array.Empty <string>(), "." }, { new[] { "/.", "x/b", "..", "/b/c.js" }, "/x/b/c.js" }, { new[] { "/foo", "../../../bar" }, "/bar" }, { new[] { "foo", "../../../bar" }, "../../bar" }, { new[] { "foo/", "../../../bar" }, "../../bar" }, { new[] { "foo/x", "../../../bar" }, "../bar" }, { new[] { "foo/x", "./bar" }, "foo/x/bar" }, { new[] { "foo/x/", "./bar" }, "foo/x/bar" }, { new[] { "foo/x/", ".", "bar" }, "foo/x/bar" }, { new[] { "./" }, "./" }, { new[] { ".", "./" }, "./" }, { new[] { ".", ".", "." }, "." }, { new[] { ".", "./", "." }, "." }, { new[] { ".", "/./", "." }, "." }, { new[] { ".", "/////./", "." }, "." }, { new[] { "." }, "." }, { new[] { "", "." }, "." }, { new[] { "", "foo" }, "foo" }, { new[] { "foo", "/bar" }, "foo/bar" }, { new[] { "", "/foo" }, "/foo" }, { new[] { "", "", "/foo" }, "/foo" }, { new[] { "", "", "foo" }, "foo" }, { new[] { "foo", "" }, "foo" }, { new[] { "foo/", "" }, "foo/" }, { new[] { "foo", "", "/bar" }, "foo/bar" }, { new[] { "./", "..", "/foo" }, "../foo" }, { new[] { "./", "..", "..", "/foo" }, "../../foo" }, { new[] { ".", "..", "..", "/foo" }, "../../foo" }, { new[] { "", "..", "..", "/foo" }, "../../foo" }, { new[] { "/" }, "/" }, { new[] { "/", "." }, "/" }, { new[] { "/", ".." }, "/" }, { new[] { "/", "..", ".." }, "/" }, { new[] { "" }, "." }, { new[] { "", "" }, "." }, { new[] { " /foo" }, " /foo" }, { new[] { " ", "foo" }, " /foo" }, { new[] { " ", "." }, " " }, { new[] { " ", "/" }, " /" }, { new[] { " ", "" }, " " }, { new[] { "/", "foo" }, "/foo" }, { new[] { "/", "/foo" }, "/foo" }, { new[] { "/", "//foo" }, "/foo" }, { new[] { "/", "", "/foo" }, "/foo" }, { new[] { "", "/", "foo" }, "/foo" }, { new[] { "", "/", "/foo" }, "/foo" } }; foreach (var(test, expected) in joinTests) { Assert.AreEqual(expected, PathLib.Join(test)); } }
public void SetOutputFilename(string outFileName) { outputFileName = PathLib.ReplaceExtension(outFileName, ".m4b"); outDir = Path.GetDirectoryName(outputFileName); if (File.Exists(outputFileName)) { File.Delete(outputFileName); } }
public void DirnameTest() { Assert.AreEqual("/a", PathLib.Dirname("/a/b/")); Assert.AreEqual("/a", PathLib.Dirname("/a/b")); Assert.AreEqual("/", PathLib.Dirname("/a")); Assert.AreEqual(".", PathLib.Dirname("")); Assert.AreEqual("/", PathLib.Dirname("/")); Assert.AreEqual("/", PathLib.Dirname("////")); Assert.AreEqual("//", PathLib.Dirname("//a")); Assert.AreEqual(".", PathLib.Dirname("foo")); }
public void ResolveTest() { Assert.AreEqual("/var/file", PathLib.Resolve("/var/lib", "../", "file/")); Assert.AreEqual("/var/file", PathLib.Resolve("/var/lib", "../", "", "file/")); Assert.AreEqual("/file", PathLib.Resolve("/var/lib", "/../", "file/")); Assert.AreEqual("/", PathLib.Resolve("a/b/c/", "../../..")); Assert.AreEqual("/", PathLib.Resolve(".")); Assert.AreEqual("/absolute", PathLib.Resolve("/some/dir", ".", "/absolute/")); Assert.AreEqual("/foo/tmp.3/cycles/root.js", PathLib.Resolve("/foo/tmp.3/", "../tmp.3/cycles/root.js")); Assert.AreEqual("/foo", PathLib.Resolve("../foo")); }
public static void WriteXmlToDirectory(object obj) { var formatter = new XmlSerializer(obj.GetType()); var fileName = obj.ToString() + ".xml"; using (var fStream = new FileStream(PathLib.MyDocuments(fileName), FileMode.OpenOrCreate)) { formatter.Serialize(fStream, obj); Console.WriteLine("Success..."); } }
public bool Step4_CreateNfo() { // not a critical step. its failure should not prevent future steps from running try { File.WriteAllText(PathLib.ReplaceExtension(OutputFileName, ".nfo"), NFO.CreateContents(AppName, aaxFile, downloadLicense.ChapterInfo)); } catch (Exception ex) { Serilog.Log.Logger.Error(ex, $"{nameof(Step4_CreateNfo)}. FAILED"); } return(!isCanceled); }
public static void Main(string[] args) { var jsonRequestPath = PathLib.GetJsonFilePath("pay_check_request"); var jsonRequest = File.ReadAllText(jsonRequestPath); Console.WriteLine(jsonRequest.Length); HttpSender.SendRestSharp(jsonRequest); //var cli = new WebClient {Headers = {[HttpRequestHeader.ContentType] = "application/json"}}; //var response = cli.UploadString(HttpSettings.Address, jsonRequest); //Console.ReadKey(); }
private async Task prelimProcessing() { tags = new Tags(inputFileName); encodingInfo = new EncodingInfo(inputFileName); chapters = new Chapters(inputFileName, tags.duration.TotalSeconds); var defaultFilename = Path.Combine( Path.GetDirectoryName(inputFileName), PathLib.ToPathSafeString(tags.author), PathLib.ToPathSafeString(tags.title) + ".m4b" ); // set default name SetOutputFilename(defaultFilename); await Task.Run(() => saveCover(inputFileName)); }
public override async ValueTask Delete(FileHandle fileHandle, FileHandle parentFileHandle, string name, bool recursive) { var localFileHandle = new LocalFileHandle(fileHandle); var parentLocalFileHandle = new LocalFileHandle(parentFileHandle); // check if (localFileHandle.Path != PathLib.Join(parentLocalFileHandle.Path, name)) { throw new FileNotFoundException("File handles are inconsistent."); } var stats = StatRealPath(GetRealPath(localFileHandle.Path)); var parentStats = StatRealPath(GetRealPath(parentLocalFileHandle.Path)); if (!localFileHandle.IsSameFile(stats)) { throw new FileNotFoundException(fileHandle); } if (!parentLocalFileHandle.IsSameFile(parentStats)) { throw new FileNotFoundException(parentFileHandle); } var realPath = GetRealPath(localFileHandle.Path); if (stats.Type.HasFlag(FileType.Directory)) { if (recursive) { Directory.Delete(realPath, true); } else { throw new FileIsADirectoryException(fileHandle); } } else { File.Delete(realPath); } await IndexDeletedFile(localFileHandle.Path, fileHandle); }
public static void WriteXmlToDirectoryWithEncoding(object obj, Encoding encoding) { var formatter = new XmlSerializer(obj.GetType()); var fileName = obj.ToString() + ".Encoding.xml"; using (var fStream = new FileStream(PathLib.MyDocuments(fileName), FileMode.OpenOrCreate)) { using (var xmlWriter = XmlWriter.Create(fStream, new XmlWriterSettings() { Encoding = encoding })) { formatter.Serialize(xmlWriter, obj); } Console.WriteLine("Success..."); } }
public override async ValueTask <IEnumerable <Dirent> > ReadDirectory(FileHandle fileHandle) { var localFileHandle = new LocalFileHandle(fileHandle); var realPath = GetRealPath(localFileHandle.Path); var directoryInfo = new DirectoryInfo(realPath); if (!directoryInfo.Exists) { var fileType = GetFileType(realPath); if (fileType != null && !fileType.Value.HasFlag(FileType.Directory)) { throw new FileNotADirectoryException(fileHandle); } throw new FileNotFoundException(fileHandle); } var stats = GetFileStatFromFileSystemInfo(directoryInfo); if (!localFileHandle.IsSameFile(stats)) { throw new FileNotFoundException(fileHandle); } var result = directoryInfo.EnumerateFileSystemInfos().Select(info => { var entryLocalFileHandle = new LocalFileHandle( PathLib.Join(localFileHandle.Path, info.Name), GetFileStatFromFileSystemInfo(info)); return(new Dirent( info.Name, entryLocalFileHandle.FileHandle, GetFileStatFromFileSystemInfo(info))); }).ToImmutableArray(); await IndexDirectory(localFileHandle.Path, fileHandle, result); return(result); }
public void NormalizeTest() { Assert.AreEqual("fixtures/b/c.js", PathLib.Normalize("./fixtures///b/../b/c.js")); Assert.AreEqual("/bar", PathLib.Normalize("/foo/../../../bar")); Assert.AreEqual("a/b", PathLib.Normalize("a//b//../b")); Assert.AreEqual("a/b/c", PathLib.Normalize("a//b//./c")); Assert.AreEqual("a/b", PathLib.Normalize("a//b//.")); Assert.AreEqual("/x/y/z", PathLib.Normalize("/a/b/c/../../../x/y/z")); Assert.AreEqual("/foo/bar", PathLib.Normalize("///..//./foo/.//bar")); Assert.AreEqual("bar/", PathLib.Normalize("bar/foo../../")); Assert.AreEqual("bar", PathLib.Normalize("bar/foo../..")); Assert.AreEqual("bar/baz", PathLib.Normalize("bar/foo../../baz")); Assert.AreEqual("bar/foo../", PathLib.Normalize("bar/foo../")); Assert.AreEqual("bar/foo..", PathLib.Normalize("bar/foo..")); Assert.AreEqual("../../bar", PathLib.Normalize("../foo../../../bar")); Assert.AreEqual("../../bar", PathLib.Normalize("../.../.././.../../../bar")); Assert.AreEqual("../../../../../bar", PathLib.Normalize("../../../foo/../../../bar")); Assert.AreEqual("../../../../../../", PathLib.Normalize("../../../foo/../../../bar/../../")); Assert.AreEqual("../../", PathLib.Normalize("../foobar/barfoo/foo/../../../bar/../../")); Assert.AreEqual("../../../../baz", PathLib.Normalize("../.../../foobar/../../../bar/../../baz")); Assert.AreEqual("foo/bar\\baz", PathLib.Normalize("foo/bar\\baz")); }
public void BasenameTest() { Assert.AreEqual("test-path-basename.js", PathLib.Basename("/fixtures/test/test-path-basename.js")); Assert.AreEqual(".js", PathLib.Basename(".js")); Assert.AreEqual("", PathLib.Basename("")); Assert.AreEqual("basename.ext", PathLib.Basename("/dir/basename.ext")); Assert.AreEqual("basename.ext", PathLib.Basename("/basename.ext")); Assert.AreEqual("basename.ext", PathLib.Basename("basename.ext")); Assert.AreEqual("basename.ext", PathLib.Basename("basename.ext/")); Assert.AreEqual("basename.ext", PathLib.Basename("basename.ext//")); Assert.AreEqual("bbb", PathLib.Basename("/aaa/bbb")); Assert.AreEqual("aaa", PathLib.Basename("/aaa/")); Assert.AreEqual("b", PathLib.Basename("/aaa/b")); Assert.AreEqual("b", PathLib.Basename("/a/b")); Assert.AreEqual("a", PathLib.Basename("//a")); Assert.AreEqual("\\dir\\basename.ext", PathLib.Basename("\\dir\\basename.ext")); Assert.AreEqual("\\basename.ext", PathLib.Basename("\\basename.ext")); Assert.AreEqual("basename.ext", PathLib.Basename("basename.ext")); Assert.AreEqual("basename.ext\\", PathLib.Basename("basename.ext\\")); Assert.AreEqual("basename.ext\\\\", PathLib.Basename("basename.ext\\\\")); Assert.AreEqual("foo", PathLib.Basename("foo")); }
public override async ValueTask <FileHandle> CreateFile(FileHandle parentFileHandle, string name, ReadOnlyMemory <byte> content) { var parentLocalFileHandle = new LocalFileHandle(parentFileHandle); var parentFilePath = parentLocalFileHandle.Path; var filePath = PathLib.Join(parentFilePath, name); var parentStats = StatRealPath(GetRealPath(parentFilePath)); if (!parentLocalFileHandle.IsSameFile(parentStats)) { throw new FileNotFoundException(parentFileHandle); } if (!parentStats.Type.HasFlag(FileType.Directory)) { throw new FileNotADirectoryException(parentFileHandle); } var realPath = GetRealPath(filePath); if (GetFileType(realPath) != null) { throw new FileExistsException($"The file '{filePath}' existed."); } await using var fileStream = File.OpenWrite(realPath); await fileStream.WriteAsync(content); await fileStream.FlushAsync(); var newStats = StatRealPath(realPath); var newFileHandle = new LocalFileHandle(filePath, newStats).FileHandle; await IndexFile(parentFilePath, newFileHandle, newStats); return(newFileHandle); }
public void ExtnameTest() { var extnameTests = new[] { new[] { "", "" }, new[] { "/path/to/file", "" }, new[] { "/path/to/file.ext", ".ext" }, new[] { "/path.to/file.ext", ".ext" }, new[] { "/path.to/file", "" }, new[] { "/path.to/.file", "" }, new[] { "/path.to/.file.ext", ".ext" }, new[] { "/path/to/f.ext", ".ext" }, new[] { "/path/to/..ext", ".ext" }, new[] { "/path/to/..", "" }, new[] { "file", "" }, new[] { "file.ext", ".ext" }, new[] { ".file", "" }, new[] { ".file.ext", ".ext" }, new[] { "/file", "" }, new[] { "/file.ext", ".ext" }, new[] { "/.file", "" }, new[] { "/.file.ext", ".ext" }, new[] { ".path/file.ext", ".ext" }, new[] { "file.ext.ext", ".ext" }, new[] { "file.", "." }, new[] { ".", "" }, new[] { "./", "" }, new[] { ".file.ext", ".ext" }, new[] { ".file", "" }, new[] { ".file.", "." }, new[] { ".file..", "." }, new[] { "..", "" }, new[] { "../", "" }, new[] { "..file.ext", ".ext" }, new[] { "..file", ".file" }, new[] { "..file.", "." }, new[] { "..file..", "." }, new[] { "...", "." }, new[] { "...ext", ".ext" }, new[] { "....", "." }, new[] { "file.ext/", ".ext" }, new[] { "file.ext//", ".ext" }, new[] { "file/", "" }, new[] { "file//", "" }, new[] { "file./", "." }, new[] { "file.//", "." }, new[] { ".\\", "" }, new[] { "..\\", ".\\" }, new[] { "file.ext\\", ".ext\\" }, new[] { "file.ext\\\\", ".ext\\\\" }, new[] { "file\\", "" }, new[] { "file.\\", ".\\" }, new[] { "file.\\\\", ".\\\\" } }; foreach (var test in extnameTests) { Assert.AreEqual(test[1], PathLib.Extname(test[0])); } }
public override async ValueTask <FileHandle> Rename( FileHandle fileHandle, FileHandle oldParentFileHandle, string oldName, FileHandle newParentFileHandle, string newName) { var localFileHandle = new LocalFileHandle(fileHandle); var oldParentLocalFileHandle = new LocalFileHandle(oldParentFileHandle); var newParentLocalFileHandle = new LocalFileHandle(newParentFileHandle); // check if (localFileHandle.Path != PathLib.Join(oldParentLocalFileHandle.Path, oldName)) { throw new FileNotFoundException("File handles are inconsistent."); } var oldRealPath = GetRealPath(localFileHandle.Path); var oldFileStats = StatRealPath(oldRealPath); var oldParentStats = StatRealPath(GetRealPath(oldParentLocalFileHandle.Path)); var newParentStats = StatRealPath(GetRealPath(newParentLocalFileHandle.Path)); if (!localFileHandle.IsSameFile(oldFileStats)) { throw new FileNotFoundException(fileHandle); } if (!oldParentLocalFileHandle.IsSameFile(oldParentStats)) { throw new FileNotFoundException(oldParentFileHandle); } if (!newParentLocalFileHandle.IsSameFile(newParentStats)) { throw new FileNotFoundException(newParentFileHandle); } if (!newParentStats.Type.HasFlag(FileType.Directory)) { throw new FileNotADirectoryException(newParentFileHandle); } var newPath = PathLib.Join(newParentLocalFileHandle.Path, newName); var newRealPath = GetRealPath(newPath); if (GetFileType(newRealPath) != null) { throw new FileExistsException($"The file '{newPath}' existed."); } if (oldFileStats.Type.HasFlag(FileType.Directory)) { Directory.Move(oldRealPath, newRealPath); } else { File.Move(oldRealPath, newRealPath, false); } var newFileStats = StatRealPath(newRealPath); await IndexDeletedFile(localFileHandle.Path, fileHandle); var newFileHandle = new LocalFileHandle(newPath, newFileStats).FileHandle; await IndexFile(newPath, new LocalFileHandle(newPath, newFileStats).FileHandle, newFileStats); return(newFileHandle); }
private async ValueTask <long> IndexFile( IDbTransaction transaction, string path, FileHandle fileHandle, FileStats fileStats, FileChangeEventBuilder eventBuilder) { if (path == "/") { return(0); } var fileType = fileStats.Type; var isDirectory = fileStats.Type.HasFlag(FileType.Directory); var oldFile = await _databaseTable.SelectByPathAsync(transaction, path); if (oldFile == null) { long?parentId = await CreateDirectory(transaction, PathLib.Dirname(path), eventBuilder); var newId = await _databaseTable.InsertAsync( transaction, path, parentId, fileType.HasFlag(FileType.Directory), fileHandle.Identifier, fileStats.Hash.ContentTag); eventBuilder.Created(fileHandle); return(newId); } if (oldFile.IsDirectory != isDirectory) { await Delete(transaction, oldFile, eventBuilder); var parentId = await CreateDirectory(transaction, PathLib.Dirname(path), eventBuilder); var newId = await _databaseTable.InsertAsync( transaction, path, parentId, fileType.HasFlag(FileType.Directory), fileHandle.Identifier, fileStats.Hash.ContentTag); eventBuilder.Created(fileHandle); return(newId); } if (oldFile.IdentifierTag == null) { await _databaseTable.UpdateIdentifierTagByIdAsync( transaction, oldFile.Id, fileHandle.Identifier, fileStats.Hash.ContentTag); eventBuilder.Created(fileHandle); return(oldFile.Id); } if (oldFile.IdentifierTag != fileHandle.Identifier) { await Delete(transaction, oldFile, eventBuilder); var parentId = await CreateDirectory(transaction, PathLib.Dirname(path), eventBuilder); var newId = await _databaseTable.InsertAsync( transaction, path, parentId, fileType.HasFlag(FileType.Directory), fileHandle.Identifier, fileStats.Hash.ContentTag); eventBuilder.Created(fileHandle); return(newId); } if (oldFile.ContentTag != fileStats.Hash.ContentTag) { await _databaseTable.UpdateStatsByIdAsync( transaction, oldFile.Id, fileStats.Hash.ContentTag); await _databaseTable.DeletePropertyOnFileUpdated(transaction, oldFile.Id); eventBuilder.Changed(fileHandle); return(oldFile.Id); } return(oldFile.Id); }
/// <summary> /// Create indexes of the contents in the directory. /// </summary> /// <param name="path">The path of the directory.</param> /// <param name="contents">The contents in the directory.</param> private async ValueTask IndexDirectory( IDbTransaction transaction, string path, IEnumerable <Dirent> contents, FileChangeEventBuilder eventBuilder) { var directoryId = await CreateDirectory(transaction, path, eventBuilder); var oldContents = (await _databaseTable.SelectByParentAsync(transaction, directoryId)).ToDictionary(content => content.Path); var newContents = contents.Select( content => new { Path = PathLib.Join(path, content.Name), Parent = directoryId, IsDirectory = content.Stats.Type.HasFlag(FileType.Directory), IdentifierTag = content.FileHandle.Identifier, content.FileHandle, FileStats = content.Stats }) .ToDictionary(content => content.Path); var addedContents = newContents.Keys.Except(oldContents.Keys).Select(key => newContents[key]).ToList(); var removedContents = oldContents.Keys.Except(newContents.Keys).Select(key => oldContents[key]).ToList(); var reservedContents = oldContents.Keys.Intersect(newContents.Keys).Select( key => new { oldContents[key].Path, oldFile = oldContents[key], newFile = newContents[key] }); var updatedTagContents = new List <(long Id, string Path, FileHandle FileHandle, FileStats FileStats, bool IsNew)>(); foreach (var reservedContent in reservedContents) { var oldFile = reservedContent.oldFile; var newFile = reservedContent.newFile; if (oldFile.IsDirectory != newFile.IsDirectory) { removedContents.Add(oldFile); addedContents.Add(newFile); } else if (oldFile.IdentifierTag == null) { updatedTagContents.Add( (oldFile.Id, newFile.Path, newFile.FileHandle, newFile.FileStats, true)); } else if (oldFile.IdentifierTag != newFile.IdentifierTag) { removedContents.Add(oldFile); addedContents.Add(newFile); } else if (oldFile.ContentTag != newFile.FileStats.Hash.ContentTag) { updatedTagContents.Add((oldFile.Id, newFile.Path, newFile.FileHandle, newFile.FileStats, false)); } } foreach (var removed in removedContents) { await Delete(transaction, removed, eventBuilder); } foreach (var added in addedContents) { await _databaseTable.InsertAsync( transaction, added.Path, directoryId, added.IsDirectory, added.FileHandle.Identifier, added.FileStats.Hash.ContentTag); eventBuilder.Created(added.FileHandle); } foreach (var updatedTagContent in updatedTagContents) { if (updatedTagContent.IsNew) { await _databaseTable.UpdateIdentifierTagByIdAsync( transaction, updatedTagContent.Id, updatedTagContent.FileHandle.Identifier, updatedTagContent.FileStats.Hash.ContentTag); eventBuilder.Created(updatedTagContent.FileHandle); } else { await _databaseTable.UpdateStatsByIdAsync( transaction, updatedTagContent.Id, updatedTagContent.FileStats.Hash.ContentTag); await _databaseTable.DeletePropertyOnFileUpdated(transaction, updatedTagContent.Id); eventBuilder.Changed(updatedTagContent.FileHandle); } } }
private string GetRealPath(string path) { return(Path.Join(_rootPath, PathLib.Resolve(path))); }
private string GetPath(string realpath) { return(PathLib.Resolve(Path.GetRelativePath(realpath, _rootPath))); }
private async Task HandleScanner(FileSystemDirectoryWalker.WalkerItem item) { await IndexDirectory(PathLib.Resolve("/", item.Path), item.FileHandle, item.Entries); }
private async Task <string> aaxToM4bConverterDecryptAsync(string cacheDir, string destinationDir, LibraryBook libraryBook) { DecryptBegin?.Invoke(this, $"Begin decrypting {libraryBook}"); try { validate(libraryBook); var api = await InternalUtilities.AudibleApiActions.GetApiAsync(libraryBook.Account, libraryBook.Book.Locale); var contentLic = await api.GetDownloadLicenseAsync(libraryBook.Book.AudibleProductId); var aaxcDecryptDlLic = new DownloadLicense ( contentLic.ContentMetadata?.ContentUrl?.OfflineUrl, contentLic.Voucher?.Key, contentLic.Voucher?.Iv, Resources.UserAgent ); if (Configuration.Instance.AllowLibationFixup) { aaxcDecryptDlLic.ChapterInfo = new AAXClean.ChapterInfo(); foreach (var chap in contentLic.ContentMetadata?.ChapterInfo?.Chapters) { aaxcDecryptDlLic.ChapterInfo.AddChapter(chap.Title, TimeSpan.FromMilliseconds(chap.LengthMs)); } } var format = Configuration.Instance.DecryptToLossy ? OutputFormat.Mp3 : OutputFormat.Mp4a; var extension = format switch { OutputFormat.Mp4a => "m4b", OutputFormat.Mp3 => "mp3", _ => throw new NotImplementedException(), }; var proposedOutputFile = Path.Combine(destinationDir, $"{PathLib.ToPathSafeString(libraryBook.Book.Title)} [{libraryBook.Book.AudibleProductId}].{extension}"); aaxcDownloader = new AaxcDownloadConverter(proposedOutputFile, cacheDir, aaxcDecryptDlLic, format) { AppName = "Libation" }; aaxcDownloader.DecryptProgressUpdate += (s, progress) => UpdateProgress?.Invoke(this, progress); aaxcDownloader.DecryptTimeRemaining += (s, remaining) => UpdateRemainingTime?.Invoke(this, remaining); aaxcDownloader.RetrievedCoverArt += AaxcDownloader_RetrievedCoverArt; aaxcDownloader.RetrievedTags += aaxcDownloader_RetrievedTags; // REAL WORK DONE HERE var success = await Task.Run(() => aaxcDownloader.Run()); // decrypt failed if (!success) { return(null); } return(aaxcDownloader.OutputFileName); } finally { DecryptCompleted?.Invoke(this, $"Completed downloading and decrypting {libraryBook.Book.Title}"); } }
public override ValueTask <string> GetFileName(FileHandle fileHandle) { return(ValueTask.FromResult(PathLib.Basename(new LocalFileHandle(fileHandle).Path))); }
private string outputFileWithNewExt(string extension) => PathLib.ReplaceExtension(outputFileName, extension);
private static async IAsyncEnumerable <FileSystemWalkerEntry> EnumerateAllFiles( ISingletonFileSystem singletonFileSystem, FileHandle rootFileHandle) { var directoryWalker = new FileSystemDirectoryWalker(singletonFileSystem, rootFileHandle); await foreach (var directory in directoryWalker) { foreach (var entries in directory.Entries) { yield return(new FileSystemWalkerEntry(entries.FileHandle, entries.Stats, PathLib.Join(directory.Path, entries.Name))); } } }