Skip to content
Merged
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ indent_size = 2
[*.yml]
indent_size = 2

[*.{cs,vb}]
dotnet_sort_system_directives_first = true

[*.java]
ij_java_align_consecutive_assignments = false
ij_java_align_consecutive_variable_declarations = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,20 @@ public long getCreationDate() {
}
}

@Override
public long getModificationDate() {
try {
final NSObject object = this.getNativeAttribute(NSFileManager.NSFileModificationDate);
if(object.isKindOfClass(Rococoa.createClass("NSDate", NSDate._Class.class))) {
return (long) (Rococoa.cast(object, NSDate.class).timeIntervalSince1970() * 1000);
}
return -1;
}
catch(AccessDeniedException | NotfoundException e) {
return -1;
}
}

@Override
public String getOwner() {
try {
Expand Down
9 changes: 9 additions & 0 deletions core/src/main/csharp/NativeMethods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
BHID_DataObject
CLSID_QueryAssociations
CoTaskMemFree
CreateFile
CRED_FLAGS
CRED_PERSIST
CRED_TYPE
Expand All @@ -11,8 +12,11 @@ CredRead
CredWrite
DefWindowProc
ExtractIconEx
FILE_ID_INFO
FOLDERID_Downloads
GetCurrentPackageFullName
GetFileInformationByHandleEx
GetFinalPathNameByHandle
GetTokenInformation
GetWindowLong
GetWindowLongPtr
Expand All @@ -29,6 +33,11 @@ KNOWN_FOLDER_FLAG
LoadLibrary
LoadString
MESSAGEBOX_RESULT
OpenFileById
PATHCCH_ALLOW_LONG_PATHS
PATHCCH_MAX_CCH
PathCchCanonicalizeEx
PathCchStripPrefix
PathParseIconLocation
PBST_ERROR
PBST_NORMAL
Expand Down
74 changes: 74 additions & 0 deletions core/src/main/csharp/Windows/Win32/CorePInvoke.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
using Windows.Win32.Foundation;
using Windows.Win32.Security;
using Windows.Win32.Security.Credentials;
using Windows.Win32.Storage.FileSystem;
using Windows.Win32.UI.Shell;
Expand All @@ -22,6 +24,48 @@ public static unsafe int LoadString(SafeHandle hInstance, uint uID, out PCWSTR l
}
}

/// <inheritdoc cref="CreateFile(PCWSTR, uint, FILE_SHARE_MODE, SECURITY_ATTRIBUTES*, FILE_CREATION_DISPOSITION, FILE_FLAGS_AND_ATTRIBUTES, HANDLE)"/>
public static unsafe SafeFileHandle CreateFile(
in ReadOnlySpan<char> lpFileName,
uint dwDesiredAccess,
FILE_SHARE_MODE dwShareMode,
SECURITY_ATTRIBUTES? lpSecurityAttributes,
FILE_CREATION_DISPOSITION dwCreationDisposition,
FILE_FLAGS_AND_ATTRIBUTES dwFlagsAndAttributes,
SafeHandle hTemplateFile)
{
bool hTemplateFileAddRef = false;
try
{
fixed (char* lpFileNameLocal = lpFileName)
{
SECURITY_ATTRIBUTES lpSecurityAttributesLocal = lpSecurityAttributes ?? default(SECURITY_ATTRIBUTES);
HANDLE hTemplateFileLocal;
if (hTemplateFile is object)
{
hTemplateFile.DangerousAddRef(ref hTemplateFileAddRef);
hTemplateFileLocal = (HANDLE)hTemplateFile.DangerousGetHandle();
}
else
hTemplateFileLocal = (HANDLE)new IntPtr(0L);
HANDLE __result = CorePInvoke.CreateFile(
lpFileName: lpFileNameLocal,
dwDesiredAccess: dwDesiredAccess,
dwShareMode: dwShareMode,
lpSecurityAttributes: lpSecurityAttributes.HasValue ? &lpSecurityAttributesLocal : null,
dwCreationDisposition: dwCreationDisposition,
dwFlagsAndAttributes: dwFlagsAndAttributes,
hTemplateFile: hTemplateFileLocal);
return new SafeFileHandle(__result, ownsHandle: true);
}
}
finally
{
if (hTemplateFileAddRef)
hTemplateFile.DangerousRelease();
}
}

/// <inheritdoc cref="CredDelete(PCWSTR, CRED_TYPE, uint)" />
public static unsafe bool CredDelete(string TargetName, CRED_TYPE type, CRED_FLAGS flags)
{
Expand All @@ -43,6 +87,36 @@ public static unsafe SafeCredentialHandle CredRead(string TargetName, CRED_TYPE
return new((nint)credential, true);
}

/// <inheritdoc cref="GetFileInformationByHandleEx(HANDLE, FILE_INFO_BY_HANDLE_CLASS, void*, uint)"/>
public static unsafe BOOL GetFileInformationByHandleEx<T>(SafeHandle hFile, FILE_INFO_BY_HANDLE_CLASS FileInformationClass, out T value) where T : unmanaged
{
fixed (T* valueLocal = &value)
{
return GetFileInformationByHandleEx(hFile, FileInformationClass, valueLocal, (uint)Marshal.SizeOf<T>());
}
}

/// <inheritdoc cref="GetFinalPathNameByHandle(HANDLE, PWSTR, uint, GETFINALPATHNAMEBYHANDLE_FLAGS)"/>
public static unsafe partial uint GetFinalPathNameByHandle(SafeHandle hFile, Span<char> lpszFilePath, GETFINALPATHNAMEBYHANDLE_FLAGS dwFlags)
{
fixed (char* lpszFilePathLocal = lpszFilePath)
{
return GetFinalPathNameByHandle(hFile, lpszFilePathLocal, (uint)lpszFilePath.Length, dwFlags);
}
}

/// <inheritdoc cref="PathCchCanonicalizeEx(PWSTR, nuint, PCWSTR, PATHCCH_OPTIONS)"/>
public static unsafe HRESULT PathCchCanonicalizeEx(ref Span<char> pszPathOut, string pszPathIn, PATHCCH_OPTIONS dwFlags)
{
fixed (char* ppszPathOut = pszPathOut)
{
PWSTR wstrpszPathOut = ppszPathOut;
HRESULT __result = CorePInvoke.PathCchCanonicalizeEx(wstrpszPathOut, (nuint)pszPathOut.Length, pszPathIn, dwFlags);
pszPathOut = pszPathOut.Slice(0, wstrpszPathOut.Length);
return __result;
}
}

/// <inheritdoc cref="SHCreateAssociationRegistration(Guid*, object)"/>
public static unsafe HRESULT SHCreateAssociationRegistration<T>(out T ppv) where T : class
{
Expand Down
10 changes: 10 additions & 0 deletions core/src/main/csharp/Windows/Win32/CorePInvoke.net472.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using System.Runtime.InteropServices;
using Windows.Win32.Storage.FileSystem;

namespace Windows.Win32;

partial class CorePInvoke
{
public static unsafe partial uint GetFinalPathNameByHandle(SafeHandle hFile, Span<char> lpszFilePath, GETFINALPATHNAMEBYHANDLE_FLAGS dwFlags);
}
12 changes: 12 additions & 0 deletions core/src/main/csharp/Windows/Win32/CorePInvoke.net8.0.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using Windows.Win32.Storage.FileSystem;

namespace Windows.Win32;

partial class CorePInvoke
{
[SupportedOSPlatform("windows6.0.6000")]
public static unsafe partial uint GetFinalPathNameByHandle(SafeHandle hFile, Span<char> lpszFilePath, GETFINALPATHNAMEBYHANDLE_FLAGS dwFlags);
}
Loading