Show notice if ShellLink can't be loaded

This commit is contained in:
pizzaboxer 2023-08-26 14:49:06 +01:00
parent 0df4840873
commit 30ae314537
No known key found for this signature in database
GPG Key ID: 59D4A1DBAD0F2BA8
4 changed files with 65 additions and 27 deletions

View File

@ -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");

View File

@ -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,46 +507,33 @@ 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
{
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;
}
catch (Exception)
{
// suppress, we likely just don't have write perms for the desktop folder
}
}
}
private async Task CheckForUpdates()

View File

@ -0,0 +1,9 @@
namespace Bloxstrap.Enums
{
enum AssemblyLoadStatus
{
NotAttempted,
Failed,
Successful
}
}

View File

@ -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
);
}
}
}
}