Skip to content

Commit

Permalink
Fix 'An error occurred trying to start process 'explorer.exe'' crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Equbuxu committed Dec 2, 2023
1 parent dc9de5a commit f09eeef
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
6 changes: 5 additions & 1 deletion src/PixiEditor/Helpers/ProcessHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Security.Principal;
using System.Windows.Input;
using PixiEditor.Exceptions;

namespace PixiEditor.Helpers;

Expand Down Expand Up @@ -32,10 +33,13 @@ public static void OpenInExplorer(string path)
{
string fixedPath = Path.GetFullPath(path);
var process = Process.Start("explorer.exe", $"/select,\"{fixedPath}\"");

// Explorer might need a second to show up
process.WaitForExit(500);
}
catch (Win32Exception)
{
throw new RecoverableException("ERROR_FAILED_TO_OPEN_EXPLORER");
}
finally
{
Mouse.OverrideCursor = null;
Expand Down
27 changes: 17 additions & 10 deletions src/PixiEditor/ViewModels/SubViewModels/Main/FileViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,18 +345,25 @@ public bool SaveDocument(DocumentViewModel document, bool asNew)
[Command.Basic("PixiEditor.File.Export", "EXPORT", "EXPORT_IMAGE", CanExecute = "PixiEditor.HasDocument", Key = Key.E, Modifiers = ModifierKeys.Control)]
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");
}
}

Expand Down
15 changes: 13 additions & 2 deletions src/PixiEditor/Views/Dialogs/HelloTherePopup.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
using System.IO;
using System.Windows;
using System.Windows.Input;
using PixiEditor.Exceptions;
using PixiEditor.Extensions.Common.UserPreferences;
using PixiEditor.Helpers;
using PixiEditor.Models.Commands;
using PixiEditor.Models.DataHolders;
using PixiEditor.Models.Dialogs;
using PixiEditor.Models.Services.NewsFeed;
using PixiEditor.ViewModels.SubViewModels.Main;

Expand Down Expand Up @@ -193,8 +195,17 @@ private void OpenRecent(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);
Expand Down

0 comments on commit f09eeef

Please sign in to comment.