Skip to content

Commit c3b8376

Browse files
author
yerudako
committed
Add conditional _PrjFillDirEntryBuffer2 pointing code to the enumeration callbacks
1 parent 0bdde8a commit c3b8376

1 file changed

Lines changed: 30 additions & 2 deletions

File tree

ProjectedFSLib.Managed.API/DirectoryEnumerationResults.h

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
#include "IDirectoryEnumerationResults.h"
77

8+
using namespace System;
9+
using namespace System::Globalization;
10+
using namespace System::IO;
11+
812
namespace Microsoft {
913
namespace Windows {
1014
namespace ProjFS {
@@ -21,6 +25,21 @@ public ref class DirectoryEnumerationResults : public IDirectoryEnumerationResul
2125
DirectoryEnumerationResults(PRJ_DIR_ENTRY_BUFFER_HANDLE bufferHandle)
2226
{
2327
m_dirEntryBufferHandle = bufferHandle;
28+
29+
auto projFsLib = ::LoadLibraryW(L"ProjectedFSLib.dll");
30+
if (!projFsLib)
31+
{
32+
throw gcnew FileLoadException(String::Format(CultureInfo::InvariantCulture, "Could not load ProjectedFSLib.dll to set up entry points."));
33+
}
34+
35+
if (::GetProcAddress(projFsLib, "PrjWritePlaceholderInfo2") != nullptr)
36+
{
37+
// We have the API introduced in Windows 10 version 2004.
38+
this->_PrjFillDirEntryBuffer2 = reinterpret_cast<t_PrjFillDirEntryBuffer2>(::GetProcAddress(projFsLib,
39+
"PrjFillDirEntryBuffer2"));
40+
}
41+
42+
::FreeLibrary(projFsLib);
2443
}
2544

2645
// Provides access to the native handle to the directory entry buffer.
@@ -220,15 +239,15 @@ public ref class DirectoryEnumerationResults : public IDirectoryEnumerationResul
220239
changeTime);
221240

222241
HRESULT hr;
223-
if (symlinkTargetOrNull != nullptr)
242+
if (symlinkTargetOrNull != nullptr && this->_PrjFillDirEntryBuffer2 != nullptr)
224243
{
225244
PRJ_EXTENDED_INFO extendedInfo = {};
226245

227246
extendedInfo.InfoType = PRJ_EXT_INFO_TYPE_SYMLINK;
228247
pin_ptr<const WCHAR> targetPath = PtrToStringChars(symlinkTargetOrNull);
229248
extendedInfo.Symlink.TargetName = targetPath;
230249

231-
hr = ::PrjFillDirEntryBuffer2(m_dirEntryBufferHandle,
250+
hr = this->_PrjFillDirEntryBuffer2(m_dirEntryBufferHandle,
232251
pFileName,
233252
&basicInfo,
234253
&extendedInfo);
@@ -297,5 +316,14 @@ public ref class DirectoryEnumerationResults : public IDirectoryEnumerationResul
297316

298317
return basicInfo;
299318
}
319+
320+
typedef HRESULT(__stdcall* t_PrjFillDirEntryBuffer2)(
321+
_In_ PRJ_DIR_ENTRY_BUFFER_HANDLE dirEntryBufferHandle,
322+
_In_ PCWSTR fileName,
323+
_In_opt_ PRJ_FILE_BASIC_INFO* fileBasicInfo,
324+
_In_opt_ PRJ_EXTENDED_INFO* extendedInfo
325+
);
326+
327+
t_PrjFillDirEntryBuffer2 _PrjFillDirEntryBuffer2 = nullptr;
300328
};
301329
}}} // namespace Microsoft.Windows.ProjFS

0 commit comments

Comments
 (0)