Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Files.App/Files.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@
<Compile Remove="Helpers\Layout\LayoutPreferencesDatabase.Linux.cs" />
<Compile Remove="Services\SizeProvider\CachedSizeProvider.Linux.cs" />
<Compile Remove="Utils\Storage\Operations\FileSizeCalculator.Linux.cs" />
<Compile Remove="Utils\Storage\Helpers\SyncRootHelpers.Linux.cs" />
</ItemGroup>

<!-- XAML pages are matched by SDK default globs that run after this file, so Page Remove has no effect; use DefaultItemExcludes -->
Expand Down
12 changes: 12 additions & 0 deletions src/Files.App/Utils/Storage/Helpers/SyncRootHelpers.Linux.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) Files Community
// Licensed under the MIT License.

namespace Files.App.Utils.Storage
{
internal static class SyncRootHelpers
{
// LINUX-TODO(cloud): Windows cloud sync roots have no Linux equivalent; report no quota.
public static Task<(bool Success, ulong Capacity, ulong Used)> GetSyncRootQuotaAsync(string path)
=> Task.FromResult((false, 0ul, 0ul));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) Files Community
// Licensed under the MIT License.

using Files.Shared.Helpers;
using System.IO;
using Windows.Win32;
using Windows.Win32.Storage.FileSystem;

namespace Files.App.ViewModels.UserControls
{
public sealed partial class NavigationToolbarViewModel
{
/// <summary>
/// Enumerates subfolders using Win32 API, including hidden folders based on user settings.
/// Returns null if the path cannot be enumerated with Win32.
/// </summary>
private unsafe List<(string Name, string Path, bool IsHidden)>? GetSubfolders(string parentPath)
{
WIN32_FIND_DATAW findData = default;
using FindCloseSafeHandle hFile = PInvoke.FindFirstFileEx(
$"{parentPath}{Path.DirectorySeparatorChar}*.*",
FINDEX_INFO_LEVELS.FindExInfoBasic,
&findData,
FINDEX_SEARCH_OPS.FindExSearchNameMatch,
FIND_FIRST_EX_FLAGS.FIND_FIRST_EX_LARGE_FETCH);

if (hFile.IsInvalid)
return null;

var showHidden = UserSettingsService.FoldersSettingsService.ShowHiddenItems;
var showSystem = UserSettingsService.FoldersSettingsService.ShowProtectedSystemFiles;
var showDot = UserSettingsService.FoldersSettingsService.ShowDotFiles;
var folders = new List<(string Name, string Path, bool IsHidden)>();

do
{
if (((FileAttributes)findData.dwFileAttributes & FileAttributes.Directory) == 0)
continue;

string fileName = findData.cFileName.ToString();
if (fileName is "." or "..")
continue;

bool isHidden = ((FileAttributes)findData.dwFileAttributes & FileAttributes.Hidden) != 0;
bool isSystem = ((FileAttributes)findData.dwFileAttributes & FileAttributes.System) != 0;

if (isHidden && (!showHidden || (isSystem && !showSystem)))
continue;

if (fileName.StartsWith('.') && !showDot)
continue;

folders.Add((fileName, Path.Combine(parentPath, fileName), isHidden));
}
while (PInvoke.FindNextFile(hFile, out findData));

var naturalComparer = NaturalStringComparer.GetForProcessor();
folders.Sort((a, b) => naturalComparer.Compare(a.Name, b.Name));

return folders;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
using System.Windows.Input;
using Windows.ApplicationModel.DataTransfer;
using WinRT;
using Windows.Win32;
using Windows.Win32.Storage.FileSystem;

namespace Files.App.ViewModels.UserControls
{
Expand Down Expand Up @@ -712,7 +710,11 @@ public async Task SetPathBoxDropDownFlyoutAsync(MenuFlyout flyout, PathBoxItem p
var path = pathItem.Path
?? throw new InvalidOperationException("The path box item does not have a path.");

#if WINDOWS
var childFolders = OperatingSystem.IsWindows() ? GetSubfolders(path) : await GetSubfoldersAsync(path);
#else
var childFolders = await GetSubfoldersAsync(path);
#endif

// Fall back to StorageFolder API for non-filesystem paths (e.g. FTP)
if (childFolders is null)
Expand Down Expand Up @@ -827,56 +829,6 @@ public async Task SetPathBoxDropDownFlyoutAsync(MenuFlyout flyout, PathBoxItem p
}
}

/// <summary>
/// Enumerates subfolders using Win32 API, including hidden folders based on user settings.
/// Returns null if the path cannot be enumerated with Win32.
/// </summary>
private unsafe List<(string Name, string Path, bool IsHidden)>? GetSubfolders(string parentPath)
{
WIN32_FIND_DATAW findData = default;
using FindCloseSafeHandle hFile = PInvoke.FindFirstFileEx(
$"{parentPath}{Path.DirectorySeparatorChar}*.*",
FINDEX_INFO_LEVELS.FindExInfoBasic,
&findData,
FINDEX_SEARCH_OPS.FindExSearchNameMatch,
FIND_FIRST_EX_FLAGS.FIND_FIRST_EX_LARGE_FETCH);

if (hFile.IsInvalid)
return null;

var showHidden = UserSettingsService.FoldersSettingsService.ShowHiddenItems;
var showSystem = UserSettingsService.FoldersSettingsService.ShowProtectedSystemFiles;
var showDot = UserSettingsService.FoldersSettingsService.ShowDotFiles;
var folders = new List<(string Name, string Path, bool IsHidden)>();

do
{
if (((FileAttributes)findData.dwFileAttributes & FileAttributes.Directory) == 0)
continue;

string fileName = findData.cFileName.ToString();
if (fileName is "." or "..")
continue;

bool isHidden = ((FileAttributes)findData.dwFileAttributes & FileAttributes.Hidden) != 0;
bool isSystem = ((FileAttributes)findData.dwFileAttributes & FileAttributes.System) != 0;

if (isHidden && (!showHidden || (isSystem && !showSystem)))
continue;

if (fileName.StartsWith('.') && !showDot)
continue;

folders.Add((fileName, Path.Combine(parentPath, fileName), isHidden));
}
while (PInvoke.FindNextFile(hFile, out findData));

var naturalComparer = NaturalStringComparer.GetForProcessor();
folders.Sort((a, b) => naturalComparer.Compare(a.Name, b.Name));

return folders;
}

private async Task LoadFlyoutItemIconAsync(MenuFlyoutItem flyoutItem, string path)
{
var imageSource = await NavigationHelpers.GetIconForPathAsync(path);
Expand Down
Loading