From 720277e265efab99574a1165ed96355eccc64b8b Mon Sep 17 00:00:00 2001 From: Bitl Date: Wed, 2 Nov 2022 12:53:20 -0700 Subject: [PATCH] add bz2 support. use compress.bat to compress your maps --- .../StorageAndFunctions/ClientManagement.cs | 66 +++++++++++++++++-- .../StorageAndFunctions/GlobalVars.cs | 1 + .../Classes/Launcher/ModManager.cs | 2 +- .../Forms/LauncherForm/LauncherFormShared.cs | 10 +-- .../LauncherFormStylishInterface.xaml.cs | 4 +- Novetus/NovetusURI/App.config | 14 ++-- scripts/batch/compress.bat | 11 ++++ 7 files changed, 90 insertions(+), 18 deletions(-) create mode 100644 scripts/batch/compress.bat diff --git a/Novetus/NovetusCore/StorageAndFunctions/ClientManagement.cs b/Novetus/NovetusCore/StorageAndFunctions/ClientManagement.cs index 1744ce3..d774ce0 100644 --- a/Novetus/NovetusCore/StorageAndFunctions/ClientManagement.cs +++ b/Novetus/NovetusCore/StorageAndFunctions/ClientManagement.cs @@ -981,6 +981,60 @@ 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) + { + 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; + } + + 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) + { + if ((type != ScriptType.Client || type != ScriptType.EasterEgg) && !nomap && GlobalVars.UserConfiguration.Map.Contains(".bz2")) + { + Decompress(true); + + GlobalVars.UserConfiguration.MapPath = GlobalVars.UserConfiguration.MapPath.Replace(".bz2", ""); + GlobalVars.UserConfiguration.Map = GlobalVars.UserConfiguration.Map.Replace(".bz2", ""); + GlobalVars.isMapCompressed = true; + } + } + + public static void ResetDecompressedMap() + { + if (GlobalVars.isMapCompressed) + { + Util.FixedFileDelete(GlobalVars.UserConfiguration.MapPath); + GlobalVars.UserConfiguration.MapPath = GlobalVars.UserConfiguration.MapPath.Replace(".rbxlx", ".rbxlx.bz2").Replace(".rbxl", ".rbxl.bz2"); + GlobalVars.UserConfiguration.Map = GlobalVars.UserConfiguration.Map.Replace(".rbxlx", ".rbxlx.bz2").Replace(".rbxl", ".rbxl.bz2"); + GlobalVars.isMapCompressed = false; + } + } +#endif + #if URI public static void LaunchRBXClient(ScriptType type, bool no3d, bool nomap, EventHandler e, Label label) #else @@ -1000,6 +1054,10 @@ public class ClientManagement public static void LaunchRBXClient(string ClientName, ScriptType type, bool no3d, bool nomap, EventHandler e) #endif { + #if LAUNCHER + DecompressMap(type, nomap); + #endif + switch (type) { case ScriptType.Client: @@ -1324,7 +1382,7 @@ public class ClientManagement #region Script Functions public class ScriptFuncs { - #region Script Generator/Signer +#region Script Generator/Signer public class Generator { public static void SignGeneratedScript(string scriptFileName, bool newSigFormat = false, bool encodeInBase64 = true) @@ -1509,9 +1567,9 @@ public class ScriptFuncs return ClientManagement.GetGenLuaFileName(ClientName, type); } } - #endregion +#endregion - #region ClientScript Parser +#region ClientScript Parser public class ClientScript { public static string GetArgsFromTag(string code, string tag, string endtag) @@ -1759,6 +1817,6 @@ public class ScriptFuncs return compiled; } } - #endregion +#endregion } #endregion diff --git a/Novetus/NovetusCore/StorageAndFunctions/GlobalVars.cs b/Novetus/NovetusCore/StorageAndFunctions/GlobalVars.cs index 9136ff4..6854e80 100644 --- a/Novetus/NovetusCore/StorageAndFunctions/GlobalVars.cs +++ b/Novetus/NovetusCore/StorageAndFunctions/GlobalVars.cs @@ -143,6 +143,7 @@ public static class GlobalVars public static string NextCommand = ""; public static bool AppClosed = false; public static bool isConsoleOnly = false; + public static bool isMapCompressed = false; #endregion } #endregion diff --git a/Novetus/NovetusLauncher/Classes/Launcher/ModManager.cs b/Novetus/NovetusLauncher/Classes/Launcher/ModManager.cs index 6b16092..bf9be1c 100644 --- a/Novetus/NovetusLauncher/Classes/Launcher/ModManager.cs +++ b/Novetus/NovetusLauncher/Classes/Launcher/ModManager.cs @@ -93,7 +93,7 @@ public class ModManager if (globalType == ModType.ModPackage) { - MessageBox.Show("Your mod is loading. You will recieve a notification when it is installed. Please keep the launcher open. You can see the installation progress in the Console.", "Novetus - Mod Loading"); + MessageBox.Show("Your mod is loading. You will recieve a notification when it is installed. Please keep the launcher open. If the Console is open, you can see the installation progress.", "Novetus - Mod Loading"); int filecount = 0; StringBuilder filelistbuilder = new StringBuilder(); diff --git a/Novetus/NovetusLauncher/Forms/LauncherForm/LauncherFormShared.cs b/Novetus/NovetusLauncher/Forms/LauncherForm/LauncherFormShared.cs index b292071..f014e4c 100644 --- a/Novetus/NovetusLauncher/Forms/LauncherForm/LauncherFormShared.cs +++ b/Novetus/NovetusLauncher/Forms/LauncherForm/LauncherFormShared.cs @@ -436,6 +436,8 @@ namespace NovetusLauncher Parent.Visible = true; } + ClientManagement.ResetDecompressedMap(); + if (GlobalVars.isConsoleOnly) { CloseEventInternal(); @@ -779,7 +781,7 @@ namespace NovetusLauncher Util.RenameFileWithInvalidChars(path); } - string[] fileexts = new string[] { ".rbxl", ".rbxlx" }; + string[] fileexts = new string[] { ".rbxl", ".rbxlx", ".bz2" }; TreeNodeHelper.ListDirectory(Tree, mapdir, fileexts); TreeNodeHelper.CopyNodes(Tree.Nodes, _TreeCache.Nodes); Tree.SelectedNode = TreeNodeHelper.SearchTreeView(GlobalVars.UserConfiguration.Map, Tree.Nodes); @@ -853,9 +855,9 @@ namespace NovetusLauncher if (Tree.SelectedNode == null) return; - if (File.Exists(GlobalPaths.RootPath + @"\\" + Tree.SelectedNode.FullPath.Replace(".rbxl", "").Replace(".rbxlx", "") + "_desc.txt")) + if (File.Exists(GlobalPaths.RootPath + @"\\" + Tree.SelectedNode.FullPath.Replace(".rbxl", "").Replace(".rbxlx", "").Replace(".bz2", "") + "_desc.txt")) { - MapDescBox.Text = File.ReadAllText(GlobalPaths.RootPath + @"\\" + Tree.SelectedNode.FullPath.Replace(".rbxl", "").Replace(".rbxlx", "") + "_desc.txt"); + MapDescBox.Text = File.ReadAllText(GlobalPaths.RootPath + @"\\" + Tree.SelectedNode.FullPath.Replace(".rbxl", "").Replace(".rbxlx", "").Replace(".bz2", "") + "_desc.txt"); } else { @@ -1093,7 +1095,7 @@ namespace NovetusLauncher { using (var ofd = new OpenFileDialog()) { - ofd.Filter = "Roblox Level (*.rbxl)|*.rbxl|Roblox Level (*.rbxlx)|*.rbxlx"; + 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) diff --git a/Novetus/NovetusLauncher/Forms/LauncherForm/Stylish/LauncherFormStylishInterface.xaml.cs b/Novetus/NovetusLauncher/Forms/LauncherForm/Stylish/LauncherFormStylishInterface.xaml.cs index 1a84539..40800d6 100644 --- a/Novetus/NovetusLauncher/Forms/LauncherForm/Stylish/LauncherFormStylishInterface.xaml.cs +++ b/Novetus/NovetusLauncher/Forms/LauncherForm/Stylish/LauncherFormStylishInterface.xaml.cs @@ -547,9 +547,9 @@ namespace NovetusLauncher if (mapsBox.SelectedNode == null) return; - if (File.Exists(GlobalPaths.RootPath + @"\\" + mapsBox.SelectedNode.FullPath.Replace(".rbxl", "").Replace(".rbxlx", "") + "_desc.txt")) + if (File.Exists(GlobalPaths.RootPath + @"\\" + mapsBox.SelectedNode.FullPath.Replace(".rbxl", "").Replace(".rbxlx", "").Replace(".bz2", "") + "_desc.txt")) { - mapsDescBox.Text = mapsBox.SelectedNode.Text + ": " + File.ReadAllText(GlobalPaths.RootPath + @"\\" + mapsBox.SelectedNode.FullPath.Replace(".rbxl", "").Replace(".rbxlx", "") + "_desc.txt"); + mapsDescBox.Text = mapsBox.SelectedNode.Text + ": " + File.ReadAllText(GlobalPaths.RootPath + @"\\" + mapsBox.SelectedNode.FullPath.Replace(".rbxl", "").Replace(".rbxlx", "").Replace(".bz2", "") + "_desc.txt"); } else { diff --git a/Novetus/NovetusURI/App.config b/Novetus/NovetusURI/App.config index b767554..c101a1b 100644 --- a/Novetus/NovetusURI/App.config +++ b/Novetus/NovetusURI/App.config @@ -1,19 +1,19 @@ - + - + - - + + - - + + - + diff --git a/scripts/batch/compress.bat b/scripts/batch/compress.bat new file mode 100644 index 0000000..d5e46d6 --- /dev/null +++ b/scripts/batch/compress.bat @@ -0,0 +1,11 @@ +@ECHO OFF + +SET SourceDir=%CD% +SET DestDir=%CD% + +for %%f in (*.rbxl) do ( + if "%%~xf"==".rbxl" ( + "C:\Program Files\7-Zip\7z.exe" a "%DestDir%\%%f.bz2" "%SourceDir%\%%f" + del "%%f" + ) +) \ No newline at end of file