Exemple #1
0
        private void WriteChangeHash(HashInfo info, Dictionary <string, FileHash> hashes, string[] files)
        {
            info.state = FileState.Changed;
            hashes.Clear();

            FileHash fileHash = null;
            var      hash     = string.Empty;
            var      md5Hash  = MD5Hash.instance;

            foreach (var file in files)
            {
                hash     = md5Hash.GetHashCode(file);
                fileHash = new FileHash(file, hash);

                hashes.Add(file, fileHash);
            }
        }
Exemple #2
0
        public void LoadHashes()
        {
            mHashes.Clear();

            var temp = string.Format("{0}/hashes.hsh", mOutPath);

            if (!File.Exists(temp))
            {
                return;
            }

            var data = File.ReadAllText(temp);

            if (string.IsNullOrEmpty(data))
            {
                Debug.LogError("Invalid data.");
                return;
            }

            var json = new JsonUnity(data);

            if (json == null)
            {
                Debug.LogError("Failed to create a json.");
                return;
            }

            temp = json.GetError();
            if (!string.IsNullOrEmpty(temp))
            {
                Debug.LogError(temp);
                return;
            }

            var key   = "Hashes";
            var array = json.GetArrayWithKey(key);

            if (array == null)
            {
                Debug.LogError("Failed to get the Hashes.");
                return;
            }

            var subKey        = string.Empty;
            var keyString     = "key";
            var subKeyString  = "subKey";
            var fileKeyString = "Files";
            var hashKeyString = "Hash";
            var hashstring    = string.Empty;

            JsonObject obj    = null;
            JsonObject subObj = null;
            JsonArray  sub    = null;
            FileHash   file   = null;
            HashInfo   hash   = null;
            Dictionary <string, FileHash> files = new Dictionary <string, FileHash>();

            for (var i = default(int); i < array.GetCount(); ++i)
            {
                files.Clear();

                obj = array.GetObjectWithIndex(i);
                key = obj.GetValueWithKey(keyString);
                sub = obj.GetArrayWithKey(fileKeyString);

                for (var j = default(int); j < sub.GetCount(); ++j)
                {
                    subObj     = sub.GetObjectWithIndex(j);
                    subKey     = subObj.GetValueWithKey(subKeyString);
                    hashstring = subObj.GetValueWithKey(hashKeyString);
                    file       = new FileHash(subKey, hashstring);

                    files.Add(subKey, file);
                    Debug.Log(subKey);
                }

                hash = new HashInfo(HashInfo.NOT_CHANGED, key, files);

                mHashes.Add(key, hash);
            }

            Debug.Log("Load hashes complete.");
        }
Exemple #3
0
        private void RecursionETCHash(string path, string parent, string src)
        {
            var files = GetAssetFiles(ref path);

            if (files == null)
            {
                Debug.LogError("Failed to get files.");
                return;
            }

            if (files.Length <= default(int))
            {
                return;
            }

            var asset   = GetAssetName(ref parent, ref src);
            var outPath = string.Format("{0}/{1}", parent, asset);

            FileHash fileHash = null;
            Dictionary <string, FileHash> hashes = null;
            HashInfo info = null;

            var hash   = string.Empty;
            var ext    = string.Empty;
            var isSame = true;

            var md5Hash = MD5Hash.instance;

            if (mHashes.ContainsKey(outPath))
            {
                info   = mHashes[outPath];
                hashes = info.files;

                if (!hashes.Count.Equals(files.Length))
                {
                    WriteChangeHash(info, hashes, files);
                }
                else
                {
                    isSame = true;
                    foreach (var file in files)
                    {
                        if (!hashes.ContainsKey(file))
                        {
                            isSame = false;
                            break;
                        }
                    }

                    if (!isSame)
                    {
                        WriteChangeHash(info, hashes, files);
                    }
                    else
                    {
                        foreach (var file in files)
                        {
                            ext = Path.GetExtension(file);
                            if (ext.Equals(".unity"))
                            {
                                continue;
                            }

                            hash = md5Hash.GetHashCode(file);

                            if (hashes[file].hash.Equals(hash))
                            {
                                continue;
                            }

                            hashes[file].hash = hash;

                            info.state = FileState.Changed;
                        }
                    }
                }
            }
            else
            {
                hashes = new Dictionary <string, FileHash>();
                foreach (var file in files)
                {
                    ext = Path.GetExtension(file);
                    if (ext.Equals(".unity"))
                    {
                        continue;
                    }

                    hash     = md5Hash.GetHashCode(file);
                    fileHash = new FileHash(file, hash);

                    hashes.Add(file, fileHash);
                }

                info = new HashInfo(HashInfo.CHANGED, outPath, hashes);

                mHashes.Add(outPath, info);
            }
        }
Exemple #4
0
        private void RecursionDataHash(ref string path, ref string parent)
        {
            var files = GetAssetFiles(ref path);

            if (files == null)
            {
                Debug.LogError("Failed to get files.");
                return;
            }

            if (files.Length <= default(int))
            {
                return;
            }

            FileHash fileHash = null;
            Dictionary <string, FileHash> hashes = null;
            HashInfo info = null;
            var      hash = string.Empty;
            var      key  = string.Empty;
            var      ext  = string.Empty;

            var md5Hash = MD5Hash.instance;

            foreach (var file in files)
            {
                ext = Path.GetExtension(file);

                if (ext.Equals(".unity"))
                {
                    continue;
                }

                key  = string.Format("{0}/{1}.asset", parent, Path.GetFileNameWithoutExtension(file));
                hash = md5Hash.GetHashCode(file);

                if (mHashes.ContainsKey(key))
                {
                    info     = mHashes[key];
                    fileHash = info.files[file];

                    if (fileHash.hash.Equals(hash))
                    {
                        info.state = FileState.NotChanged;
                    }
                    else
                    {
                        info.state    = FileState.Changed;
                        fileHash.hash = hash;
                    }
                }
                else
                {
                    fileHash = new FileHash(file, hash);
                    hashes   = new Dictionary <string, FileHash>();
                    hashes.Add(file, fileHash);

                    info = new HashInfo(HashInfo.CHANGED, file, hashes);

                    mHashes.Add(key, info);
                }
            }
        }