Skip to content

Commit

Permalink
Fix: Fixed issues with opening certain file formats (#16102)
Browse files Browse the repository at this point in the history
  • Loading branch information
yaira2 authored Aug 30, 2024
1 parent c795771 commit c75d3d7
Showing 1 changed file with 2 additions and 81 deletions.
83 changes: 2 additions & 81 deletions src/Files.App/Helpers/Navigation/NavigationHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@

using Files.Shared.Helpers;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Media.Imaging;
using Windows.Storage;
using Windows.Storage.Search;
using Windows.System;
using Microsoft.UI.Xaml.Media;

namespace Files.App.Helpers
{
Expand Down Expand Up @@ -587,85 +586,7 @@ private static async Task<FilesystemResult> OpenFile(string path, IShellPage ass
}
else
{
//try using launcher first
bool launchSuccess = false;
BaseStorageFileQueryResult? fileQueryResult = null;
//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)
BaseStorageFolder currentFolder = await associatedInstance.ShellViewModel.GetFolderFromPathAsync(PathNormalization.GetParentDir(path));
if (currentFolder is not null)
{
QueryOptions queryOptions = new(CommonFileQuery.DefaultQuery, null);
//We can have many sort entries
SortEntry sortEntry = new()
{
AscendingOrder = associatedInstance.InstanceViewModel.FolderSettings.DirectorySortDirection == SortDirection.Ascending
};
//Basically we tell to the launched app to follow how we sorted the files in the directory.
var sortOption = associatedInstance.InstanceViewModel.FolderSettings.DirectorySortOption;
switch (sortOption)
{
case SortOption.Name:
sortEntry.PropertyName = "System.ItemNameDisplay";
queryOptions.SortOrder.Clear();
queryOptions.SortOrder.Add(sortEntry);
break;
case SortOption.DateModified:
sortEntry.PropertyName = "System.DateModified";
queryOptions.SortOrder.Clear();
queryOptions.SortOrder.Add(sortEntry);
break;
case SortOption.DateCreated:
sortEntry.PropertyName = "System.DateCreated";
queryOptions.SortOrder.Clear();
queryOptions.SortOrder.Add(sortEntry);
break;
//Unfortunately this is unsupported | Remarks: https://learn.microsoft.com/uwp/api/windows.storage.search.queryoptions.sortorder?view=winrt-19041
//case Enums.SortOption.Size:
//sortEntry.PropertyName = "System.TotalFileSize";
//queryOptions.SortOrder.Clear();
//queryOptions.SortOrder.Add(sortEntry);
//break;
//Unfortunately this is unsupported | Remarks: https://learn.microsoft.com/uwp/api/windows.storage.search.queryoptions.sortorder?view=winrt-19041
//case Enums.SortOption.FileType:
//sortEntry.PropertyName = "System.FileExtension";
//queryOptions.SortOrder.Clear();
//queryOptions.SortOrder.Add(sortEntry);
//break;
//Handle unsupported
default:
//keep the default one in SortOrder IList
break;
}
var options = InitializeWithWindow(new LauncherOptions());
if (currentFolder.AreQueryOptionsSupported(queryOptions))
{
fileQueryResult = currentFolder.CreateFileQueryWithOptions(queryOptions);
options.NeighboringFilesQuery = fileQueryResult.ToStorageFileQueryResult();
}
// Now launch file with options.
var storageItem = (StorageFile)await FilesystemTasks.Wrap(() => childFile.Item.ToStorageFileAsync().AsTask());
if (storageItem is not null)
launchSuccess = await Launcher.LaunchFileAsync(storageItem, options);
}
if (!launchSuccess)
await Win32Helper.InvokeWin32ComponentAsync(path, associatedInstance, args);
await Win32Helper.InvokeWin32ComponentAsync(path, associatedInstance, args);
}
});
}
Expand Down

0 comments on commit c75d3d7

Please sign in to comment.