-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Initial wslc settings support #14548
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
c0ef1a1
Add yaml-cpp
yao-msft e12830e
Settings def
yao-msft 9e95135
settings header
yao-msft 546d86f
Settings cpp
yao-msft d46a22e
settings command
yao-msft 9922970
hook up
yao-msft 2ad3e32
Fix build
yao-msft 93155aa
Remove SettingDefinitions
yao-msft 68ebd0c
cleanup
yao-msft 98188ef
improvements
yao-msft 57901e2
clang
yao-msft 0482059
fix build
yao-msft 69bc3ee
Test
yao-msft 2589a01
fix
yao-msft 59808c8
clang
yao-msft a22cde7
Merge remote-tracking branch 'origin/feature/wsl-for-apps' into user/…
yao-msft 3a91acc
fix storage path
yao-msft e8fdaf4
pr comments
yao-msft 1cc3044
swap
yao-msft fddd922
fix test
yao-msft 7118b30
pr comments
yao-msft dc297c2
Merge branch 'feature/wsl-for-apps' into user/yaosun/wslcsettings
yao-msft 7e5baa3
pr comments
yao-msft 8c616b5
Merge branch 'user/yaosun/wslcsettings' of https://github.com/microso…
yao-msft 70d42e4
remove backup settings
yao-msft 53e1a2c
comments
yao-msft 03d9833
fix
yao-msft b1af0eb
Merge remote-tracking branch 'origin/feature/wsl-for-apps' into user/…
yao-msft 0b8aa80
settings.yaml
yao-msft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.