diff --git a/DistroLauncher/WslApiLoader.cpp b/DistroLauncher/WslApiLoader.cpp index 223a02c4..8697fafd 100644 --- a/DistroLauncher/WslApiLoader.cpp +++ b/DistroLauncher/WslApiLoader.cpp @@ -6,8 +6,14 @@ #include "stdafx.h" #include "WslApiLoader.h" -WslApiLoader::WslApiLoader(const std::wstring& distributionName) : - _distributionName(distributionName) +WslApiLoader::WslApiLoader(const std::wstring& distributionName) + : _distributionName(distributionName) + , _wslApiDll() + , _isDistributionRegistered() + , _registerDistribution() + , _configureDistribution() + , _launchInteractive() + , _launch() { _wslApiDll = LoadLibraryEx(L"wslapi.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32); if (_wslApiDll != nullptr) { @@ -26,7 +32,7 @@ WslApiLoader::~WslApiLoader() } } -BOOL WslApiLoader::WslIsOptionalComponentInstalled() +BOOL WslApiLoader::WslIsOptionalComponentInstalled() const { return ((_wslApiDll != nullptr) && (_isDistributionRegistered != nullptr) && @@ -36,14 +42,14 @@ BOOL WslApiLoader::WslIsOptionalComponentInstalled() (_launch != nullptr)); } -BOOL WslApiLoader::WslIsDistributionRegistered() +BOOL WslApiLoader::WslIsDistributionRegistered() const { return _isDistributionRegistered(_distributionName.c_str()); } -HRESULT WslApiLoader::WslRegisterDistribution() +HRESULT WslApiLoader::WslRegisterDistribution() const { - HRESULT hr = _registerDistribution(_distributionName.c_str(), L"install.tar.gz"); + const auto hr = _registerDistribution(_distributionName.c_str(), L"install.tar.gz"); if (FAILED(hr)) { Helpers::PrintMessage(MSG_WSL_REGISTER_DISTRIBUTION_FAILED, hr); } @@ -51,9 +57,9 @@ HRESULT WslApiLoader::WslRegisterDistribution() return hr; } -HRESULT WslApiLoader::WslConfigureDistribution(ULONG defaultUID, WSL_DISTRIBUTION_FLAGS wslDistributionFlags) +HRESULT WslApiLoader::WslConfigureDistribution(ULONG defaultUID, WSL_DISTRIBUTION_FLAGS wslDistributionFlags) const { - HRESULT hr = _configureDistribution(_distributionName.c_str(), defaultUID, wslDistributionFlags); + const auto hr = _configureDistribution(_distributionName.c_str(), defaultUID, wslDistributionFlags); if (FAILED(hr)) { Helpers::PrintMessage(MSG_WSL_CONFIGURE_DISTRIBUTION_FAILED, hr); } @@ -61,9 +67,9 @@ HRESULT WslApiLoader::WslConfigureDistribution(ULONG defaultUID, WSL_DISTRIBUTIO return hr; } -HRESULT WslApiLoader::WslLaunchInteractive(PCWSTR command, BOOL useCurrentWorkingDirectory, DWORD *exitCode) +HRESULT WslApiLoader::WslLaunchInteractive(PCWSTR command, BOOL useCurrentWorkingDirectory, DWORD *exitCode) const { - HRESULT hr = _launchInteractive(_distributionName.c_str(), command, useCurrentWorkingDirectory, exitCode); + const auto hr = _launchInteractive(_distributionName.c_str(), command, useCurrentWorkingDirectory, exitCode); if (FAILED(hr)) { Helpers::PrintMessage(MSG_WSL_LAUNCH_INTERACTIVE_FAILED, command, hr); } @@ -71,9 +77,9 @@ HRESULT WslApiLoader::WslLaunchInteractive(PCWSTR command, BOOL useCurrentWorkin return hr; } -HRESULT WslApiLoader::WslLaunch(PCWSTR command, BOOL useCurrentWorkingDirectory, HANDLE stdIn, HANDLE stdOut, HANDLE stdErr, HANDLE *process) +HRESULT WslApiLoader::WslLaunch(PCWSTR command, BOOL useCurrentWorkingDirectory, HANDLE stdIn, HANDLE stdOut, HANDLE stdErr, HANDLE *process) const { - HRESULT hr = _launch(_distributionName.c_str(), command, useCurrentWorkingDirectory, stdIn, stdOut, stdErr, process); + const auto hr = _launch(_distributionName.c_str(), command, useCurrentWorkingDirectory, stdIn, stdOut, stdErr, process); if (FAILED(hr)) { Helpers::PrintMessage(MSG_WSL_LAUNCH_FAILED, command, hr); } diff --git a/DistroLauncher/WslApiLoader.h b/DistroLauncher/WslApiLoader.h index 5d8ba948..59a1c12e 100644 --- a/DistroLauncher/WslApiLoader.h +++ b/DistroLauncher/WslApiLoader.h @@ -24,28 +24,28 @@ class WslApiLoader WslApiLoader(const std::wstring& distributionName); ~WslApiLoader(); - BOOL WslIsOptionalComponentInstalled(); + BOOL WslIsOptionalComponentInstalled() const; - BOOL WslIsDistributionRegistered(); + BOOL WslIsDistributionRegistered() const; - HRESULT WslRegisterDistribution(); + HRESULT WslRegisterDistribution() const; HRESULT WslConfigureDistribution(ULONG defaultUID, - WSL_DISTRIBUTION_FLAGS wslDistributionFlags); + WSL_DISTRIBUTION_FLAGS wslDistributionFlags) const; HRESULT WslLaunchInteractive(PCWSTR command, BOOL useCurrentWorkingDirectory, - DWORD *exitCode); + DWORD *exitCode) const; HRESULT WslLaunch(PCWSTR command, BOOL useCurrentWorkingDirectory, HANDLE stdIn, HANDLE stdOut, HANDLE stdErr, - HANDLE *process); + HANDLE *process) const; private: - std::wstring _distributionName; + const std::wstring _distributionName; HMODULE _wslApiDll; WSL_IS_DISTRIBUTION_REGISTERED _isDistributionRegistered; WSL_REGISTER_DISTRIBUTION _registerDistribution;