Exemple #1
0
        internal BuildHashes(string buildPath, List <FileHash> fileHashes, SHA1Wrapper sha1)
        {
            fileHashes.Sort((x, y) => string.Compare(x.Hash, y.Hash, StringComparison.Ordinal));

            BuildPath   = buildPath;
            SummaryHash = CalculateSummaryCodeHash(fileHashes, sha1);
            FileHashes  = fileHashes.ToArray();
        }
Exemple #2
0
        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));
        }
Exemple #3
0
        private void GenerateHashThread(object folder)
        {
            var buildFolder = (string)folder;

            try
            {
                var sha1 = new SHA1Wrapper();
#if ENABLE_IL2CPP
                var il2cpp = true;
#else
                var il2cpp = false;
#endif
                var buildHashes = GetBuildHashes(buildFolder, CodeHashGenerator.GetFileFiltersStandaloneWindows(il2cpp), sha1);
                sha1.Clear();
                Complete(HashGeneratorResult.FromBuildHashes(buildHashes));
            }
            catch (Exception e)
            {
                Debug.LogError(ACTkConstants.LogPrefix + "Something went wrong in thread: " + e);
                Complete(HashGeneratorResult.FromError(e.ToString()));
            }
        }
Exemple #4
0
        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));
        }