Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion BundleFormat/BundleEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public byte[] Data
return null;

if (Compressed)
return RawData.Decompress((int)UncompressedSize);
return RawData.Decompress();

return RawData;
}
Expand Down
3 changes: 0 additions & 3 deletions BundleFormat/BundleFormat.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
<OutputType>Library</OutputType>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="LibDeflate.NET" Version="1.19.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BundleUtilities\BundleUtilities.csproj" />
</ItemGroup>
Expand Down
27 changes: 14 additions & 13 deletions BundleFormat/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
using System;
using System.Buffers;
using System.Buffers.Binary;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Numerics;
using System.Text;
using System.Windows.Forms;
using LibDeflate;

namespace BundleFormat
{
public static class Extensions
{
private static Decompressor decompressor = new ZlibDecompressor();
private static Compressor compressor = new ZlibCompressor(9);

public static string AsString(this byte[] self)
{
if (self == null)
Expand Down Expand Up @@ -45,18 +41,23 @@ public static string MakePreview(this byte[] self, int start, int end)

public static byte[] Compress(this byte[] self)
{
return compressor.Compress(self).Memory.ToArray();
MemoryStream uncompressed = new(self);
MemoryStream compressed = new();
using (ZLibStream zlibStream = new(compressed, CompressionLevel.SmallestSize, true))
{
uncompressed.CopyTo(zlibStream);
}
return compressed.ToArray();
}

public static byte[] Decompress(this byte[] self, int uncompressedSize)
public static byte[] Decompress(this byte[] self)
{
var status = decompressor.Decompress(self, uncompressedSize, out var owner, out var bytesRead);
if (status != OperationStatus.Done)
MemoryStream decompressed = new();
using (ZLibStream zlibStream = new(new MemoryStream(self), CompressionMode.Decompress))
{
MessageBox.Show("Error decompressing data, status: " + status.ToString() + ", read: " + bytesRead.ToString(), "Error", MessageBoxButtons.OK);
return null;
zlibStream.CopyTo(decompressed);
}
return owner.Memory.ToArray();
return decompressed.ToArray();
}

public static bool Matches(this byte[] self, byte[] other)
Expand Down
1 change: 0 additions & 1 deletion BundleManager/BundleManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="DebugHelper" Version="1.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
<PackageReference Include="ScottPlot.WinForms" Version="5.1.58" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.12" />
</ItemGroup>
Expand Down
10 changes: 8 additions & 2 deletions VaultFormat/AttribSysVaultForm.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
using BundleUtilities;
using LangEditor;
using Newtonsoft.Json;
using PluginAPI;
using System;
using System.Collections;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Text.Json;
using System.Windows.Forms;

namespace VaultFormat
{
public delegate void Notify(); // delegate
public partial class AttribSysVaultForm : Form, IEntryEditor
{
private readonly JsonSerializerOptions jsonSerializerOptions = new()
{
WriteIndented = true
};

public AttribSysVaultForm()
{
InitializeComponent();
Expand Down Expand Up @@ -148,7 +153,8 @@ private void exportVaultToolStripMenuItem_Click(object sender, EventArgs e)
try
{
// Convertion of the AttribSys. Might need smarter structure to only keep the essential data concerning the configuration of the vehicle
string jsonContent = JsonConvert.SerializeObject(AttribSys, Formatting.Indented);

string jsonContent = JsonSerializer.Serialize(AttribSys, jsonSerializerOptions);

File.WriteAllText(saveDialog.FileName, jsonContent);

Expand Down
3 changes: 0 additions & 3 deletions VaultFormat/VaultFormat.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
<OutputType>Library</OutputType>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BundleFormat\BundleFormat.csproj" />
<ProjectReference Include="..\BundleUtilities\BundleUtilities.csproj" />
Expand Down