Skip to content

Commit c75d3d7

Browse files
authored
Fix: Fixed issues with opening certain file formats (#16102)
1 parent c795771 commit c75d3d7

File tree

1 file changed

+2
-81
lines changed

1 file changed

+2
-81
lines changed

src/Files.App/Helpers/Navigation/NavigationHelpers.cs

+2-81
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33

44
using Files.Shared.Helpers;
55
using Microsoft.UI.Xaml.Controls;
6+
using Microsoft.UI.Xaml.Media;
67
using Microsoft.UI.Xaml.Media.Imaging;
78
using Windows.Storage;
8-
using Windows.Storage.Search;
99
using Windows.System;
10-
using Microsoft.UI.Xaml.Media;
1110

1211
namespace Files.App.Helpers
1312
{
@@ -587,85 +586,7 @@ private static async Task<FilesystemResult> OpenFile(string path, IShellPage ass
587586
}
588587
else
589588
{
590-
//try using launcher first
591-
bool launchSuccess = false;
592-
593-
BaseStorageFileQueryResult? fileQueryResult = null;
594-
595-
//Get folder to create a file query (to pass to apps like Photos, Movies & TV..., needed to scroll through the folder like what Windows Explorer does)
596-
BaseStorageFolder currentFolder = await associatedInstance.ShellViewModel.GetFolderFromPathAsync(PathNormalization.GetParentDir(path));
597-
598-
if (currentFolder is not null)
599-
{
600-
QueryOptions queryOptions = new(CommonFileQuery.DefaultQuery, null);
601-
602-
//We can have many sort entries
603-
SortEntry sortEntry = new()
604-
{
605-
AscendingOrder = associatedInstance.InstanceViewModel.FolderSettings.DirectorySortDirection == SortDirection.Ascending
606-
};
607-
608-
//Basically we tell to the launched app to follow how we sorted the files in the directory.
609-
var sortOption = associatedInstance.InstanceViewModel.FolderSettings.DirectorySortOption;
610-
611-
switch (sortOption)
612-
{
613-
case SortOption.Name:
614-
sortEntry.PropertyName = "System.ItemNameDisplay";
615-
queryOptions.SortOrder.Clear();
616-
queryOptions.SortOrder.Add(sortEntry);
617-
break;
618-
619-
case SortOption.DateModified:
620-
sortEntry.PropertyName = "System.DateModified";
621-
queryOptions.SortOrder.Clear();
622-
queryOptions.SortOrder.Add(sortEntry);
623-
break;
624-
625-
case SortOption.DateCreated:
626-
sortEntry.PropertyName = "System.DateCreated";
627-
queryOptions.SortOrder.Clear();
628-
queryOptions.SortOrder.Add(sortEntry);
629-
break;
630-
631-
//Unfortunately this is unsupported | Remarks: https://learn.microsoft.com/uwp/api/windows.storage.search.queryoptions.sortorder?view=winrt-19041
632-
//case Enums.SortOption.Size:
633-
634-
//sortEntry.PropertyName = "System.TotalFileSize";
635-
//queryOptions.SortOrder.Clear();
636-
//queryOptions.SortOrder.Add(sortEntry);
637-
//break;
638-
639-
//Unfortunately this is unsupported | Remarks: https://learn.microsoft.com/uwp/api/windows.storage.search.queryoptions.sortorder?view=winrt-19041
640-
//case Enums.SortOption.FileType:
641-
642-
//sortEntry.PropertyName = "System.FileExtension";
643-
//queryOptions.SortOrder.Clear();
644-
//queryOptions.SortOrder.Add(sortEntry);
645-
//break;
646-
647-
//Handle unsupported
648-
default:
649-
//keep the default one in SortOrder IList
650-
break;
651-
}
652-
653-
var options = InitializeWithWindow(new LauncherOptions());
654-
if (currentFolder.AreQueryOptionsSupported(queryOptions))
655-
{
656-
fileQueryResult = currentFolder.CreateFileQueryWithOptions(queryOptions);
657-
options.NeighboringFilesQuery = fileQueryResult.ToStorageFileQueryResult();
658-
}
659-
660-
// Now launch file with options.
661-
var storageItem = (StorageFile)await FilesystemTasks.Wrap(() => childFile.Item.ToStorageFileAsync().AsTask());
662-
663-
if (storageItem is not null)
664-
launchSuccess = await Launcher.LaunchFileAsync(storageItem, options);
665-
}
666-
667-
if (!launchSuccess)
668-
await Win32Helper.InvokeWin32ComponentAsync(path, associatedInstance, args);
589+
await Win32Helper.InvokeWin32ComponentAsync(path, associatedInstance, args);
669590
}
670591
});
671592
}

0 commit comments

Comments
 (0)