diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs index 3a4a181..a28ce22 100644 --- a/Bloxstrap/Bootstrapper.cs +++ b/Bloxstrap/Bootstrapper.cs @@ -252,7 +252,7 @@ namespace Bloxstrap clientVersion = await RobloxDeployment.GetInfo(channel, AppData.BinaryType); } - key.SetValue("www.roblox.com", channel); + key.SetValueSafe("www.roblox.com", channel); _latestVersionGuid = clientVersion.VersionGuid; @@ -724,7 +724,7 @@ namespace Bloxstrap 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"); diff --git a/Bloxstrap/Extensions/RegistryKeyEx.cs b/Bloxstrap/Extensions/RegistryKeyEx.cs new file mode 100644 index 0000000..a5e9af4 --- /dev/null +++ b/Bloxstrap/Extensions/RegistryKeyEx.cs @@ -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(); + } + } + } +} diff --git a/Bloxstrap/Installer.cs b/Bloxstrap/Installer.cs index 59fc133..bda9f34 100644 --- a/Bloxstrap/Installer.cs +++ b/Bloxstrap/Installer.cs @@ -53,23 +53,23 @@ namespace Bloxstrap // 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.SetValueSafe("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("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, @@ -426,12 +426,12 @@ namespace Bloxstrap 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 diff --git a/Bloxstrap/Resources/Strings.Designer.cs b/Bloxstrap/Resources/Strings.Designer.cs index 8a3f4a5..82d3c72 100644 --- a/Bloxstrap/Resources/Strings.Designer.cs +++ b/Bloxstrap/Resources/Strings.Designer.cs @@ -1021,6 +1021,15 @@ namespace Bloxstrap.Resources { } } + /// + /// Looks up a localized string similar to Bloxstrap is unable to write to the Windows Registry. An antivirus is likely interfering and causing issues. Please check to make sure there isn't anything that would restrict Bloxstrap's operation.. + /// + public static string Dialog_RegistryWriteError { + get { + return ResourceManager.GetString("Dialog.RegistryWriteError", resourceCulture); + } + } + /// /// Looks up a localized string similar to Early 2015. /// diff --git a/Bloxstrap/Resources/Strings.resx b/Bloxstrap/Resources/Strings.resx index 231b03f..6ae9486 100644 --- a/Bloxstrap/Resources/Strings.resx +++ b/Bloxstrap/Resources/Strings.resx @@ -1204,4 +1204,7 @@ Please manually delete Bloxstrap.exe from the install location or try restarting To use for your shortcuts, right-click it, open properties, change icon, browse, and pick from the Icons folder. + + Bloxstrap is unable to write to the Windows Registry. An antivirus is likely interfering and causing issues. Please check to make sure there isn't anything that would restrict Bloxstrap's operation. + \ No newline at end of file diff --git a/Bloxstrap/Utility/WindowsRegistry.cs b/Bloxstrap/Utility/WindowsRegistry.cs index be2981c..23ca712 100644 --- a/Bloxstrap/Utility/WindowsRegistry.cs +++ b/Bloxstrap/Utility/WindowsRegistry.cs @@ -16,14 +16,14 @@ namespace Bloxstrap.Utility if (uriKey.GetValue("") is null) { - uriKey.SetValue("", $"URL: {name} Protocol"); - uriKey.SetValue("URL Protocol", ""); + uriKey.SetValueSafe("", $"URL: {name} Protocol"); + uriKey.SetValueSafe("URL Protocol", ""); } if (uriCommandKey.GetValue("") as string != handlerArgs) { - uriIconKey.SetValue("", handler); - uriCommandKey.SetValue("", handlerArgs); + uriIconKey.SetValueSafe("", handler); + uriCommandKey.SetValueSafe("", handlerArgs); } } @@ -85,16 +85,16 @@ namespace Bloxstrap.Utility using RegistryKey uriCommandKey = uriOpenKey.CreateSubKey(@"command"); if (uriKey.GetValue("") as string != keyValue) - uriKey.SetValue("", keyValue); + uriKey.SetValueSafe("", keyValue); if (uriCommandKey.GetValue("") as string != handlerArgs) - uriCommandKey.SetValue("", handlerArgs); + uriCommandKey.SetValueSafe("", handlerArgs); if (uriOpenKey.GetValue("") as string != "Open") - uriOpenKey.SetValue("", "Open"); + uriOpenKey.SetValueSafe("", "Open"); if (uriIconKey.GetValue("") as string != iconValue) - uriIconKey.SetValue("", iconValue); + uriIconKey.SetValueSafe("", iconValue); } public static void RegisterStudioFileType(string key) @@ -103,7 +103,7 @@ namespace Bloxstrap.Utility uriKey.CreateSubKey(RobloxPlaceKey + @"\ShellNew"); if (uriKey.GetValue("") as string != RobloxPlaceKey) - uriKey.SetValue("", RobloxPlaceKey); + uriKey.SetValueSafe("", RobloxPlaceKey); } public static void Unregister(string key)