Skip to content

Commit

Permalink
Merge branch 'main' into user-pfp-discord-rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
pizzaboxer committed Sep 27, 2024
2 parents 8667167 + 0acf1ee commit 5d79a95
Show file tree
Hide file tree
Showing 29 changed files with 435 additions and 201 deletions.
9 changes: 9 additions & 0 deletions Bloxstrap/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ public static void Terminate(ErrorCode exitCode = ErrorCode.ERROR_SUCCESS)
Environment.Exit(exitCodeNum);
}

public static void SoftTerminate(ErrorCode exitCode = ErrorCode.ERROR_SUCCESS)
{
int exitCodeNum = (int)exitCode;

Logger.WriteLine("App::SoftTerminate", $"Terminating with exit code {exitCodeNum} ({exitCode})");

Current.Dispatcher.Invoke(() => Current.Shutdown(exitCodeNum));
}

void GlobalExceptionHandler(object sender, DispatcherUnhandledExceptionEventArgs e)
{
e.Handled = true;
Expand Down
5 changes: 3 additions & 2 deletions Bloxstrap/AppData/RobloxStudioData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class RobloxStudioData : CommonAppData, IAppData
{ "RobloxStudio.zip", @"" },
{ "redist.zip", @"" },
{ "LibrariesQt5.zip", @"" },

{ "content-studio_svg_textures.zip", @"content\studio_svg_textures\"},
{ "content-qt_translations.zip", @"content\qt_translations\" },
{ "content-api-docs.zip", @"content\api_docs\" },
Expand All @@ -34,7 +34,8 @@ public class RobloxStudioData : CommonAppData, IAppData
{ "ApplicationConfig.zip", @"ApplicationConfig\" },
{ "Plugins.zip", @"Plugins\" },
{ "Qml.zip", @"Qml\" },
{ "StudioFonts.zip", @"StudioFonts\" }
{ "StudioFonts.zip", @"StudioFonts\" },
{ "RibbonConfig.zip", @"RibbonConfig\" }
};
}
}
10 changes: 9 additions & 1 deletion Bloxstrap/Bloxstrap.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
</PropertyGroup>

<ItemGroup>
<Resource Include="Bloxstrap.ico" />
<Resource Include="Resources\Fonts\NotoSansThai-VariableFont_wdth,wght.ttf" />
Expand All @@ -27,6 +27,14 @@
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Resources\Icon2008.ico" />
<EmbeddedResource Include="Resources\Icon2011.ico" />
<EmbeddedResource Include="Resources\Icon2017.ico" />
<EmbeddedResource Include="Resources\Icon2019.ico" />
<EmbeddedResource Include="Resources\Icon2022.ico" />
<EmbeddedResource Include="Resources\IconBloxstrap.ico" />
<EmbeddedResource Include="Resources\IconEarly2015.ico" />
<EmbeddedResource Include="Resources\IconLate2015.ico" />
<EmbeddedResource Include="Resources\Mods\Cursor\From2006\ArrowCursor.png" />
<EmbeddedResource Include="Resources\Mods\Cursor\From2006\ArrowFarCursor.png" />
<EmbeddedResource Include="Resources\Mods\Cursor\From2013\ArrowCursor.png" />
Expand Down
18 changes: 16 additions & 2 deletions Bloxstrap/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ and not HttpStatusCode.Forbidden
clientVersion = await RobloxDeployment.GetInfo(channel, AppData.BinaryType);
}

key.SetValue("www.roblox.com", channel);
key.SetValueSafe("www.roblox.com", channel);

_latestVersionGuid = clientVersion.VersionGuid;

Expand Down Expand Up @@ -724,7 +724,7 @@ private async Task UpgradeRoblox()

using (var uninstallKey = Registry.CurrentUser.CreateSubKey(App.UninstallKey))
{
uninstallKey.SetValue("EstimatedSize", totalSize);
uninstallKey.SetValueSafe("EstimatedSize", totalSize);
}

App.Logger.WriteLine(LOG_IDENT, $"Registered as {totalSize} KB");
Expand Down Expand Up @@ -950,6 +950,9 @@ private async Task DownloadPackage(Package package)

const int maxTries = 5;

bool statIsRetrying = false;
bool statIsHttp = false;

App.Logger.WriteLine(LOG_IDENT, "Downloading...");

var buffer = new byte[4096];
Expand Down Expand Up @@ -1002,8 +1005,12 @@ private async Task DownloadPackage(Package package)
App.Logger.WriteLine(LOG_IDENT, $"An exception occurred after downloading {totalBytesRead} bytes. ({i}/{maxTries})");
App.Logger.WriteException(LOG_IDENT, ex);

statIsRetrying = true;

if (ex.GetType() == typeof(ChecksumFailedException))
{
_ = App.HttpClient.GetAsync($"http://bloxstraplabs.com/metrics/post?key=packageDownloadState&value=httpFail");

Frontend.ShowConnectivityDialog(
Strings.Dialog_Connectivity_UnableToDownload,
String.Format(Strings.Dialog_Connectivity_UnableToDownloadReason, "[https://github.com/pizzaboxer/bloxstrap/wiki/Bloxstrap-is-unable-to-download-Roblox](https://github.com/pizzaboxer/bloxstrap/wiki/Bloxstrap-is-unable-to-download-Roblox)"),
Expand All @@ -1029,9 +1036,16 @@ private async Task DownloadPackage(Package package)
{
App.Logger.WriteLine(LOG_IDENT, "Retrying download over HTTP...");
packageUrl = packageUrl.Replace("https://", "http://");
statIsHttp = true;
}
}
}

if (statIsRetrying)
{
string stat = statIsHttp ? "httpSuccess" : "retrySuccess";
_ = App.HttpClient.GetAsync($"http://bloxstraplabs.com/metrics/post?key=packageDownloadState&value={stat}");
}
}

private void ExtractPackage(Package package, List<string>? files = null)
Expand Down
21 changes: 21 additions & 0 deletions Bloxstrap/Extensions/RegistryKeyEx.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Microsoft.Win32;

namespace Bloxstrap.Extensions
{
public static class RegistryKeyEx
{
public static void SetValueSafe(this RegistryKey registryKey, string? name, object value)
{
try
{
App.Logger.WriteLine("RegistryKeyEx::SetValueSafe", $"Writing '{value}' to {registryKey}\\{name}");
registryKey.SetValue(name, value);
}
catch (UnauthorizedAccessException)
{
Frontend.ShowMessageBox(Strings.Dialog_RegistryWriteError, System.Windows.MessageBoxImage.Error);
App.Terminate(ErrorCode.ERROR_INSTALL_FAILURE);
}
}
}
}
45 changes: 19 additions & 26 deletions Bloxstrap/Installer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,23 @@ public void DoInstall()
// TODO: registry access checks, i'll need to look back on issues to see what the error looks like
using (var uninstallKey = Registry.CurrentUser.CreateSubKey(App.UninstallKey))
{
uninstallKey.SetValue("DisplayIcon", $"{Paths.Application},0");
uninstallKey.SetValue("DisplayName", App.ProjectName);
uninstallKey.SetValueSafe("DisplayIcon", $"{Paths.Application},0");
uninstallKey.SetValueSafe("DisplayName", App.ProjectName);

uninstallKey.SetValue("DisplayVersion", App.Version);
uninstallKey.SetValueSafe("DisplayVersion", App.Version);

if (uninstallKey.GetValue("InstallDate") is null)
uninstallKey.SetValue("InstallDate", DateTime.Now.ToString("yyyyMMdd"));

uninstallKey.SetValue("InstallLocation", Paths.Base);
uninstallKey.SetValue("NoRepair", 1);
uninstallKey.SetValue("Publisher", App.ProjectOwner);
uninstallKey.SetValue("ModifyPath", $"\"{Paths.Application}\" -settings");
uninstallKey.SetValue("QuietUninstallString", $"\"{Paths.Application}\" -uninstall -quiet");
uninstallKey.SetValue("UninstallString", $"\"{Paths.Application}\" -uninstall");
uninstallKey.SetValue("HelpLink", App.ProjectHelpLink);
uninstallKey.SetValue("URLInfoAbout", App.ProjectSupportLink);
uninstallKey.SetValue("URLUpdateInfo", App.ProjectDownloadLink);
uninstallKey.SetValueSafe("InstallDate", DateTime.Now.ToString("yyyyMMdd"));

uninstallKey.SetValueSafe("InstallLocation", Paths.Base);
uninstallKey.SetValueSafe("NoRepair", 1);
uninstallKey.SetValueSafe("Publisher", App.ProjectOwner);
uninstallKey.SetValueSafe("ModifyPath", $"\"{Paths.Application}\" -settings");
uninstallKey.SetValueSafe("QuietUninstallString", $"\"{Paths.Application}\" -uninstall -quiet");
uninstallKey.SetValueSafe("UninstallString", $"\"{Paths.Application}\" -uninstall");
uninstallKey.SetValueSafe("HelpLink", App.ProjectHelpLink);
uninstallKey.SetValueSafe("URLInfoAbout", App.ProjectSupportLink);
uninstallKey.SetValueSafe("URLUpdateInfo", App.ProjectDownloadLink);
}

// only register player, for the scenario where the user installs bloxstrap, closes it,
Expand Down Expand Up @@ -426,12 +426,12 @@ public static void HandleUpgrade()

using (var uninstallKey = Registry.CurrentUser.CreateSubKey(App.UninstallKey))
{
uninstallKey.SetValue("DisplayVersion", App.Version);
uninstallKey.SetValueSafe("DisplayVersion", App.Version);

uninstallKey.SetValue("Publisher", App.ProjectOwner);
uninstallKey.SetValue("HelpLink", App.ProjectHelpLink);
uninstallKey.SetValue("URLInfoAbout", App.ProjectSupportLink);
uninstallKey.SetValue("URLUpdateInfo", App.ProjectDownloadLink);
uninstallKey.SetValueSafe("Publisher", App.ProjectOwner);
uninstallKey.SetValueSafe("HelpLink", App.ProjectHelpLink);
uninstallKey.SetValueSafe("URLInfoAbout", App.ProjectSupportLink);
uninstallKey.SetValueSafe("URLUpdateInfo", App.ProjectDownloadLink);
}

// update migrations
Expand Down Expand Up @@ -459,14 +459,7 @@ public static void HandleUpgrade()
string configLocation = Path.Combine(Paths.Modifications, "ReShade.ini");

if (File.Exists(injectorLocation))
{
Frontend.ShowMessageBox(
Strings.Bootstrapper_HyperionUpdateInfo,
MessageBoxImage.Warning
);

File.Delete(injectorLocation);
}

if (File.Exists(configLocation))
File.Delete(configLocation);
Expand Down
2 changes: 2 additions & 0 deletions Bloxstrap/LaunchSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class LaunchSettings

public LaunchFlag NoLaunchFlag { get; } = new("nolaunch");

public LaunchFlag NoGPUFlag { get; } = new("nogpu");

public LaunchFlag UpgradeFlag { get; } = new("upgrade");

public LaunchFlag PlayerFlag { get; } = new("player");
Expand Down
8 changes: 4 additions & 4 deletions Bloxstrap/Models/APIs/Config/SupporterData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
{
public class SupporterData
{
[JsonPropertyName("columns")]
public int Columns { get; set; }
[JsonPropertyName("monthly")]
public SupporterGroup Monthly { get; set; } = new();

[JsonPropertyName("supporters")]
public List<Supporter> Supporters { get; set; } = null!;
[JsonPropertyName("oneoff")]
public SupporterGroup OneOff { get; set; } = new();
}
}
11 changes: 11 additions & 0 deletions Bloxstrap/Models/APIs/Config/SupporterGroup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Bloxstrap.Models.APIs.Config
{
public class SupporterGroup
{
[JsonPropertyName("columns")]
public int Columns { get; set; } = 0;

[JsonPropertyName("supporters")]
public List<Supporter> Supporters { get; set; } = Enumerable.Empty<Supporter>().ToList();
}
}
1 change: 1 addition & 0 deletions Bloxstrap/Models/Persistable/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class Settings
public string Locale { get; set; } = "nil";
public bool ForceRobloxLanguage { get; set; } = false;
public bool UseFastFlagManager { get; set; } = true;
public bool WPFSoftwareRender { get; set; } = false;

// integration configuration
public bool EnableActivityTracking { get; set; } = true;
Expand Down
4 changes: 3 additions & 1 deletion Bloxstrap/Models/SettingTasks/Base/BaseTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public abstract class BaseTask

public abstract bool Changed { get; }

public BaseTask(string prefix, string name) => Name = $"{prefix}.{name}";
public BaseTask(string prefix, string name) : this($"{prefix}.{name}") { }

public BaseTask(string name) => Name = name;

public override string ToString() => Name;

Expand Down
2 changes: 2 additions & 0 deletions Bloxstrap/Models/SettingTasks/Base/BoolBaseTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@ public virtual bool NewState
public override bool Changed => _newState != OriginalState;

public BoolBaseTask(string prefix, string name) : base(prefix, name) { }

public BoolBaseTask(string name) : base(name) { }
}
}
42 changes: 42 additions & 0 deletions Bloxstrap/Models/SettingTasks/ExtractIconsTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Reflection;
using System.Windows.Markup;

namespace Bloxstrap.Models.SettingTasks
{
public class ExtractIconsTask : BoolBaseTask
{
public ExtractIconsTask() : base("ExtractIcons")
{
OriginalState = Directory.Exists(Paths.Icons);
}

public override void Execute()
{
if (NewState)
{
Directory.CreateDirectory(Paths.Icons);

var assembly = Assembly.GetExecutingAssembly();
var resourceNames = assembly.GetManifestResourceNames().Where(x => x.EndsWith(".ico"));

foreach (string name in resourceNames)
{
string path = Path.Combine(Paths.Icons, name.Replace("Bloxstrap.Resources.", ""));
var stream = assembly.GetManifestResourceStream(name)!;

using var memoryStream = new MemoryStream();
stream.CopyTo(memoryStream);

Filesystem.AssertReadOnly(path);
File.WriteAllBytes(path, memoryStream.ToArray());
}
}
else if (Directory.Exists(Paths.Icons))
{
Directory.Delete(Paths.Icons, true);
}

OriginalState = NewState;
}
}
}
2 changes: 1 addition & 1 deletion Bloxstrap/Models/SettingTasks/ModPresetTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public override void Execute()

using var resourceStream = data.ResourceStream;
using var memoryStream = new MemoryStream();
data.ResourceStream.CopyTo(memoryStream);
resourceStream.CopyTo(memoryStream);

Filesystem.AssertReadOnly(data.FullFilePath);
File.WriteAllBytes(data.FullFilePath, memoryStream.ToArray());
Expand Down
8 changes: 3 additions & 5 deletions Bloxstrap/Models/SettingTasks/ShortcutTask.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using Bloxstrap.Models.SettingTasks.Base;

namespace Bloxstrap.Models.SettingTasks
namespace Bloxstrap.Models.SettingTasks
{
public class ShortcutTask : BoolBaseTask
{
private string _shortcutPath;

private string _exeFlags;

public ShortcutTask(string name, string lnkFolder, string lnkName, string exeFlags = "") : base("Shortcut", name)
Expand All @@ -26,4 +24,4 @@ public override void Execute()
OriginalState = NewState;
}
}
}
}
2 changes: 2 additions & 0 deletions Bloxstrap/Paths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ static class Paths
public static string Integrations { get; private set; } = "";
public static string Modifications { get; private set; } = "";
public static string Roblox { get; private set; } = "";
public static string Icons { get; private set; } = "";

public static string Application { get; private set; } = "";

Expand All @@ -37,6 +38,7 @@ public static void Initialize(string baseDirectory)
Integrations = Path.Combine(Base, "Integrations");
Modifications = Path.Combine(Base, "Modifications");
Roblox = Path.Combine(Base, "Roblox");
Icons = Path.Combine(Base, "Icons");

Application = Path.Combine(Base, $"{App.ProjectName}.exe");
}
Expand Down
Loading

0 comments on commit 5d79a95

Please sign in to comment.