Skip to content
This repository has been archived by the owner on Dec 7, 2024. It is now read-only.

Commit

Permalink
Detect WinFsp when not installed in Program Files (x86)
Browse files Browse the repository at this point in the history
  • Loading branch information
WorkingRobot committed Jun 5, 2020
1 parent 04910e6 commit 01b6a62
Showing 1 changed file with 33 additions and 10 deletions.
43 changes: 33 additions & 10 deletions checks/winfspcheck.cpp
Original file line number Diff line number Diff line change
@@ -1,33 +1,56 @@
#include "winfspcheck.h"

#define WINFSP_INSTALL_REGKEY L"Software\\WOW6432Node\\WinFsp"
#define WINFSP_INSTALL_REGVALUE L"InstallDir"

#include <filesystem>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <ShlObj_core.h>

namespace fs = std::filesystem;

fs::path GetRegInstallDir() {
HKEY key;
auto Result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, WINFSP_INSTALL_REGKEY, NULL, KEY_READ, &key);

if (Result != ERROR_SUCCESS) { // should be ERROR_NO_MATCH or ERROR_FILE_NOT_FOUND
return nullptr; // In reality, it should always exist, so this shouldn't run
}
else {
WCHAR data[MAX_PATH];
DWORD type = REG_SZ;
DWORD size = sizeof(data);
Result = RegQueryValueEx(key, WINFSP_INSTALL_REGVALUE, NULL, &type, (LPBYTE)&data, &size);
RegCloseKey(key);
return Result == ERROR_SUCCESS ? data : nullptr;
}
}

WinFspCheckResult LoadWinFsp() {
static bool alreadyLoaded = false;
if (alreadyLoaded) {
return WinFspCheckResult::LOADED;
}

fs::path DataFolder;
{
PWSTR appDataFolder;
if (SHGetKnownFolderPath(FOLDERID_ProgramFilesX86, 0, NULL, &appDataFolder) != S_OK) {
return WinFspCheckResult::NO_PATH;
fs::path InstallDir = GetRegInstallDir();
if (InstallDir.empty()) {
{
PWSTR appDataFolder;
if (SHGetKnownFolderPath(FOLDERID_ProgramFilesX86, 0, NULL, &appDataFolder) != S_OK) {
return WinFspCheckResult::NO_PATH;
}
InstallDir = fs::path(appDataFolder) / "WinFsp";
CoTaskMemFree(appDataFolder);
}
DataFolder = appDataFolder;
CoTaskMemFree(appDataFolder);
}
DataFolder = DataFolder / "WinFsp" / "bin" / "winfsp-x64.dll";

if (fs::status(DataFolder).type() != fs::file_type::regular) {
InstallDir = InstallDir / "bin" / "winfsp-x64.dll";

if (fs::status(InstallDir).type() != fs::file_type::regular) {
return WinFspCheckResult::NO_DLL;
}
if (LoadLibraryA(DataFolder.string().c_str()) == NULL) {
if (LoadLibraryA(InstallDir.string().c_str()) == NULL) {
return WinFspCheckResult::CANNOT_LOAD;
}
alreadyLoaded = true;
Expand Down

0 comments on commit 01b6a62

Please sign in to comment.