81 lines
No EOL
2.8 KiB
C#
81 lines
No EOL
2.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using Plume.Icons;
|
|
using Plume.Perforce.Service.Api;
|
|
using Ubisoft.Perforce;
|
|
using Ubisoft.Perforce.Helper;
|
|
|
|
namespace Orbit.AfterEffects.Actions
|
|
{
|
|
public class RemoveAllMapsFromWorkspace : BaseAction
|
|
{
|
|
private readonly IPerforceService _perforceService;
|
|
|
|
public RemoveAllMapsFromWorkspace(IPerforceService perforceService)
|
|
: base("Remove all maps from disk", "Remove all maps from the current workspace", StandardIcon.DeleteFolder)
|
|
{
|
|
_perforceService = perforceService ?? throw new ArgumentNullException(nameof(perforceService));
|
|
}
|
|
|
|
public override void TryExecute()
|
|
{
|
|
var result = MessageBoxResult.Cancel;
|
|
App.Current.Dispatcher?.Invoke(() =>
|
|
{
|
|
result = MessageBox.Show("Are you sure to delete all maps from your current workspace?",
|
|
"Confirm deletion", MessageBoxButton.OKCancel);
|
|
});
|
|
if (result == MessageBoxResult.OK)
|
|
App.Current.TaskManager.ExecuteAsync(RemoveMapsWorkspace,"Removing all maps from the workspace");
|
|
}
|
|
|
|
private Task RemoveMapsWorkspace()
|
|
{
|
|
return Task.Run(() =>
|
|
{
|
|
var streamRoot = _perforceService.GetCurrentStreamDepotRoot();
|
|
var mapFolder = streamRoot + @"/data/World/Maps/...";
|
|
|
|
var errors = new List<string>();
|
|
var result = _perforceService.Connection.SyncPath(mapFolder, "none", SyncOptions.Parallel,
|
|
PerforceWrapper.SyncType.Revision, errors);
|
|
|
|
if (result == PerforceWrapper.SyncFileResult.Success)
|
|
return;
|
|
|
|
List<string> actualErrors = new List<string>();
|
|
List<string> justWarnings = new List<string>();
|
|
foreach (var log in errors)
|
|
{
|
|
if (log.StartsWith("[warning]"))
|
|
{
|
|
justWarnings.Add(log);
|
|
}
|
|
else
|
|
{
|
|
actualErrors.Add(log);
|
|
}
|
|
}
|
|
|
|
if (actualErrors.Any())
|
|
{
|
|
Context.Logger.Error(string.Join(Environment.NewLine, actualErrors));
|
|
throw new Exception($"Unable to remove maps from workspace: {actualErrors.Count} errors occured.");
|
|
}
|
|
|
|
if (justWarnings.Any())
|
|
{
|
|
Context.Logger.Info(string.Join(Environment.NewLine, justWarnings));
|
|
}
|
|
});
|
|
}
|
|
|
|
public override bool CanExecute()
|
|
{
|
|
return App.Current.PerforceIsOk && _perforceService.HasCurrentClient;
|
|
}
|
|
}
|
|
} |