/// <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)); }
private string GetFullFilePath(string path) { // TODO: check that the path is in the mod directory (avoid accidental directory traversal) ModUtil.CheckPath(path); return(System.IO.Path.Combine(Dir.FullName, path.Substring(1))); }