Skip to content

Commit

Permalink
Show notice if ShellLink can't be loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
pizzaboxer committed Aug 26, 2023
1 parent 0df4840 commit 30ae314
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Bloxstrap/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ protected override void OnStartup(StartupEventArgs e)
}
}

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");
Expand Down
38 changes: 12 additions & 26 deletions Bloxstrap/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public class Bootstrapper
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");

Expand Down Expand Up @@ -508,45 +507,32 @@ public static void CheckInstall()
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
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions Bloxstrap/Enums/AssemblyLoadStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Bloxstrap.Enums
{
enum AssemblyLoadStatus
{
NotAttempted,
Failed,
Successful
}
}
43 changes: 43 additions & 0 deletions Bloxstrap/Utility/Shortcut.cs
Original file line number Diff line number Diff line change
@@ -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
);
}
}
}
}

0 comments on commit 30ae314

Please sign in to comment.