Skip to content

Commit a2f2596

Browse files
authored
[Hidden files] - Fix opening hidden folder in new tab (#2430)
1 parent 1f38c31 commit a2f2596

File tree

3 files changed

+54
-37
lines changed

3 files changed

+54
-37
lines changed

Files/Interacts/Interaction.cs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -405,23 +405,29 @@ private async void OpenSelectedItems(bool displayApplicationPicker)
405405
var clickedOnItemPath = clickedOnItem.ItemPath;
406406
if (clickedOnItem.PrimaryItemAttribute == StorageItemTypes.Folder && !clickedOnItem.IsHiddenItem)
407407
{
408-
opened = await AssociatedInstance.FilesystemViewModel.GetFolderWithPathFromPathAsync(
409-
(clickedOnItem as ShortcutItem)?.TargetPath ?? clickedOnItem.ItemPath)
410-
.OnSuccess(async childFolder =>
408+
var folderPath = (clickedOnItem as ShortcutItem)?.TargetPath ?? clickedOnItem.ItemPath;
409+
opened = await AssociatedInstance.FilesystemViewModel.GetFolderWithPathFromPathAsync(folderPath)
410+
.OnSuccess(childFolder =>
411411
{
412412
// Add location to MRU List
413413
mostRecentlyUsed.Add(childFolder.Folder, childFolder.Path);
414-
415-
await AssociatedInstance.FilesystemViewModel.SetWorkingDirectoryAsync(childFolder.Path);
416-
AssociatedInstance.NavigationToolbar.PathControlDisplayText = childFolder.Path;
417-
418-
AssociatedInstance.FilesystemViewModel.IsFolderEmptyTextDisplayed = false;
419-
AssociatedInstance.ContentFrame.Navigate(sourcePageType, new NavigationArguments()
420-
{
421-
NavPathParam = childFolder.Path,
422-
AssociatedTabInstance = AssociatedInstance
423-
}, new SuppressNavigationTransitionInfo());
424414
});
415+
if (!opened)
416+
{
417+
opened = (FilesystemResult)AssociatedInstance.FilesystemViewModel.CheckFolderAccessWithWin32(folderPath);
418+
}
419+
if (opened)
420+
{
421+
await AssociatedInstance.FilesystemViewModel.SetWorkingDirectoryAsync(folderPath);
422+
AssociatedInstance.NavigationToolbar.PathControlDisplayText = folderPath;
423+
424+
AssociatedInstance.FilesystemViewModel.IsFolderEmptyTextDisplayed = false;
425+
AssociatedInstance.ContentFrame.Navigate(sourcePageType, new NavigationArguments()
426+
{
427+
NavPathParam = folderPath,
428+
AssociatedTabInstance = AssociatedInstance
429+
}, new SuppressNavigationTransitionInfo());
430+
}
425431
}
426432
else if (clickedOnItem.IsHiddenItem)
427433
{

Files/View Models/ItemViewModel.cs

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -828,30 +828,27 @@ public async Task<bool> EnumerateItemsFromStandardFolderAsync(string path)
828828
{
829829
_rootFolder = res.Result;
830830
}
831-
else if (res == FilesystemErrorCode.ERROR_UNAUTHORIZED)
831+
else if (_workingRoot != null)
832832
{
833-
if (!CheckFolderForHiddenAttribute(path)) // Is a standard location
833+
_rootFolder = _currentStorageFolder.Folder;
834+
enumFromStorageFolder = true;
835+
}
836+
else if (!CheckFolderAccessWithWin32(path)) // The folder is really inaccessible
837+
{
838+
if (res == FilesystemErrorCode.ERROR_UNAUTHORIZED)
834839
{
835840
//TODO: proper dialog
836841
await DialogDisplayHelper.ShowDialogAsync(
837-
"AccessDeniedDeleteDialog/Title".GetLocalized(),
838-
"SubDirectoryAccessDenied".GetLocalized());
842+
"AccessDeniedDeleteDialog/Title".GetLocalized(),
843+
"SubDirectoryAccessDenied".GetLocalized());
839844
return false;
840845
}
841-
}
842-
else if (res == FilesystemErrorCode.ERROR_NOTFOUND)
843-
{
844-
await DialogDisplayHelper.ShowDialogAsync(
845-
"FolderNotFoundDialog/Title".GetLocalized(),
846-
"FolderNotFoundDialog/Text".GetLocalized());
847-
return false;
848-
}
849-
else
850-
{
851-
if (_workingRoot != null)
846+
else if (res == FilesystemErrorCode.ERROR_NOTFOUND)
852847
{
853-
_rootFolder = _currentStorageFolder.Folder;
854-
enumFromStorageFolder = true;
848+
await DialogDisplayHelper.ShowDialogAsync(
849+
"FolderNotFoundDialog/Title".GetLocalized(),
850+
"FolderNotFoundDialog/Text".GetLocalized());
851+
return false;
855852
}
856853
else
857854
{
@@ -944,19 +941,19 @@ await DialogDisplayHelper.ShowDialogAsync(
944941
opacity = 0.4;
945942
}
946943

947-
CurrentFolder = new ListedItem(_rootFolder.FolderRelativeId, returnformat)
944+
CurrentFolder = new ListedItem(null, returnformat)
948945
{
949946
PrimaryItemAttribute = StorageItemTypes.Folder,
950947
ItemPropertiesInitialized = true,
951-
ItemName = _rootFolder.Name,
948+
ItemName = Path.GetFileName(path.TrimEnd('\\')),
952949
ItemDateModifiedReal = itemDate,
953-
ItemType = _rootFolder.DisplayType,
950+
ItemType = "FileFolderListItem".GetLocalized(),
954951
LoadFolderGlyph = true,
955952
FileImage = null,
956953
IsHiddenItem = isHidden,
957954
Opacity = opacity,
958955
LoadFileIcon = false,
959-
ItemPath = string.IsNullOrEmpty(_rootFolder.Path) ? _currentStorageFolder.Path : _rootFolder.Path,
956+
ItemPath = path,
960957
LoadUnknownTypeGlyph = false,
961958
FileSize = null,
962959
FileSizeBytes = 0
@@ -1086,6 +1083,20 @@ private async Task EnumFromStorageFolderAsync()
10861083
Debug.WriteLine($"Enumerating items in {WorkingDirectory} (device) completed in {stopwatch.ElapsedMilliseconds} milliseconds.\n");
10871084
}
10881085

1086+
public bool CheckFolderAccessWithWin32(string path)
1087+
{
1088+
FINDEX_INFO_LEVELS findInfoLevel = FINDEX_INFO_LEVELS.FindExInfoBasic;
1089+
int additionalFlags = FIND_FIRST_EX_LARGE_FETCH;
1090+
IntPtr hFileTsk = FindFirstFileExFromApp(path + "\\*.*", findInfoLevel, out WIN32_FIND_DATA findDataTsk, FINDEX_SEARCH_OPS.FindExSearchNameMatch, IntPtr.Zero,
1091+
additionalFlags);
1092+
if (hFileTsk.ToInt64() != -1)
1093+
{
1094+
FindClose(hFileTsk);
1095+
return true;
1096+
}
1097+
return false;
1098+
}
1099+
10891100
public bool CheckFolderForHiddenAttribute(string path)
10901101
{
10911102
FINDEX_INFO_LEVELS findInfoLevel = FINDEX_INFO_LEVELS.FindExInfoBasic;

Files/Views/ModernShellPage.xaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,16 +385,16 @@ private async Task SetPathBoxDropDownFlyoutAsync(MenuFlyout flyout, PathBoxItem
385385
{
386386
var nextPathItemTitle = NavigationToolbar.PathComponents
387387
[NavigationToolbar.PathComponents.IndexOf(pathItem) + 1].Title;
388-
IList<StorageFolderWithPath> childFolders = new List<StorageFolderWithPath>();
388+
IList<StorageFolderWithPath> childFolders = null;
389389

390390
StorageFolderWithPath folder = await FilesystemViewModel.GetFolderWithPathFromPathAsync(pathItem.Path);
391391
if (folder != null)
392392
{
393-
childFolders = await folder.GetFoldersWithPathAsync(string.Empty);
393+
childFolders = (await FilesystemTasks.Wrap(() => folder.GetFoldersWithPathAsync(string.Empty))).Result;
394394
}
395395
flyout.Items?.Clear();
396396

397-
if (childFolders.Count == 0)
397+
if (childFolders == null || childFolders.Count == 0)
398398
{
399399
var flyoutItem = new MenuFlyoutItem
400400
{

0 commit comments

Comments
 (0)