private string CalculateSummaryCodeHash(List <FileHash> fileHashes, SHA1Wrapper sha1) { var hashesString = string.Empty; foreach (var fileHash in fileHashes) { hashesString += fileHash.Hash; } var hashesBytes = StringUtils.StringToBytes(hashesString); var codeHashBytes = sha1.ComputeHash(hashesBytes); return(StringUtils.HashBytesToHexString(codeHashBytes)); }
public static BuildHashes GetBuildHashes(string buildPath, FileFilter[] fileFilters, SHA1Wrapper sha1) { var files = Directory.GetFiles(buildPath, "*", SearchOption.AllDirectories); var count = files.Length; if (count == 0) { return(null); } var fileHashes = new List <FileHash>(); for (var i = 0; i < count; i++) { var filePath = files[i]; // skip folders since we can't hash them if (Directory.Exists(filePath)) { continue; } foreach (var fileFilter in fileFilters) { if (fileFilter.MatchesPath(filePath, buildPath)) { #if UNITY_EDITOR UnityEditor.EditorUtility.DisplayProgressBar("ACTk: Generating code hash", "Hashing files...", (i + 1f) / count); #endif using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read)) using (var bs = new BufferedStream(fs)) { var hash = sha1.ComputeHash(bs); var hashString = StringUtils.HashBytesToHexString(hash); //Debug.Log("Path: " + filePath + "\nHash: " + hashString); fileHashes.Add(new FileHash(filePath, hashString)); } } } } if (fileHashes.Count == 0) { return(null); } return(new BuildHashes(buildPath, fileHashes, sha1)); }