using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; using Plume.Icons; using Plume.Perforce.Service.Api; using Ubisoft.Perforce; using Ubisoft.Perforce.Helper; namespace Orbit.AfterEffects.Actions { public class GetLatestEngineAction : BaseAction { private readonly IPerforceService _perforceService; public GetLatestEngineAction(IPerforceService perforceService) : base("Get latest engine", "Download the latest game files.", null) { _perforceService = perforceService ?? throw new ArgumentNullException(nameof(perforceService)); Icon = new Icon(GetType().Assembly, "Resources/getlatest.png"); } public override void TryExecute() { App.Current.TaskManager.ExecuteAsync(GetLatest, $"Downloading game files"); } private Task GetLatest() { return Task.Run(() => { if (string.IsNullOrEmpty(_perforceService.CurrentClient?.Stream)) { throw new InvalidOperationException("Perforce stream is invalid."); } // Get necessary dependent folder to make the engine work properly var foldersToGet = new string[] { "engine/", "data/EngineData/", "data/World/_COMMON/", "data/World/Avatars/", "data/World/Features/Collectibles/", "data/World/skins/", "data/World/ui/", "data/World/AUDIO/", "data/World/SkuScenes/", }; for (int i = 0; i < foldersToGet.Length; i++) { Context.NotificationManager.ShowInformation($"Getting engine step {i + 1}/{foldersToGet.Length}, this might take a while..."); string folderToGet = foldersToGet[i]; Context.Logger.Info($"Getting '{folderToGet}'..."); string depotRoot = _perforceService.GetCurrentStreamDepotRoot(); string depotPath = $"{depotRoot}/{folderToGet}"; var files = _perforceService.Connection.GetFiles(depotPath).Where(f => !f.EndsWith(".psd")).ToList(); _perforceService.Connection.Sync(files, "head", SyncOptions.None, PerforceWrapper.SyncType.Revision, new List()); Context.Logger.Info($"Got '{folderToGet}'."); } string engineExePath = Path.Combine(_perforceService.CurrentClient.Root, "engine/ua_engine.exe"); if (!File.Exists(engineExePath)) { throw new FileNotFoundException($"Unable to find engine at '{engineExePath}'.", engineExePath); } }); } public override bool CanExecute() { return App.Current.PerforceIsOk && _perforceService.HasCurrentClient && !App.Current.TaskManager.TaskInProgress; } } }