Browse Source

Fix 'An error occurred trying to start process 'explorer.exe'' crash

Equbuxu 1 year ago
parent
commit
f09eeef7dd

+ 5 - 1
src/PixiEditor/Helpers/ProcessHelper.cs

@@ -3,6 +3,7 @@ using System.Diagnostics;
 using System.IO;
 using System.IO;
 using System.Security.Principal;
 using System.Security.Principal;
 using System.Windows.Input;
 using System.Windows.Input;
+using PixiEditor.Exceptions;
 
 
 namespace PixiEditor.Helpers;
 namespace PixiEditor.Helpers;
 
 
@@ -32,10 +33,13 @@ internal static class ProcessHelper
         {
         {
             string fixedPath = Path.GetFullPath(path);
             string fixedPath = Path.GetFullPath(path);
             var process = Process.Start("explorer.exe", $"/select,\"{fixedPath}\"");
             var process = Process.Start("explorer.exe", $"/select,\"{fixedPath}\"");
-
             // Explorer might need a second to show up
             // Explorer might need a second to show up
             process.WaitForExit(500);
             process.WaitForExit(500);
         }
         }
+        catch (Win32Exception)
+        {
+            throw new RecoverableException("ERROR_FAILED_TO_OPEN_EXPLORER");
+        }
         finally
         finally
         {
         {
             Mouse.OverrideCursor = null;
             Mouse.OverrideCursor = null;

+ 17 - 10
src/PixiEditor/ViewModels/SubViewModels/Main/FileViewModel.cs

@@ -345,18 +345,25 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
     [Command.Basic("PixiEditor.File.Export", "EXPORT", "EXPORT_IMAGE", CanExecute = "PixiEditor.HasDocument", Key = Key.E, Modifiers = ModifierKeys.Control)]
     [Command.Basic("PixiEditor.File.Export", "EXPORT", "EXPORT_IMAGE", CanExecute = "PixiEditor.HasDocument", Key = Key.E, Modifiers = ModifierKeys.Control)]
     public void ExportFile()
     public void ExportFile()
     {
     {
-        DocumentViewModel doc = Owner.DocumentManagerSubViewModel.ActiveDocument;
-        if (doc is null)
-            return;
+        try
+        {
+            DocumentViewModel doc = Owner.DocumentManagerSubViewModel.ActiveDocument;
+            if (doc is null)
+                return;
 
 
-        ExportFileDialog info = new ExportFileDialog(doc.SizeBindable);
-        if (info.ShowDialog())
+            ExportFileDialog info = new ExportFileDialog(doc.SizeBindable);
+            if (info.ShowDialog())
+            {
+                SaveResult result = Exporter.TrySaveUsingDataFromDialog(doc, info.FilePath, info.ChosenFormat, out string finalPath, new(info.FileWidth, info.FileHeight));
+                if (result == SaveResult.Success)
+                    ProcessHelper.OpenInExplorer(finalPath);
+                else
+                    ShowSaveError((DialogSaveResult)result);
+            }
+        }
+        catch (RecoverableException e)
         {
         {
-            SaveResult result = Exporter.TrySaveUsingDataFromDialog(doc, info.FilePath, info.ChosenFormat, out string finalPath, new(info.FileWidth, info.FileHeight));
-            if (result == SaveResult.Success)
-                ProcessHelper.OpenInExplorer(finalPath);
-            else
-                ShowSaveError((DialogSaveResult)result);
+            NoticeDialog.Show(e.DisplayMessage, "ERROR");
         }
         }
     }
     }
 
 

+ 13 - 2
src/PixiEditor/Views/Dialogs/HelloTherePopup.xaml.cs

@@ -3,10 +3,12 @@ using System.Diagnostics;
 using System.IO;
 using System.IO;
 using System.Windows;
 using System.Windows;
 using System.Windows.Input;
 using System.Windows.Input;
+using PixiEditor.Exceptions;
 using PixiEditor.Extensions.Common.UserPreferences;
 using PixiEditor.Extensions.Common.UserPreferences;
 using PixiEditor.Helpers;
 using PixiEditor.Helpers;
 using PixiEditor.Models.Commands;
 using PixiEditor.Models.Commands;
 using PixiEditor.Models.DataHolders;
 using PixiEditor.Models.DataHolders;
+using PixiEditor.Models.Dialogs;
 using PixiEditor.Models.Services.NewsFeed;
 using PixiEditor.Models.Services.NewsFeed;
 using PixiEditor.ViewModels.SubViewModels.Main;
 using PixiEditor.ViewModels.SubViewModels.Main;
 
 
@@ -193,8 +195,17 @@ internal partial class HelloTherePopup : Window
 
 
     private void OpenInExplorer(object parameter)
     private void OpenInExplorer(object parameter)
     {
     {
-        if (parameter is not string value) return;
-        ProcessHelper.OpenInExplorer(value);
+        if (parameter is not string value) 
+            return;
+
+        try
+        {
+            ProcessHelper.OpenInExplorer(value);
+        }
+        catch (RecoverableException e)
+        {
+            NoticeDialog.Show(e.DisplayMessage, "INTERNAL_ERROR");
+        }
     }
     }
 
 
     private bool CanOpenInExplorer(object parameter) => File.Exists((string)parameter);
     private bool CanOpenInExplorer(object parameter) => File.Exists((string)parameter);