您不能選擇超過 %s 個話題 話題必須以字母或數字為開頭,可包含連接號 ('-') 且最長為 35 個字
 
 
 

152 行
3.7 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using SUISS.Core;
  5. using UnityEngine;
  6. namespace Inno.DLC
  7. {
  8. public class DLCManager
  9. {
  10. public DLCManager(string propertiesFilename)
  11. {
  12. this._propertiesFilename = propertiesFilename;
  13. try
  14. {
  15. this.ParseConfig();
  16. this.CheckFolder();
  17. this.CheckFiles();
  18. this._enabled = true;
  19. }
  20. catch (Exception ex)
  21. {
  22. UnityEngine.Debug.LogError(string.Format("Disabling DLC: {0}", ex.Message));
  23. this._enabled = false;
  24. }
  25. }
  26. public static string AbsolutePath(string name)
  27. {
  28. return PathHandler.Combine(DLCManager.DLCFolderPath, name);
  29. }
  30. public DLCGroup GetGroup(string id)
  31. {
  32. if (this._groups.ContainsKey(id))
  33. {
  34. return this._groups[id];
  35. }
  36. return this._emptyGroup;
  37. }
  38. public IList<DLCGroup> AllGroups
  39. {
  40. get
  41. {
  42. return new List<DLCGroup>(this._groups.Values).AsReadOnly();
  43. }
  44. }
  45. public bool IsEnabled
  46. {
  47. get
  48. {
  49. return this._enabled;
  50. }
  51. }
  52. private static string DLCFolderPath
  53. {
  54. get
  55. {
  56. return PathHandler.Combine(Application.persistentDataPath, "dlc");
  57. }
  58. }
  59. private void ParseConfig()
  60. {
  61. TextAsset textAsset = Resources.Load(this._propertiesFilename) as TextAsset;
  62. if (textAsset != null)
  63. {
  64. string text = textAsset.text.Trim();
  65. string[] array = text.Split(new char[]
  66. {
  67. '\n'
  68. });
  69. Dictionary<string, Dictionary<string, Dictionary<string, string>>> dictionary = new Dictionary<string, Dictionary<string, Dictionary<string, string>>>();
  70. int num = 0;
  71. foreach (string text2 in array)
  72. {
  73. num++;
  74. string text3 = text2.Trim();
  75. if (text3.Length > 0)
  76. {
  77. int num2 = text3.IndexOf('=');
  78. if (num2 >= 0)
  79. {
  80. string text4 = text3.Substring(0, num2).TrimEnd(new char[0]);
  81. string value = text3.Substring(num2 + 1).TrimStart(new char[0]);
  82. int num3 = text4.IndexOf('.');
  83. if (num3 >= 0)
  84. {
  85. string key = text4.Substring(0, num3).TrimEnd(new char[0]);
  86. string text5 = text4.Substring(num3 + 1).TrimStart(new char[0]);
  87. int num4 = text5.IndexOf('.');
  88. if (num4 >= 0)
  89. {
  90. string key2 = text5.Substring(0, num4).TrimEnd(new char[0]);
  91. string key3 = text5.Substring(num4 + 1).TrimStart(new char[0]);
  92. if (!dictionary.ContainsKey(key))
  93. {
  94. dictionary[key] = new Dictionary<string, Dictionary<string, string>>();
  95. }
  96. if (!dictionary[key].ContainsKey(key2))
  97. {
  98. dictionary[key][key2] = new Dictionary<string, string>();
  99. }
  100. dictionary[key][key2][key3] = value;
  101. }
  102. }
  103. }
  104. else
  105. {
  106. UnityEngine.Debug.LogWarning(string.Format("Parse error in dlc.properties line {0}: cannot find '=' token.", num));
  107. }
  108. }
  109. }
  110. foreach (KeyValuePair<string, Dictionary<string, Dictionary<string, string>>> keyValuePair in dictionary)
  111. {
  112. this._groups[keyValuePair.Key] = new DLCGroup(keyValuePair.Key, keyValuePair.Value);
  113. }
  114. }
  115. }
  116. private void CheckFolder()
  117. {
  118. string dlcfolderPath = DLCManager.DLCFolderPath;
  119. if (!Directory.Exists(dlcfolderPath))
  120. {
  121. Directory.CreateDirectory(dlcfolderPath);
  122. }
  123. }
  124. private void CheckFiles()
  125. {
  126. foreach (DLCGroup dlcgroup in this._groups.Values)
  127. {
  128. dlcgroup.CheckFiles();
  129. }
  130. }
  131. private const string DLCFolder = "dlc";
  132. private string _propertiesFilename;
  133. private Dictionary<string, DLCGroup> _groups = new Dictionary<string, DLCGroup>();
  134. private readonly DLCGroup _emptyGroup = new DLCGroup(string.Empty, new Dictionary<string, Dictionary<string, string>>());
  135. private bool _enabled;
  136. }
  137. }