暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

CloudProjectDownloader.cs 2.8KB

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