Unofficial CardLife revival project, pronounced like "celery"
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

132 lignes
4.5KB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using System.Text;
  6. namespace CLre.Fixes
  7. {
  8. [AttributeUsage(AttributeTargets.Class)]
  9. public class BugfixAttribute : Attribute
  10. {
  11. public string name { get; set; }
  12. public string description { get; set; }
  13. public Type target { get; set; }
  14. public string more { get; set; }
  15. public uint id { get; set; }
  16. public BugfixType component { get; set; }
  17. }
  18. public enum BugfixType : byte
  19. {
  20. Miscellaneous = 0x00,
  21. HarmonyPatch,
  22. Initialiser,
  23. Workaround,
  24. API,
  25. Debug
  26. }
  27. internal static class BugfixAttributeUtility
  28. {
  29. public static int Count { get; private set; }
  30. public static void LogBugfixes()
  31. {
  32. API.Utility.Logging.Log(BugfixMessage());
  33. }
  34. public static string BugfixMessage()
  35. {
  36. Dictionary<uint, BugfixStruct> fixes = Bugfixes();
  37. List<uint> keys = new List<uint>(fixes.Keys);
  38. keys.Sort();
  39. //keys.Sort((u, u1) => u.CompareTo(u1));
  40. StringBuilder sb = new StringBuilder();
  41. sb.AppendFormat("Applying {0} CLre fixes\n", keys.Count);
  42. sb.AppendFormat("-----------------------------\n");
  43. foreach (uint i in keys)
  44. {
  45. sb.Append(fixes[i].ToString());
  46. sb.Append("\n");
  47. }
  48. sb.AppendFormat("-----------------------------\n");
  49. return sb.ToString();
  50. }
  51. public static Dictionary<uint, BugfixStruct> Bugfixes()
  52. {
  53. Dictionary<uint, BugfixStruct> fixes = new Dictionary<uint, BugfixStruct>();
  54. foreach (Type t in Assembly.GetExecutingAssembly().GetTypes())
  55. {
  56. BugfixAttribute b = t.GetCustomAttribute<BugfixAttribute>(true);
  57. if (b != null)
  58. {
  59. if (!fixes.ContainsKey(b.id))
  60. {
  61. BugfixStruct bugfixStruct = new BugfixStruct{id = b.id};
  62. bugfixStruct.Merge(b);
  63. fixes[b.id] = bugfixStruct;
  64. }
  65. else
  66. {
  67. BugfixStruct bugfixStruct = fixes[b.id];
  68. bugfixStruct.Merge(b);
  69. fixes[b.id] = bugfixStruct;
  70. }
  71. }
  72. }
  73. Count = fixes.Count;
  74. return fixes;
  75. }
  76. public struct BugfixStruct
  77. {
  78. public string name;
  79. public string description;
  80. public Type target;
  81. public string more;
  82. public uint id;
  83. private uint total;
  84. private uint[] bugfixTypeCount;
  85. public void Merge(BugfixAttribute b)
  86. {
  87. if (name == null && b.name != null) name = b.name;
  88. if (description == null && b.description != null) description = b.description;
  89. if (target == null && b.target != null) target = b.target;
  90. if (more == null && b.more != null) more = b.more;
  91. total++;
  92. if (bugfixTypeCount == null) bugfixTypeCount = new uint[Enum.GetNames(typeof(BugfixType)).Length];
  93. bugfixTypeCount[(byte) b.component]++;
  94. }
  95. public override string ToString()
  96. {
  97. StringBuilder sb = new StringBuilder();
  98. sb.AppendFormat(" {0}: ", name);
  99. if (more != null)
  100. {
  101. sb.AppendFormat("[MORE: {0}] ", more);
  102. }
  103. else if (description != null)
  104. {
  105. sb.Append(description);
  106. sb.Append(" ");
  107. }
  108. if (target != null)
  109. {
  110. sb.AppendFormat("[TARGET: {0}] ", target.FullName);
  111. }
  112. sb.AppendFormat("[ID: {0}] ", id);
  113. sb.AppendFormat("({0}M/{1}P/{2}I/{3}W/{4}A/{5}D/{6}T)",
  114. bugfixTypeCount[(byte) BugfixType.Miscellaneous], bugfixTypeCount[(byte) BugfixType.HarmonyPatch],
  115. bugfixTypeCount[(byte) BugfixType.Initialiser], bugfixTypeCount[(byte) BugfixType.Workaround],
  116. bugfixTypeCount[(byte) BugfixType.API], bugfixTypeCount[(byte) BugfixType.Debug], total);
  117. return sb.ToString();
  118. }
  119. }
  120. }
  121. }