Skip to content
This repository was archived by the owner on Jan 7, 2025. It is now read-only.

[WslApiLoader] add const modifications, initializate all member in the list. #85

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions DistroLauncher/WslApiLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -26,7 +32,7 @@ WslApiLoader::~WslApiLoader()
}
}

BOOL WslApiLoader::WslIsOptionalComponentInstalled()
BOOL WslApiLoader::WslIsOptionalComponentInstalled() const
{
return ((_wslApiDll != nullptr) &&
(_isDistributionRegistered != nullptr) &&
Expand All @@ -36,44 +42,44 @@ 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);
}

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);
}

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);
}

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);
}
Expand Down
14 changes: 7 additions & 7 deletions DistroLauncher/WslApiLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down