123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- using System;
- using System.IO;
- using System.Collections;
- using System.Collections.Generic;
- namespace YooAsset
- {
-
-
-
-
-
- internal static class DownloadSystem
- {
- private static readonly Dictionary<string, DownloaderBase> _downloaderDic = new Dictionary<string, DownloaderBase>();
- private static readonly List<string> _removeList = new List<string>(100);
- private static int _breakpointResumeFileSize = int.MaxValue;
-
-
-
- public static void Initialize(int breakpointResumeFileSize)
- {
- _breakpointResumeFileSize = breakpointResumeFileSize;
- }
-
-
-
- public static void Update()
- {
-
- _removeList.Clear();
- foreach (var valuePair in _downloaderDic)
- {
- var downloader = valuePair.Value;
- downloader.Update();
- if (downloader.IsDone())
- _removeList.Add(valuePair.Key);
- }
-
- foreach (var key in _removeList)
- {
- _downloaderDic.Remove(key);
- }
- }
-
-
-
- public static void DestroyAll()
- {
- foreach (var valuePair in _downloaderDic)
- {
- var downloader = valuePair.Value;
- downloader.Abort();
- }
- _downloaderDic.Clear();
- _removeList.Clear();
- _breakpointResumeFileSize = int.MaxValue;
- }
-
-
-
-
- public static DownloaderBase BeginDownload(BundleInfo bundleInfo, int failedTryAgain, int timeout = 60)
- {
-
- if (_downloaderDic.TryGetValue(bundleInfo.Bundle.CachedFilePath, out var downloader))
- {
- return downloader;
- }
-
- if (CacheSystem.IsCached(bundleInfo.Bundle))
- {
- var tempDownloader = new TempDownloader(bundleInfo);
- return tempDownloader;
- }
-
- {
- YooLogger.Log($"Beginning to download file : {bundleInfo.Bundle.FileName} URL : {bundleInfo.RemoteMainURL}");
- FileUtility.CreateFileDirectory(bundleInfo.Bundle.CachedFilePath);
- bool breakDownload = bundleInfo.Bundle.FileSize >= _breakpointResumeFileSize;
- DownloaderBase newDownloader = new FileDownloader(bundleInfo, breakDownload);
- newDownloader.SendRequest(failedTryAgain, timeout);
- _downloaderDic.Add(bundleInfo.Bundle.CachedFilePath, newDownloader);
- return newDownloader;
- }
- }
-
-
-
- public static int GetDownloaderTotalCount()
- {
- return _downloaderDic.Count;
- }
- }
- }
|