add BZip2 support to Asset Fixer.

This commit is contained in:
Bitl 2022-11-02 13:22:43 -07:00
parent 8f8a1b891d
commit 506ceaa1db
4 changed files with 112 additions and 43 deletions

View File

@ -982,40 +982,16 @@ public class ClientManagement
#endif
#if LAUNCHER
//https://stackoverflow.com/questions/30687987/unable-to-decompress-bz2-file-has-orginal-file-using-dotnetzip-library
private static string Decompress(bool forceOverwrite)
public static void DecompressMap()
{
var outFname = GlobalVars.UserConfiguration.MapPath.Replace(".bz2", "");
if (File.Exists(outFname))
{
if (forceOverwrite)
File.Delete(outFname);
else
return null;
}
using (Stream fs = File.OpenRead(GlobalVars.UserConfiguration.MapPath),
output = File.Create(outFname),
decompressor = new Ionic.BZip2.BZip2InputStream(fs))
Pump(decompressor, output);
return outFname;
DecompressMap(ScriptType.None, false);
}
private static void Pump(Stream src, Stream dest)
{
byte[] buffer = new byte[2048];
int n;
while ((n = src.Read(buffer, 0, buffer.Length)) > 0)
dest.Write(buffer, 0, n);
}
private static void DecompressMap(ScriptType type, bool nomap)
public static void DecompressMap(ScriptType type, bool nomap)
{
if ((type != ScriptType.Client || type != ScriptType.EasterEgg) && !nomap && GlobalVars.UserConfiguration.Map.Contains(".bz2"))
{
Decompress(true);
Util.Decompress(GlobalVars.UserConfiguration.MapPath, true);
GlobalVars.UserConfiguration.MapPath = GlobalVars.UserConfiguration.MapPath.Replace(".bz2", "");
GlobalVars.UserConfiguration.Map = GlobalVars.UserConfiguration.Map.Replace(".bz2", "");

View File

@ -791,6 +791,85 @@ public static class Util
}
}
}
#if LAUNCHER
//https://stackoverflow.com/questions/30687987/unable-to-decompress-bz2-file-has-orginal-file-using-dotnetzip-library
public static string Compress(string sourceFile, bool forceOverwrite)
{
var outFname = sourceFile + ".bz2";
if (File.Exists(outFname))
{
if (forceOverwrite)
File.Delete(outFname);
else
return null;
}
long rowCount = 0;
var output = File.Create(outFname);
try
{
using (StreamReader reader = new StreamReader(sourceFile))
{
using (var compressor = new Ionic.BZip2.ParallelBZip2OutputStream(output))
{
StreamWriter writer = new StreamWriter(compressor, Encoding.UTF8);
string line = "";
while ((line = reader.ReadLine()) != null)
{
writer.WriteLine(line);
rowCount++;
}
writer.Close();
compressor.Close();
}
}
}
catch (Exception)
{
throw;
}
finally
{
if (output != null)
output = null;
}
// Pump(fs, compressor);
return outFname;
}
public static string Decompress(string sourceFile, bool forceOverwrite)
{
var outFname = sourceFile.Replace(".bz2", "");
if (File.Exists(outFname))
{
if (forceOverwrite)
File.Delete(outFname);
else
return null;
}
using (Stream fs = File.OpenRead(sourceFile),
output = File.Create(outFname),
decompressor = new Ionic.BZip2.BZip2InputStream(fs))
Pump(decompressor, output);
return outFname;
}
private static void Pump(Stream src, Stream dest)
{
byte[] buffer = new byte[2048];
int n;
while ((n = src.Read(buffer, 0, buffer.Length)) > 0)
dest.Write(buffer, 0, n);
}
#endif
#endregion
#if !BASICLAUNCHER

View File

@ -1095,7 +1095,7 @@ namespace NovetusLauncher
{
using (var ofd = new OpenFileDialog())
{
ofd.Filter = "Roblox Level (*.rbxl)|*.rbxl|Roblox Level (*.rbxlx)|*.rbxlx|bzip2 compressed Roblox Level (*.bz2)|*.bz2";
ofd.Filter = "Roblox Level (*.rbxl)|*.rbxl|Roblox Level (*.rbxlx)|*.rbxlx|BZip2 compressed Roblox Level (*.bz2)|*.bz2";
ofd.FilterIndex = 1;
ofd.Title = "Load Roblox map";
if (ofd.ShowDialog() == DialogResult.OK)

View File

@ -23,6 +23,7 @@ public partial class AssetFixer : Form
private string customFolder;
private int errors = 0;
private bool hasOverrideWarningOpenedOnce = false;
private bool compressedMap = true;
#endregion
#region Constructor
@ -132,7 +133,7 @@ public partial class AssetFixer : Form
switch (type)
{
case RobloxFileType.RBXL:
typeFilter = "Roblox Level (*.rbxl)|*.rbxl|Roblox Level (*.rbxlx)|*.rbxlx";
typeFilter = "Roblox Level (*.rbxl)|*.rbxl|Roblox Level (*.rbxlx)|*.rbxlx|BZip2 compressed Roblox Level (*.bz2)|*.bz2";
break;
case RobloxFileType.Script:
typeFilter = "Lua Script (*.lua)|*.lua";
@ -283,6 +284,25 @@ public partial class AssetFixer : Form
public void LocalizeAsset(RobloxFileType type, BackgroundWorker worker, string path, bool useURLs = false, string remoteurl = "")
{
if (GlobalVars.UserConfiguration.AssetSDKFixerSaveBackups)
{
try
{
Util.FixedFileCopy(path, path + ".bak", false);
}
catch (Exception ex)
{
Util.LogExceptions(ex);
return;
}
}
if (path.Contains(".bz2"))
{
Util.Decompress(path, true);
compressedMap = true;
}
LocalizePermanentlyIfNeeded();
AssetFixer_ProgressLabel.Text = "Loading...";
@ -298,19 +318,6 @@ public partial class AssetFixer : Form
}
}
if (!error && GlobalVars.UserConfiguration.AssetSDKFixerSaveBackups)
{
try
{
Util.FixedFileCopy(path, path.Replace(".", " - BAK."), false);
}
catch (Exception ex)
{
Util.LogExceptions(ex);
return;
}
}
//assume we're a script
try
{
@ -321,6 +328,13 @@ public partial class AssetFixer : Form
else
{
FixURLSOrDownloadFromScript(path, GlobalPaths.AssetCacheDirAssets, GlobalPaths.AssetCacheAssetsGameDir, useURLs, url);
if (compressedMap)
{
//compress adds bz2 to our file though? this shouldn't be necessary.
Util.Compress(path.Replace(".rbxlx.bz2", ".rbxlx").Replace(".rbxl.bz2", ".rbxl"), true);
Util.FixedFileDelete(path.Replace(".rbxlx.bz2", ".rbxlx").Replace(".rbxl.bz2", ".rbxl"));
}
}
}
catch (Exception ex)