Skip to content

Code Quality: Removed unused P/Invoke methods from helper class #17120

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

Merged
merged 3 commits into from
May 13, 2025
Merged
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
82 changes: 0 additions & 82 deletions src/Files.App/Helpers/Win32/Win32PInvoke.Enums.cs
Original file line number Diff line number Diff line change
@@ -81,88 +81,6 @@ public enum StreamInfoLevels
FindStreamInfoStandard = 0
}

[Flags]
public enum CryptProtectFlags
{
CRYPTPROTECT_UI_FORBIDDEN = 0x1,
CRYPTPROTECT_LOCAL_MACHINE = 0x4,
CRYPTPROTECT_CRED_SYNC = 0x8,
CRYPTPROTECT_AUDIT = 0x10,
CRYPTPROTECT_NO_RECOVERY = 0x20,
CRYPTPROTECT_VERIFY_PROTECTION = 0x40,
CRYPTPROTECT_CRED_REGENERATE = 0x80
}

public enum TOKEN_INFORMATION_CLASS
{
TokenUser = 1,
TokenGroups,
TokenPrivileges,
TokenOwner,
TokenPrimaryGroup,
TokenDefaultDacl,
TokenSource,
TokenType,
TokenImpersonationLevel,
TokenStatistics,
TokenRestrictedSids,
TokenSessionId,
TokenGroupsAndPrivileges,
TokenSessionReference,
TokenSandBoxInert,
TokenAuditPolicy,
TokenOrigin,
TokenElevationType,
TokenLinkedToken,
TokenElevation,
TokenHasRestrictions,
TokenAccessInformation,
TokenVirtualizationAllowed,
TokenVirtualizationEnabled,
TokenIntegrityLevel,
TokenUIAccess,
TokenMandatoryPolicy,
TokenLogonSid,
TokenIsAppContainer,
TokenCapabilities,
TokenAppContainerSid,
TokenAppContainerNumber,
TokenUserClaimAttributes,
TokenDeviceClaimAttributes,
TokenRestrictedUserClaimAttributes,
TokenRestrictedDeviceClaimAttributes,
TokenDeviceGroups,
TokenRestrictedDeviceGroups,
TokenSecurityAttributes,
TokenIsRestricted
}

[Serializable]
public enum TOKEN_TYPE
{
TokenPrimary = 1,
TokenImpersonation = 2
}

[Flags]
public enum TokenAccess : uint
{
TOKEN_ASSIGN_PRIMARY = 0x0001,
TOKEN_DUPLICATE = 0x0002,
TOKEN_IMPERSONATE = 0x0004,
TOKEN_QUERY = 0x0008,
TOKEN_QUERY_SOURCE = 0x0010,
TOKEN_ADJUST_PRIVILEGES = 0x0020,
TOKEN_ADJUST_GROUPS = 0x0040,
TOKEN_ADJUST_DEFAULT = 0x0080,
TOKEN_ADJUST_SESSIONID = 0x0100,
TOKEN_ALL_ACCESS_P = 0x000F00FF,
TOKEN_ALL_ACCESS = 0x000F01FF,
TOKEN_READ = 0x00020008,
TOKEN_WRITE = 0x000200E0,
TOKEN_EXECUTE = 0x00020000
}

public enum FINDEX_INFO_LEVELS
{
FindExInfoStandard = 0,
123 changes: 1 addition & 122 deletions src/Files.App/Helpers/Win32/Win32PInvoke.Methods.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Files Community
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

using System.IO;
@@ -56,13 +56,6 @@ public static extern int RmGetList(
ref uint lpdwRebootReasons
);

[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool SetPropW(
IntPtr hWnd,
string lpString,
IntPtr hData
);

[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr CreateEvent(
IntPtr lpEventAttributes,
@@ -102,39 +95,12 @@ public static extern bool CloseHandle(
IntPtr hObject
);

[DllImport("api-ms-win-core-io-l1-1-1.dll")]
public static extern bool GetOverlappedResult(
IntPtr hFile,
OVERLAPPED lpOverlapped,
out int lpNumberOfBytesTransferred,
bool bWait
);

[DllImport("api-ms-win-core-io-l1-1-1.dll")]
public static extern bool CancelIo(
IntPtr hFile
);

[DllImport("api-ms-win-core-io-l1-1-1.dll")]
public static extern bool CancelIoEx(
IntPtr hFile,
IntPtr lpOverlapped
);

[DllImport("api-ms-win-core-synch-l1-2-0.dll")]
public static extern uint WaitForMultipleObjectsEx(
uint nCount,
IntPtr[] lpHandles,
bool bWaitAll,
uint dwMilliseconds,
bool bAlertable
);

[DllImport("api-ms-win-core-synch-l1-2-0.dll", SetLastError = true)]
public static extern bool ResetEvent(
IntPtr hEvent
);

[DllImport("api-ms-win-core-synch-l1-2-0.dll", SetLastError = true)]
public static extern uint WaitForSingleObjectEx(
IntPtr hHandle,
@@ -202,16 +168,6 @@ public static extern bool DeviceIoControl(
out uint lpBytesReturned,
IntPtr lpOverlapped);

[DllImport("user32.dll")]
public static extern int ToUnicode(
uint virtualKeyCode,
uint scanCode,
byte[] keyboardState,
[Out, MarshalAs(UnmanagedType.LPWStr, SizeConst = 64)] StringBuilder receivingBuffer,
int bufferSize,
uint flags
);

[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int ToUnicodeEx(
uint virtualKeyCode,
@@ -223,11 +179,6 @@ public static extern int ToUnicodeEx(
IntPtr keyboardLayout
);

[DllImport("user32.dll")]
public static extern bool TranslateMessage(
ref MSG lpMsg
);

[DllImport("api-ms-win-core-file-fromapp-l1-1-0.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, SetLastError = true)]
public static extern IntPtr CreateFileFromApp(
string lpFileName,
@@ -252,14 +203,6 @@ public static extern bool SetFileAttributesFromApp(
string lpFileName,
FileAttributes dwFileAttributes);

[DllImport("api-ms-win-core-file-l1-2-1.dll", ExactSpelling = true, CallingConvention = CallingConvention.StdCall, SetLastError = true)]
public static extern uint SetFilePointer(
IntPtr hFile,
long lDistanceToMove,
IntPtr lpDistanceToMoveHigh,
uint dwMoveMethod
);

[DllImport("api-ms-win-core-file-l1-2-1.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, SetLastError = true)]
public unsafe static extern bool ReadFile(
IntPtr hFile,
@@ -310,14 +253,6 @@ public static extern bool GetFileInformationByHandleEx(
uint dwBufferSize
);

[DllImport("api-ms-win-core-file-l2-1-1.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, SetLastError = true)]
public static extern bool GetFileInformationByHandleEx(
IntPtr hFile,
FILE_INFO_BY_HANDLE_CLASS infoClass,
IntPtr dirInfo,
uint dwBufferSize
);

[DllImport("kernel32.dll", ExactSpelling = true, CharSet = CharSet.Auto, SetLastError = true)]
public static extern IntPtr FindFirstStreamW(
string lpFileName,
@@ -333,49 +268,6 @@ public static extern bool FindNextStreamW(
[In, Out, MarshalAs(UnmanagedType.LPStruct)] WIN32_FIND_STREAM_DATA lpFindStreamData
);

[DllImport("Shcore.dll", SetLastError = true)]
public static extern int GetDpiForMonitor(
IntPtr hmonitor,
uint dpiType,
out uint dpiX,
out uint dpiY
);

[DllImport("api-ms-win-core-processthreads-l1-1-0.dll", SetLastError = true, ExactSpelling = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool OpenProcessToken(
[In] IntPtr ProcessHandle, TokenAccess DesiredAccess, out IntPtr TokenHandle);

[DllImport("api-ms-win-core-processthreads-l1-1-2.dll", SetLastError = true, ExactSpelling = true)]
public static extern IntPtr GetCurrentProcess();

[DllImport("api-ms-win-security-base-l1-1-0.dll", SetLastError = true, ExactSpelling = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetTokenInformation(
IntPtr hObject,
TOKEN_INFORMATION_CLASS tokenInfoClass,
IntPtr pTokenInfo,
int tokenInfoLength,
out int returnLength
);

[DllImport("api-ms-win-security-base-l1-1-0.dll", ExactSpelling = true, SetLastError = true)]
public static extern int GetLengthSid(
IntPtr pSid
);

[DllImport("crypt32.dll", SetLastError = true, CharSet = CharSet.Auto)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CryptUnprotectData(
in CRYPTOAPI_BLOB pDataIn,
StringBuilder szDataDescr,
in CRYPTOAPI_BLOB pOptionalEntropy,
IntPtr pvReserved,
IntPtr pPromptStruct,
CryptProtectFlags dwFlags,
out CRYPTOAPI_BLOB pDataOut
);

[DllImport("api-ms-win-core-wow64-l1-1-1.dll", SetLastError = true)]
public static extern bool IsWow64Process2(
IntPtr process,
@@ -410,19 +302,6 @@ public static extern IntPtr FindFirstFileExFromApp(
int dwAdditionalFlags
);

[DllImport("api-ms-win-core-string-l1-1-0.dll", CharSet = CharSet.Unicode)]
public static extern int CompareStringEx(
string localeName,
int flags,
string str1,
int count1,
string str2,
int count2,
IntPtr versionInformation,
IntPtr reserved,
int param
);

[LibraryImport("shell32.dll", EntryPoint = "#865", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static partial bool IsElevationRequired(
24 changes: 0 additions & 24 deletions src/Files.App/Helpers/Win32/Win32PInvoke.Structs.cs
Original file line number Diff line number Diff line change
@@ -139,12 +139,6 @@ public sealed class WIN32_FIND_STREAM_DATA
public string cStreamName;
}

[StructLayout(LayoutKind.Sequential)]
public struct TOKEN_USER
{
public SID_AND_ATTRIBUTES User;
}

[StructLayout(LayoutKind.Sequential)]
public struct SID_AND_ATTRIBUTES
{
@@ -153,13 +147,6 @@ public struct SID_AND_ATTRIBUTES
public uint Attributes;
}

[StructLayout(LayoutKind.Sequential)]
public struct CRYPTOAPI_BLOB
{
public uint cbData;
public IntPtr pbData;
}

[StructLayout(LayoutKind.Sequential)]
public struct SYSTEMTIME
{
@@ -211,16 +198,5 @@ public struct WIN32_FIND_DATA
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
public string cAlternateFileName;
}

[StructLayout(LayoutKind.Sequential)]
public struct MSG
{
public IntPtr hwnd;
public uint message;
public IntPtr wParam;
public IntPtr lParam;
public uint time;
public System.Drawing.Point pt;
}
}
}
Loading