diff --git a/src/Files.App.CsWin32/NativeMethods.txt b/src/Files.App.CsWin32/NativeMethods.txt index 9f10fdd3870b..9d900f53d0e9 100644 --- a/src/Files.App.CsWin32/NativeMethods.txt +++ b/src/Files.App.CsWin32/NativeMethods.txt @@ -267,3 +267,4 @@ WINTRUST_DATA HCERTSTORE CERT_QUERY_ENCODING_TYPE CertGetNameString +MessageBox diff --git a/src/Files.App/Constants.cs b/src/Files.App/Constants.cs index c3a531e502dd..578c8951644f 100644 --- a/src/Files.App/Constants.cs +++ b/src/Files.App/Constants.cs @@ -282,5 +282,13 @@ public static class Distributions "FilesDev", // dev }; } + + public static class Startup + { + // These strings are intentionally hardcoded and cannot be moved to resource files. + // The Windows App Runtime (which powers the resource loading system) may itself be unavailable at this point + public const string MissingRuntimeMessage = "Files failed to start. A required Windows component could not be loaded. Try reinstalling Files from the Microsoft Store or from https://files.community/download"; + public const string MissingRuntimeTitle = "Files - Startup Error"; + } } } diff --git a/src/Files.App/Program.cs b/src/Files.App/Program.cs index 5676b750ed43..91702da505af 100644 --- a/src/Files.App/Program.cs +++ b/src/Files.App/Program.cs @@ -6,7 +6,9 @@ using Microsoft.UI.Xaml; using Microsoft.Windows.AppLifecycle; using System.IO; +using System.Runtime.InteropServices; using System.Text; +using Windows.Win32.UI.WindowsAndMessaging; using Windows.ApplicationModel.Activation; using Windows.Storage; @@ -101,7 +103,23 @@ static bool ProcessPathPredicate(Process p) //Server.AppInstanceMonitor.StartMonitor(Environment.ProcessId); var OpenTabInExistingInstance = ApplicationData.Current.LocalSettings.Values.Get("OpenTabInExistingInstance", true); - var activatedArgs = AppInstance.GetCurrent().GetActivatedEventArgs(); + + AppActivationArguments activatedArgs; + try + { + activatedArgs = AppInstance.GetCurrent().GetActivatedEventArgs(); + } + catch (COMException ex) when (ex.HResult == unchecked((int)0x80040154)) + { + Windows.Win32.PInvoke.MessageBox( + default, + Constants.Startup.MissingRuntimeMessage, + Constants.Startup.MissingRuntimeTitle, + MESSAGEBOX_STYLE.MB_ICONERROR); + + throw new InvalidOperationException(Constants.Startup.MissingRuntimeMessage, ex); + } + var commandLineArgs = GetCommandLineArgs(activatedArgs); if (commandLineArgs is not null)