GetDownloadSize.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System.Collections.Generic;
  2. using System.IO;
  3. namespace VEngine
  4. {
  5. public sealed class GetDownloadSize : Operation
  6. {
  7. public readonly List<ManifestBundle> bundles = new List<ManifestBundle>();
  8. public readonly List<DownloadInfo> result = new List<DownloadInfo>();
  9. public long totalSize { get; private set; }
  10. public override void Start()
  11. {
  12. base.Start();
  13. if (Versions.OfflineMode)
  14. {
  15. Finish();
  16. return;
  17. }
  18. totalSize = 0;
  19. if (bundles.Count == 0) Finish();
  20. }
  21. protected override void Update()
  22. {
  23. if (status == OperationStatus.Processing)
  24. {
  25. while (bundles.Count > 0)
  26. {
  27. var bundle = bundles[0];
  28. var savePath = Versions.GetDownloadDataPath(bundle.nameWithAppendHash);
  29. if (!Versions.IsDownloaded(bundle) && !result.Exists(info => info.savePath == savePath))
  30. {
  31. var file = new FileInfo(savePath);
  32. if (file.Exists)
  33. totalSize += bundle.size - file.Length;
  34. else
  35. totalSize += bundle.size;
  36. result.Add(new DownloadInfo
  37. {
  38. crc = bundle.crc,
  39. url = Versions.GetDownloadURL(bundle.nameWithAppendHash),
  40. size = bundle.size,
  41. savePath = savePath
  42. });
  43. }
  44. bundles.RemoveAt(0);
  45. if (Updater.Instance.busy) return;
  46. }
  47. Finish();
  48. }
  49. }
  50. }
  51. }