diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..bdb3d0e --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,27 @@ +name: Publish +on: + pull_request: + branches: + - master + push: + branches: + - master +jobs: + publish: + runs-on: windows-latest + permissions: + packages: write + contents: read + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-dotnet@v2 + with: + dotnet-version: '6.0.x' + - name: Build + run: dotnet pack -c Release + - #if: ${{ github.ref == 'refs/heads/master' }} + name: Push + run: | + dotnet nuget add source --username USERNAME --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/OpenSimTools/index.json" + dotnet nuget push .\PCarsTools\bin\Release\PCarsTools.*.nupkg --skip-duplicate --source github + dotnet nuget push .\XCompression\bin\Release\PCarsTools.XCompression.*.nupkg --skip-duplicate --source github \ No newline at end of file diff --git a/PCarsTools/BPakFile.cs b/PCarsTools/BPakFile.cs index 66c676d..1bcfbc0 100644 --- a/PCarsTools/BPakFile.cs +++ b/PCarsTools/BPakFile.cs @@ -20,10 +20,12 @@ namespace PCarsTools { - public class BPakFile + public class BPakFile : IDisposable { public const string TagId = "PAK "; + private readonly TextWriter outputWriter; + public BVersion Version { get; set; } public string Name { get; set; } public ePakFlags Flags { get; set; } @@ -41,24 +43,29 @@ public class BPakFile /// public string Path { get; set; } + private BPakFile(TextWriter outputWriter) + { + this.outputWriter = outputWriter is null ? Console.Out : outputWriter; + } + /// /// Reads a pak file from a provided file name. /// /// /// /// - public static BPakFile FromFile(string inputFile, bool withExtraInfo = true) + public static BPakFile FromFile(string inputFile, bool withExtraInfo = true, TextWriter outputWriter = null) { var fs = new FileStream(inputFile, FileMode.Open); - var pak = FromStream(fs, withExtraInfo: withExtraInfo, tocFileName: inputFile); + var pak = FromStream(fs, withExtraInfo: withExtraInfo, tocFileName: inputFile, outputWriter: outputWriter); pak._fs = fs; return pak; } - public static BPakFile FromStream(Stream stream, bool withExtraInfo = false, string tocFileName = null) + public static BPakFile FromStream(Stream stream, bool withExtraInfo = false, string tocFileName = null, TextWriter outputWriter = null) { - var pak = new BPakFile(); + var pak = new BPakFile(outputWriter); int pakOffset = (int)stream.Position; pak.Path = tocFileName.ToLower().Replace('/', '\\'); @@ -120,7 +127,7 @@ public static BPakFile FromStream(Stream stream, bool withExtraInfo = false, str } if (pakTocBuffer[14] != 0 && pakTocBuffer[15] != 0) // Check if first entry offset is absurdly too big that its possibly not decrypted correctly - Console.WriteLine($"Warning - possible crash: {pak.Name} toc could most likely not be decrypted correctly using key No.{pak.KeyIndex}"); + outputWriter.WriteLine($"Warning - possible crash: {pak.Name} toc could most likely not be decrypted correctly using key No.{pak.KeyIndex}"); pak.Entries = new List(fileCount); SpanReader sr = new SpanReader(pakTocBuffer); @@ -177,7 +184,7 @@ public static BPakFile FromStream(Stream stream, bool withExtraInfo = false, str BPakFileEncryption.DecryptData(pak.EncryptionType, tmp, tmp.Length, 0); if (tmp[6] != 0 && tmp[7] != 0) - Console.WriteLine("Warning: possibly failed to decrypt Extended Info Table"); + outputWriter.WriteLine("Warning: possibly failed to decrypt Extended Info Table"); extTocBuffer = tmp; } @@ -200,7 +207,7 @@ public static BPakFile FromStream(Stream stream, bool withExtraInfo = false, str ulong uid = BHashCode.CreateUidRaw(extEntry.Path); if (pak.Entries[i].UId != uid) - Console.WriteLine($"Warning - unmatched UID/Hash: {extEntry.Path} (target={pak.Entries[i].UId:X16}, got={uid}"); + outputWriter.WriteLine($"Warning - unmatched UID/Hash: {extEntry.Path} (target={pak.Entries[i].UId:X16}, got={uid}"); pak.ExtEntries.Add(extEntry); } @@ -227,17 +234,17 @@ public void UnpackAll(string outputDir) if (UnpackFromStream(entry, extEntry, outPath)) { - Console.WriteLine($"Unpacked: [{Name}]\\{extEntry.Path}"); + outputWriter.WriteLine($"Unpacked: [{Name}]\\{extEntry.Path}"); totalCount++; } else { - Console.WriteLine($"Failed to unpack: {extEntry.Path}"); + outputWriter.WriteLine($"Failed to unpack: {extEntry.Path}"); failed++; } } - Console.WriteLine($"Done. Extracted {totalCount} files ({failed} not extracted)"); + outputWriter.WriteLine($"Done. Extracted {totalCount} files ({failed} not extracted)"); } public bool UnpackFromLocalStoredFile(string outputDir, BPakFileTocEntry entry, BExtendedFileInfoEntry extEntry) @@ -252,7 +259,7 @@ public bool UnpackFromLocalStoredFile(string outputDir, BPakFileTocEntry entry, } else { - Console.WriteLine($"File {extEntry.Path} not found to extract, can be ignored"); + outputWriter.WriteLine($"File {extEntry.Path} not found to extract, can be ignored"); } return false; @@ -352,7 +359,7 @@ private bool Unpack(byte[] bytes, BPakFileTocEntry entry, BExtendedFileInfoEntry int outLen = (int)entry.FileSize; ErrorCode err = decompContext.Decompress(bytes, 0, ref pakLen, decBuffer, 0, ref outLen); if (err != ErrorCode.None) - Console.WriteLine($"Error: Failed to unpack {extEntry.Path} (XMemDecompress/LZX) - Code: {(int)err:X8}"); + outputWriter.WriteLine($"Error: Failed to unpack {extEntry.Path} (XMemDecompress/LZX) - Code: {(int)err:X8}"); if (outLen == entry.FileSize) { @@ -365,7 +372,7 @@ private bool Unpack(byte[] bytes, BPakFileTocEntry entry, BExtendedFileInfoEntry } else if (entry.Compression != PakFileCompressionType.None) { - Console.WriteLine($"Warning: Unrecognized compression type {entry.Compression} for {extEntry.Path}"); + outputWriter.WriteLine($"Warning: Unrecognized compression type {entry.Compression} for {extEntry.Path}"); return false; } else @@ -375,6 +382,13 @@ private bool Unpack(byte[] bytes, BPakFileTocEntry entry, BExtendedFileInfoEntry return true; } } + + public void Dispose() + { + if (_fs is not null) { + _fs.Dispose(); + } + } } diff --git a/PCarsTools/Compression/Oodle.cs b/PCarsTools/Compression/Oodle.cs index d342fb6..38de31b 100644 --- a/PCarsTools/Compression/Oodle.cs +++ b/PCarsTools/Compression/Oodle.cs @@ -14,7 +14,7 @@ public class Oodle /// /// Oodle Library Path /// - private const string OodleLibraryPath = "oo2core_7_win64"; + private const string OodleLibraryPath = "oo2core_4_win64"; /// /// Oodle64 Decompression Method diff --git a/PCarsTools/PCarsTools.csproj b/PCarsTools/PCarsTools.csproj index 8396ce9..1f96078 100644 --- a/PCarsTools/PCarsTools.csproj +++ b/PCarsTools/PCarsTools.csproj @@ -3,7 +3,7 @@ Exe net6.0 - 1.1.2 + 1.1.2.5 AnyCPU;x86;x64 PCarsTools_Debug_x86 @@ -13,7 +13,7 @@ - + diff --git a/XCompression/XCompression.csproj b/XCompression/XCompression.csproj index c906228..edd45f5 100644 --- a/XCompression/XCompression.csproj +++ b/XCompression/XCompression.csproj @@ -1,5 +1,6 @@  + PCarsTools.XCompression net6.0; Gibbed Gibbed