Skip to content

Commit

Permalink
Merge pull request #9 from kiraio-moe/dev
Browse files Browse the repository at this point in the history
[PULL REQUEST] Rewrite the main program and some fixes
  • Loading branch information
kiraio-moe authored Oct 21, 2023
2 parents 0bb557f + 8a1c75c commit e404769
Show file tree
Hide file tree
Showing 10 changed files with 1,154 additions and 688 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"args": [],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "integratedTerminal",
"console": "externalTerminal",
"stopAtEntry": false,
"requireExactSource": false
},
Expand Down
33 changes: 26 additions & 7 deletions BrotliUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace USSR.Utilities
{
public class BrotliUtils
internal class BrotliUtils
{
static CompressionLevel GetCompressionLevel()
{
Expand All @@ -13,7 +13,7 @@ static CompressionLevel GetCompressionLevel()
return CompressionLevel.Optimal;
}

public static byte[] CompressBytes(byte[] bytes)
internal static byte[] CompressBytes(byte[] bytes)
{
using MemoryStream? outputStream = new();
using (BrotliStream? compressionStream = new(outputStream, GetCompressionLevel()))
Expand All @@ -22,7 +22,7 @@ public static byte[] CompressBytes(byte[] bytes)
return outputStream.ToArray();
}

public static string CompressFile(string originalFileName, string compressedFileName)
internal static string CompressFile(string originalFileName, string compressedFileName)
{
using FileStream originalStream = File.Open(originalFileName, FileMode.Open);
using FileStream compressedStream = File.Create(compressedFileName);
Expand All @@ -31,13 +31,13 @@ public static string CompressFile(string originalFileName, string compressedFile
return compressedFileName;
}

public static void CompressStream(Stream originalStream, Stream compressedStream)
internal static void CompressStream(Stream originalStream, Stream compressedStream)
{
using BrotliStream? compressor = new(compressedStream, GetCompressionLevel());
originalStream.CopyTo(compressor);
}

public static byte[] DecompressBytes(byte[] bytes)
internal static byte[] DecompressBytes(byte[] bytes)
{
using MemoryStream? inputStream = new(bytes);
using MemoryStream outputStream = new();
Expand All @@ -47,7 +47,7 @@ public static byte[] DecompressBytes(byte[] bytes)
return outputStream.ToArray();
}

public static string DecompressFile(string compressedFileName, string outputFileName)
internal static string DecompressFile(string compressedFileName, string outputFileName)
{
using FileStream compressedFileStream = File.Open(compressedFileName, FileMode.Open);
using FileStream outputFileStream = File.Create(outputFileName);
Expand All @@ -56,11 +56,30 @@ public static string DecompressFile(string compressedFileName, string outputFile
return outputFileName;
}

public static void DecompressStream(Stream compressedStream, Stream outputStream)
internal static void DecompressStream(Stream compressedStream, Stream outputStream)
{
using BrotliStream decompressor = new(compressedStream, CompressionMode.Decompress);
decompressor.CopyTo(outputStream);
}

internal static void WriteUnityIdentifier(string filePath, byte[] magicBytes)
{
try
{
using (
FileStream fileStream = new FileStream(
filePath,
FileMode.Open,
FileAccess.ReadWrite
)
)
{
fileStream.Seek(0, SeekOrigin.Begin);
fileStream.Write(magicBytes, 0, magicBytes.Length);
}
}
catch (Exception) { }
}
}
}

Expand Down
16 changes: 8 additions & 8 deletions GZipUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace USSR.Utilities
{
public class GZipUtils
internal class GZipUtils
{
private static CompressionLevel GetCompressionLevel()
static CompressionLevel GetCompressionLevel()
{
// NOTE: CompressionLevel.SmallestSize == 3 is not supported in .NET Core 3.1 but is in .NET 6
if (Enum.IsDefined(typeof(CompressionLevel), 3))
Expand All @@ -13,7 +13,7 @@ private static CompressionLevel GetCompressionLevel()
return CompressionLevel.Optimal;
}

public static byte[] CompressBytes(byte[] bytes)
internal static byte[] CompressBytes(byte[] bytes)
{
using MemoryStream? outputStream = new();
using (GZipStream? compressionStream = new(outputStream, GetCompressionLevel()))
Expand All @@ -22,7 +22,7 @@ public static byte[] CompressBytes(byte[] bytes)
return outputStream.ToArray();
}

public static string CompressFile(string originalFileName, string compressedFileName)
internal static string CompressFile(string originalFileName, string compressedFileName)
{
using FileStream originalStream = File.Open(originalFileName, FileMode.Open);
using FileStream compressedStream = File.Create(compressedFileName);
Expand All @@ -31,13 +31,13 @@ public static string CompressFile(string originalFileName, string compressedFile
return compressedFileName;
}

public static void CompressStream(Stream originalStream, Stream compressedStream)
internal static void CompressStream(Stream originalStream, Stream compressedStream)
{
using GZipStream? compressor = new(compressedStream, GetCompressionLevel());
originalStream.CopyTo(compressor);
}

public static byte[] DecompressBytes(byte[] bytes)
internal static byte[] DecompressBytes(byte[] bytes)
{
using MemoryStream? inputStream = new(bytes);
using MemoryStream? outputStream = new();
Expand All @@ -47,7 +47,7 @@ public static byte[] DecompressBytes(byte[] bytes)
return outputStream.ToArray();
}

public static string DecompressFile(string compressedFileName, string outputFileName)
internal static string DecompressFile(string compressedFileName, string outputFileName)
{
using FileStream compressedFileStream = File.Open(compressedFileName, FileMode.Open);
using FileStream outputFileStream = File.Create(outputFileName);
Expand All @@ -56,7 +56,7 @@ public static string DecompressFile(string compressedFileName, string outputFile
return outputFileName;
}

public static void DecompressStream(Stream compressedStream, Stream outputStream)
internal static void DecompressStream(Stream compressedStream, Stream outputStream)
{
using GZipStream? decompressor = new(compressedStream, CompressionMode.Decompress);
decompressor.CopyTo(outputStream);
Expand Down
Loading

0 comments on commit e404769

Please sign in to comment.