public void Init(NodeAddedEvent e, SingleNode <AssetBundleDatabaseComponent> dbNode, SingleNode <BaseUrlComponent> baseUrlNode)
        {
            bool flag;
            AssetBundleDiskCache cache = new AssetBundleDiskCache(dbNode.component.AssetBundleDatabase, baseUrlNode.component.Url);

            try
            {
                cache.CleanOldBundlesCache();
                flag = this.EnoughFreeSpaceForCache(cache);
            }
            catch (Exception exception)
            {
                this.SheduleErrorEvent <InvalidGameDataErrorEvent>(dbNode.Entity, "AssetBundleDiskCacheSystem: " + exception.Message);
                return;
            }
            if (!flag)
            {
                this.SheduleErrorEvent <NotEnoughDiskSpaceForCacheErrorEvent>(dbNode.Entity, "Not enough disk space for cache");
            }
            else
            {
                AssetBundleDiskCacheComponent component = new AssetBundleDiskCacheComponent {
                    AssetBundleDiskCache = cache
                };
                baseUrlNode.Entity.AddComponent(component);
            }
        }
 public void StartPreload(NodeAddedEvent e, SingleNode <PreloadAllResourcesComponent> preload, [JoinAll] DataBaseNode db)
 {
     if (DiskCaching.Enabled)
     {
         AssetBundleDatabase  assetBundleDatabase             = db.assetBundleDatabase.AssetBundleDatabase;
         AssetBundleDiskCache assetBundleDiskCache            = db.assetBundleDiskCache.AssetBundleDiskCache;
         List <string>        prioritizedAssetsConfigPathList = GetPrioritizedAssetsConfigPathList();
         int           num   = 100 + prioritizedAssetsConfigPathList.Count;
         List <string> list2 = new List <string>();
         for (int i = 0; i < prioritizedAssetsConfigPathList.Count; i++)
         {
             AssetReferenceComponent assetReferenceComponent = AssetReferenceComponent.createFromConfig(prioritizedAssetsConfigPathList[i]);
             string assetGuid = assetReferenceComponent.Reference.AssetGuid;
             list2.Add(assetGuid);
             AssetBundleInfo assetBundleInfoByGuid = assetBundleDatabase.GetAssetBundleInfoByGuid(assetGuid);
             if (!assetBundleDiskCache.IsCached(assetBundleInfoByGuid))
             {
                 this.CreateEntityForPreloadingBundles(assetReferenceComponent, num - i);
             }
         }
         foreach (string str2 in assetBundleDatabase.GetRootGuids())
         {
             AssetBundleInfo assetBundleInfoByGuid = assetBundleDatabase.GetAssetBundleInfoByGuid(str2);
             if (!list2.Contains(str2) && !assetBundleDiskCache.IsCached(assetBundleInfoByGuid))
             {
                 AssetReferenceComponent assetReferenceComponent = new AssetReferenceComponent(new AssetReference(str2));
                 this.CreateEntityForPreloadingBundles(assetReferenceComponent, 0);
             }
         }
     }
 }
 public AssetBundleDiskCache(AssetBundleDatabase dataBase, string baseUrl)
 {
     this.DataBase         = dataBase;
     this.BaseUrl          = baseUrl;
     this.CachePath        = this.ResolveAssetBundlesCachePath();
     this.diskWriter       = new DiskCacheWriterThread();
     this.diskWriterThread = new Thread(new ThreadStart(this.diskWriter.Run));
     this.diskWriterThread.Start();
     INSTANCE = this;
 }
        private bool EnoughFreeSpaceForCache(AssetBundleDiskCache cache)
        {
            long num = cache.RequiredFreeSpaceInBytes();

            Console.WriteLine("AssetBundleDiskCache: requiredFreeSpace: " + num + " bytes.");
            int  num2 = (int)(num / 0x12c00000L);
            long num3 = (num - (0x12c00000L * num2)) + 0x3200000L;

            num2++;
            List <FileStream> list = new List <FileStream>();

            try
            {
                for (int i = 0; i < num2; i++)
                {
                    string testFileName = this.GetTestFileName(cache.CachePath, i);
                    list.Add(File.Open(testFileName, FileMode.OpenOrCreate));
                }
            }
            catch (Exception)
            {
                return(true);
            }
            bool flag2 = true;

            try
            {
                int num5 = 0;
                while (true)
                {
                    if (num5 >= (num2 - 1))
                    {
                        list[num2 - 1].SetLength(num3);
                        break;
                    }
                    list[num5].SetLength(0x12c00000L);
                    num5++;
                }
            }
            catch (IOException)
            {
                flag2 = false;
            }
            finally
            {
                for (int i = 0; i < num2; i++)
                {
                    list[i].Close();
                    File.Delete(this.GetTestFileName(cache.CachePath, i));
                }
            }
            return(flag2);
        }
 public AssetBundleDiskCacheTask(AssetBundleDiskCache _assetBundleDiskCache)
 {
     this.assetBundleDiskCache = _assetBundleDiskCache;
     this.state2action.Add(AssetBundleDiskCacheState.INIT, new Action(this.Initialize));
     this.state2action.Add(AssetBundleDiskCacheState.START_LOAD_FROM_HTTP, new Action(this.StartLoadFromHTTP));
     this.state2action.Add(AssetBundleDiskCacheState.LOADING_FROM_HTTP, new Action(this.LoadingFromHTTP));
     this.state2action.Add(AssetBundleDiskCacheState.START_LOAD_FROM_DISK, new Action(this.StartLoadFromDisk));
     this.state2action.Add(AssetBundleDiskCacheState.START_WRITE_TO_DISK, new Action(this.StartWriteToDisk));
     this.state2action.Add(AssetBundleDiskCacheState.WRITE_TO_DISK, new Action(this.WriteToDisk));
     this.state2action.Add(AssetBundleDiskCacheState.CREATE_ASSETBUNDLE, new Action(this.CreateAssetBundle));
     this.state2action.Add(AssetBundleDiskCacheState.COMPLETE, new Action(this.Complete));
     this.Log = LoggerProvider.GetLogger(this);
 }
        public void HandleBundleLoadComplete(LoadCompleteEvent e, AssetBundleLoadingNode node, [JoinAll] AssetBundleDatabaseNode dbNode)
        {
            AssetBundleLoadingComponent assetBundleLoading   = node.assetBundleLoading;
            AssetBundleDiskCache        assetBundleDiskCache = dbNode.assetBundleDiskCache.AssetBundleDiskCache;
            AssetBundleInfo             info = node.assetBundleLoading.Info;

            if (!info.IsCached)
            {
                this.LogDownloadInfoIfBundleIsBig(assetBundleLoading, AssetBundleNaming.GetAssetBundleUrl(assetBundleDiskCache.BaseUrl, info.Filename), info.Size);
                info.IsCached = true;
            }
            this.ReleaseLoadingChannel(node.Entity);
        }