CloudProjectDownloader.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using UnityEditor;
  5. using UnityEngine;
  6. using Codice.LogWrapper;
  7. namespace Unity.PlasticSCM.Editor.ProjectDownloader
  8. {
  9. [InitializeOnLoad]
  10. internal static class CloudProjectDownloader
  11. {
  12. static CloudProjectDownloader()
  13. {
  14. EditorApplication.update += RunOnceWhenAccessTokenIsInitialized;
  15. }
  16. static void RunOnceWhenAccessTokenIsInitialized()
  17. {
  18. if (string.IsNullOrEmpty(CloudProjectSettings.accessToken))
  19. return;
  20. EditorApplication.update -= RunOnceWhenAccessTokenIsInitialized;
  21. Execute(CloudProjectSettings.accessToken);
  22. }
  23. static void Execute(string unityAccessToken)
  24. {
  25. if (SessionState.GetBool(
  26. IS_PROJECT_DOWNLOADER_ALREADY_EXECUTED_KEY, false))
  27. {
  28. return;
  29. }
  30. SessionState.SetBool(
  31. IS_PROJECT_DOWNLOADER_ALREADY_EXECUTED_KEY, true);
  32. DownloadRepository(unityAccessToken);
  33. }
  34. internal static void DownloadRepository(string unityAccessToken)
  35. {
  36. DownloadRepository(unityAccessToken, Environment.GetCommandLineArgs());
  37. }
  38. internal static void DownloadRepository(string unityAccessToken, string[] commandLineArgs)
  39. {
  40. Dictionary<string, string> args = CommandLineArguments.Build(commandLineArgs);
  41. mLog.DebugFormat(
  42. "Processing Unity arguments: {0}", string.Join(" ", commandLineArgs));
  43. string projectPath = ParseArguments.ProjectPath(args);
  44. string cloudRepository = ParseArguments.CloudProject(args);
  45. string cloudOrganization = ParseArguments.CloudOrganization(args);
  46. if (string.IsNullOrEmpty(projectPath) ||
  47. string.IsNullOrEmpty(cloudRepository) ||
  48. string.IsNullOrEmpty(cloudOrganization))
  49. return;
  50. PlasticApp.InitializeIfNeeded();
  51. DownloadRepositoryOperation downloadOperation =
  52. new DownloadRepositoryOperation();
  53. downloadOperation.DownloadRepositoryToPathIfNeeded(
  54. cloudRepository,
  55. cloudOrganization,
  56. Path.GetFullPath(projectPath),
  57. unityAccessToken);
  58. }
  59. const string IS_PROJECT_DOWNLOADER_ALREADY_EXECUTED_KEY =
  60. "PlasticSCM.ProjectDownloader.IsAlreadyExecuted";
  61. static readonly ILog mLog = LogManager.GetLogger("ProjectDownloader");
  62. }
  63. }