Skip to content

Commit d55b793

Browse files
authored
Fixed a crash that sometimes occurred when opening files and folders (#2138)
1 parent bad3a7e commit d55b793

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

Files.Launcher/Program.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,10 @@ await Win32API.StartSTATask(() =>
656656
}
657657
}
658658
}
659+
catch (InvalidOperationException)
660+
{
661+
// Invalid file path
662+
}
659663
}
660664

661665
private static bool HandleCommandLineArgs()

Files.Launcher/Win32API.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static async Task<string> GetFileAssociation(string filename)
4343
}
4444

4545
// Find desktop apps
46-
var lpResult = new StringBuilder();
46+
var lpResult = new StringBuilder(2048);
4747
var hResult = Shell32.FindExecutable(filename, null, lpResult);
4848
if (hResult.ToInt64() > 32)
4949
{

Files/Interacts/Interaction.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -485,10 +485,6 @@ private async void OpenSelectedItems(bool displayApplicationPicker)
485485
}
486486
else if (selectedItemCount > 1)
487487
{
488-
foreach (ListedItem clickedOnItem in CurrentInstance.ContentPage.SelectedItems.Where(x => x.PrimaryItemAttribute == StorageItemTypes.Folder))
489-
{
490-
await MainPage.AddNewTab(typeof(ModernShellPage), (clickedOnItem as ShortcutItem)?.TargetPath ?? clickedOnItem.ItemPath);
491-
}
492488
foreach (ListedItem clickedOnItem in CurrentInstance.ContentPage.SelectedItems.Where(x => x.PrimaryItemAttribute == StorageItemTypes.File
493489
&& !x.IsShortcutItem))
494490
{
@@ -510,6 +506,10 @@ private async void OpenSelectedItems(bool displayApplicationPicker)
510506
var applicationPath = string.Join('|', CurrentInstance.ContentPage.SelectedItems.Where(x => x.PrimaryItemAttribute == StorageItemTypes.File).Select(x => x.ItemPath));
511507
await InvokeWin32Component(applicationPath);
512508
}
509+
foreach (ListedItem clickedOnItem in CurrentInstance.ContentPage.SelectedItems.Where(x => x.PrimaryItemAttribute == StorageItemTypes.Folder))
510+
{
511+
await MainPage.AddNewTab(typeof(ModernShellPage), (clickedOnItem as ShortcutItem)?.TargetPath ?? clickedOnItem.ItemPath);
512+
}
513513
}
514514
}
515515
catch (FileNotFoundException)

0 commit comments

Comments
 (0)