The Swartz-Manning’s first exhibit will provide a detailed history of Aaron Swartz Day. https://www.aaronswartzday.org/vr
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pb_VersionUtil.cs 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.IO;
  4. using System.Text;
  5. using System.Collections;
  6. using System.Text.RegularExpressions;
  7. namespace ProBuilder2.EditorCommon
  8. {
  9. /**
  10. * Contains information that the pb_AboutEntry.txt file holds.
  11. */
  12. [System.Serializable]
  13. internal class pb_AboutEntry
  14. {
  15. public string name;
  16. public string identifier;
  17. public string version;
  18. public string date;
  19. public string changelogPath;
  20. public const string KEY_NAME = "name: ";
  21. public const string KEY_IDENTIFIER = "identifier: ";
  22. public const string KEY_VERSION = "version: ";
  23. public const string KEY_DATE = "date: ";
  24. public const string KEY_CHANGELOG = "changelog: ";
  25. }
  26. /**
  27. * Utility methods for finding and extracting version & changelog information.
  28. */
  29. internal static class pb_VersionUtil
  30. {
  31. /**
  32. * Get information from the currently installed ProBuilder version.
  33. */
  34. public static bool GetAboutEntry(out pb_AboutEntry about)
  35. {
  36. about = null;
  37. string[] matches = Directory.GetFiles("./Assets", "pc_AboutEntry_ProBuilder.txt", SearchOption.AllDirectories);
  38. if(matches == null || matches.Length < 1)
  39. return false;
  40. for(int i = 0; i < matches.Length && about == null; i++)
  41. about = ParseAboutEntry(matches[i]);
  42. return about != null;
  43. }
  44. public static bool GetCurrent(out pb_VersionInfo version)
  45. {
  46. pb_AboutEntry about;
  47. if(!GetAboutEntry(out about))
  48. {
  49. version = new pb_VersionInfo();
  50. return false;
  51. }
  52. version = pb_VersionInfo.FromString(about.version);
  53. return true;
  54. }
  55. /**
  56. * Extracts and formats the latest changelog entry into rich text. Also grabs the version.
  57. */
  58. public static bool FormatChangelog(string raw, out pb_VersionInfo version, out string formatted_changes)
  59. {
  60. bool success = true;
  61. // get first version entry
  62. string[] split = Regex.Split(raw, "(?mi)^#\\s", RegexOptions.Multiline);
  63. // get the version info
  64. try
  65. {
  66. Match versionMatch = Regex.Match(split[1], @"(?<=^ProBuilder\s).[0-9]*\.[0-9]*\.[0-9]*[a-z][0-9]*");
  67. version = pb_VersionInfo.FromString(versionMatch.Success ? versionMatch.Value : split[1].Split('\n')[0]);
  68. }
  69. catch
  70. {
  71. version = pb_VersionInfo.FromString("not found");
  72. success = false;
  73. }
  74. try
  75. {
  76. StringBuilder sb = new StringBuilder();
  77. string[] newLineSplit = split[1].Trim().Split('\n');
  78. for(int i = 2; i < newLineSplit.Length; i++)
  79. sb.AppendLine(newLineSplit[i]);
  80. formatted_changes = sb.ToString();
  81. formatted_changes = Regex.Replace(formatted_changes, "^-", "\u2022", RegexOptions.Multiline);
  82. formatted_changes = Regex.Replace(formatted_changes, @"(?<=^##\\s).*", "<size=16><b>${0}</b></size>", RegexOptions.Multiline);
  83. formatted_changes = Regex.Replace(formatted_changes, @"^##\ ", "", RegexOptions.Multiline);
  84. }
  85. catch
  86. {
  87. formatted_changes = "";
  88. success = false;
  89. }
  90. return success;
  91. }
  92. private static pb_AboutEntry ParseAboutEntry(string path)
  93. {
  94. if (!File.Exists(path))
  95. return null;
  96. pb_AboutEntry about = new pb_AboutEntry();
  97. foreach(string str in File.ReadAllLines(path))
  98. {
  99. if(str.StartsWith(pb_AboutEntry.KEY_NAME))
  100. about.name = str.Replace(pb_AboutEntry.KEY_NAME, "").Trim();
  101. else if(str.StartsWith(pb_AboutEntry.KEY_IDENTIFIER))
  102. about.identifier = str.Replace(pb_AboutEntry.KEY_IDENTIFIER, "").Trim();
  103. else if(str.StartsWith(pb_AboutEntry.KEY_VERSION))
  104. about.version = str.Replace(pb_AboutEntry.KEY_VERSION, "").Trim();
  105. else if(str.StartsWith(pb_AboutEntry.KEY_DATE))
  106. about.date = str.Replace(pb_AboutEntry.KEY_DATE, "").Trim();
  107. else if(str.StartsWith(pb_AboutEntry.KEY_CHANGELOG))
  108. about.changelogPath = str.Replace(pb_AboutEntry.KEY_CHANGELOG, "").Trim();
  109. }
  110. return about;
  111. }
  112. }
  113. }