Address "Access to the path is denied" error

This commit is contained in:
pizzaboxer 2024-09-09 16:17:54 +01:00
parent ff387cfc59
commit 3f0ab22393
No known key found for this signature in database
GPG Key ID: 59D4A1DBAD0F2BA8
7 changed files with 39 additions and 24 deletions

View File

@ -57,21 +57,13 @@ namespace Bloxstrap
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 @@ namespace Bloxstrap
public static async Task<GithubRelease?> GetLatestRelease()
{
const string LOG_IDENT = "App::GetLatestRelease";
try
{
var releaseInfo = await Http.GetJson<GithubRelease>($"https://api.github.com/repos/{ProjectRepository}/releases/latest");

View File

@ -35,7 +35,19 @@ namespace Bloxstrap
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 @@ namespace Bloxstrap
() => 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 @@ namespace Bloxstrap
() => 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 @@ namespace Bloxstrap
}
App.FastFlags.SetValue("FFlagFixGraphicsQuality", null);
Directory.Delete(Path.Combine(Paths.Base, "Versions"));
}
App.Settings.Save();

View File

@ -20,7 +20,6 @@
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 @@
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");

View File

@ -1446,6 +1446,17 @@ namespace Bloxstrap.Resources {
}
}
/// <summary>
/// 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..
/// </summary>
public static string Installer_Install_CannotOverwrite {
get {
return ResourceManager.GetString("Installer.Install.CannotOverwrite", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Existing data found. Your mods and settings will be restored..
/// </summary>

View File

@ -1177,4 +1177,9 @@ Are you sure you want to continue?</value>
<data name="Dialog.Connectivity.RobloxUpgradeNeeded" xml:space="preserve">
<value>Because Roblox needs to be installed or upgraded, Bloxstrap cannot continue.</value>
</data>
<data name="Installer.Install.CannotOverwrite" xml:space="preserve">
<value>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.</value>
</data>
</root>

View File

@ -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

View File

@ -1,5 +1,4 @@
using System.ComponentModel;
using System.Security.Principal;
namespace Bloxstrap
{
@ -52,9 +51,9 @@ namespace Bloxstrap
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 "";