| 21 | static HRESULT SetDefaultUser(std::wstring_view userName); |
| 22 | |
| 23 | HRESULT InstallDistribution(bool createUser) |
| 24 | { |
| 25 | // Register the distribution. |
| 26 | Helpers::PrintMessage(MSG_STATUS_INSTALLING); |
| 27 | HRESULT hr = g_wslApi.WslRegisterDistribution(); |
| 28 | if (FAILED(hr)) |
| 29 | { |
| 30 | return hr; |
| 31 | } |
| 32 | |
| 33 | // Delete /etc/resolv.conf to allow WSL to generate a version based on Windows networking information. |
| 34 | DWORD exitCode; |
| 35 | hr = g_wslApi.WslLaunchInteractive(L"/bin/rm /etc/resolv.conf", true, &exitCode); |
| 36 | if (FAILED(hr)) |
| 37 | { |
| 38 | return hr; |
| 39 | } |
| 40 | |
| 41 | // Create a user account. |
| 42 | if (createUser) |
| 43 | { |
| 44 | Helpers::PrintMessage(MSG_CREATE_USER_PROMPT); |
| 45 | std::wstring userName; |
| 46 | do |
| 47 | { |
| 48 | // Take user input for the username. |
| 49 | userName = Helpers::GetUserInput(MSG_ENTER_USERNAME, 32); |
| 50 | } while (!DistributionInfo::CreateUser(userName)); |
| 51 | |
| 52 | // Set this user account as the default. |
| 53 | hr = SetDefaultUser(userName); |
| 54 | if (FAILED(hr)) |
| 55 | { |
| 56 | return hr; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | return hr; |
| 61 | } |
| 62 | |
| 63 | HRESULT SetDefaultUser(std::wstring_view userName) |
| 64 | { |
no test coverage detected