示例#1
0
 public static string LoadTextData(string path)
 {
     AssetList.Item itemByPath1 = AssetManager.TxtAssetList.FindItemByPath(path);
     if (itemByPath1 != null)
     {
         int    size;
         IntPtr num = NativePlugin.DecompressFile(AssetDownloader.TextCachePath + itemByPath1.IDStr, out size);
         if (num == IntPtr.Zero)
         {
             return((string)null);
         }
         byte[] numArray = new byte[size];
         Marshal.Copy(num, numArray, 0, size);
         NativePlugin.FreePtr(num);
         using (StreamReader streamReader = new StreamReader((Stream) new MemoryStream(numArray), Encoding.UTF8))
             return(streamReader.ReadToEnd());
     }
     else
     {
         AssetList.Item itemByPath2 = AssetManager.AssetList.FindItemByPath(path);
         if (itemByPath2 != null)
         {
             int    size;
             IntPtr num = NativePlugin.DecompressFile(AssetDownloader.CachePath + itemByPath2.IDStr, out size);
             if (num == IntPtr.Zero)
             {
                 return((string)null);
             }
             byte[] numArray = new byte[size];
             Marshal.Copy(num, numArray, 0, size);
             NativePlugin.FreePtr(num);
             using (StreamReader streamReader = new StreamReader((Stream) new MemoryStream(numArray), Encoding.UTF8))
                 return(streamReader.ReadToEnd());
         }
         else
         {
             TextAsset textAsset = (TextAsset)Resources.Load <TextAsset>(path);
             if (Object.op_Inequality((Object)textAsset, (Object)null))
             {
                 return(textAsset.get_text());
             }
             return((string)null);
         }
     }
 }
示例#2
0
    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();
    }
示例#3
0
    private AssetBundleCache OpenAssetBundle(string assetbundleID, bool persistent = false, bool isDependency = false)
    {
        AssetList.Item itemById = AssetManager.AssetList.FindItemByID(assetbundleID);
        if (itemById == null)
        {
            DebugUtility.LogError("AssetBundle not found: " + assetbundleID);
            return((AssetBundleCache)null);
        }
        for (int index = 0; index < this.mAssetBundles.Count; ++index)
        {
            if (this.mAssetBundles[index].Name == assetbundleID)
            {
                return(this.mAssetBundles[index]);
            }
        }
        if (this.mAssetBundles.Count >= AssetManager.MaxAssetBundles)
        {
            this.UnloadUnusedAssetBundles(true, true);
        }
        string path = AssetDownloader.CachePath + assetbundleID;

        if (!File.Exists(path))
        {
            DebugUtility.LogError("AssetBundle doesn't exist: " + assetbundleID);
            return((AssetBundleCache)null);
        }
        if ((itemById.Flags & AssetBundleFlags.RawData) != (AssetBundleFlags)0)
        {
            DebugUtility.LogError("AssetBundle is RawData: " + assetbundleID);
            return((AssetBundleCache)null);
        }
        AssetBundle ab;

        if ((itemById.Flags & AssetBundleFlags.Compressed) != (AssetBundleFlags)0)
        {
            int    size;
            IntPtr num = NativePlugin.DecompressFile(path, out size);
            if (num == IntPtr.Zero)
            {
                DebugUtility.LogError("Failed to decompress AssetBundle: " + assetbundleID);
                return((AssetBundleCache)null);
            }
            byte[] destination = new byte[size];
            Marshal.Copy(num, destination, 0, size);
            NativePlugin.FreePtr(num);
            ab = AssetBundle.LoadFromMemory(destination);
            if (Object.op_Equality((Object)ab, (Object)null))
            {
                DebugUtility.LogError("Failed to create AssetBundle from memory: " + assetbundleID);
            }
        }
        else
        {
            ab = AssetBundle.LoadFromFile(path);
            if (Object.op_Equality((Object)ab, (Object)null))
            {
                DebugUtility.LogError("Failed to open AssetBundle: " + assetbundleID);
            }
        }
        AssetBundleCache assetBundleCache = new AssetBundleCache(assetbundleID, ab);

        this.mAssetBundles.Add(assetBundleCache);
        assetBundleCache.Persistent = persistent;
        return(assetBundleCache);
    }