Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

142 rindas
2.4 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using UnityEngine;
  5. namespace Inno.DLC
  6. {
  7. public class DLCFile
  8. {
  9. public DLCFile(string id, Dictionary<string, string> values)
  10. {
  11. this._identifier = id;
  12. this._name = values["Name"];
  13. this._url = values["URL"];
  14. this._checksum = long.Parse(values["Checksum"]);
  15. this._bytes = long.Parse(values["Bytes"]);
  16. this._properties = values;
  17. }
  18. public string Identifier
  19. {
  20. get
  21. {
  22. return this._identifier;
  23. }
  24. }
  25. public string Name
  26. {
  27. get
  28. {
  29. return this._name;
  30. }
  31. }
  32. public bool Exists
  33. {
  34. get
  35. {
  36. return File.Exists(this.AbsolutePath);
  37. }
  38. }
  39. public long Bytes
  40. {
  41. get
  42. {
  43. return this._bytes;
  44. }
  45. }
  46. public byte[] GetContents()
  47. {
  48. return File.ReadAllBytes(this.AbsolutePath);
  49. }
  50. public bool Check()
  51. {
  52. string absolutePath = this.AbsolutePath;
  53. if (!File.Exists(absolutePath))
  54. {
  55. UnityEngine.Debug.LogWarning("Exists");
  56. return false;
  57. }
  58. FileInfo fileInfo = new FileInfo(absolutePath);
  59. if (fileInfo.Length != this._bytes)
  60. {
  61. UnityEngine.Debug.LogWarning("Length");
  62. return false;
  63. }
  64. byte[] contents = this.GetContents();
  65. long num = 0L;
  66. foreach (byte b in contents)
  67. {
  68. num *= 31L;
  69. num += (long)b;
  70. }
  71. if (num != this._checksum)
  72. {
  73. UnityEngine.Debug.LogWarning("Checksum");
  74. return false;
  75. }
  76. return true;
  77. }
  78. public void Delete()
  79. {
  80. string absolutePath = this.AbsolutePath;
  81. if (File.Exists(absolutePath))
  82. {
  83. File.Delete(absolutePath);
  84. }
  85. }
  86. public DLCDownloadTask Download()
  87. {
  88. return new DLCDownloadTask(this._url, this.AbsolutePath);
  89. }
  90. public string GetProperty(string key)
  91. {
  92. return this._properties[key];
  93. }
  94. public string URI
  95. {
  96. get
  97. {
  98. return "file://" + this.AbsolutePath;
  99. }
  100. }
  101. private string AbsolutePath
  102. {
  103. get
  104. {
  105. return DLCManager.AbsolutePath(this._name);
  106. }
  107. }
  108. private const string NameKey = "Name";
  109. private const string URLKey = "URL";
  110. private const string ChecksumKey = "Checksum";
  111. private const string BytesKey = "Bytes";
  112. private string _identifier;
  113. private string _name;
  114. private string _url;
  115. private long _checksum;
  116. private long _bytes;
  117. private Dictionary<string, string> _properties;
  118. }
  119. }