using System; using System.IO; using Orbit.AfterEffects.Workspaces; using Plume.Icons; using Plume.Perforce.Service.Api; namespace Orbit.AfterEffects.Actions { /// /// Show the current asset in P4V /// public class ShowInPerforceAction : BaseAction { private readonly IPerforceService _perforceService; private readonly IExplorerSelection _appContext; /// 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)); } /// 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); } /// public override bool CanExecute() { return _appContext.SelectedExplorerAsset != null && App.Current.PerforceIsOk && _perforceService.HasCurrentClient; } } }