68 lines
2.4 KiB
C#
68 lines
2.4 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text.RegularExpressions;
|
|
using JD.Serialization;
|
|
using JD.Timeline.Model;
|
|
using TeaBox.Macros;
|
|
|
|
namespace JDSongConverter.Tasks
|
|
{
|
|
/// <summary>
|
|
/// Converts all pictograms from tga to png and updates dance tape
|
|
/// </summary>
|
|
public class ConvertPictogramsToPngTask : Task
|
|
{
|
|
public override string Name
|
|
{
|
|
get { return "Convert pictograms from .tga to .png"; }
|
|
set { }
|
|
}
|
|
|
|
public override string ProgressText
|
|
{
|
|
get { return "Converting pictograms from .tga to .png"; }
|
|
}
|
|
|
|
public override TaskResult Process(IExecutionContext executionContext)
|
|
{
|
|
var pictoOutputDir = AppDefinitions.Default.AbsoluteMapPath(MapPathType.PictosDir, Context.OutputMap.Folder, Context.Song.Name, JDSongVersion.JD2015, JDFolderLayout.Engine);
|
|
var dtapeFile = AppDefinitions.Default.AbsoluteMapPath(MapPathType.DanceTapeFile, Context.OutputMap.Folder, Context.Song.Name, JDSongVersion.JD2015, JDFolderLayout.Engine);
|
|
|
|
var tape = Tape.CreateTape(dtapeFile);
|
|
foreach (var picto in tape.Clips.OfType<PictogramClip>())
|
|
{
|
|
var newPath = Regex.Replace(picto.PictoPath.getAbsolute(), "tga", "png", RegexOptions.IgnoreCase);
|
|
picto.PictoPath = new JD.Serialization.Path(newPath);
|
|
}
|
|
tape.Save(dtapeFile);
|
|
|
|
var images = System.IO.Directory.EnumerateFiles(pictoOutputDir, "*.tga").ToList();
|
|
foreach (var imageAsTga in images)
|
|
{
|
|
string imageAsPng = System.IO.Path.ChangeExtension(imageAsTga, "png");
|
|
try
|
|
{
|
|
|
|
using (var image = JD.Core.Drawing.ImageUtility.LoadBitmap(imageAsTga))
|
|
{
|
|
image.Save(imageAsPng);
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return TaskResult.Error;
|
|
}
|
|
System.IO.File.Delete(imageAsTga);
|
|
|
|
string tfiForTga = imageAsTga + ".tfi";
|
|
string tfiForPng = imageAsPng + ".tfi";
|
|
if (File.Exists(tfiForTga))
|
|
{
|
|
File.Move(tfiForTga, tfiForPng);
|
|
}
|
|
}
|
|
return TaskResult.Ok;
|
|
}
|
|
}
|
|
}
|