diff options
| author | Chris-SG <chris.shandgost@gmail.com> | 2019-10-08 15:00:59 +1100 |
|---|---|---|
| committer | Curtis J Bezault <curtbezault@gmail.com> | 2019-10-07 21:00:59 -0700 |
| commit | 9f26ae8bf0888c8a5b6a92c792859dde044d005f (patch) | |
| tree | 737af2da95155bc0bccaf6d6d0a1e0d67ca60f18 | |
| parent | b2f2d896077eeb88863e34d3a909e37340707838 (diff) | |
| download | vcpkg-9f26ae8bf0888c8a5b6a92c792859dde044d005f.tar.gz vcpkg-9f26ae8bf0888c8a5b6a92c792859dde044d005f.zip | |
Find default for text/plain on Linux and Windows (#567) (#8435)
* Find default for text/plain on machines with xdg (#567)
* Add unicode aware detection of text/plain on windows
| -rw-r--r-- | toolsrc/src/vcpkg/commands.edit.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/toolsrc/src/vcpkg/commands.edit.cpp b/toolsrc/src/vcpkg/commands.edit.cpp index 6e98f5818..314af1167 100644 --- a/toolsrc/src/vcpkg/commands.edit.cpp +++ b/toolsrc/src/vcpkg/commands.edit.cpp @@ -167,6 +167,22 @@ namespace vcpkg::Commands::Edit const std::vector<fs::path> from_registry = find_from_registry(); candidate_paths.insert(candidate_paths.end(), from_registry.cbegin(), from_registry.cend()); + + const auto txt_default = System::get_registry_string(HKEY_CLASSES_ROOT, R"(.txt\ShellNew)", "ItemName"); + if(const auto entry = txt_default.get()) + { + #ifdef UNICODE + LPWSTR dst = new wchar_t[MAX_PATH]; + ExpandEnvironmentStrings(Strings::to_utf16(*entry).c_str(), dst, MAX_PATH); + auto full_path = Strings::to_utf8(dst); + #else + LPSTR dst = new char[MAX_PATH]; + ExpandEnvironmentStrings(entry->c_str(), dst, MAX_PATH); + auto full_path = std::string(dst); + #endif + auto begin = full_path.find_first_not_of('@'); + candidate_paths.push_back(fs::u8path(full_path.substr(begin, full_path.find_first_of(',')-begin))); + } #elif defined(__APPLE__) candidate_paths.push_back( fs::path{"/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/bin/code"}); @@ -174,6 +190,22 @@ namespace vcpkg::Commands::Edit #elif defined(__linux__) candidate_paths.push_back(fs::path{"/usr/share/code/bin/code"}); candidate_paths.push_back(fs::path{"/usr/bin/code"}); + + if(System::cmd_execute("command -v xdg-mime") == 0) + { + auto mime_qry = Strings::format(R"(xdg-mime query default text/plain)"); + auto execute_result = System::cmd_execute_and_capture_output(mime_qry); + if(execute_result.exit_code == 0 && !execute_result.output.empty()) + { + mime_qry = Strings::format(R"(command -v %s)", execute_result.output.substr(0, execute_result.output.find('.'))); + execute_result = System::cmd_execute_and_capture_output(mime_qry); + if(execute_result.exit_code == 0 && !execute_result.output.empty()) + { + execute_result.output.erase(std::remove(std::begin(execute_result.output), std::end(execute_result.output), '\n'), std::end(execute_result.output)); + candidate_paths.push_back(fs::path{execute_result.output}); + } + } + } #endif const auto it = Util::find_if(candidate_paths, [&](const fs::path& p) { return fs.exists(p); }); |
