/// <summary> /// Get hash of a local file. Exception if it doesn't exist. /// </summary> /// <param name="path">Relative path. Using forward slashes, starting with a forward slash, and in lower case.</param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <FileHash> GetFileHash(string path, CancellationToken cancellationToken) { ModUtil.CheckPath(path); var extension = Utils.GetExtension(path).ToLowerInvariant(); var file = await OpenRead(path, cancellationToken); if (file == null) { throw new FileNotFoundException(path); } return(await Sha1AndPboHash.BuildAsync(file, extension, cancellationToken)); }
// TODO: use more specialized interface to get files public static async Task <VersionHash> CreateAsync(IStorageMod mod, CancellationToken cancellationToken) { var hashes = new Dictionary <string, FileHash>(); foreach (var file in await mod.GetFileList(cancellationToken)) { var stream = await mod.OpenRead(file, cancellationToken); if (stream == null) { throw new InvalidOperationException(); } var hash = await Sha1AndPboHash.BuildAsync(stream, Utils.GetExtension(file), cancellationToken); hashes.Add(file, hash); } return(new VersionHash(BuildHash(hashes))); }