Skip to content

Commit

Permalink
Code Quality: Merged all interop into Win32PInvoke (files-community#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
0x5bfa authored May 1, 2024
1 parent 24a7c17 commit 8781bfa
Show file tree
Hide file tree
Showing 40 changed files with 1,088 additions and 1,135 deletions.
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

0 comments on commit 8781bfa

Please sign in to comment.