JD2022-TU1/main/tools/apps/Orbit.AfterEffects/Actions/ShowInPerforceAction.cs

55 lines
1.9 KiB
C#

using System;
using System.IO;
using Orbit.AfterEffects.Workspaces;
using Plume.Icons;
using Plume.Perforce.Service.Api;
namespace Orbit.AfterEffects.Actions
{
/// <summary>
/// Show the current asset in P4V
/// </summary>
public class ShowInPerforceAction : BaseAction
{
private readonly IPerforceService _perforceService;
private readonly IExplorerSelection _appContext;
/// <inheritdoc />
public ShowInPerforceAction(IPerforceService perforceService, IExplorerSelection appContext) :
base("Show in Perforce", "Open P4V directly focused on the folder of the map.", StandardIcon.Perforce)
{
_perforceService = perforceService ?? throw new ArgumentNullException(nameof(perforceService));
_appContext = appContext ?? throw new ArgumentNullException(nameof(appContext));
}
/// <inheritdoc />
public override void TryExecute()
{
if (_appContext.SelectedExplorerAsset == null)
{
throw new Exception("No asset selected.");
}
string streamRoot = _perforceService.GetCurrentStreamDepotRoot();
var mapName = _appContext.SelectedExplorerAsset.MapName;
var mapPath = Path.Combine(streamRoot, "data/World/Maps", mapName);
if (!Directory.Exists(mapPath))
{
if (string.IsNullOrEmpty(streamRoot))
{
throw new InvalidOperationException("Perforce stream is invalid.");
}
mapPath = $"{streamRoot}/data/World/MAPS/{mapName}/";
}
_perforceService.Connection.ShowInP4V(mapPath);
}
/// <inheritdoc />
public override bool CanExecute()
{
return _appContext.SelectedExplorerAsset != null && App.Current.PerforceIsOk && _perforceService.HasCurrentClient;
}
}
}