DownloadMgr.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  1. using Game.Config;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Reflection;
  7. using System.Text;
  8. using UnityEngine;
  9. using UnityEngine.Networking;
  10. class LocalFilePathInfo
  11. {
  12. public string Path;
  13. /// <summary>
  14. /// 是否可读可写文件夹
  15. /// </summary>
  16. public bool IsLocalRW;
  17. public LocalFilePathInfo()
  18. {
  19. Path = "";
  20. IsLocalRW = false;
  21. }
  22. public LocalFilePathInfo(string path,bool rw)
  23. {
  24. Path = path;
  25. IsLocalRW = rw;
  26. }
  27. }
  28. public class DownloadMgr : Singleton<DownloadMgr>
  29. {
  30. public const int TimeOut = 60;
  31. private string downloadBaseUrl;
  32. private string downloadUrl;
  33. public string DownloadUrl { get => downloadUrl; }
  34. private int downloadTaskMaxNum;
  35. public int DownloadTaskMaxNum { get => downloadTaskMaxNum; }
  36. private string localFilePath;
  37. public string LocalFilePath { get => localFilePath; }
  38. private List<DownloadDataEntity> needDownloadList;
  39. private Dictionary<DownloadDataEntity,ulong> downloadingList;
  40. private List<DownloadDataEntity> downloadSucessList;
  41. private List<DownloadDataEntity> remoteResList;
  42. private Dictionary<string, DownloadDataEntity> localResMap;
  43. private Dictionary<string, DownloadDataEntity> remoteResMap;
  44. private bool isInited = false;
  45. private GameDataFormatInfo downloadFormatInfo;
  46. private string versionFileName;
  47. private string assetsFileName;
  48. private string downloadedAssetsFileName;
  49. private ulong downloadSize;
  50. private ulong downloadingSize;
  51. public ulong DownloadSize { get => downloadSize + GetDownloadingSize(); }
  52. private ulong totalSize;//总大小
  53. public ulong TotalSize { get => totalSize; }
  54. public bool CheckFinish { get;private set; }
  55. public bool DowmloadError { get; private set; }
  56. //private byte[] versionData;
  57. //private byte[] mainfestData;
  58. private string versionData;
  59. //private UnityWebRequest mainfestData;
  60. public override void Init()
  61. {
  62. InitField();
  63. }
  64. private ulong GetDownloadingSize()
  65. {
  66. downloadingSize = 0;
  67. foreach (var item in downloadingList)
  68. {
  69. downloadingSize += item.Value;
  70. }
  71. return downloadingSize;
  72. }
  73. private string GetIOSDownloadPath()
  74. {
  75. return "res/IosRes/";
  76. //#if GAME_DEBUG
  77. //#else
  78. //#endif
  79. }
  80. private string GetAndroidDownloadPath()
  81. {
  82. #if GAME_ONE
  83. return "res/WDAndroidRes/";
  84. #elif GAME_DEBUG
  85. return "res/TestServerRes/";
  86. #else
  87. return "res/WDAndroidRes/";
  88. #endif
  89. }
  90. private string GetDownloadBaseUrl()
  91. {
  92. #if GAME_ONE
  93. return "http://101.43.46.101:88/";
  94. #elif CN_I7GAME_0_1
  95. return "http://weix.vvfyj.cn:88/";//"http://103.239.245.64:88/";
  96. #elif GAME_DEBUG
  97. return "http://110.40.223.119:88/";
  98. #else
  99. #if UNITY_EDITOR
  100. return "http://43.248.187.68:88/";
  101. #else
  102. return "http://cdn.yishanyou.com:88/";
  103. #endif
  104. #endif
  105. }
  106. private string GetDownloadUrl()
  107. {
  108. #if UNITY_IOS
  109. return GetDownloadBaseUrl() + GetIOSDownloadPath();
  110. #else
  111. return GetDownloadBaseUrl() + GetAndroidDownloadPath();
  112. #endif
  113. }
  114. private void InitField()
  115. {
  116. if (!isInited)
  117. {
  118. // //downloadBaseUrl = "http://cxzcdn.hkhappygame.com/";//"http://165.154.29.92:88/"; //http://cxzcdn.hkhappygame.com/res/
  119. // //downloadBaseUrl = "http://127.0.0.1:8060/";//"http://127.0.0.1:8060/";//
  120. //#if GAME_DEBUG
  121. // downloadBaseUrl = "http://110.40.223.119:88/";
  122. // downloadUrl = downloadBaseUrl + "res/TestServerRes/";
  123. //#else
  124. // downloadBaseUrl = "http://cxzcdn.hkhappygame.com/";
  125. //#if UNITY_IOS
  126. // downloadUrl = downloadBaseUrl + "res/IosRes/";
  127. //#else
  128. // downloadUrl = downloadBaseUrl + "res/AndroidNewRes/";
  129. //#endif
  130. //#endif
  131. downloadUrl = GetDownloadUrl();
  132. downloadTaskMaxNum = 5;
  133. localFilePath = GetLocalResPath();//FileSystem.LocalDocumentPath;
  134. versionFileName = "Version";
  135. assetsFileName = "mainfest";
  136. downloadedAssetsFileName = "downloaded";
  137. needDownloadList = new List<DownloadDataEntity>(100);
  138. downloadSucessList = new List<DownloadDataEntity>(100);
  139. downloadingList = new Dictionary<DownloadDataEntity,ulong>(downloadTaskMaxNum);
  140. remoteResList = new List<DownloadDataEntity>(1024);
  141. localResMap = new Dictionary<string, DownloadDataEntity>(1024);
  142. remoteResMap = new Dictionary<string, DownloadDataEntity>(1024);
  143. isInited = true;
  144. CheckFinish = false;
  145. DowmloadError = false;
  146. downloadSize = 0;
  147. downloadingSize = 0;
  148. totalSize = 0;
  149. }
  150. }
  151. public void CheckVersion()
  152. {
  153. AssetDownloader.Instance.DownLoadFileByCoroutine(GetRemoteUrl(versionFileName), webRqst =>
  154. {
  155. if (webRqst == null)
  156. {
  157. CheckFinish = true;
  158. DowmloadError = true;
  159. return;
  160. }
  161. byte[] data = webRqst.downloadHandler.data;
  162. //versionData = new byte[data.Length];
  163. //data.CopyTo(versionData,0);
  164. string version = Encoding.UTF8.GetString(data);
  165. Debug.Log("服务器 version = " + version);
  166. versionData = version;
  167. ReadDataFromFile(versionFileName,lVdatas=>
  168. {
  169. //OnloadedVersion(lVdatas, version);
  170. OnloadedLocalVersion(lVdatas, version);
  171. },true);
  172. });
  173. }
  174. public void DownLoadRemoteRes()
  175. {
  176. int size = needDownloadList.Count;
  177. int downsize = downloadSucessList.Count;
  178. downloadSize = 0;
  179. totalSize = 0;
  180. for (int i = 0; i < size; i++)
  181. {
  182. if (needDownloadList[i].FullName == "Version")
  183. {
  184. needDownloadList[i].State = DownloadTaskState.DownloadSuccess;
  185. continue;
  186. }
  187. totalSize += needDownloadList[i].Size;
  188. DownloadDataEntity entity = downloadSucessList.FindFirst(it=>it.FullName == needDownloadList[i].FullName);
  189. if (downsize > 0 && entity != null && entity.MD5 == needDownloadList[i].MD5)
  190. {
  191. needDownloadList[i].State = DownloadTaskState.DownloadSuccess;
  192. downloadSize += needDownloadList[i].Size;
  193. }
  194. else
  195. {
  196. needDownloadList[i].Callback = DownloadedCallback;
  197. needDownloadList[i].UpDateCallback = DownloadedUpdateCallback;
  198. AssetDownloader.Instance.AddDownloadTask(needDownloadList[i]);
  199. }
  200. }
  201. }
  202. public bool DownLoadFinish()
  203. {
  204. bool ret = true;
  205. int size = needDownloadList.Count;
  206. for (int i = 0; i < size; i++)
  207. {
  208. if (needDownloadList[i].State != DownloadTaskState.DownloadSuccess)
  209. {
  210. ret = false;
  211. }
  212. }
  213. return ret || DowmloadError || !AssetDownloader.Instance.HasTask();
  214. }
  215. public bool CheckNeedDownload()
  216. {
  217. return downloadSize < totalSize;
  218. }
  219. private void DownloadedUpdateCallback(DownloadTask task)
  220. {
  221. if (task == null)
  222. {
  223. // DowmloadError = true;
  224. //AssetDownloader.Instance.CancelDownLoad = true;
  225. return;
  226. }
  227. //Debug.Log($"下载:{downloadingSize}/{task.CurDownloadEntity.Size} 进度:{task.CurLoadProgress*100}%");
  228. //downloadingSize = task.downloadSize;
  229. if (!downloadingList.ContainsKey(task.CurDownloadEntity))
  230. {
  231. downloadingList.Add(task.CurDownloadEntity, task.downloadSize);
  232. }
  233. else
  234. {
  235. downloadingList[task.CurDownloadEntity] = task.downloadSize;
  236. }
  237. }
  238. private void DownloadedCallback(DownloadTask task)
  239. {
  240. if (task == null)
  241. {
  242. //DowmloadError = true;
  243. //AssetDownloader.Instance.CancelDownLoad = true;
  244. return;
  245. }
  246. DownloadDataEntity entity = downloadSucessList.FindFirst(it => it.FullName == task.CurDownloadEntity.FullName);
  247. if (entity != null)
  248. {
  249. entity.MD5 = task.CurDownloadEntity.MD5;
  250. entity.Size = task.CurDownloadEntity.Size;
  251. }
  252. else
  253. {
  254. downloadSucessList.Add(task.CurDownloadEntity);
  255. }
  256. if (downloadingList.ContainsKey(task.CurDownloadEntity))
  257. {
  258. downloadingList.Remove(task.CurDownloadEntity);
  259. }
  260. downloadingSize = 0;
  261. downloadSize += task.downloadSize;
  262. string savepath = localFilePath + downloadedAssetsFileName;
  263. CsvWriter<DownloadDataEntity> csvWriter = new CsvWriter<DownloadDataEntity>(savepath, "", downloadSucessList, downloadFormatInfo);
  264. csvWriter.Write();
  265. }
  266. private List<DownloadDataEntity> SerizlizeResList(byte[] data)
  267. {
  268. CsvReader csvReader = new CsvReader(FileHelper.GetName(assetsFileName), data);
  269. if (downloadFormatInfo == null)
  270. {
  271. downloadFormatInfo = new GameDataFormatInfo(csvReader.Fields(), csvReader.Types());
  272. }
  273. Type type = typeof(DownloadDataEntity);
  274. MethodInfo methodInfo = type.GetMethod("OnCsvLoad", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  275. methodInfo?.Invoke(null, new object[] { csvReader });
  276. List<DownloadDataEntity> resList = DownloadDataEntity.AllData();
  277. DownloadDataEntity.Clear();
  278. return resList;
  279. }
  280. private void GetRemoteResList()
  281. {
  282. string remoteversionpath = downloadUrl + assetsFileName;
  283. AssetDownloader.Instance.DownLoadFileByCoroutine(remoteversionpath, webRqst =>
  284. {
  285. if (webRqst == null)
  286. {
  287. CheckFinish = true;
  288. DowmloadError = true;
  289. return;
  290. }
  291. byte[] data = webRqst.downloadHandler.data;
  292. // mainfestData = new byte[data.Length];
  293. // data.CopyTo(mainfestData,0);
  294. //mainfestData = webRqst;
  295. List<DownloadDataEntity> reResList = SerizlizeResList(data);
  296. if (reResList != null)
  297. {
  298. OnRomoteListDownloaded(reResList);
  299. }
  300. });
  301. }
  302. private void OnRomoteListDownloaded(List<DownloadDataEntity> downloadDatas)
  303. {
  304. remoteResList.AddRange(downloadDatas);
  305. int size = downloadDatas.Count;
  306. for (int i = 0; i < size; i++)
  307. {
  308. remoteResMap.Add(downloadDatas[i].FullName, downloadDatas[i]);
  309. }
  310. //#if UNITY_IOS
  311. // ReadDataFromFile(assetsFileName, OnloadedLocalResList, false, 1);
  312. //#else
  313. // ReadDataFromFile(assetsFileName, OnloadedLocalResList);
  314. //#endif
  315. ReadDataFromFile(assetsFileName, OnloadedLocalResList);
  316. }
  317. //uint major
  318. //uint minor
  319. //uint release
  320. //uint patch
  321. private void SetCheckFinish()
  322. {
  323. versionData = null;
  324. CheckFinish = true;
  325. }
  326. private string GetLocalResPath()
  327. {
  328. string localPath = FileSystem.LocalDocumentPath;
  329. //#if UNITY_IOS
  330. // localPath = "file://" + localPath;
  331. //#endif
  332. return localPath;
  333. }
  334. private string GetStreamResPath()
  335. {
  336. string streamPath = FileSystem.LocalPackagePath;
  337. #if UNITY_IOS
  338. streamPath = "file://" + streamPath;
  339. #endif
  340. return streamPath;
  341. }
  342. private void OnloadedLocalVersion(byte[] datas, string version)
  343. {
  344. string lVersionstr = "0.0.0.0";
  345. if (datas != null)
  346. {
  347. lVersionstr = Encoding.UTF8.GetString(datas);
  348. }
  349. VersionCode lVersionCode = lVersionstr;//本地 local version
  350. VersionCode RVersionCode = version;// 远端 version
  351. string streamPath = GetStreamResPath();
  352. AssetDownloader.Instance.AssetLoadByCorutine(streamPath + versionFileName, filedatas =>
  353. {
  354. if (filedatas == null)
  355. {
  356. GetRemoteResList();
  357. Debug.Log("====== SVersionstr 为空 =====");
  358. return;
  359. }
  360. VersionCode SVersionCode;// stream data version
  361. string SVersionstr = Encoding.UTF8.GetString(filedatas);
  362. SVersionCode = SVersionstr;
  363. VersionCode localMaxCode = lVersionCode > SVersionCode ? lVersionCode : SVersionCode;
  364. if (localMaxCode == RVersionCode)
  365. {
  366. Debug.Log($"lVersionstr = {lVersionstr} SVersionstr = {SVersionstr} ===== version = {version} 不需要更新");
  367. SetCheckFinish();
  368. return;
  369. }
  370. if (localMaxCode >= RVersionCode && SVersionCode == localMaxCode)
  371. {
  372. Debug.Log($"lVersionstr = {lVersionstr} SVersionstr = {SVersionstr} ===== version = {version} 不需要跟新 需要删除之前下载资源");
  373. versionData = null;
  374. ReadDataFromFile(downloadedAssetsFileName, dlocaldatas =>
  375. {
  376. if (dlocaldatas != null)
  377. {
  378. List<DownloadDataEntity> localdownloadedList = SerizlizeResList(dlocaldatas);
  379. if (localdownloadedList != null && localdownloadedList.Count > 0)
  380. {
  381. downloadSucessList.AddRange(localdownloadedList);
  382. }
  383. DeleteDownloadFiles();
  384. }
  385. else
  386. {
  387. SetCheckFinish();
  388. }
  389. },true);
  390. }
  391. else
  392. {
  393. Debug.Log($"lVersionstr = {lVersionstr} SVersionstr = {SVersionstr} ===== version = {version} 需要更新");
  394. GetRemoteResList();
  395. //CheckFinish = true;
  396. }
  397. });
  398. }
  399. private void OnloadedVersion(byte[] datas,string version)
  400. {
  401. if (datas == null)
  402. {
  403. GetRemoteResList();
  404. Debug.Log("====== data 为空 =====");
  405. }
  406. else
  407. {
  408. string lVersionstr = Encoding.UTF8.GetString(datas);
  409. Debug.Log($"lVersionstr = {lVersionstr} ===== version = {version} ");
  410. if (lVersionstr == version)
  411. {
  412. Debug.Log($"lVersionstr = {lVersionstr} ===== version = {version} 不需要更新");
  413. SetCheckFinish();
  414. return;
  415. }
  416. else
  417. {
  418. VersionCode lVersionCode = lVersionstr;//本地 local version
  419. VersionCode RVersionCode = version;// 远端 version
  420. if (RVersionCode < lVersionCode)
  421. {
  422. SetCheckFinish();
  423. }
  424. else if (RVersionCode.major > lVersionCode.major || (RVersionCode.major == lVersionCode.major && RVersionCode.minor > lVersionCode.minor))
  425. {
  426. AssetDownloader.Instance.AssetLoadByCorutine(GetStreamResPath() + versionFileName, filedatas =>
  427. {
  428. VersionCode SVersionCode;// stream data version
  429. string SVersionstr = Encoding.UTF8.GetString(filedatas);
  430. SVersionCode = SVersionstr;
  431. if (SVersionCode >= RVersionCode && SVersionCode >= lVersionCode)
  432. {
  433. Debug.Log($"lVersionstr = {SVersionstr} ===== version = {version} 重新安装后需要删除之前资源");
  434. versionData = null;
  435. ReadDataFromFile(downloadedAssetsFileName, dlocaldatas=>
  436. {
  437. if (dlocaldatas != null)
  438. {
  439. List<DownloadDataEntity> localdownloadedList = SerizlizeResList(dlocaldatas);
  440. if (localdownloadedList != null && localdownloadedList.Count > 0)
  441. {
  442. downloadSucessList.AddRange(localdownloadedList);
  443. }
  444. DeleteDownloadFiles();
  445. }
  446. });
  447. }
  448. else
  449. {
  450. Debug.Log($"lVersionstr = {lVersionstr} ===== version = {version} 需要更新");
  451. GetRemoteResList();
  452. //CheckFinish = true;
  453. }
  454. });
  455. }
  456. else if (RVersionCode.release > lVersionCode.release || (RVersionCode.release == lVersionCode.release && RVersionCode.patch > lVersionCode.patch))
  457. {
  458. Debug.Log($"lVersionstr = {lVersionstr} ===== version = {version} 需要更新");
  459. GetRemoteResList();
  460. }
  461. else
  462. {
  463. SetCheckFinish();
  464. }
  465. }
  466. }
  467. }
  468. private void OnloadedLocalResList(byte[] datas)
  469. {
  470. if (datas == null)
  471. {
  472. }
  473. else
  474. {
  475. List<DownloadDataEntity> localList = SerizlizeResList(datas);
  476. if (localList != null)
  477. {
  478. int size = localList.Count;
  479. for (int i = 0; i < size; i++)
  480. {
  481. localResMap.Add(localList[i].FullName, localList[i]);
  482. }
  483. }
  484. }
  485. ReadDataFromFile(downloadedAssetsFileName, OnloadedDownloadResList);
  486. }
  487. private void OnloadedDownloadResList(byte[] datas)
  488. {
  489. if (datas != null)
  490. {
  491. List<DownloadDataEntity> localdownloadedList = SerizlizeResList(datas);
  492. if (localdownloadedList != null && localdownloadedList.Count > 0)
  493. {
  494. downloadSucessList.AddRange(localdownloadedList);
  495. }
  496. }
  497. GetNeedDownloadlist();
  498. DownLoadRemoteRes();
  499. }
  500. private List<DownloadDataEntity> GetLoacalResList(string path)
  501. {
  502. List<DownloadDataEntity> resList = null;
  503. if (System.IO.File.Exists(path))
  504. {
  505. byte[] data = System.IO.File.ReadAllBytes(path);
  506. resList = SerizlizeResList(data);
  507. }
  508. return resList;
  509. }
  510. private void GetNeedDownloadlist()
  511. {
  512. string ver = "Version";
  513. if (localResMap.ContainsKey(ver) && remoteResMap.ContainsKey(ver)&& localResMap[ver].MD5 == remoteResMap[ver].MD5)
  514. {
  515. Debug.Log("版本为最新状态");
  516. SetCheckFinish();
  517. //string savepath = localFilePath + downloadedAssetsFileName;
  518. //FileHelper.DeleteFile(savepath);
  519. return;
  520. }
  521. if (localResMap == null || localResMap.Count <= 0)
  522. {
  523. foreach (var item in remoteResMap)
  524. {
  525. needDownloadList.Add(item.Value);
  526. }
  527. }
  528. else
  529. {
  530. foreach (var item in remoteResMap)
  531. {
  532. if (item.Key == ver)
  533. {
  534. continue;
  535. }
  536. if (!localResMap.ContainsKey(item.Key) || localResMap[item.Key].MD5 != item.Value.MD5)
  537. {
  538. Debug.Log($"需跟新文件:{item.Value.FullName}");
  539. needDownloadList.Add(item.Value);
  540. }
  541. }
  542. }
  543. CheckFinish = true;
  544. }
  545. private string GetRemoteUrl( string name)
  546. {
  547. return downloadUrl + name;
  548. }
  549. private LocalFilePathInfo GetLocalFilePath(string name, bool onlyLocal = false, uint streamPerPath = 0)
  550. {
  551. LocalFilePathInfo ret = new LocalFilePathInfo();
  552. string path = LocalFilePath + name;
  553. ret.IsLocalRW = true;
  554. if (!FileSystem.Exists(path))
  555. {
  556. Debug.Log($" ========= LocalFilePath Path = {path} 不存在");
  557. if (!onlyLocal)
  558. {
  559. string lpPath = GetStreamResPath();
  560. for (int i = 0; i < streamPerPath; i++)
  561. {
  562. lpPath += "../";
  563. }
  564. path = lpPath + name;
  565. }
  566. ret.IsLocalRW = false;
  567. }
  568. ret.Path = path;
  569. Debug.Log($" ========= local Path = {path} ");
  570. return ret;
  571. }
  572. private void ReadDataFromFile(string name,Action<byte[]> callback,bool onlyLocal = false,uint streamPerPath = 0)
  573. {
  574. LocalFilePathInfo dlocalPath = GetLocalFilePath(name,onlyLocal, streamPerPath);
  575. if (dlocalPath.IsLocalRW)
  576. {
  577. try
  578. {
  579. byte[] dlocaldatas = File.ReadAllBytes(dlocalPath.Path);
  580. callback?.Invoke(dlocaldatas);
  581. }
  582. catch
  583. {
  584. Debug.Log("读取失败" + dlocalPath.Path);
  585. callback?.Invoke(null);
  586. }
  587. }
  588. else if(onlyLocal)
  589. {
  590. callback?.Invoke(null);
  591. }
  592. else
  593. {
  594. AssetDownloader.Instance.AssetLoadByCorutine(dlocalPath.Path, callback);
  595. }
  596. }
  597. private IEnumerator DeleteFiles()
  598. {
  599. ;
  600. int length = downloadSucessList.Count;
  601. string savepath = null;
  602. for (int i = 0; i < length; i++)
  603. {
  604. if (downloadSucessList[i].FullName == "font.unity3d")
  605. {
  606. Debug.Log("跳过删除");
  607. continue;
  608. }
  609. savepath = localFilePath + downloadSucessList[i].FullName;
  610. Debug.Log(savepath);
  611. FileHelper.DeleteFile(savepath);
  612. yield return null;
  613. }
  614. FileHelper.DeleteFile(localFilePath + downloadedAssetsFileName);
  615. yield return null;
  616. FileHelper.DeleteFile(localFilePath + versionFileName);
  617. yield return null;
  618. FileHelper.DeleteFile(LocalFilePath + assetsFileName);
  619. yield return null;
  620. SetCheckFinish();
  621. }
  622. public void DeleteDownloadFiles()
  623. {
  624. AssetDownloader.Instance.DoByCorutine(DeleteFiles);
  625. }
  626. public void Free()
  627. {
  628. //string savepath = localFilePath + downloadedAssetsFileName;
  629. //FileHelper.DeleteFile(savepath);
  630. if (!DowmloadError)
  631. {
  632. if( !string.IsNullOrEmpty(versionData))
  633. FileHelper.WirteStringToFile(localFilePath + versionFileName, versionData);
  634. //PlayerPrefs.SetString(versionFileName, versionData);
  635. //if(mainfestData!=null)
  636. // FileHelper.WirteToFile(LocalFilePath + assetsFileName, mainfestData.downloadHandler.data);
  637. if (remoteResList.Count > 0)
  638. {
  639. //Debug.Log($" ============= remoteResList.Count = {remoteResList.Count}" );
  640. CsvWriter<DownloadDataEntity> csvWriter = new CsvWriter<DownloadDataEntity>(LocalFilePath + assetsFileName, "", remoteResList, downloadFormatInfo);
  641. csvWriter.Write();
  642. }
  643. }
  644. needDownloadList = null;
  645. downloadSucessList = null;
  646. remoteResList = null;
  647. localResMap = null;
  648. remoteResMap = null;
  649. versionData = null;
  650. //mainfestData = null;
  651. AssetDownloader.Instance.ClearTasks();
  652. }
  653. }