Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Quality: Merged all interop into Win32PInvoke #15209

Merged
merged 8 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
16 changes: 8 additions & 8 deletions src/Files.App/Data/Models/ItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
using Windows.Storage.FileProperties;
using Windows.Storage.Search;
using static Files.App.Helpers.Win32PInvoke;
using static Files.App.Helpers.NativeFindStorageItemHelper;
using static Files.App.Helpers.Win32Helper;
using DispatcherQueue = Microsoft.UI.Dispatching.DispatcherQueue;
using FileAttributes = System.IO.FileAttributes;

Expand Down Expand Up @@ -680,7 +680,7 @@ void ClearDisplay()
DirectoryInfoUpdated?.Invoke(this, EventArgs.Empty);
}

if (NativeWinApiHelper.IsHasThreadAccessPropertyPresent && dispatcherQueue.HasThreadAccess)
if (Win32Helper.IsHasThreadAccessPropertyPresent && dispatcherQueue.HasThreadAccess)
ClearDisplay();
else
await dispatcherQueue.EnqueueOrInvokeAsync(ClearDisplay);
Expand Down Expand Up @@ -768,7 +768,7 @@ void OrderEntries()
folderSettings.SortDirectoriesAlongsideFiles, folderSettings.SortFilesFirst));
}

if (NativeWinApiHelper.IsHasThreadAccessPropertyPresent && dispatcherQueue.HasThreadAccess)
if (Win32Helper.IsHasThreadAccessPropertyPresent && dispatcherQueue.HasThreadAccess)
return Task.Run(OrderEntries);

OrderEntries();
Expand Down Expand Up @@ -1865,8 +1865,8 @@ await dispatcherQueue.EnqueueOrInvokeAsync(() =>
private void WatchForDirectoryChanges(string path, CloudDriveSyncStatus syncStatus)
{
Debug.WriteLine($"WatchForDirectoryChanges: {path}");
var hWatchDir = NativeFileOperationsHelper.CreateFileFromApp(path, 1, 1 | 2 | 4,
IntPtr.Zero, 3, (uint)NativeFileOperationsHelper.File_Attributes.BackupSemantics | (uint)NativeFileOperationsHelper.File_Attributes.Overlapped, IntPtr.Zero);
var hWatchDir = Win32PInvoke.CreateFileFromApp(path, 1, 1 | 2 | 4,
IntPtr.Zero, 3, (uint)Win32PInvoke.File_Attributes.BackupSemantics | (uint)Win32PInvoke.File_Attributes.Overlapped, IntPtr.Zero);
if (hWatchDir.ToInt64() == -1)
return;

Expand Down Expand Up @@ -1974,13 +1974,13 @@ private void WatchForDirectoryChanges(string path, CloudDriveSyncStatus syncStat

private void WatchForGitChanges()
{
var hWatchDir = NativeFileOperationsHelper.CreateFileFromApp(
var hWatchDir = Win32PInvoke.CreateFileFromApp(
GitDirectory!,
1,
1 | 2 | 4,
IntPtr.Zero,
3,
(uint)NativeFileOperationsHelper.File_Attributes.BackupSemantics | (uint)NativeFileOperationsHelper.File_Attributes.Overlapped,
(uint)Win32PInvoke.File_Attributes.BackupSemantics | (uint)Win32PInvoke.File_Attributes.Overlapped,
IntPtr.Zero);

if (hWatchDir.ToInt64() == -1)
Expand Down Expand Up @@ -2226,7 +2226,7 @@ private async Task AddFileOrFolderAsync(ListedItem? item)
if (UserSettingsService.FoldersSettingsService.AreAlternateStreamsVisible)
{
// New file added, enumerate ADS
foreach (var ads in NativeFileOperationsHelper.GetAlternateStreams(item.ItemPath))
foreach (var ads in Win32Helper.GetAlternateStreams(item.ItemPath))
{
var adsItem = Win32StorageEnumerator.GetAlternateStream(ads, item);
filesAndFolders.Add(adsItem);
Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/Extensions/Win32FindDataExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

using static Files.App.Helpers.NativeFindStorageItemHelper;
using static Files.App.Helpers.Win32Helper;

namespace Files.App.Extensions
{
public static class Win32FindDataExtensions
{
private const long MAX_DWORD = 4294967295;

public static long GetSize(this WIN32_FIND_DATA findData)
public static long GetSize(this Win32PInvoke.WIN32_FIND_DATA findData)
{
long fDataFSize = findData.nFileSizeLow;

Expand Down
5 changes: 1 addition & 4 deletions src/Files.App/Helpers/Environment/ElevationHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@ namespace Files.App.Helpers
{
public static class ElevationHelpers
{
[DllImport("shell32.dll", EntryPoint = "#865", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)] private static extern bool _IsElevationRequired([MarshalAs(UnmanagedType.LPWStr)] string pszPath);

public static bool IsElevationRequired(string filePath)
{
if (string.IsNullOrEmpty(filePath))
return false;

return _IsElevationRequired(filePath);
return Win32PInvoke._IsElevationRequired(filePath);
}

public static bool IsAppRunAsAdmin()
Expand Down
Loading
Loading