No Description
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.

UnityConfigurationChecker.cs 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using System.IO;
  2. using UnityEditor;
  3. using Codice.Client.Common;
  4. using Codice.Utils;
  5. using Unity.PlasticSCM.Editor.Tool;
  6. using Unity.PlasticSCM.Editor.Views;
  7. namespace Unity.PlasticSCM.Editor
  8. {
  9. internal static class UnityConfigurationChecker
  10. {
  11. internal static void SynchronizeUnityEditionToken()
  12. {
  13. string plasticClientBinDir = PlasticInstallPath.GetClientBinDir();
  14. if (!string.IsNullOrEmpty(plasticClientBinDir) && !IsPlasticInstalling())
  15. SetupUnityEditionToken.FromPlasticInstallation(plasticClientBinDir);
  16. }
  17. internal static bool NeedsConfiguration()
  18. {
  19. SynchronizeUnityEditionToken();
  20. if (ConfigurationChecker.NeedConfiguration())
  21. return true;
  22. if (ClientConfig.Get().GetClientConfigData().WorkingMode == "SSOWorkingMode" &&
  23. !CmConnection.Get().IsAnyTokenConfigured())
  24. return true;
  25. return false;
  26. }
  27. static bool IsPlasticInstalling()
  28. {
  29. if (!EditorWindow.HasOpenInstances<DownloadPlasticExeDialog>())
  30. return false;
  31. DownloadPlasticExeDialog window = EditorWindow.
  32. GetWindow<DownloadPlasticExeDialog>(null,false);
  33. if (window == null)
  34. return false;
  35. return window.IsPlasticInstalling;
  36. }
  37. }
  38. // The plugin rely on the "cloudedition.token" to be created in the "plastic4e config folder, instead of checking
  39. // the one in the UVCS installation directory, since it can run without an existing installation.
  40. internal static class SetupUnityEditionToken
  41. {
  42. // When called from the Hub; if the UVCS installation directory is found, synchronize the token file from it.
  43. // Else, create the "cloudedition.token" file unconditionally so it's treated as a Cloud Edition going forward.
  44. internal static void CreateCloudEditionTokenIfNeeded()
  45. {
  46. string plasticClientBinDir = PlasticInstallPath.GetClientBinDir();
  47. if (!string.IsNullOrEmpty(plasticClientBinDir))
  48. {
  49. FromPlasticInstallation(plasticClientBinDir);
  50. return;
  51. }
  52. string tokenFilePath = UserConfigFolder.GetConfigFile(EditionToken.CLOUD_EDITION_FILE_NAME);
  53. if (!File.Exists(tokenFilePath))
  54. File.Create(tokenFilePath).Dispose();
  55. }
  56. // Synchronize the "cloudedition.token" file between the installation directory and the "plastic4" config folder
  57. internal static void FromPlasticInstallation(string plasticClientBinDir)
  58. {
  59. bool isCloudPlasticInstall = IsPlasticInstallOfEdition(
  60. plasticClientBinDir,
  61. EditionToken.CLOUD_EDITION_FILE_NAME);
  62. bool isDvcsPlasticInstall = IsPlasticInstallOfEdition(
  63. plasticClientBinDir,
  64. EditionToken.DVCS_EDITION_FILE_NAME);
  65. SetupTokenFiles(
  66. isCloudPlasticInstall,
  67. isDvcsPlasticInstall);
  68. }
  69. static void SetupTokenFiles(
  70. bool isCloudPlasticInstall,
  71. bool isDvcsPlasticInstall)
  72. {
  73. string unityCloudEditionTokenFile = UserConfigFolder.GetConfigFile(
  74. EditionToken.CLOUD_EDITION_FILE_NAME);
  75. string unityDvcsEditionTokenFile = UserConfigFolder.GetConfigFile(
  76. EditionToken.DVCS_EDITION_FILE_NAME);
  77. CreateOrDeleteTokenFile(isCloudPlasticInstall, unityCloudEditionTokenFile);
  78. CreateOrDeleteTokenFile(isDvcsPlasticInstall, unityDvcsEditionTokenFile);
  79. }
  80. static void CreateOrDeleteTokenFile(bool isEdition, string editionTokenFile)
  81. {
  82. if (isEdition && !File.Exists(editionTokenFile))
  83. {
  84. File.Create(editionTokenFile).Dispose();
  85. return;
  86. }
  87. if (!isEdition && File.Exists(editionTokenFile))
  88. {
  89. File.Delete(editionTokenFile);
  90. return;
  91. }
  92. }
  93. static bool IsPlasticInstallOfEdition(
  94. string plasticClientBinDir,
  95. string editionFileName)
  96. {
  97. return File.Exists(Path.Combine(
  98. plasticClientBinDir,
  99. editionFileName));
  100. }
  101. }
  102. }