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_UpdateCheck.cs 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Text.RegularExpressions;
  4. using ProBuilder2.Common;
  5. namespace ProBuilder2.EditorCommon
  6. {
  7. /**
  8. * Check for updates to ProBuilder.
  9. */
  10. [InitializeOnLoad]
  11. static class pb_UpdateCheck
  12. {
  13. const string PROBUILDER_VERSION_URL = "http://procore3d.github.io/probuilder2/current.txt";
  14. const string pbLastWebVersionChecked = "pbLastWebVersionChecked";
  15. static WWW updateQuery;
  16. static bool calledFromMenu = false;
  17. static pb_UpdateCheck()
  18. {
  19. if(pb_PreferencesInternal.GetBool(pb_Constant.pbCheckForProBuilderUpdates))
  20. {
  21. calledFromMenu = false;
  22. CheckForUpdate();
  23. }
  24. }
  25. [MenuItem("Tools/" + pb_Constant.PRODUCT_NAME + "/Check for Updates", false, pb_Constant.MENU_ABOUT + 1)]
  26. static void MenuCheckForUpdate()
  27. {
  28. calledFromMenu = true;
  29. CheckForUpdate();
  30. }
  31. public static void CheckForUpdate()
  32. {
  33. if(updateQuery == null)
  34. {
  35. updateQuery = new WWW(PROBUILDER_VERSION_URL);
  36. EditorApplication.update += Update;
  37. }
  38. }
  39. static void Update()
  40. {
  41. if (updateQuery != null)
  42. {
  43. if (!updateQuery.isDone)
  44. return;
  45. try
  46. {
  47. if (string.IsNullOrEmpty(updateQuery.error) || !Regex.IsMatch(updateQuery.text, "404 not found", RegexOptions.IgnoreCase) )
  48. {
  49. pb_VersionInfo webVersion;
  50. string webChangelog;
  51. if(!pb_VersionUtil.FormatChangelog(updateQuery.text, out webVersion, out webChangelog))
  52. {
  53. FailedConnection();
  54. }
  55. else
  56. {
  57. pb_VersionInfo current;
  58. // first test if the installed version is already up to date
  59. if( !pb_VersionUtil.GetCurrent(out current) || webVersion.CompareTo(current) > 0 )
  60. {
  61. // next, test if a notification for this version has already been shown
  62. string lastNotification = pb_PreferencesInternal.GetString(pbLastWebVersionChecked, "");
  63. if(calledFromMenu || !lastNotification.Equals(webVersion.text))
  64. {
  65. pb_UpdateAvailable.Init(webVersion, webChangelog);
  66. pb_PreferencesInternal.SetString(pbLastWebVersionChecked, webVersion.text);
  67. }
  68. }
  69. else
  70. {
  71. UpToDate(current.ToString());
  72. }
  73. }
  74. }
  75. else
  76. {
  77. FailedConnection();
  78. }
  79. }
  80. catch(System.Exception e)
  81. {
  82. FailedConnection(string.Format("Error: Is build target is Webplayer?\n\n{0}", e.ToString()));
  83. }
  84. updateQuery = null;
  85. }
  86. calledFromMenu = false;
  87. EditorApplication.update -= Update;
  88. }
  89. static void UpToDate(string version)
  90. {
  91. if(calledFromMenu)
  92. EditorUtility.DisplayDialog("ProBuilder Update Check", string.Format("You're up to date!\n\nInstalled Version: {0}\nLatest Version: {0}", version), "Okay");
  93. }
  94. static void FailedConnection(string error = null)
  95. {
  96. if(calledFromMenu)
  97. EditorUtility.DisplayDialog(
  98. "ProBuilder Update Check",
  99. error == null ? "Failed to connect to server!" : string.Format("Failed to connect to server!\n\n{0}", error.ToString()),
  100. "Okay");
  101. }
  102. }
  103. }