Merge pull request #65 from bluepilledgreat/mod-to-resources

get rid of base64 mod strings
This commit is contained in:
pizzaboxer 2023-01-08 15:15:02 +00:00 committed by GitHub
commit bd9dc7e22c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 42 additions and 18 deletions

View File

@ -18,6 +18,12 @@
<Content Include="Bloxstrap.ico" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\Mods\OldCursor.png" />
<EmbeddedResource Include="Resources\Mods\OldDeath.ogg" />
<EmbeddedResource Include="Resources\Mods\OldFarCursor.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="DiscordRichPresence" Version="1.1.3.18" />
<PackageReference Include="securifybv.ShellLink" Version="0.1.0" />

View File

@ -114,7 +114,7 @@ namespace Bloxstrap
if (!Directory.Exists(VersionFolder) && CheckIfRunning(true) || Program.Settings.VersionGuid != VersionGuid && !CheckIfRunning(false))
await InstallLatestVersion();
ApplyModifications();
await ApplyModifications();
if (Program.IsFirstRun)
Program.SettingsManager.ShouldSave = true;
@ -475,7 +475,7 @@ namespace Bloxstrap
Program.Settings.VersionGuid = VersionGuid;
}
private void ApplyModifications()
private async Task ApplyModifications()
{
Dialog.Message = "Applying Roblox modifications...";
@ -488,13 +488,13 @@ namespace Bloxstrap
if (!Directory.Exists(modFolder))
{
Directory.CreateDirectory(modFolder);
File.WriteAllText(Path.Combine(modFolder, "README.txt"), ModReadme);
await File.WriteAllTextAsync(Path.Combine(modFolder, "README.txt"), ModReadme);
}
CheckModPreset(Program.Settings.UseOldDeathSound, @"content\sounds\ouch.ogg", Program.Base64OldDeathSound);
CheckModPreset(Program.Settings.UseOldMouseCursor, @"content\textures\Cursors\KeyboardMouse\ArrowCursor.png", Program.Base64OldArrowCursor);
CheckModPreset(Program.Settings.UseOldMouseCursor, @"content\textures\Cursors\KeyboardMouse\ArrowFarCursor.png", Program.Base64OldArrowFarCursor);
CheckModPreset(Program.Settings.UseDisableAppPatch, @"ExtraContent\places\Mobile.rbxl", "");
await CheckModPreset(Program.Settings.UseOldDeathSound, @"content\sounds\ouch.ogg", "OldDeath.ogg");
await CheckModPreset(Program.Settings.UseOldMouseCursor, @"content\textures\Cursors\KeyboardMouse\ArrowCursor.png", "OldCursor.png");
await CheckModPreset(Program.Settings.UseOldMouseCursor, @"content\textures\Cursors\KeyboardMouse\ArrowFarCursor.png", "OldFarCursor.png");
await CheckModPreset(Program.Settings.UseDisableAppPatch, @"ExtraContent\places\Mobile.rbxl", "");
foreach (string file in Directory.GetFiles(modFolder, "*.*", SearchOption.AllDirectories))
{
@ -513,7 +513,7 @@ namespace Bloxstrap
// original files from the downloaded packages
if (File.Exists(manifestFile))
manifestFiles = File.ReadAllLines(manifestFile).ToList<string>();
manifestFiles = (await File.ReadAllLinesAsync(manifestFile)).ToList();
else
manifestFiles = modFolderFiles;
@ -567,10 +567,10 @@ namespace Bloxstrap
File.WriteAllLines(manifestFile, modFolderFiles);
}
private static void CheckModPreset(bool condition, string location, string base64Contents)
private static async Task CheckModPreset(bool condition, string location, string name)
{
string modFolderLocation = Path.Combine(Directories.Modifications, location);
byte[] binaryData = Convert.FromBase64String(base64Contents);
byte[] binaryData = string.IsNullOrEmpty(name) ? Array.Empty<byte>() : await ResourceHelper.Get(name);
if (condition)
{
@ -583,7 +583,7 @@ namespace Bloxstrap
Directory.CreateDirectory(directory);
File.WriteAllBytes(modFolderLocation, binaryData);
await File.WriteAllBytesAsync(modFolderLocation, binaryData);
}
}
else if (File.Exists(modFolderLocation) && Utilities.MD5File(modFolderLocation) == Utilities.MD5Data(binaryData))

View File

@ -0,0 +1,25 @@
using System.IO;
using System.Reflection;
namespace Bloxstrap.Helpers
{
internal class ResourceHelper
{
static readonly Assembly assembly = Assembly.GetExecutingAssembly();
static readonly string[] resourceNames = assembly.GetManifestResourceNames();
public static async Task<byte[]> Get(string name)
{
string path = resourceNames.Single(str => str.EndsWith(name));
using (Stream stream = assembly.GetManifestResourceStream(path)!)
{
using (MemoryStream memoryStream = new())
{
await stream.CopyToAsync(memoryStream);
return memoryStream.ToArray();
}
}
}
}
}

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 232 B

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 235 B