Skip to content

Commit 8c478f6

Browse files
authored
Merge pull request #17544 from iterate-ch/bugfix/MD-25106-localresolve
Add NTFS Alias Resolver implementation
2 parents 5e4129a + 4b92d2d commit 8c478f6

File tree

10 files changed

+521
-15
lines changed

10 files changed

+521
-15
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ indent_size = 2
2222
[*.yml]
2323
indent_size = 2
2424

25+
[*.{cs,vb}]
26+
dotnet_sort_system_directives_first = true
27+
2528
[*.java]
2629
ij_java_align_consecutive_assignments = false
2730
ij_java_align_consecutive_variable_declarations = false

core/dylib/src/main/java/ch/cyberduck/core/local/FinderLocalAttributes.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,20 @@ public long getCreationDate() {
123123
}
124124
}
125125

126+
@Override
127+
public long getModificationDate() {
128+
try {
129+
final NSObject object = this.getNativeAttribute(NSFileManager.NSFileModificationDate);
130+
if(object.isKindOfClass(Rococoa.createClass("NSDate", NSDate._Class.class))) {
131+
return (long) (Rococoa.cast(object, NSDate.class).timeIntervalSince1970() * 1000);
132+
}
133+
return -1;
134+
}
135+
catch(AccessDeniedException | NotfoundException e) {
136+
return -1;
137+
}
138+
}
139+
126140
@Override
127141
public String getOwner() {
128142
try {

core/src/main/csharp/NativeMethods.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
BHID_DataObject
33
CLSID_QueryAssociations
44
CoTaskMemFree
5+
CreateFile
56
CRED_FLAGS
67
CRED_PERSIST
78
CRED_TYPE
@@ -11,8 +12,11 @@ CredRead
1112
CredWrite
1213
DefWindowProc
1314
ExtractIconEx
15+
FILE_ID_INFO
1416
FOLDERID_Downloads
1517
GetCurrentPackageFullName
18+
GetFileInformationByHandleEx
19+
GetFinalPathNameByHandle
1620
GetTokenInformation
1721
GetWindowLong
1822
GetWindowLongPtr
@@ -29,6 +33,11 @@ KNOWN_FOLDER_FLAG
2933
LoadLibrary
3034
LoadString
3135
MESSAGEBOX_RESULT
36+
OpenFileById
37+
PATHCCH_ALLOW_LONG_PATHS
38+
PATHCCH_MAX_CCH
39+
PathCchCanonicalizeEx
40+
PathCchStripPrefix
3241
PathParseIconLocation
3342
PBST_ERROR
3443
PBST_NORMAL

core/src/main/csharp/Windows/Win32/CorePInvoke.cs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.Runtime.InteropServices;
3+
using Microsoft.Win32.SafeHandles;
34
using Windows.Win32.Foundation;
5+
using Windows.Win32.Security;
46
using Windows.Win32.Security.Credentials;
57
using Windows.Win32.Storage.FileSystem;
68
using Windows.Win32.UI.Shell;
@@ -22,6 +24,48 @@ public static unsafe int LoadString(SafeHandle hInstance, uint uID, out PCWSTR l
2224
}
2325
}
2426

27+
/// <inheritdoc cref="CreateFile(PCWSTR, uint, FILE_SHARE_MODE, SECURITY_ATTRIBUTES*, FILE_CREATION_DISPOSITION, FILE_FLAGS_AND_ATTRIBUTES, HANDLE)"/>
28+
public static unsafe SafeFileHandle CreateFile(
29+
in ReadOnlySpan<char> lpFileName,
30+
uint dwDesiredAccess,
31+
FILE_SHARE_MODE dwShareMode,
32+
SECURITY_ATTRIBUTES? lpSecurityAttributes,
33+
FILE_CREATION_DISPOSITION dwCreationDisposition,
34+
FILE_FLAGS_AND_ATTRIBUTES dwFlagsAndAttributes,
35+
SafeHandle hTemplateFile)
36+
{
37+
bool hTemplateFileAddRef = false;
38+
try
39+
{
40+
fixed (char* lpFileNameLocal = lpFileName)
41+
{
42+
SECURITY_ATTRIBUTES lpSecurityAttributesLocal = lpSecurityAttributes ?? default(SECURITY_ATTRIBUTES);
43+
HANDLE hTemplateFileLocal;
44+
if (hTemplateFile is object)
45+
{
46+
hTemplateFile.DangerousAddRef(ref hTemplateFileAddRef);
47+
hTemplateFileLocal = (HANDLE)hTemplateFile.DangerousGetHandle();
48+
}
49+
else
50+
hTemplateFileLocal = (HANDLE)new IntPtr(0L);
51+
HANDLE __result = CorePInvoke.CreateFile(
52+
lpFileName: lpFileNameLocal,
53+
dwDesiredAccess: dwDesiredAccess,
54+
dwShareMode: dwShareMode,
55+
lpSecurityAttributes: lpSecurityAttributes.HasValue ? &lpSecurityAttributesLocal : null,
56+
dwCreationDisposition: dwCreationDisposition,
57+
dwFlagsAndAttributes: dwFlagsAndAttributes,
58+
hTemplateFile: hTemplateFileLocal);
59+
return new SafeFileHandle(__result, ownsHandle: true);
60+
}
61+
}
62+
finally
63+
{
64+
if (hTemplateFileAddRef)
65+
hTemplateFile.DangerousRelease();
66+
}
67+
}
68+
2569
/// <inheritdoc cref="CredDelete(PCWSTR, CRED_TYPE, uint)" />
2670
public static unsafe bool CredDelete(string TargetName, CRED_TYPE type, CRED_FLAGS flags)
2771
{
@@ -43,6 +87,36 @@ public static unsafe SafeCredentialHandle CredRead(string TargetName, CRED_TYPE
4387
return new((nint)credential, true);
4488
}
4589

90+
/// <inheritdoc cref="GetFileInformationByHandleEx(HANDLE, FILE_INFO_BY_HANDLE_CLASS, void*, uint)"/>
91+
public static unsafe BOOL GetFileInformationByHandleEx<T>(SafeHandle hFile, FILE_INFO_BY_HANDLE_CLASS FileInformationClass, out T value) where T : unmanaged
92+
{
93+
fixed (T* valueLocal = &value)
94+
{
95+
return GetFileInformationByHandleEx(hFile, FileInformationClass, valueLocal, (uint)Marshal.SizeOf<T>());
96+
}
97+
}
98+
99+
/// <inheritdoc cref="GetFinalPathNameByHandle(HANDLE, PWSTR, uint, GETFINALPATHNAMEBYHANDLE_FLAGS)"/>
100+
public static unsafe partial uint GetFinalPathNameByHandle(SafeHandle hFile, Span<char> lpszFilePath, GETFINALPATHNAMEBYHANDLE_FLAGS dwFlags)
101+
{
102+
fixed (char* lpszFilePathLocal = lpszFilePath)
103+
{
104+
return GetFinalPathNameByHandle(hFile, lpszFilePathLocal, (uint)lpszFilePath.Length, dwFlags);
105+
}
106+
}
107+
108+
/// <inheritdoc cref="PathCchCanonicalizeEx(PWSTR, nuint, PCWSTR, PATHCCH_OPTIONS)"/>
109+
public static unsafe HRESULT PathCchCanonicalizeEx(ref Span<char> pszPathOut, string pszPathIn, PATHCCH_OPTIONS dwFlags)
110+
{
111+
fixed (char* ppszPathOut = pszPathOut)
112+
{
113+
PWSTR wstrpszPathOut = ppszPathOut;
114+
HRESULT __result = CorePInvoke.PathCchCanonicalizeEx(wstrpszPathOut, (nuint)pszPathOut.Length, pszPathIn, dwFlags);
115+
pszPathOut = pszPathOut.Slice(0, wstrpszPathOut.Length);
116+
return __result;
117+
}
118+
}
119+
46120
/// <inheritdoc cref="SHCreateAssociationRegistration(Guid*, object)"/>
47121
public static unsafe HRESULT SHCreateAssociationRegistration<T>(out T ppv) where T : class
48122
{
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
using Windows.Win32.Storage.FileSystem;
4+
5+
namespace Windows.Win32;
6+
7+
partial class CorePInvoke
8+
{
9+
public static unsafe partial uint GetFinalPathNameByHandle(SafeHandle hFile, Span<char> lpszFilePath, GETFINALPATHNAMEBYHANDLE_FLAGS dwFlags);
10+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
using System.Runtime.Versioning;
4+
using Windows.Win32.Storage.FileSystem;
5+
6+
namespace Windows.Win32;
7+
8+
partial class CorePInvoke
9+
{
10+
[SupportedOSPlatform("windows6.0.6000")]
11+
public static unsafe partial uint GetFinalPathNameByHandle(SafeHandle hFile, Span<char> lpszFilePath, GETFINALPATHNAMEBYHANDLE_FLAGS dwFlags);
12+
}

0 commit comments

Comments
 (0)