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.

ProcessCommand.cs 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEditor;
  4. using Codice.LogWrapper;
  5. using Unity.PlasticSCM.Editor.Hub.Operations;
  6. namespace Unity.PlasticSCM.Editor.Hub
  7. {
  8. internal static class ProcessCommand
  9. {
  10. internal const string IS_PROCESS_COMMAND_ALREADY_EXECUTED_KEY =
  11. "PlasticSCM.ProcessCommand.IsAlreadyExecuted";
  12. internal const string IS_PLASTIC_COMMAND_KEY =
  13. "PlasticSCM.ProcessCommand.IsPlasticCommand";
  14. internal static void Initialize()
  15. {
  16. EditorApplication.update += RunOnceWhenAccessTokenIsInitialized;
  17. }
  18. static void RunOnceWhenAccessTokenIsInitialized()
  19. {
  20. if (string.IsNullOrEmpty(CloudProjectSettings.accessToken))
  21. return;
  22. EditorApplication.update -= RunOnceWhenAccessTokenIsInitialized;
  23. Execute(CloudProjectSettings.accessToken);
  24. }
  25. static void Execute(string unityAccessToken)
  26. {
  27. if (SessionState.GetBool(
  28. IS_PROCESS_COMMAND_ALREADY_EXECUTED_KEY, false))
  29. {
  30. return;
  31. }
  32. ProcessCommandFromArgs(
  33. Environment.GetCommandLineArgs(),
  34. unityAccessToken);
  35. SessionState.SetBool(
  36. IS_PROCESS_COMMAND_ALREADY_EXECUTED_KEY, true);
  37. }
  38. internal static void ProcessCommandFromArgs(
  39. string[] commandLineArgs,
  40. string unityAccessToken)
  41. {
  42. Dictionary<string, string> args =
  43. CommandLineArguments.Build(commandLineArgs);
  44. mLog.DebugFormat(
  45. "Processing Unity arguments: {0}",
  46. string.Join(" ", commandLineArgs));
  47. ParseArguments.Command command =
  48. ParseArguments.GetCommand(args);
  49. if (!command.IsValid())
  50. {
  51. mLog.Debug("There is no valid command to process");
  52. return;
  53. }
  54. SessionState.SetBool(
  55. IS_PLASTIC_COMMAND_KEY, true);
  56. mLog.DebugFormat("Processing command: {0}", command.OperationType);
  57. OperationParams parameters = OperationParams.
  58. BuildFromCommand(command, unityAccessToken);
  59. switch (command.OperationType)
  60. {
  61. case ParseArguments.Command.Operation.CreateWorkspace:
  62. CreateWorkspace.LaunchOperation(parameters);
  63. return;
  64. case ParseArguments.Command.Operation.DownloadRepository:
  65. DownloadRepository.LaunchOperation(parameters);
  66. return;
  67. }
  68. }
  69. static readonly ILog mLog = PlasticApp.GetLogger("ProcessCommand");
  70. }
  71. }