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 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using System.IO;
  2. using Codice.Client.Common;
  3. using Codice.CM.Common;
  4. using Codice.Utils;
  5. using Unity.PlasticSCM.Editor.Tool;
  6. using Unity.PlasticSCM.Editor.Views;
  7. using UnityEditor;
  8. namespace Unity.PlasticSCM.Editor
  9. {
  10. internal static class UnityConfigurationChecker
  11. {
  12. internal static bool NeedsConfiguration()
  13. {
  14. string plasticClientBinDir = PlasticInstallPath.GetClientBinDir();
  15. if (!string.IsNullOrEmpty(plasticClientBinDir) && !IsPlasticInstalling())
  16. SetupUnityEditionToken.FromPlasticInstallation(plasticClientBinDir);
  17. if (ConfigurationChecker.NeedConfiguration())
  18. return true;
  19. if (ClientConfig.Get().GetClientConfigData().WorkingMode == "SSOWorkingMode" &&
  20. !CmConnection.Get().IsAnyTokenConfigured())
  21. return true;
  22. return false;
  23. }
  24. static bool IsPlasticInstalling()
  25. {
  26. if (!EditorWindow.HasOpenInstances<DownloadPlasticExeWindow>())
  27. return false;
  28. DownloadPlasticExeWindow window = EditorWindow.
  29. GetWindow<DownloadPlasticExeWindow>(null,false);
  30. if (window == null)
  31. return false;
  32. return window.IsPlasticInstalling;
  33. }
  34. }
  35. internal static class SetupUnityEditionToken
  36. {
  37. internal static void CreateCloudEditionTokenIfNeeded()
  38. {
  39. string toolPath = PlasticInstallPath.GetPlasticExePath();
  40. if (!string.IsNullOrEmpty(toolPath))
  41. return;
  42. string tokenFilePath = UserConfigFolder.GetConfigFile(
  43. EditionToken.CLOUD_EDITION_FILE_NAME);
  44. File.Create(tokenFilePath).Dispose();
  45. }
  46. internal static void FromPlasticInstallation(string plasticClientBinDir)
  47. {
  48. bool isCloudPlasticInstall = IsPlasticInstallOfEdition(
  49. plasticClientBinDir,
  50. EditionToken.CLOUD_EDITION_FILE_NAME);
  51. bool isDvcsPlasticInstall = IsPlasticInstallOfEdition(
  52. plasticClientBinDir,
  53. EditionToken.DVCS_EDITION_FILE_NAME);
  54. SetupTokenFiles(
  55. isCloudPlasticInstall,
  56. isDvcsPlasticInstall);
  57. }
  58. static void SetupTokenFiles(
  59. bool isCloudPlasticInstall,
  60. bool isDvcsPlasticInstall)
  61. {
  62. string unityCloudEditionTokenFile = UserConfigFolder.GetConfigFile(
  63. EditionToken.CLOUD_EDITION_FILE_NAME);
  64. string unityDvcsEditionTokenFile = UserConfigFolder.GetConfigFile(
  65. EditionToken.DVCS_EDITION_FILE_NAME);
  66. CreateOrDeleteTokenFile(isCloudPlasticInstall, unityCloudEditionTokenFile);
  67. CreateOrDeleteTokenFile(isDvcsPlasticInstall, unityDvcsEditionTokenFile);
  68. }
  69. static void CreateOrDeleteTokenFile(bool isEdition, string editionTokenFile)
  70. {
  71. if (isEdition && !File.Exists(editionTokenFile))
  72. {
  73. File.Create(editionTokenFile).Dispose();
  74. return;
  75. }
  76. if (!isEdition && File.Exists(editionTokenFile))
  77. {
  78. File.Delete(editionTokenFile);
  79. return;
  80. }
  81. }
  82. static bool IsPlasticInstallOfEdition(
  83. string plasticClientBinDir,
  84. string editionFileName)
  85. {
  86. return File.Exists(Path.Combine(
  87. plasticClientBinDir,
  88. editionFileName));
  89. }
  90. }
  91. }