Skip to content

Commit

Permalink
Reworked more functions
Browse files Browse the repository at this point in the history
  • Loading branch information
nefarius committed Aug 7, 2024
1 parent 3a28a9c commit 7d3e33a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 24 deletions.
33 changes: 11 additions & 22 deletions src/Devcon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,9 @@ bool devcon::enable_disable_bth_usb_device(bool state)
return succeeded;
}

bool devcon::install_driver(const std::wstring& fullInfPath, bool* rebootRequired)
std::expected<void, Win32Error> devcon::install_driver(const std::wstring& fullInfPath,
bool* rebootRequired)
{
el::Logger* logger = el::Loggers::getLogger("default");

Newdev newdev;
BOOL reboot;

Expand All @@ -414,26 +413,20 @@ bool devcon::install_driver(const std::wstring& fullInfPath, bool* rebootRequire
))
{
case FunctionCallResult::NotAvailable:
logger->error("Couldn't find DiInstallDriverW export");
SetLastError(ERROR_INVALID_FUNCTION);
return false;
return std::unexpected(Win32Error(ERROR_INVALID_FUNCTION));
case FunctionCallResult::Failure:
return false;
return std::unexpected(Win32Error(GetLastError()));
case FunctionCallResult::Success:
if (rebootRequired)
{
*rebootRequired = reboot > 0;
}
return true;
return {};
}

return false;
return std::unexpected(Win32Error(ERROR_INTERNAL_ERROR));
}

bool devcon::uninstall_driver(const std::wstring& fullInfPath, bool* rebootRequired)
std::expected<void, Win32Error> devcon::uninstall_driver(const std::wstring& fullInfPath, bool* rebootRequired)
{
el::Logger* logger = el::Loggers::getLogger("default");

Newdev newdev;
BOOL reboot;

Expand All @@ -446,20 +439,16 @@ bool devcon::uninstall_driver(const std::wstring& fullInfPath, bool* rebootRequi
))
{
case FunctionCallResult::NotAvailable:
logger->error("Couldn't find DiUninstallDriverW export");
SetLastError(ERROR_INVALID_FUNCTION);
return false;
return std::unexpected(Win32Error(ERROR_INVALID_FUNCTION));
case FunctionCallResult::Failure:
return false;
return std::unexpected(Win32Error(GetLastError()));
case FunctionCallResult::Success:
if (rebootRequired)
{
*rebootRequired = reboot > 0;
}
return true;
return {};
}

return false;
return std::unexpected(Win32Error(ERROR_INTERNAL_ERROR));
}

bool devcon::add_device_class_filter(const GUID* classGuid, const std::wstring& filterName,
Expand Down
4 changes: 2 additions & 2 deletions src/Devcon.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ namespace devcon

bool enable_disable_bth_usb_device(bool state);

bool install_driver(const std::wstring& fullInfPath, bool* rebootRequired);
std::expected<void, nefarius::util::Win32Error> install_driver(const std::wstring& fullInfPath, bool* rebootRequired);

bool uninstall_driver(const std::wstring& fullInfPath, bool* rebootRequired);
std::expected<void, nefarius::util::Win32Error> uninstall_driver(const std::wstring& fullInfPath, bool* rebootRequired);

bool add_device_class_filter(const GUID* classGuid, const std::wstring& filterName,
DeviceClassFilterPosition position);
Expand Down

0 comments on commit 7d3e33a

Please sign in to comment.