Ejemplo n.º 1
0
    private void CompareFileListHashThread(object args)
    {
        AssetDownloader.CompareFileListHashArg compareFileListHashArg = args as AssetDownloader.CompareFileListHashArg;
        if (compareFileListHashArg == null || string.IsNullOrEmpty(compareFileListHashArg.cacheDir) || compareFileListHashArg.nodes == null)
        {
            return;
        }
        string    cacheDir  = compareFileListHashArg.cacheDir;
        AssetList assetList = AssetManager.AssetList;

        if (compareFileListHashArg.dic.Count == 0)
        {
            AssetDownloader.mExistFile.Clear();
            for (int index = 0; index < compareFileListHashArg.nodes.Count; ++index)
            {
                this.mCompareHashMutex.WaitOne();
                this.mCompareHashProgressShared = (float)index / (float)compareFileListHashArg.nodes.Count;
                this.mCompareHashMutex.ReleaseMutex();
                AssetDownloader.CompareFileListHashArg.Node node = compareFileListHashArg.nodes[index];
                if (node != null && !string.IsNullOrEmpty(node.IDStr) && !string.IsNullOrEmpty(node.metaPath))
                {
                    string path     = cacheDir + node.IDStr;
                    string metaPath = node.metaPath;
                    bool   flag1    = File.Exists(path);
                    bool   flag2    = false;
                    if (File.Exists(metaPath))
                    {
                        if (flag1)
                        {
                            if (AssetDownloader.GetFileSize(path) != (long)node.Size)
                            {
                                flag2 = true;
                                goto label_17;
                            }
                        }
                        try
                        {
                            using (FileStream fileStream = new FileStream(metaPath, FileMode.Open))
                            {
                                uint num = new BinaryReader((Stream)fileStream).ReadUInt32();
                                if ((int)node.Hash != (int)num)
                                {
                                    flag2 = true;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            flag2 = true;
                        }
label_17:
                        if (flag2)
                        {
                            File.Delete(metaPath);
                        }
                    }
                    else
                    {
                        flag2 = true;
                    }
                    if (flag1)
                    {
                        if (flag2)
                        {
                            File.Delete(path);
                        }
                        else
                        {
                            node.Item.Exist = true;
                            AssetDownloader.mExistFile.Add(new AssetDownloader.ExistAssetList(node.Item.ID, assetList.SearchItemIdx(node.Item.ID)));
                        }
                    }
                }
            }
        }
        else
        {
            AssetDownloader.ExistAssetList[] array = AssetDownloader.mExistFile.ToArray();
            for (int index = 0; index < array.Length; ++index)
            {
                this.mCompareHashMutex.WaitOne();
                this.mCompareHashProgressShared = (float)index / (float)array.Length;
                this.mCompareHashMutex.ReleaseMutex();
                bool           flag     = false;
                AssetList.Item itemById = AssetManager.AssetList.FastFindItemByID(array[index].FileID);
                AssetList.Item obj;
                if (itemById != null && compareFileListHashArg.dic.TryGetValue(array[index].FileID, out obj))
                {
                    if (flag | itemById.Size != obj.Size | (int)itemById.Hash != (int)obj.Hash)
                    {
                        AssetDownloader.mExistFile.Remove(array[index]);
                    }
                    else
                    {
                        itemById.Exist = true;
                    }
                }
            }
        }
    }