private void BeginUnzip(byte[] bytes, int size, string dest, string requestID, AssetList assetList)
 {
     if (!this.mMutexAcquired)
     {
         this.mMutex.WaitOne();
         this.mMutexAcquired = true;
     }
     AssetDownloader.UnzipJob unzipJob = new AssetDownloader.UnzipJob();
     unzipJob.Bytes = bytes;
     unzipJob.Size  = size;
     unzipJob.Dest  = dest;
     unzipJob.nodes = new List <AssetDownloader.UnzipJob.Node>();
     AssetList.Item itemById = assetList.FindItemByID(requestID);
     unzipJob.nodes.Add(new AssetDownloader.UnzipJob.Node()
     {
         ID   = requestID,
         hash = itemById.Hash,
         Item = itemById
     });
     this.mUnzipJobs.Add(unzipJob);
     if (size <= 0)
     {
         unzipJob.State = AssetDownloader.UnzipJobState.Error;
     }
     this.mMutex.ReleaseMutex();
     this.mMutexAcquired = false;
     this.mUnzipSignal.Set();
 }
 private void BeginUnzip(byte[] bytes, int size, string dest, List <string> requestIDs, AssetList assetList)
 {
     if (!this.mMutexAcquired)
     {
         this.mMutex.WaitOne();
         this.mMutexAcquired = true;
     }
     AssetDownloader.UnzipJob unzipJob = new AssetDownloader.UnzipJob();
     unzipJob.Bytes = bytes;
     unzipJob.Size  = size;
     unzipJob.Dest  = dest;
     unzipJob.nodes = new List <AssetDownloader.UnzipJob.Node>();
     using (List <string> .Enumerator enumerator = requestIDs.GetEnumerator())
     {
         while (enumerator.MoveNext())
         {
             string         current  = enumerator.Current;
             AssetList.Item itemById = assetList.FindItemByID(current);
             unzipJob.nodes.Add(new AssetDownloader.UnzipJob.Node()
             {
                 ID   = current,
                 hash = itemById.Hash
             });
         }
     }
     this.mUnzipJobs.Add(unzipJob);
     if (size <= 0)
     {
         unzipJob.State = AssetDownloader.UnzipJobState.Error;
     }
     this.mMutex.ReleaseMutex();
     this.mMutexAcquired = false;
     this.mUnzipSignal.Set();
 }
    private void UnzipThread()
    {
label_1:
        while (true)
        {
            this.mUnzipSignal.WaitOne();
            this.mMutex.WaitOne();
            if (!this.mShuttingDown)
            {
                if (this.mUnzipJobs == null)
                {
                    this.mMutex.ReleaseMutex();
                }
                else
                {
                    goto label_5;
                }
            }
            else
            {
                break;
            }
        }
        this.mMutex.ReleaseMutex();
        return;

label_5:
        AssetDownloader.UnzipJob[] array = this.mUnzipJobs.ToArray();
        for (int index = 0; index < array.Length; ++index)
        {
            if (array[index].State == AssetDownloader.UnzipJobState.Waiting)
            {
                array[index].State = AssetDownloader.UnzipJobState.Extracting;
            }
        }
        this.mMutex.ReleaseMutex();
        for (int index = 0; index < array.Length; ++index)
        {
            AssetDownloader.UnzipJob unzipJob = array[index];
            if (unzipJob.State == AssetDownloader.UnzipJobState.Extracting)
            {
                if (NativePlugin.UnZip(unzipJob.Dest, unzipJob.Bytes, unzipJob.Size) != 0)
                {
                    this.mMutex.WaitOne();
                    unzipJob.State = AssetDownloader.UnzipJobState.Error;
                    this.mMutex.ReleaseMutex();
                }
                else
                {
                    this.mMutex.WaitOne();
                    unzipJob.State = AssetDownloader.UnzipJobState.Finished;
                    this.mMutex.ReleaseMutex();
                }
            }
        }
        goto label_1;
    }
    private void UnzipThread2()
    {
        AssetDownloader.UnzipThread2Arg mUnzipThreadArg = this.mUnzipThreadArg;
        if (mUnzipThreadArg == null)
        {
            return;
        }
        bool flag = false;

        while (!flag)
        {
            this.mMutex.WaitOne();
            AssetDownloader.UnzipJob[] array = this.mUnzipJobs.ToArray();
            this.mUnzipJobs.Clear();
            bool completed     = mUnzipThreadArg.completed;
            bool abort         = mUnzipThreadArg.abort;
            bool mShuttingDown = this.mShuttingDown;
            this.mMutex.ReleaseMutex();
            if (mShuttingDown || abort)
            {
                return;
            }
            if (array == null || array.Length <= 0)
            {
                if (completed)
                {
                    return;
                }
                this.mUnzipSignal.WaitOne();
            }
            else
            {
                AssetDownloader.UnzipJob unzipJob = (AssetDownloader.UnzipJob)null;
                for (int index1 = 0; index1 < array.Length; ++index1)
                {
                    unzipJob = array[index1];
                    if (unzipJob.State == AssetDownloader.UnzipJobState.Error)
                    {
                        flag = true;
                        break;
                    }
                    try
                    {
                        if (array != null)
                        {
                            AssetDownloader.UnZipFileSize = (long)((IEnumerable <AssetDownloader.UnzipJob>)array).Sum <AssetDownloader.UnzipJob>((Func <AssetDownloader.UnzipJob, int>)(arg => arg.Size));
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.Log((object)ex.ToString());
                    }
                    File.WriteAllBytes(AssetDownloader.CachePath + unzipJob.nodes[0].ID, unzipJob.Bytes);
                    if ((unzipJob.nodes[0].Item.Flags & AssetBundleFlags.IsCombined) != (AssetBundleFlags)0)
                    {
                        int    size = 0;
                        string path = AssetDownloader.CachePath + unzipJob.nodes[0].ID;
                        if ((unzipJob.nodes[0].Item.Flags & AssetBundleFlags.Compressed) != (AssetBundleFlags)0)
                        {
                            IntPtr num1 = NativePlugin.DecompressFile(path, out size);
                            if (num1 == IntPtr.Zero)
                            {
                                throw new Exception("Failed to decompress file [" + path + "]");
                            }
                            byte[] numArray = new byte[size];
                            Marshal.Copy(num1, numArray, 0, size);
                            using (BinaryReader binaryReader = new BinaryReader((Stream) new MemoryStream(numArray)))
                            {
                                int num2 = binaryReader.ReadInt32();
                                for (int index2 = 0; index2 < num2; ++index2)
                                {
                                    string lower = binaryReader.ReadInt32().ToString("X8").ToLower();
                                    int    count = binaryReader.ReadInt32();
                                    byte[] bytes = binaryReader.ReadBytes(count);
                                    File.WriteAllBytes(AssetDownloader.CachePath + lower, bytes);
                                    AssetList.Item itemById = mUnzipThreadArg.assetlist.FindItemByID(lower);
                                    itemById.Exist = true;
                                    AssetDownloader.mExistFile.Add(new AssetDownloader.ExistAssetList(itemById.ID, mUnzipThreadArg.assetlist.SearchItemIdx(itemById.ID)));
                                }
                            }
                            NativePlugin.FreePtr(num1);
                            File.Delete(path + ".tmp");
                        }
                        else
                        {
                            using (BinaryReader binaryReader = new BinaryReader((Stream)File.Open(path, FileMode.Open)))
                            {
                                int num = binaryReader.ReadInt32();
                                for (int index2 = 0; index2 < num; ++index2)
                                {
                                    string lower = binaryReader.ReadInt32().ToString("X8").ToLower();
                                    int    count = binaryReader.ReadInt32();
                                    byte[] bytes = binaryReader.ReadBytes(count);
                                    File.WriteAllBytes(AssetDownloader.CachePath + lower, bytes);
                                    AssetList.Item itemById = mUnzipThreadArg.assetlist.FindItemByID(lower);
                                    itemById.Exist = true;
                                    AssetDownloader.mExistFile.Add(new AssetDownloader.ExistAssetList(itemById.ID, mUnzipThreadArg.assetlist.SearchItemIdx(itemById.ID)));
                                }
                            }
                        }
                    }
                    using (List <AssetDownloader.UnzipJob.Node> .Enumerator enumerator = unzipJob.nodes.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            AssetDownloader.UnzipJob.Node current = enumerator.Current;
                            if (!File.Exists(unzipJob.Dest + current.ID))
                            {
                                flag = true;
                                break;
                            }
                        }
                    }
                    if (!flag)
                    {
                        using (List <AssetDownloader.UnzipJob.Node> .Enumerator enumerator = unzipJob.nodes.GetEnumerator())
                        {
                            while (enumerator.MoveNext())
                            {
                                AssetDownloader.UnzipJob.Node current = enumerator.Current;
                                current.Item.Exist = true;
                                AssetDownloader.mExistFile.Add(new AssetDownloader.ExistAssetList(current.Item.ID, mUnzipThreadArg.assetlist.SearchItemIdx(current.Item.ID)));
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                try
                {
                    AssetDownloader.UnZipFileSize = 0L;
                    if (this.mDownloadObserver != null)
                    {
                        this.mDownloadObserver.IsWait = false;
                    }
                }
                catch (Exception ex)
                {
                    Debug.Log((object)ex.ToString());
                }
                if (flag && unzipJob != null)
                {
                    for (int index = 0; index < unzipJob.nodes.Count; ++index)
                    {
                        string path1 = unzipJob.Dest + unzipJob.nodes[index].ID;
                        if (File.Exists(path1))
                        {
                            File.Delete(path1);
                        }
                        string path2 = unzipJob.Dest + unzipJob.nodes[index].ID + ".meta";
                        if (!File.Exists(path2))
                        {
                            File.Delete(path2);
                        }
                        unzipJob.nodes[index].Item.Exist = false;
                    }
                }
            }
        }
        this.mMutex.WaitOne();
        mUnzipThreadArg.error = true;
        this.mMutex.ReleaseMutex();
    }