Skip to content
Snippets Groups Projects
Commit 92316f44 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

win32: DeviceLister: Fix network drives listing

Fix #439
parent c7f52c74
No related branches found
No related tags found
No related merge requests found
......@@ -37,12 +37,52 @@
#include <sstream>
#include <windows.h>
#include <winnetwk.h>
namespace medialibrary
{
namespace fs
{
std::vector<CommonDeviceLister::Device> DeviceLister::networkDevices() const
{
std::vector<Device> devs;
DWORD cbBuffer = 16384;
DWORD cEntries = -1;
HANDLE enumHandle;
if ( WNetOpenEnum( RESOURCE_CONNECTED, RESOURCETYPE_DISK, 0, nullptr, &enumHandle ) != NO_ERROR )
{
std::stringstream ss;
ss << "WNetOpenEnum error: #" << GetLastError();
throw fs::errors::DeviceListing{ ss.str() };
}
std::unique_ptr<typename std::remove_pointer<HANDLE>::type, decltype(&WNetCloseEnum)> handlePtr {
enumHandle, &WNetCloseEnum
};
auto buffer = std::make_unique<char[]>( cbBuffer );
auto netResources = reinterpret_cast<LPNETRESOURCE>( buffer.get() );
do
{
auto res = WNetEnumResource( enumHandle, &cEntries, netResources, &cbBuffer );
if ( res == ERROR_NO_MORE_ITEMS )
break;
if ( res != NO_ERROR )
{
std::stringstream ss;
ss << "WNetEnumResource error: #" << GetLastError();
throw fs::errors::DeviceListing{ ss.str() };
}
std::string mountpoint = charset::FromWide( netResources->lpLocalName ).get();
std::string uuid = charset::FromWide( netResources->lpRemoteName ).get();
devs.emplace_back( std::move( uuid ),
std::vector<std::string>{ utils::file::toMrl( mountpoint ) }, true );
} while ( true );
return devs;
}
std::vector<CommonDeviceLister::Device> DeviceLister::localDevices() const
{
wchar_t volumeName[MAX_PATH];
......@@ -100,6 +140,17 @@ std::vector<CommonDeviceLister::Device> DeviceLister::localDevices() const
std::vector<CommonDeviceLister::Device> DeviceLister::devices() const
{
auto devs = localDevices();
try
{
auto netDevs = networkDevices();
devs.insert(devs.end(), std::make_move_iterator( begin( netDevs ) ),
std::make_move_iterator( end( netDevs ) ) );
}
catch ( const fs::errors::DeviceListing& ex )
{
LOG_DEBUG( "Failed to list network devices: ", ex.what() );
}
return devs;
}
......
......@@ -40,6 +40,7 @@ public:
private:
std::vector<Device> localDevices() const;
std::vector<Device> networkDevices() const;
};
}
......
......@@ -120,6 +120,12 @@ else
medialib_soversion = medialib_major_version
endif
if host_machine.system() == 'windows'
mpr_dep = cxx.find_library('mpr', required: true)
else
mpr_dep = []
endif
medialib = library('medialibrary', medialib_src,
dependencies: [
sqlite_dep,
......@@ -129,6 +135,7 @@ medialib = library('medialibrary', medialib_src,
threads_dep,
libxxhash_dep,
macosx_dep,
mpr_dep,
],
install: true,
soversion: medialib_soversion,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment