Add output path arg for convert DAT and TXM

This commit is contained in:
Yukai Li 2021-02-16 17:33:54 -07:00
parent e84f027bd5
commit d697c36821

View file

@ -47,11 +47,13 @@ namespace DgfTxmConvert
var datPathArg = config.Argument("datPath", "Path of the DAT to extract").IsRequired(); var datPathArg = config.Argument("datPath", "Path of the DAT to extract").IsRequired();
datPathArg.Accepts().ExistingFile(); datPathArg.Accepts().ExistingFile();
var outBaseArg = config.Argument("outBase", "Directory to write extracted files");
outBaseArg.Accepts().LegalFilePath();
config.HelpOption(); config.HelpOption();
config.OnExecute(() => config.OnExecute(() =>
{ {
ConvertDat(datPathArg.Value); ConvertDat(datPathArg.Value, outBaseArg.Value);
}); });
}); });
@ -62,11 +64,13 @@ namespace DgfTxmConvert
var txmPathArg = config.Argument("txmPath", "Path of the TXM to convert").IsRequired(); var txmPathArg = config.Argument("txmPath", "Path of the TXM to convert").IsRequired();
txmPathArg.Accepts().ExistingFile(); txmPathArg.Accepts().ExistingFile();
var outPathArg = config.Argument("outPath", "Path of converted PNG");
outPathArg.Accepts().LegalFilePath();
config.HelpOption(); config.HelpOption();
config.OnExecute(() => config.OnExecute(() =>
{ {
ConvertTxm(txmPathArg.Value); ConvertTxm(txmPathArg.Value, outPathArg.Value);
}); });
}); });
@ -163,8 +167,10 @@ namespace DgfTxmConvert
} }
static void ConvertDat(string path) static void ConvertDat(string path, string outBase = null)
{ {
if (outBase == null) outBase = Path.GetDirectoryName(path);
Directory.CreateDirectory(outBase);
using (Stream fs = Utils.CheckDecompress(File.OpenRead(path))) using (Stream fs = Utils.CheckDecompress(File.OpenRead(path)))
using (DatReader dat = new DatReader(fs)) using (DatReader dat = new DatReader(fs))
{ {
@ -172,7 +178,7 @@ namespace DgfTxmConvert
{ {
using (MemoryStream subfile = new MemoryStream(dat.GetData(i))) using (MemoryStream subfile = new MemoryStream(dat.GetData(i)))
{ {
string outPath = path + $"_{i}.png"; string outPath = Path.Combine(outBase, Path.GetFileName(path + $"_{i}.png"));
Console.WriteLine(outPath); Console.WriteLine(outPath);
try try
{ {
@ -196,11 +202,11 @@ namespace DgfTxmConvert
} }
} }
static void ConvertTxm(string path) static void ConvertTxm(string path, string outPath = null)
{ {
using (Stream fs = Utils.CheckDecompress(File.OpenRead(path))) using (Stream fs = Utils.CheckDecompress(File.OpenRead(path)))
{ {
string outPath = Path.ChangeExtension(path, ".png"); if (outPath == null) outPath = Path.ChangeExtension(path, ".png");
TxmConversion.ConvertTxmToPng(fs, outPath); TxmConversion.ConvertTxmToPng(fs, outPath);
} }
} }