diff --git a/Bloxstrap/App.xaml.cs b/Bloxstrap/App.xaml.cs index d760390..12b62fa 100644 --- a/Bloxstrap/App.xaml.cs +++ b/Bloxstrap/App.xaml.cs @@ -277,7 +277,7 @@ namespace Bloxstrap } } - Task bootstrapperTask = Task.Run(() => bootstrapper.Run()).ContinueWith(t => + Task bootstrapperTask = Task.Run(async () => await bootstrapper.Run()).ContinueWith(t => { Logger.WriteLine(LOG_IDENT, "Bootstrapper task has finished"); diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs index d192b25..2edd60e 100644 --- a/Bloxstrap/Bootstrapper.cs +++ b/Bloxstrap/Bootstrapper.cs @@ -52,7 +52,6 @@ namespace Bloxstrap private readonly CancellationTokenSource _cancelTokenSource = new(); private static bool FreshInstall => String.IsNullOrEmpty(App.State.Prop.VersionGuid); - private static string DesktopShortcutLocation => Path.Combine(Paths.Desktop, "Play Roblox.lnk"); private string _playerLocation => Path.Combine(_versionFolder, "RobloxPlayerBeta.exe"); @@ -508,45 +507,32 @@ namespace Bloxstrap if (!Directory.Exists(Paths.StartMenu)) { Directory.CreateDirectory(Paths.StartMenu); - - ShellLink.Shortcut.CreateShortcut(Paths.Application, "", Paths.Application, 0) - .WriteToFile(Path.Combine(Paths.StartMenu, "Play Roblox.lnk")); - - ShellLink.Shortcut.CreateShortcut(Paths.Application, "-menu", Paths.Application, 0) - .WriteToFile(Path.Combine(Paths.StartMenu, $"{App.ProjectName} Menu.lnk")); } else { // v2.0.0 - rebadge configuration menu as just "Bloxstrap Menu" string oldMenuShortcut = Path.Combine(Paths.StartMenu, $"Configure {App.ProjectName}.lnk"); - string newMenuShortcut = Path.Combine(Paths.StartMenu, $"{App.ProjectName} Menu.lnk"); if (File.Exists(oldMenuShortcut)) File.Delete(oldMenuShortcut); - - if (!File.Exists(newMenuShortcut)) - ShellLink.Shortcut.CreateShortcut(Paths.Application, "-menu", Paths.Application, 0) - .WriteToFile(newMenuShortcut); } + Utility.Shortcut.Create(Paths.Application, "", Path.Combine(Paths.StartMenu, "Play Roblox.lnk")); + Utility.Shortcut.Create(Paths.Application, "-menu", Path.Combine(Paths.StartMenu, $"{App.ProjectName} Menu.lnk")); + if (App.Settings.Prop.CreateDesktopIcon) { - if (!File.Exists(DesktopShortcutLocation)) + try { - try - { - ShellLink.Shortcut.CreateShortcut(Paths.Application, "", Paths.Application, 0) - .WriteToFile(DesktopShortcutLocation); - } - catch (Exception ex) - { - App.Logger.WriteLine(LOG_IDENT, "Could not create desktop shortcut, aborting"); - App.Logger.WriteException(LOG_IDENT, ex); - } - } + Utility.Shortcut.Create(Paths.Application, "", Path.Combine(Paths.Desktop, "Play Roblox.lnk")); - // one-time toggle, set it back to false - App.Settings.Prop.CreateDesktopIcon = false; + // one-time toggle, set it back to false + App.Settings.Prop.CreateDesktopIcon = false; + } + catch (Exception) + { + // suppress, we likely just don't have write perms for the desktop folder + } } } diff --git a/Bloxstrap/Enums/AssemblyLoadStatus.cs b/Bloxstrap/Enums/AssemblyLoadStatus.cs new file mode 100644 index 0000000..08ef104 --- /dev/null +++ b/Bloxstrap/Enums/AssemblyLoadStatus.cs @@ -0,0 +1,9 @@ +namespace Bloxstrap.Enums +{ + enum AssemblyLoadStatus + { + NotAttempted, + Failed, + Successful + } +} diff --git a/Bloxstrap/Utility/Shortcut.cs b/Bloxstrap/Utility/Shortcut.cs new file mode 100644 index 0000000..1594a90 --- /dev/null +++ b/Bloxstrap/Utility/Shortcut.cs @@ -0,0 +1,43 @@ +using System.Windows; + +namespace Bloxstrap.Utility +{ + internal static class Shortcut + { + private static AssemblyLoadStatus _loadStatus = AssemblyLoadStatus.NotAttempted; + + public static void Create(string exePath, string exeArgs, string lnkPath) + { + const string LOG_IDENT = "Shortcut::Create"; + + if (File.Exists(lnkPath)) + return; + + try + { + ShellLink.Shortcut.CreateShortcut(exePath, exeArgs, exePath, 0).WriteToFile(lnkPath); + + if (_loadStatus != AssemblyLoadStatus.Successful) + _loadStatus = AssemblyLoadStatus.Successful; + } + catch (Exception ex) + { + App.Logger.WriteLine(LOG_IDENT, $"Failed to create a shortcut for {lnkPath}!"); + App.Logger.WriteException(LOG_IDENT, ex); + + if (ex.GetType() != typeof(FileNotFoundException)) + throw; + + if (_loadStatus == AssemblyLoadStatus.Failed) + return; + + _loadStatus = AssemblyLoadStatus.Failed; + + Controls.ShowMessageBox( + $"{App.ProjectName} was unable to create shortcuts for the Desktop and Start menu. They will be created the next time Roblox is launched.", + MessageBoxImage.Information + ); + } + } + } +}