130 lines
4.5 KiB
C#
130 lines
4.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using JD.Application.View.PropertyGrid;
|
|
using JD.Asset.Types.Map;
|
|
using JD.Core;
|
|
using JD.LogService;
|
|
using TeaBox;
|
|
using TeaBox.Gui.PropertyGrid;
|
|
using TeaBox.Macros;
|
|
|
|
|
|
|
|
namespace DanceEditor.Source.Macros
|
|
{
|
|
[Module]
|
|
public static class FileOperations
|
|
{
|
|
[Macro]
|
|
[Description("Format tracks to DanceEditor")]
|
|
public static void CopyMovesFromPlatformToAnother(IExecutionContext context, [PropertyEditor(typeof(MapMultiSelectEditor))] MapList maps, [DefaultValue(PlatformMask.X360)] PlatformMask sourcePlatform, [DefaultValue(PlatformMask.ORBIS | PlatformMask.DURANGO)] PlatformMask destinationPlatforms)
|
|
{
|
|
foreach (var map in maps)
|
|
{
|
|
var files = Directory.GetFiles(map.MovesFolder(sourcePlatform)).Where(x => !x.EndsWith("TEMPLATE.txt"));
|
|
foreach (var filePath in files)
|
|
{
|
|
var fileName = Path.GetFileName(filePath);
|
|
foreach (var destinationPlatform in GetFlags(destinationPlatforms))
|
|
{
|
|
var destFilePath = Path.Combine(map.MovesFolder((PlatformMask)destinationPlatform), fileName);
|
|
try
|
|
{
|
|
if (File.Exists(destFilePath))
|
|
{
|
|
File.SetAttributes(destFilePath, FileAttributes.Normal);
|
|
}
|
|
File.Copy(filePath, destFilePath, true);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
context.LogError("Error copying {0} to {1}", filePath, destFilePath);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
static string MovesFolder(this Map map, PlatformMask platform)
|
|
{
|
|
return Path.Combine(map.MovesFolder, platform.ToString());
|
|
}
|
|
|
|
static IEnumerable<Enum> GetFlags(Enum input)
|
|
{
|
|
foreach (Enum value in Enum.GetValues(input.GetType()))
|
|
if (input.HasFlag(value))
|
|
yield return value;
|
|
}
|
|
}
|
|
|
|
[TypeConverter(typeof(MapListConverter))]
|
|
public class MapList : List<Map>
|
|
{
|
|
public MapList() {}
|
|
|
|
public MapList(IEnumerable<Map> list)
|
|
{
|
|
AddRange(list);
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return string.Join(",", this.Select(x => x.Name));
|
|
}
|
|
}
|
|
|
|
public class MapMultiSelectEditor : MultiSelectComboBoxEditor<Map>
|
|
{
|
|
public MapMultiSelectEditor()
|
|
{
|
|
StringFormatter = map => $"{map.Name} ({map.JdCatalogName})";
|
|
DataSource = new MapList(Map.AllMaps.OrderBy(x => x.Name));
|
|
}
|
|
}
|
|
|
|
public class MapListConverter : TypeConverter
|
|
{
|
|
public override Object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, Object value)
|
|
{
|
|
if (value.GetType() == typeof(string))
|
|
{
|
|
var valueAsString = value as string;
|
|
var maps = valueAsString.Split(',');
|
|
var mapList = new MapList();
|
|
mapList.AddRange(Map.AllMaps.Where(x => maps.Contains(x.Name + x.JdCatalogName)));
|
|
return mapList;
|
|
}
|
|
return new MapList();
|
|
}
|
|
|
|
public override Boolean CanConvertTo(ITypeDescriptorContext context, Type destinationType)
|
|
{
|
|
if (destinationType == typeof(string))
|
|
return true;
|
|
|
|
return base.CanConvertTo(context, destinationType);
|
|
}
|
|
|
|
public override Object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, System.Object value, System.Type destinationType)
|
|
{
|
|
if (value is IEnumerable<Map>)
|
|
{
|
|
var mapList = (IEnumerable<Map>)value;
|
|
if (destinationType == typeof(System.String))
|
|
{
|
|
return string.Join(",", mapList.Select(x => x.Name + x.JdCatalogName));
|
|
}
|
|
}
|
|
return base.ConvertTo(context, culture, value, destinationType);
|
|
}
|
|
|
|
public override Boolean CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
|
{
|
|
return sourceType == typeof(string);
|
|
}
|
|
}
|
|
}
|