Skip to content

Commit dcb6bf9

Browse files
committed
implement -o (--output) for PsBuild and EmtConvert
1 parent a7e4fc5 commit dcb6bf9

4 files changed

Lines changed: 281 additions & 122 deletions

File tree

FreeMote.PsBuild/PsbCompiler.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -454,15 +454,14 @@ public static MemoryStream InplaceReplace(string psbPath, string jsonPath)
454454
/// <summary>
455455
/// <inheritdoc cref="InplaceReplace"/>
456456
/// </summary>
457-
public static string InplaceReplaceToFile(string psbPath, string jsonPath)
457+
public static void InplaceReplaceToFile(string psbPath, string jsonPath, string outputPath)
458458
{
459459
var ms = InplaceReplace(psbPath, jsonPath);
460-
var outputPath = Path.ChangeExtension(psbPath, "IR.psb");
460+
//var outputPath = Path.ChangeExtension(psbPath, "IR.psb");
461461
using var fs = File.Create(outputPath);
462462
ms.WriteTo(fs);
463463
fs.Close();
464464
ms.Close();
465-
return outputPath;
466465
}
467466

468467
/// <summary>
@@ -476,10 +475,20 @@ public static string InplaceReplaceToFile(string psbPath, string jsonPath)
476475
/// <param name="enableParallel">parallel process</param>
477476
/// <param name="keyLen">key length</param>
478477
/// <param name="keepRaw">Do not try to compile json or pack MDF</param>
478+
/// <param name="outputFolder">output folder</param>
479479
public static void PackArchive(string jsonPath, string key, bool intersect, bool preferPacked, Dictionary<string, object> extraContext = null, bool enableParallel = true,
480-
int keyLen = 131, bool keepRaw = false)
480+
int keyLen = 131, bool keepRaw = false, string outputFolder = null)
481481
{
482-
if (!File.Exists(jsonPath)) return;
482+
if (!File.Exists(jsonPath))
483+
{
484+
Logger.LogError($"Input file does not exist: {jsonPath}");
485+
return;
486+
}
487+
if (!string.IsNullOrEmpty(outputFolder) && !Directory.Exists(outputFolder))
488+
{
489+
Logger.LogError($"Output folder does not exist: {outputFolder}");
490+
return;
491+
}
483492
PSB infoPsb = LoadPsbFromJsonFile(jsonPath);
484493
if (infoPsb.Type != PsbType.ArchiveInfo)
485494
{
@@ -708,7 +717,8 @@ void AddFileInfo(PsbDictionary fileInfoDic, string relativePathWithoutSuffix, lo
708717

709718
//using var mmFile =
710719
// MemoryMappedFile.CreateFromFile(bodyBinFileName, FileMode.Create, coreName, );
711-
using var bodyFs = File.OpenWrite(bodyBinFileName);
720+
string bodyBinFilePath = string.IsNullOrEmpty(outputFolder) ? bodyBinFileName : Path.Combine(outputFolder, Path.GetFileName(bodyBinFileName));
721+
using var bodyFs = File.OpenWrite(bodyBinFilePath);
712722
var fileInfoDic = new PsbDictionary(files.Count);
713723
var fmContext = FreeMount.CreateContext(context);
714724
//byte[] bodyBin = null;
@@ -926,8 +936,8 @@ void AddFileInfo(PsbDictionary fileInfoDic, string relativePathWithoutSuffix, lo
926936
}
927937

928938
using var infoMdf = fmContext.PackToShell(infoPsb.ToStream(), fmContext.HasShell ? fmContext.Shell.ToUpperInvariant() : "MDF");
929-
File.WriteAllBytes(packageName, infoMdf.ToArray());
930-
infoMdf.Dispose();
939+
string infoMdfFilePath = string.IsNullOrEmpty(outputFolder) ? packageName : Path.Combine(outputFolder, Path.GetFileName(packageName));
940+
File.WriteAllBytes(infoMdfFilePath, infoMdf.ToArray());
931941

932942
//File.WriteAllBytes(bodyBinFileName, bodyBin);
933943
}

FreeMote.Tests/PsBuildTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void TestInplaceReplace()
7575
//var path = Path.Combine(resPath, "dx_ふかみ_駅員服.psb");
7676
var path = Path.Combine(ResPath, "dx_ふかみ_駅員服.lz4.psb");
7777
var jsonPath = Path.Combine(ResPath, "dx_ふかみ_駅員服.json");
78-
PsbCompiler.InplaceReplaceToFile(path, jsonPath);
78+
PsbCompiler.InplaceReplaceToFile(path, jsonPath, path + ".IR.psb");
7979
}
8080

8181

0 commit comments

Comments
 (0)