From 3f0ab2239345c643016b7eca51a886d1672ea48c Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Mon, 9 Sep 2024 16:17:54 +0100 Subject: [PATCH] Address "Access to the path is denied" error --- Bloxstrap/App.xaml.cs | 11 ++------- Bloxstrap/Installer.cs | 23 +++++++++++++++---- Bloxstrap/Paths.cs | 2 -- Bloxstrap/Resources/Strings.Designer.cs | 11 +++++++++ Bloxstrap/Resources/Strings.resx | 5 ++++ .../ViewModels/Installer/InstallViewModel.cs | 6 ----- Bloxstrap/Utilities.cs | 5 ++-- 7 files changed, 39 insertions(+), 24 deletions(-) diff --git a/Bloxstrap/App.xaml.cs b/Bloxstrap/App.xaml.cs index e8a91e2e..373c7eec 100644 --- a/Bloxstrap/App.xaml.cs +++ b/Bloxstrap/App.xaml.cs @@ -57,21 +57,13 @@ public partial class App : Application private static bool _showingExceptionDialog = false; - private static bool _terminating = false; - public static void Terminate(ErrorCode exitCode = ErrorCode.ERROR_SUCCESS) { - if (_terminating) - return; - int exitCodeNum = (int)exitCode; Logger.WriteLine("App::Terminate", $"Terminating with exit code {exitCodeNum} ({exitCode})"); - Current.Dispatcher.Invoke(() => Current.Shutdown(exitCodeNum)); - // Environment.Exit(exitCodeNum); - - _terminating = true; + Environment.Exit(exitCodeNum); } void GlobalExceptionHandler(object sender, DispatcherUnhandledExceptionEventArgs e) @@ -109,6 +101,7 @@ public static void FinalizeExceptionHandling(Exception ex, bool log = true) public static async Task GetLatestRelease() { const string LOG_IDENT = "App::GetLatestRelease"; + try { var releaseInfo = await Http.GetJson($"https://api.github.com/repos/{ProjectRepository}/releases/latest"); diff --git a/Bloxstrap/Installer.cs b/Bloxstrap/Installer.cs index e27fe5b8..0fafded3 100644 --- a/Bloxstrap/Installer.cs +++ b/Bloxstrap/Installer.cs @@ -35,7 +35,19 @@ public void DoInstall() if (!IsImplicitInstall) { Filesystem.AssertReadOnly(Paths.Application); - File.Copy(Paths.Process, Paths.Application, true); + + try + { + File.Copy(Paths.Process, Paths.Application, true); + } + catch (Exception ex) + { + App.Logger.WriteLine(LOG_IDENT, "Could not overwrite executable"); + App.Logger.WriteException(LOG_IDENT, ex); + + Frontend.ShowMessageBox(Strings.Installer_Install_CannotOverwrite, MessageBoxImage.Error); + App.Terminate(ErrorCode.ERROR_INSTALL_FAILURE); + } } // TODO: registry access checks, i'll need to look back on issues to see what the error looks like @@ -259,8 +271,10 @@ public static void DoUninstall(bool keepData) () => File.Delete(StartMenuShortcut), - () => Directory.Delete(Paths.Versions, true), () => Directory.Delete(Paths.Downloads, true), + () => Directory.Delete(Paths.Roblox, true), + + () => File.Delete(App.State.FileLocation) }; if (!keepData) @@ -270,8 +284,7 @@ public static void DoUninstall(bool keepData) () => Directory.Delete(Paths.Modifications, true), () => Directory.Delete(Paths.Logs, true), - () => File.Delete(App.Settings.FileLocation), - () => File.Delete(App.State.FileLocation), // TODO: maybe this should always be deleted? not sure yet + () => File.Delete(App.Settings.FileLocation) }); } @@ -525,6 +538,8 @@ public static void HandleUpgrade() } App.FastFlags.SetValue("FFlagFixGraphicsQuality", null); + + Directory.Delete(Path.Combine(Paths.Base, "Versions")); } App.Settings.Save(); diff --git a/Bloxstrap/Paths.cs b/Bloxstrap/Paths.cs index 7240c6f0..36f81361 100644 --- a/Bloxstrap/Paths.cs +++ b/Bloxstrap/Paths.cs @@ -20,7 +20,6 @@ static class Paths public static string Downloads { get; private set; } = ""; public static string Logs { get; private set; } = ""; public static string Integrations { get; private set; } = ""; - public static string Versions { get; private set; } = ""; public static string Modifications { get; private set; } = ""; public static string Roblox { get; private set; } = ""; @@ -36,7 +35,6 @@ public static void Initialize(string baseDirectory) Downloads = Path.Combine(Base, "Downloads"); Logs = Path.Combine(Base, "Logs"); Integrations = Path.Combine(Base, "Integrations"); - Versions = Path.Combine(Base, "Versions"); Modifications = Path.Combine(Base, "Modifications"); Roblox = Path.Combine(Base, "Roblox"); diff --git a/Bloxstrap/Resources/Strings.Designer.cs b/Bloxstrap/Resources/Strings.Designer.cs index 67ab3a1b..99eb9bdf 100644 --- a/Bloxstrap/Resources/Strings.Designer.cs +++ b/Bloxstrap/Resources/Strings.Designer.cs @@ -1446,6 +1446,17 @@ public static string Installer_Completion_Title { } } + /// + /// Looks up a localized string similar to Bloxstrap has been installed to this location before and is still present, however the installer cannot overwrite the old executable. + /// + ///Please manually delete Bloxstrap.exe from the install location or try restarting your system, and then retry installation afterwards.. + /// + public static string Installer_Install_CannotOverwrite { + get { + return ResourceManager.GetString("Installer.Install.CannotOverwrite", resourceCulture); + } + } + /// /// Looks up a localized string similar to Existing data found. Your mods and settings will be restored.. /// diff --git a/Bloxstrap/Resources/Strings.resx b/Bloxstrap/Resources/Strings.resx index 12855853..0e2ebd12 100644 --- a/Bloxstrap/Resources/Strings.resx +++ b/Bloxstrap/Resources/Strings.resx @@ -1177,4 +1177,9 @@ Are you sure you want to continue? Because Roblox needs to be installed or upgraded, Bloxstrap cannot continue. + + Bloxstrap has been installed to this location before and is still present, however the installer cannot overwrite the old executable. + +Please manually delete Bloxstrap.exe from the install location or try restarting your system, and then retry installation afterwards. + \ No newline at end of file diff --git a/Bloxstrap/UI/ViewModels/Installer/InstallViewModel.cs b/Bloxstrap/UI/ViewModels/Installer/InstallViewModel.cs index 60988617..8bff0017 100644 --- a/Bloxstrap/UI/ViewModels/Installer/InstallViewModel.cs +++ b/Bloxstrap/UI/ViewModels/Installer/InstallViewModel.cs @@ -2,12 +2,6 @@ using System.Windows.Input; using CommunityToolkit.Mvvm.Input; -using Bloxstrap.Resources; - -using Microsoft.Win32; -using Wpf.Ui.Mvvm.Interfaces; -using System.ComponentModel; - namespace Bloxstrap.UI.ViewModels.Installer { public class InstallViewModel : NotifyPropertyChangedViewModel diff --git a/Bloxstrap/Utilities.cs b/Bloxstrap/Utilities.cs index 2b28ae7e..327f7340 100644 --- a/Bloxstrap/Utilities.cs +++ b/Bloxstrap/Utilities.cs @@ -1,5 +1,4 @@ using System.ComponentModel; -using System.Security.Principal; namespace Bloxstrap { @@ -52,9 +51,9 @@ public static VersionComparison CompareVersions(string versionStr1, string versi public static string GetRobloxVersion(bool studio) { string versionGuid = studio ? App.State.Prop.Studio.VersionGuid : App.State.Prop.Player.VersionGuid; - string fileName = studio ? "RobloxStudioBeta.exe" : "RobloxPlayerBeta.exe"; + string fileName = studio ? "Studio/RobloxStudioBeta.exe" : "Player/RobloxPlayerBeta.exe"; - string playerLocation = Path.Combine(Paths.Versions, versionGuid, fileName); + string playerLocation = Path.Combine(Paths.Roblox, fileName); if (!File.Exists(playerLocation)) return "";