diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e625743..6cc3090 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -33,7 +33,7 @@ jobs: - name: Publish GUI application (Self-contained) if: matrix.build-type == 'self-contained' - run: dotnet publish GDeflateGUI/GDeflateGUI.csproj --configuration Release --output ./publish-gui --self-contained true --runtime win-x64 + run: dotnet publish GDeflateGUI/GDeflateGUI.csproj --configuration Release --output ./publish-gui --self-contained true --runtime win-x64 /p:PublishSingleFile=true /p:EnableCompressionInSingleFile=true - name: Publish GUI application (Framework-dependent) if: matrix.build-type == 'framework-dependent' @@ -92,7 +92,7 @@ jobs: run: dotnet run --project GDeflateConsole --configuration Release test - name: Publish console application (Self-contained) - run: dotnet publish GDeflateConsole/GDeflateConsole.csproj --configuration Release --output ./publish-console --self-contained true --runtime ${{ matrix.runtime }} + run: dotnet publish GDeflateConsole/GDeflateConsole.csproj --configuration Release --output ./publish-console --self-contained true --runtime ${{ matrix.runtime }} /p:PublishSingleFile=true /p:EnableCompressionInSingleFile=true - name: Create build info (Windows) if: matrix.os == 'windows-latest' diff --git a/GDeflateConsole/GDeflateConsole.csproj b/GDeflateConsole/GDeflateConsole.csproj index 28fc07f..eb6e344 100644 --- a/GDeflateConsole/GDeflateConsole.csproj +++ b/GDeflateConsole/GDeflateConsole.csproj @@ -8,4 +8,13 @@ GDeflateConsole + + + PreserveNewest + + + PreserveNewest + + + \ No newline at end of file diff --git a/GDeflateConsole/GDeflateProcessor.cs b/GDeflateConsole/GDeflateProcessor.cs index d93530a..c4fa4d3 100644 --- a/GDeflateConsole/GDeflateProcessor.cs +++ b/GDeflateConsole/GDeflateProcessor.cs @@ -220,7 +220,7 @@ private void DecompressFileSimulation(string inputFile, string outputFile) using (var input = new FileStream(inputFile, FileMode.Open)) { var header = new byte[8]; - input.Read(header, 0, 8); + ReadExactly(input, header, 0, 8); if (System.Text.Encoding.UTF8.GetString(header) != "GDEF_SIM") { @@ -228,11 +228,11 @@ private void DecompressFileSimulation(string inputFile, string outputFile) } var sizeBytes = new byte[4]; - input.Read(sizeBytes, 0, 4); + ReadExactly(input, sizeBytes, 0, 4); int originalSize = BitConverter.ToInt32(sizeBytes, 0); var storedData = new byte[Math.Min(originalSize, 1024)]; - input.Read(storedData, 0, storedData.Length); + ReadExactly(input, storedData, 0, storedData.Length); // Create output file with stored data repeated to match original size using (var output = new FileStream(outputFile, FileMode.Create)) @@ -248,6 +248,20 @@ private void DecompressFileSimulation(string inputFile, string outputFile) } } + private static void ReadExactly(Stream stream, byte[] buffer, int offset, int count) + { + int totalBytesRead = 0; + while (totalBytesRead < count) + { + int bytesRead = stream.Read(buffer, offset + totalBytesRead, count - totalBytesRead); + if (bytesRead == 0) + { + throw new EndOfStreamException("End of stream reached before all bytes were read."); + } + totalBytesRead += bytesRead; + } + } + private void CheckCuda(int err) { if (err != 0) diff --git a/GDeflateGUI/GDeflateGUI.csproj b/GDeflateGUI/GDeflateGUI.csproj index c446ffe..ab6100e 100644 --- a/GDeflateGUI/GDeflateGUI.csproj +++ b/GDeflateGUI/GDeflateGUI.csproj @@ -10,4 +10,13 @@ true + + + PreserveNewest + + + PreserveNewest + + +