@@ -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 }
0 commit comments