first commit
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Unity.PlasticSCM.Editor.Hub
|
||||
{
|
||||
internal class CommandLineArguments
|
||||
{
|
||||
internal static Dictionary<string, string> Build(string[] args)
|
||||
{
|
||||
Dictionary<string, string> result = new Dictionary<string, string>(
|
||||
StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
if (args == null)
|
||||
return result;
|
||||
List<string> trimmedArguments = TrimArgs(args);
|
||||
|
||||
int index = 1;
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (index > trimmedArguments.Count - 1)
|
||||
break;
|
||||
|
||||
if (IsKeyValueArgumentAtIndex(trimmedArguments, index))
|
||||
{
|
||||
result[trimmedArguments[index]] = trimmedArguments[index + 1];
|
||||
index += 2;
|
||||
continue;
|
||||
}
|
||||
|
||||
result[trimmedArguments[index]] = null;
|
||||
index += 1;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static List<string> TrimArgs(string[] args)
|
||||
{
|
||||
List<string> trimmedArguments = new List<string>();
|
||||
|
||||
foreach (string argument in args)
|
||||
trimmedArguments.Add(argument.Trim());
|
||||
|
||||
return trimmedArguments;
|
||||
}
|
||||
|
||||
static bool IsKeyValueArgumentAtIndex(
|
||||
List<string> trimmedArguments,
|
||||
int index)
|
||||
{
|
||||
if (index + 1 > trimmedArguments.Count -1)
|
||||
return false;
|
||||
|
||||
return !trimmedArguments[index + 1].StartsWith("-");
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4675673a75b20a14da0806d155b5680c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b51b4ac3066a00144817d6c4f8c36c71
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,271 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
using UnityEditor;
|
||||
|
||||
using Codice.Client.Common.EventTracking;
|
||||
using Codice.CM.Common;
|
||||
using Codice.LogWrapper;
|
||||
using PlasticGui;
|
||||
using PlasticGui.Help.Conditions;
|
||||
using PlasticGui.WebApi.Responses;
|
||||
using Unity.PlasticSCM.Editor.AssetUtils;
|
||||
using Unity.PlasticSCM.Editor.Configuration;
|
||||
using Unity.PlasticSCM.Editor.UI;
|
||||
using Unity.PlasticSCM.Editor.Views.CreateWorkspace;
|
||||
using Unity.PlasticSCM.Editor.WebApi;
|
||||
|
||||
namespace Unity.PlasticSCM.Editor.Hub.Operations
|
||||
{
|
||||
internal class CreateWorkspace
|
||||
{
|
||||
internal static void LaunchOperation(
|
||||
OperationParams parameters)
|
||||
{
|
||||
PlasticApp.InitializeIfNeeded();
|
||||
|
||||
CreateWorkspace createWorkspaceOperation =
|
||||
new CreateWorkspace();
|
||||
|
||||
createWorkspaceOperation.CreateWorkspaceOperation(
|
||||
parameters);
|
||||
}
|
||||
|
||||
internal static WorkspaceInfo CreateWorkspaceForRepSpec(
|
||||
RepositorySpec repositorySpec,
|
||||
string wkPath,
|
||||
ILog log)
|
||||
{
|
||||
CreateWorkspaceDialogUserAssistant assistant =
|
||||
CreateWorkspaceDialogUserAssistant.ForWkPathAndName(
|
||||
PlasticGuiConfig.Get().Configuration.DefaultWorkspaceRoot,
|
||||
PlasticGui.Plastic.API.GetAllWorkspacesArray());
|
||||
|
||||
assistant.RepositoryChanged(
|
||||
repositorySpec.ToString(),
|
||||
string.Empty,
|
||||
string.Empty);
|
||||
|
||||
WorkspaceInfo wkInfo = PlasticGui.Plastic.API.CreateWorkspace(
|
||||
wkPath,
|
||||
assistant.GetProposedWorkspaceName(),
|
||||
repositorySpec.ToString());
|
||||
|
||||
log.DebugFormat("Created workspace {0} on {1}",
|
||||
wkInfo.Name,
|
||||
wkInfo.ClientPath);
|
||||
|
||||
return wkInfo;
|
||||
}
|
||||
|
||||
void CreateWorkspaceOperation(
|
||||
OperationParams parameters)
|
||||
{
|
||||
RefreshAsset.BeforeLongAssetOperation();
|
||||
|
||||
try
|
||||
{
|
||||
ThreadPool.QueueUserWorkItem(
|
||||
CreateWorkspaceIfNeeded,
|
||||
parameters);
|
||||
|
||||
while (mStatus != Status.Finished)
|
||||
{
|
||||
if (mDisplayProgress)
|
||||
{
|
||||
DisplayProgress(
|
||||
mStatus, parameters.Repository);
|
||||
}
|
||||
|
||||
Thread.Sleep(150);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
EditorUtility.ClearProgressBar();
|
||||
|
||||
RefreshAsset.AfterLongAssetOperation();
|
||||
|
||||
if (!mOperationFailed)
|
||||
{
|
||||
PlasticPlugin.Enable();
|
||||
ShowWindow.PlasticDisablingCollab();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CreateWorkspaceIfNeeded(object state)
|
||||
{
|
||||
OperationParams parameters = (OperationParams)state;
|
||||
|
||||
try
|
||||
{
|
||||
if (FindWorkspace.HasWorkspace(parameters.WorkspaceFullPath))
|
||||
{
|
||||
// each domain reload, the package is reloaded.
|
||||
// way need to check if we already created it
|
||||
return;
|
||||
}
|
||||
|
||||
mDisplayProgress = true;
|
||||
|
||||
mStatus = Status.ConfiguringCredentials;
|
||||
|
||||
TokenExchangeResponse tokenExchangeResponse =
|
||||
AutoConfig.PlasticCredentials(
|
||||
parameters.AccessToken,
|
||||
parameters.RepositorySpec.Server);
|
||||
|
||||
if (tokenExchangeResponse.Error != null)
|
||||
{
|
||||
mOperationFailed = true;
|
||||
|
||||
LogTokenExchangeErrorInConsole(
|
||||
tokenExchangeResponse.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
mStatus = Status.CreatingWorkspace;
|
||||
|
||||
TrackFeatureUseEvent.For(
|
||||
parameters.RepositorySpec, TrackFeatureUseEvent.
|
||||
Features.UnityPackage.CreateWorkspaceFromHub);
|
||||
|
||||
WorkspaceInfo wkInfo = CreateWorkspaceForRepSpec(
|
||||
parameters.RepositorySpec,
|
||||
parameters.WorkspaceFullPath,
|
||||
mLog);
|
||||
|
||||
mStatus = Status.PerformingInitialCheckin;
|
||||
|
||||
PerformInitialCheckinIfRepositoryIsEmpty(
|
||||
wkInfo, parameters.RepositorySpec,
|
||||
PlasticGui.Plastic.API, mLog);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogException(ex);
|
||||
LogExceptionErrorInConsole(ex);
|
||||
|
||||
mOperationFailed = true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
mStatus = Status.Finished;
|
||||
}
|
||||
}
|
||||
|
||||
static void PerformInitialCheckinIfRepositoryIsEmpty(
|
||||
WorkspaceInfo wkInfo,
|
||||
RepositorySpec repositorySpec,
|
||||
IPlasticAPI plasticApi,
|
||||
ILog log)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool isEmptyRepository = IsEmptyRepositoryCondition.
|
||||
Evaluate(wkInfo, repositorySpec, plasticApi);
|
||||
|
||||
if (!isEmptyRepository)
|
||||
return;
|
||||
|
||||
PerformInitialCheckin.PerformCheckinPackagesAndProjectSettingsFolders(
|
||||
wkInfo, false, plasticApi);
|
||||
|
||||
log.DebugFormat("Created initial checkin on repository '{0}'",
|
||||
repositorySpec.ToString());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// create the initial checkin if it's possible, otherwise
|
||||
// just log the exception (no error shown for the user)
|
||||
LogException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
static void DisplayProgress(
|
||||
Status status,
|
||||
string repository)
|
||||
{
|
||||
string progressMessage = GetProgressString(status);
|
||||
|
||||
float progressPercent = (int)status / (float)Status.Finished;
|
||||
|
||||
EditorUtility.DisplayProgressBar(
|
||||
string.Format("{0} {1}",
|
||||
PlasticLocalization.GetString(
|
||||
PlasticLocalization.Name.CreatingWorkspaceProgress),
|
||||
repository),
|
||||
progressMessage, progressPercent);
|
||||
}
|
||||
|
||||
static void LogTokenExchangeErrorInConsole(ErrorResponse.ErrorFields error)
|
||||
{
|
||||
UnityEngine.Debug.LogErrorFormat(
|
||||
PlasticLocalization.GetString(
|
||||
PlasticLocalization.Name.ErrorCreatingWorkspaceForProject),
|
||||
string.Format("Unable to get TokenExchangeResponse: {0} [code {1}]",
|
||||
error.Message, error.ErrorCode));
|
||||
}
|
||||
|
||||
static void LogExceptionErrorInConsole(Exception ex)
|
||||
{
|
||||
UnityEngine.Debug.LogErrorFormat(
|
||||
PlasticLocalization.GetString(
|
||||
PlasticLocalization.Name.ErrorCreatingWorkspaceForProject),
|
||||
ex.Message);
|
||||
}
|
||||
|
||||
static void LogException(Exception ex)
|
||||
{
|
||||
mLog.WarnFormat("Message: {0}", ex.Message);
|
||||
|
||||
mLog.DebugFormat(
|
||||
"StackTrace:{0}{1}",
|
||||
Environment.NewLine, ex.StackTrace);
|
||||
}
|
||||
|
||||
static string GetProgressString(Status status)
|
||||
{
|
||||
switch (status)
|
||||
{
|
||||
case Status.Starting:
|
||||
return PlasticLocalization.GetString(
|
||||
PlasticLocalization.Name.CreateWorkspaceProgressStarting);
|
||||
case Status.ConfiguringCredentials:
|
||||
return PlasticLocalization.GetString(
|
||||
PlasticLocalization.Name.CreateWorkspaceProgressConfiguringCredentials);
|
||||
case Status.CreatingWorkspace:
|
||||
return PlasticLocalization.GetString(
|
||||
PlasticLocalization.Name.CreateWorkspaceProgressCreatingWorkspace);
|
||||
case Status.PerformingInitialCheckin:
|
||||
return PlasticLocalization.GetString(
|
||||
PlasticLocalization.Name.CreateWorkspaceProgressPerformingInitialCheckin);
|
||||
case Status.Finished:
|
||||
return PlasticLocalization.GetString(
|
||||
PlasticLocalization.Name.CreateWorkspaceProgressFinished);
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
CreateWorkspace()
|
||||
{
|
||||
}
|
||||
|
||||
enum Status : int
|
||||
{
|
||||
Starting = 1,
|
||||
ConfiguringCredentials = 2,
|
||||
CreatingWorkspace = 3,
|
||||
PerformingInitialCheckin = 4,
|
||||
Finished = 5
|
||||
};
|
||||
|
||||
volatile Status mStatus = Status.Starting;
|
||||
volatile bool mOperationFailed = false;
|
||||
volatile bool mDisplayProgress;
|
||||
|
||||
static readonly ILog mLog = PlasticApp.GetLogger("CreateWorkspace");
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de7c5b4b6cb58e546b24137064ac9025
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,192 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
using UnityEditor;
|
||||
|
||||
using Codice.Client.BaseCommands;
|
||||
using Codice.Client.Commands;
|
||||
using Codice.Client.Common.EventTracking;
|
||||
using Codice.CM.Common;
|
||||
using Codice.LogWrapper;
|
||||
using PlasticGui;
|
||||
using PlasticGui.WebApi.Responses;
|
||||
using PlasticGui.WorkspaceWindow;
|
||||
using PlasticGui.WorkspaceWindow.Update;
|
||||
using Unity.PlasticSCM.Editor.AssetUtils;
|
||||
using Unity.PlasticSCM.Editor.UI;
|
||||
using Unity.PlasticSCM.Editor.WebApi;
|
||||
using Unity.PlasticSCM.Editor.Configuration;
|
||||
|
||||
namespace Unity.PlasticSCM.Editor.Hub.Operations
|
||||
{
|
||||
internal class DownloadRepository
|
||||
{
|
||||
internal static void LaunchOperation(
|
||||
OperationParams parameters)
|
||||
{
|
||||
PlasticApp.InitializeIfNeeded();
|
||||
|
||||
DownloadRepository downloadOperation =
|
||||
new DownloadRepository();
|
||||
|
||||
downloadOperation.DownloadRepositoryOperation(
|
||||
parameters);
|
||||
}
|
||||
|
||||
void DownloadRepositoryOperation(
|
||||
OperationParams parameters)
|
||||
{
|
||||
RefreshAsset.BeforeLongAssetOperation();
|
||||
|
||||
try
|
||||
{
|
||||
BuildProgressSpeedAndRemainingTime.ProgressData progressData =
|
||||
new BuildProgressSpeedAndRemainingTime.ProgressData(DateTime.Now);
|
||||
|
||||
ThreadPool.QueueUserWorkItem(
|
||||
DownloadRepositoryToPathIfNeeded,
|
||||
parameters);
|
||||
|
||||
while (!mOperationFinished)
|
||||
{
|
||||
if (mDisplayProgress)
|
||||
{
|
||||
DisplayProgress(
|
||||
mUpdateNotifier.GetUpdateStatus(),
|
||||
progressData,
|
||||
parameters.Repository);
|
||||
}
|
||||
|
||||
Thread.Sleep(150);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
EditorUtility.ClearProgressBar();
|
||||
|
||||
RefreshAsset.AfterLongAssetOperation();
|
||||
|
||||
if (!mOperationFailed)
|
||||
{
|
||||
PlasticPlugin.Enable();
|
||||
ShowWindow.PlasticDisablingCollab();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DownloadRepositoryToPathIfNeeded(object state)
|
||||
{
|
||||
OperationParams parameters = (OperationParams)state;
|
||||
|
||||
try
|
||||
{
|
||||
if (FindWorkspace.HasWorkspace(parameters.WorkspaceFullPath))
|
||||
{
|
||||
// each domain reload, the package is reloaded.
|
||||
// way need to check if we already downloaded it
|
||||
return;
|
||||
}
|
||||
|
||||
mDisplayProgress = true;
|
||||
|
||||
TokenExchangeResponse tokenExchangeResponse =
|
||||
AutoConfig.PlasticCredentials(
|
||||
parameters.AccessToken,
|
||||
parameters.RepositorySpec.Server);
|
||||
|
||||
if (tokenExchangeResponse.Error != null)
|
||||
{
|
||||
mOperationFailed = true;
|
||||
|
||||
LogTokenExchangeErrorInConsole(
|
||||
tokenExchangeResponse.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
TrackFeatureUseEvent.For(
|
||||
parameters.RepositorySpec, TrackFeatureUseEvent.
|
||||
Features.UnityPackage.DownloadRepositoryFromHub);
|
||||
|
||||
WorkspaceInfo wkInfo = CreateWorkspace.
|
||||
CreateWorkspaceForRepSpec(
|
||||
parameters.RepositorySpec,
|
||||
parameters.WorkspaceFullPath,
|
||||
mLog);
|
||||
|
||||
PlasticGui.Plastic.API.Update(
|
||||
wkInfo.ClientPath,
|
||||
UpdateFlags.None,
|
||||
null,
|
||||
mUpdateNotifier);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogException(ex);
|
||||
LogExceptionErrorInConsole(ex);
|
||||
|
||||
mOperationFailed = true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
mOperationFinished = true;
|
||||
}
|
||||
}
|
||||
|
||||
static void DisplayProgress(
|
||||
UpdateOperationStatus status,
|
||||
BuildProgressSpeedAndRemainingTime.ProgressData progressData,
|
||||
string cloudRepository)
|
||||
{
|
||||
string totalProgressMessage = UpdateProgressRender.
|
||||
GetProgressString(status, progressData);
|
||||
|
||||
float totalProgressPercent = GetProgressBarPercent.
|
||||
ForTransfer(status.UpdatedSize, status.TotalSize) / 100f;
|
||||
|
||||
EditorUtility.DisplayProgressBar(
|
||||
string.Format("{0} {1}",
|
||||
PlasticLocalization.GetString(
|
||||
PlasticLocalization.Name.DownloadingProgress),
|
||||
cloudRepository),
|
||||
totalProgressMessage, totalProgressPercent);
|
||||
}
|
||||
|
||||
static void LogTokenExchangeErrorInConsole(ErrorResponse.ErrorFields error)
|
||||
{
|
||||
UnityEngine.Debug.LogErrorFormat(
|
||||
PlasticLocalization.GetString(
|
||||
PlasticLocalization.Name.ErrorDownloadingCloudProject),
|
||||
string.Format("Unable to get TokenExchangeResponse: {0} [code {1}]",
|
||||
error.Message, error.ErrorCode));
|
||||
}
|
||||
|
||||
static void LogExceptionErrorInConsole(Exception ex)
|
||||
{
|
||||
UnityEngine.Debug.LogErrorFormat(
|
||||
PlasticLocalization.GetString(
|
||||
PlasticLocalization.Name.ErrorDownloadingCloudProject),
|
||||
ex.Message);
|
||||
}
|
||||
|
||||
static void LogException(Exception ex)
|
||||
{
|
||||
mLog.WarnFormat("Message: {0}", ex.Message);
|
||||
|
||||
mLog.DebugFormat(
|
||||
"StackTrace:{0}{1}",
|
||||
Environment.NewLine, ex.StackTrace);
|
||||
}
|
||||
|
||||
DownloadRepository()
|
||||
{
|
||||
}
|
||||
|
||||
volatile bool mOperationFinished = false;
|
||||
volatile bool mOperationFailed = false;
|
||||
volatile bool mDisplayProgress;
|
||||
|
||||
UpdateNotifier mUpdateNotifier = new UpdateNotifier();
|
||||
|
||||
static readonly ILog mLog = PlasticApp.GetLogger("DownloadRepository");
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 608efd4e185fb9440bb8550d98e20ca4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,60 @@
|
||||
using System.IO;
|
||||
|
||||
using Codice.CM.Common;
|
||||
using PlasticGui.WebApi;
|
||||
|
||||
namespace Unity.PlasticSCM.Editor.Hub.Operations
|
||||
{
|
||||
internal class OperationParams
|
||||
{
|
||||
internal readonly string WorkspaceFullPath;
|
||||
internal readonly string Organization;
|
||||
internal readonly string Repository;
|
||||
internal readonly RepositorySpec RepositorySpec;
|
||||
internal readonly string AccessToken;
|
||||
|
||||
internal static OperationParams BuildFromCommand(
|
||||
ParseArguments.Command command,
|
||||
string unityAccessToken)
|
||||
{
|
||||
string workspaceFullPath = command.HasWorkspacePath() ?
|
||||
Path.GetFullPath(command.WorkspacePath) :
|
||||
Path.GetFullPath(command.ProjectPath);
|
||||
|
||||
return new OperationParams(
|
||||
workspaceFullPath,
|
||||
command.Organization,
|
||||
command.Repository,
|
||||
BuildRepositorySpec(
|
||||
command.Organization, command.Repository),
|
||||
unityAccessToken);
|
||||
}
|
||||
|
||||
static RepositorySpec BuildRepositorySpec(
|
||||
string organization,
|
||||
string repository)
|
||||
{
|
||||
string defaultCloudAlias = new PlasticWebRestApi()
|
||||
.GetDefaultCloudAlias();
|
||||
|
||||
return RepositorySpec.BuildFromNameAndResolvedServer(
|
||||
repository,
|
||||
CloudServer.BuildFullyQualifiedName(organization, defaultCloudAlias)
|
||||
);
|
||||
}
|
||||
|
||||
OperationParams(
|
||||
string workspaceFullPath,
|
||||
string organization,
|
||||
string repository,
|
||||
RepositorySpec repositorySpec,
|
||||
string accessToken)
|
||||
{
|
||||
WorkspaceFullPath = workspaceFullPath;
|
||||
Organization = organization;
|
||||
Repository = repository;
|
||||
RepositorySpec = repositorySpec;
|
||||
AccessToken = accessToken;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7985a2b6ab3fac849929b1e2d51fe9cf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,211 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Unity.PlasticSCM.Editor.Hub
|
||||
{
|
||||
internal static class ParseArguments
|
||||
{
|
||||
internal class Command
|
||||
{
|
||||
internal enum Operation
|
||||
{
|
||||
None,
|
||||
DownloadRepository,
|
||||
CreateWorkspace
|
||||
}
|
||||
|
||||
internal readonly string ProjectPath;
|
||||
internal readonly string WorkspacePath;
|
||||
internal readonly string Organization;
|
||||
internal readonly string Repository;
|
||||
internal readonly Operation OperationType;
|
||||
|
||||
internal Command(
|
||||
string projectPath,
|
||||
string workspacePath,
|
||||
string organization,
|
||||
string repository,
|
||||
Operation operationType)
|
||||
{
|
||||
ProjectPath = projectPath;
|
||||
WorkspacePath = workspacePath;
|
||||
Organization = organization;
|
||||
Repository = repository;
|
||||
OperationType = operationType;
|
||||
}
|
||||
|
||||
internal bool IsValid()
|
||||
{
|
||||
return !string.IsNullOrEmpty(ProjectPath)
|
||||
&& !string.IsNullOrEmpty(Organization)
|
||||
&& !string.IsNullOrEmpty(Repository)
|
||||
&& OperationType != Operation.None;
|
||||
}
|
||||
|
||||
internal bool HasWorkspacePath()
|
||||
{
|
||||
return !string.IsNullOrEmpty(WorkspacePath);
|
||||
}
|
||||
}
|
||||
|
||||
internal static Command GetCommand(Dictionary<string, string> args)
|
||||
{
|
||||
return new Command(
|
||||
GetProjectPath(args),
|
||||
GetWorkspacePath(args),
|
||||
GetOrganization(args),
|
||||
GetRepository(args),
|
||||
GetOperation(args));
|
||||
}
|
||||
|
||||
internal static string GetProjectPath(Dictionary<string, string> args)
|
||||
{
|
||||
string data;
|
||||
|
||||
if (args.TryGetValue(CREATE_PROJECT, out data))
|
||||
return data;
|
||||
|
||||
if (args.TryGetValue(OPEN_PROJECT, out data))
|
||||
return data;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
internal static string GetOrganization(Dictionary<string, string> args)
|
||||
{
|
||||
string data;
|
||||
|
||||
if (args.TryGetValue(UVCSArguments.ORGANIZATION_ARG, out data))
|
||||
return data;
|
||||
|
||||
// -cloudOrganization 151d73c7-38cb-4eec-b11e-34764e707226-{plastic-org-name}
|
||||
if (args.TryGetValue(CloudArguments.ORGANIZATION_ARG, out data))
|
||||
return GetOrganizationNameFromData(
|
||||
data, CloudArguments.PLASTIC_ORG_PREFIX_VALUE);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
internal static string GetRepository(Dictionary<string, string> args)
|
||||
{
|
||||
string data;
|
||||
|
||||
if (args.TryGetValue(UVCSArguments.REPOSITORY_ARG, out data))
|
||||
return data;
|
||||
|
||||
if (args.TryGetValue(CloudArguments.PROJECT_ARG, out data))
|
||||
return data;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
internal static string GetWorkspacePath(Dictionary<string, string> args)
|
||||
{
|
||||
string data;
|
||||
|
||||
if (args.TryGetValue(UVCSArguments.WORKSPACE_PATH_ARG, out data))
|
||||
return data;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
static Command.Operation GetOperation(Dictionary<string, string> args)
|
||||
{
|
||||
if (IsCreateWorkspaceCommand(args))
|
||||
return Command.Operation.CreateWorkspace;
|
||||
|
||||
if (IsDownloadRepositoryCommand(args))
|
||||
return Command.Operation.DownloadRepository;
|
||||
|
||||
return Command.Operation.None;
|
||||
}
|
||||
|
||||
static string GetOrganizationNameFromData(string data, string plasticOrgPrefix)
|
||||
{
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
if (!data.StartsWith(plasticOrgPrefix))
|
||||
return null;
|
||||
|
||||
if (data.Length <= plasticOrgPrefix.Length)
|
||||
return null;
|
||||
|
||||
return data.Substring(plasticOrgPrefix.Length);
|
||||
}
|
||||
|
||||
static bool IsCreateWorkspaceCommand(Dictionary<string, string> args)
|
||||
{
|
||||
// Connect UVCS to new project or existing project commands:
|
||||
// -createProject/-projectPath {project_path}
|
||||
// -uvcsRepository {plastic_repo}
|
||||
// -uvcsOrganization {plastic_org}
|
||||
// -uvcsCreateWorkspace
|
||||
|
||||
if (!args.ContainsKey(CREATE_PROJECT) &&
|
||||
!args.ContainsKey(OPEN_PROJECT))
|
||||
return false;
|
||||
|
||||
return args.ContainsKey(UVCSArguments.ORGANIZATION_ARG)
|
||||
&& args.ContainsKey(UVCSArguments.REPOSITORY_ARG)
|
||||
&& args.ContainsKey(UVCSArguments.CREATE_WORKSPACE_FLAG);
|
||||
}
|
||||
|
||||
static bool IsDownloadRepositoryCommand(Dictionary<string, string> args)
|
||||
{
|
||||
return IsDownloadRepositoryCommandUsingLegacyArgs(args)
|
||||
|| IsDownloadRepositoryCommandUsingUVCSArgs(args);
|
||||
}
|
||||
|
||||
static bool IsDownloadRepositoryCommandUsingLegacyArgs(Dictionary<string, string> args)
|
||||
{
|
||||
// Open remote project command using legacy args:
|
||||
// -createProject {project_path}
|
||||
// -cloudProject {plastic_repo}
|
||||
// -cloudOrganization 151d73c7-38cb-4eec-b11e-34764e707226-{plastic_org}
|
||||
|
||||
if (!args.ContainsKey(CREATE_PROJECT) ||
|
||||
!args.ContainsKey(CloudArguments.PROJECT_ARG))
|
||||
return false;
|
||||
|
||||
string data;
|
||||
if (!args.TryGetValue(CloudArguments.ORGANIZATION_ARG, out data))
|
||||
return false;
|
||||
|
||||
return data != null && data.StartsWith(
|
||||
CloudArguments.PLASTIC_ORG_PREFIX_VALUE);
|
||||
}
|
||||
|
||||
static bool IsDownloadRepositoryCommandUsingUVCSArgs(Dictionary<string, string> args)
|
||||
{
|
||||
// Open remote project command using UVCS args:
|
||||
// -createProject {project_path}
|
||||
// -uvcsRepository {plastic_repo}
|
||||
// -uvcsOrganization {plastic_org_name}
|
||||
|
||||
if (!args.ContainsKey(CREATE_PROJECT))
|
||||
return false;
|
||||
|
||||
return args.ContainsKey(UVCSArguments.ORGANIZATION_ARG)
|
||||
&& args.ContainsKey(UVCSArguments.REPOSITORY_ARG);
|
||||
}
|
||||
|
||||
static class UVCSArguments
|
||||
{
|
||||
internal const string ORGANIZATION_ARG = "-uvcsOrganization";
|
||||
internal const string REPOSITORY_ARG = "-uvcsRepository";
|
||||
internal const string WORKSPACE_PATH_ARG = "-uvcsWorkspacePath";
|
||||
internal const string CREATE_WORKSPACE_FLAG = "-uvcsCreateWorkspace";
|
||||
}
|
||||
|
||||
static class CloudArguments
|
||||
{
|
||||
internal const string ORGANIZATION_ARG = "-cloudOrganization";
|
||||
internal const string PLASTIC_ORG_PREFIX_VALUE = "151d73c7-38cb-4eec-b11e-34764e707226-";
|
||||
|
||||
internal const string PROJECT_ARG = "-cloudProject";
|
||||
}
|
||||
|
||||
const string CREATE_PROJECT = "-createProject";
|
||||
const string OPEN_PROJECT = "-projectPath";
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f6b5d170f39144847822c10b478f25e5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using UnityEditor;
|
||||
|
||||
using Codice.LogWrapper;
|
||||
using Unity.PlasticSCM.Editor.Hub.Operations;
|
||||
|
||||
namespace Unity.PlasticSCM.Editor.Hub
|
||||
{
|
||||
internal static class ProcessCommand
|
||||
{
|
||||
internal const string IS_PROCESS_COMMAND_ALREADY_EXECUTED_KEY =
|
||||
"PlasticSCM.ProcessCommand.IsAlreadyExecuted";
|
||||
internal const string IS_PLASTIC_COMMAND_KEY =
|
||||
"PlasticSCM.ProcessCommand.IsPlasticCommand";
|
||||
|
||||
internal static void Initialize()
|
||||
{
|
||||
EditorApplication.update += RunOnceWhenAccessTokenIsInitialized;
|
||||
}
|
||||
|
||||
static void RunOnceWhenAccessTokenIsInitialized()
|
||||
{
|
||||
if (string.IsNullOrEmpty(CloudProjectSettings.accessToken))
|
||||
return;
|
||||
|
||||
EditorApplication.update -= RunOnceWhenAccessTokenIsInitialized;
|
||||
|
||||
Execute(CloudProjectSettings.accessToken);
|
||||
}
|
||||
|
||||
static void Execute(string unityAccessToken)
|
||||
{
|
||||
if (SessionState.GetBool(
|
||||
IS_PROCESS_COMMAND_ALREADY_EXECUTED_KEY, false))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ProcessCommandFromArgs(
|
||||
Environment.GetCommandLineArgs(),
|
||||
unityAccessToken);
|
||||
|
||||
SessionState.SetBool(
|
||||
IS_PROCESS_COMMAND_ALREADY_EXECUTED_KEY, true);
|
||||
}
|
||||
|
||||
internal static void ProcessCommandFromArgs(
|
||||
string[] commandLineArgs,
|
||||
string unityAccessToken)
|
||||
{
|
||||
Dictionary<string, string> args =
|
||||
CommandLineArguments.Build(commandLineArgs);
|
||||
|
||||
mLog.DebugFormat(
|
||||
"Processing Unity arguments: {0}",
|
||||
string.Join(" ", commandLineArgs));
|
||||
|
||||
ParseArguments.Command command =
|
||||
ParseArguments.GetCommand(args);
|
||||
|
||||
if (!command.IsValid())
|
||||
{
|
||||
mLog.Debug("There is no valid command to process");
|
||||
return;
|
||||
}
|
||||
|
||||
SessionState.SetBool(
|
||||
IS_PLASTIC_COMMAND_KEY, true);
|
||||
|
||||
mLog.DebugFormat("Processing command: {0}", command.OperationType);
|
||||
|
||||
OperationParams parameters = OperationParams.
|
||||
BuildFromCommand(command, unityAccessToken);
|
||||
|
||||
switch (command.OperationType)
|
||||
{
|
||||
case ParseArguments.Command.Operation.CreateWorkspace:
|
||||
CreateWorkspace.LaunchOperation(parameters);
|
||||
return;
|
||||
case ParseArguments.Command.Operation.DownloadRepository:
|
||||
DownloadRepository.LaunchOperation(parameters);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static readonly ILog mLog = PlasticApp.GetLogger("ProcessCommand");
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 94a5d27698bed3d42beabebcedbf1f23
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user