Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
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
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ FetchContent_Declare(nlohmannjson
FetchContent_MakeAvailable(nlohmannjson)
FetchContent_GetProperties(nlohmannjson SOURCE_DIR NLOHMAN_JSON_SOURCE_DIR)

FetchContent_Declare(yaml-cpp
URL https://github.com/jbeder/yaml-cpp/releases/download/yaml-cpp-0.9.0/yaml-cpp-yaml-cpp-0.9.0.tar.gz
Comment thread
yao-msft marked this conversation as resolved.
URL_HASH SHA256=298593d9c440fd9034b8b193d96318b76d49bc97c6ceadb7b0836edf0b6d7539)

set(YAML_CPP_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(YAML_CPP_BUILD_TOOLS OFF CACHE BOOL "" FORCE)
set(YAML_CPP_BUILD_CONTRIB OFF CACHE BOOL "" FORCE)
set(YAML_MSVC_SHARED_RT OFF CACHE BOOL "" FORCE)

FetchContent_MakeAvailable(yaml-cpp)
FetchContent_GetProperties(yaml-cpp SOURCE_DIR YAML_CPP_SOURCE_DIR)

set(BOOST_VERSION "1.90.0")
set(BOOST_TARBALL "boost_${BOOST_VERSION}")
string(REPLACE "." "_" BOOST_TARBALL "${BOOST_TARBALL}")
Expand Down
11 changes: 11 additions & 0 deletions cgmanifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@
"hash": "sha1:44500f8d6b279ec314a4cdce1290ddc30f530ed7"
}
}
},
{
"component": {
"type": "other",
"other": {
"name": "yaml-cpp",
"version": "0.9.0",
"downloadUrl": "https://github.com/jbeder/yaml-cpp/releases/download/yaml-cpp-0.9.0/yaml-cpp-yaml-cpp-0.9.0.tar.gz",
"hash": "sha256:298593d9c440fd9034b8b193d96318b76d49bc97c6ceadb7b0836edf0b6d7539"
}
}
}
]
}
5 changes: 3 additions & 2 deletions src/windows/wslc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(WSLC_SUBDIRS arguments commands core services tasks)
set(WSLC_SUBDIRS arguments commands core services settings tasks)
list(TRANSFORM WSLC_SUBDIRS PREPEND ${CMAKE_CURRENT_SOURCE_DIR}/ OUTPUT_VARIABLE WSLC_SUBDIR_PATHS)

list(TRANSFORM WSLC_SUBDIR_PATHS APPEND /*.h OUTPUT_VARIABLE HEADER_PATTERNS)
Expand All @@ -13,7 +13,8 @@ target_include_directories(wslclib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${WSLC_SUB

target_link_libraries(wslclib
${COMMON_LINK_LIBRARIES}
common)
common
yaml-cpp)

target_precompile_headers(wslclib REUSE_FROM common)
set_target_properties(wslclib PROPERTIES FOLDER windows)
Expand Down
2 changes: 2 additions & 0 deletions src/windows/wslc/commands/RootCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Module Name:
#include "ContainerCommand.h"
#include "ImageCommand.h"
#include "SessionCommand.h"
#include "SettingsCommand.h"

using namespace wsl::windows::wslc::execution;

Expand All @@ -27,6 +28,7 @@ std::vector<std::unique_ptr<Command>> RootCommand::GetCommands() const
commands.push_back(std::make_unique<ContainerCommand>(FullName()));
commands.push_back(std::make_unique<ImageCommand>(FullName()));
commands.push_back(std::make_unique<SessionCommand>(FullName()));
commands.push_back(std::make_unique<SettingsCommand>(FullName()));
commands.push_back(std::make_unique<ContainerAttachCommand>(FullName()));
Comment thread
yao-msft marked this conversation as resolved.
commands.push_back(std::make_unique<ImageBuildCommand>(FullName()));
commands.push_back(std::make_unique<ContainerCreateCommand>(FullName()));
Expand Down
92 changes: 92 additions & 0 deletions src/windows/wslc/commands/SettingsCommand.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*++

Copyright (c) Microsoft. All rights reserved.

Module Name:

SettingsCommand.cpp

Abstract:

Implementation of SettingsCommand command tree.

--*/
#include "Argument.h"
#include "SettingsCommand.h"
#include "UserSettings.h"
#include "wslutil.h"

using namespace wsl::windows::common::wslutil;
using namespace wsl::windows::wslc::execution;
using namespace wsl::windows::wslc::settings;

namespace wsl::windows::wslc {

// SettingsCommand
std::vector<std::unique_ptr<Command>> SettingsCommand::GetCommands() const
{
std::vector<std::unique_ptr<Command>> commands;
commands.push_back(std::make_unique<SettingsResetCommand>(FullName()));
return commands;
}

std::vector<Argument> SettingsCommand::GetArguments() const
{
return {};
}

std::wstring SettingsCommand::ShortDescription() const
{
return {L"Open the settings file in the default editor."};
}

std::wstring SettingsCommand::LongDescription() const
{
return {
L"Opens the wslc user settings file in the system default editor for .yaml files.\n"
L"On first run, creates the file with all settings commented out at their defaults."};
}

void SettingsCommand::ExecuteInternal(CLIExecutionContext& context) const
{
settings::User().PrepareToShellExecuteFile();

const auto& path = settings::User().SettingsFilePath();

// Some versions of windows will fail if no file extension association exists, other will pop up the dialog
// to make the user pick their default.
HINSTANCE res = ShellExecuteW(nullptr, nullptr, path.c_str(), nullptr, nullptr, SW_SHOW);
if (static_cast<int>(reinterpret_cast<uintptr_t>(res)) <= 32)
{
// User doesn't have file type association. Default to notepad
// Quote the path so that Notepad treats it as a single argument even if it contains spaces.
std::filesystem::path notepadPath = std::filesystem::path{wil::GetSystemDirectoryW().get()} / L"notepad.exe";
std::wstring quotedPath = L"\"" + path.wstring() + L"\"";
ShellExecuteW(nullptr, nullptr, notepadPath.c_str(), quotedPath.c_str(), nullptr, SW_SHOW);
}
}

// SettingsResetCommand
std::vector<Argument> SettingsResetCommand::GetArguments() const
{
return {};
}

std::wstring SettingsResetCommand::ShortDescription() const
{
return {L"Reset settings to built-in defaults."};
}

std::wstring SettingsResetCommand::LongDescription() const
{
return {L"Overwrites the settings file with a commented-out defaults template."};
}

void SettingsResetCommand::ExecuteInternal(CLIExecutionContext& context) const
{
// TODO: do we need prompt support?
settings::User().Reset();
PrintMessage(L"Settings reset to defaults.");
}

} // namespace wsl::windows::wslc
54 changes: 54 additions & 0 deletions src/windows/wslc/commands/SettingsCommand.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*++

Copyright (c) Microsoft. All rights reserved.

Module Name:

SettingsCommand.h

Abstract:

Declaration of SettingsCommand command tree.

--*/
#pragma once
#include "Command.h"

namespace wsl::windows::wslc {

// Root settings command: opens the settings file in the user's default editor.
struct SettingsCommand final : public Command
{
constexpr static std::wstring_view CommandName = L"settings";

SettingsCommand(const std::wstring& parent) : Command(CommandName, parent)
{
}

std::vector<std::unique_ptr<Command>> GetCommands() const override;
std::vector<Argument> GetArguments() const override;
std::wstring ShortDescription() const override;
std::wstring LongDescription() const override;

protected:
void ExecuteInternal(CLIExecutionContext& context) const override;
};

// Resets the settings file to built-in defaults.
struct SettingsResetCommand final : public Command
{
constexpr static std::wstring_view CommandName = L"reset";

SettingsResetCommand(const std::wstring& parent) : Command(CommandName, parent)
{
}

std::vector<Argument> GetArguments() const override;
std::wstring ShortDescription() const override;
std::wstring LongDescription() const override;

protected:
void ExecuteInternal(CLIExecutionContext& context) const override;
};

} // namespace wsl::windows::wslc
1 change: 1 addition & 0 deletions src/windows/wslc/core/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Module Name:
#include "CLIExecutionContext.h"
#include "Invocation.h"
#include "RootCommand.h"
#include "UserSettings.h"

using namespace wsl::shared;
using namespace wsl::windows::common;
Expand Down
15 changes: 9 additions & 6 deletions src/windows/wslc/services/SessionModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,24 @@ Module Name:

#include <precomp.h>
#include "SessionModel.h"
#include "UserSettings.h"

namespace wsl::windows::wslc::models {
SessionOptions SessionOptions::Default()
{
// Use a function-local static to defer path initialization until first use.
static const std::filesystem::path defaultPath = {wsl::windows::common::filesystem::GetLocalAppDataPath(nullptr) / "wslc"};
static const std::filesystem::path storagePath =
settings::User().Get<settings::Setting::SessionStoragePath>().empty()
? std::filesystem::path{wsl::windows::common::filesystem::GetLocalAppDataPath(nullptr) / L"wslc\\storage"}
: settings::User().Get<settings::Setting::SessionStoragePath>().c_str();
Comment thread
yao-msft marked this conversation as resolved.

Comment thread
yao-msft marked this conversation as resolved.
// TODO: Have a configuration file for those.
SessionOptions options{};
options.m_sessionSettings.DisplayName = s_DefaultSessionName;
options.m_sessionSettings.CpuCount = 4;
options.m_sessionSettings.MemoryMb = 2048;
options.m_sessionSettings.CpuCount = settings::User().Get<settings::Setting::SessionCpuCount>();
options.m_sessionSettings.MemoryMb = settings::User().Get<settings::Setting::SessionMemoryMb>();
options.m_sessionSettings.BootTimeoutMs = 30 * 1000;
options.m_sessionSettings.StoragePath = defaultPath.c_str();
options.m_sessionSettings.MaximumStorageSizeMb = 10000; // 10GB.
options.m_sessionSettings.StoragePath = storagePath.c_str();
options.m_sessionSettings.MaximumStorageSizeMb = settings::User().Get<settings::Setting::SessionStorageSizeMb>();
Comment thread
yao-msft marked this conversation as resolved.
options.m_sessionSettings.NetworkingMode = WSLCNetworkingModeVirtioProxy;
return options;
}
Expand Down
Loading
Loading