1
0
mirror of synced 2024-11-28 09:30:51 +01:00

feature: Added network proxy support for hex::Net (#562)

* feat(i18n): update Chinese(Simplified) translation

* feat: proxy setting

* refactor: add hex::Net::setProxy

* fix: undefined symbol: hex::Net::m_proxyUrl

* style: m_proxyUrl -> s_proxyUrl
This commit is contained in:
Shiroki Satsuki 2022-07-01 20:05:32 +08:00 committed by GitHub
parent eadcc6f38c
commit ef5fbba56b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 88 additions and 2 deletions

View File

@ -49,6 +49,8 @@ namespace hex {
void cancel() { this->m_shouldCancel = true; }
static void setProxy(const std::string &url);
private:
void setCommonSettings(std::string &response, const std::string &url, u32 timeout = 2000, const std::map<std::string, std::string> &extraHeaders = {}, const std::string &body = {});
std::optional<i32> execute();
@ -62,6 +64,8 @@ namespace hex {
std::mutex m_transmissionActive;
float m_progress = 0.0F;
bool m_shouldCancel = false;
static std::string s_proxyUrl;
};
}

View File

@ -4,6 +4,8 @@
#include <hex/helpers/file.hpp>
#include <hex/helpers/logger.hpp>
#include <hex/api/content_registry.hpp>
#include <filesystem>
#include <cstdio>
@ -113,6 +115,8 @@ namespace hex {
curl_easy_setopt(this->m_ctx, CURLOPT_SSLCERTTYPE, "PEM");
curl_easy_setopt(this->m_ctx, CURLOPT_SSL_CTX_FUNCTION, sslCtxFunction);
#endif
curl_easy_setopt(this->m_ctx, CURLOPT_PROXY, Net::s_proxyUrl.c_str());
}
std::optional<i32> Net::execute() {
@ -241,4 +245,10 @@ namespace hex {
return {};
}
std::string Net::s_proxyUrl;
void Net::setProxy(const std::string &url) {
Net::s_proxyUrl = url;
}
}

View File

@ -6,6 +6,7 @@
#include <imgui.h>
#include <hex/ui/imgui_imhex_extensions.h>
#include <fonts/codicons_font.h>
#include <hex/helpers/net.hpp>
#include <hex/helpers/utils.hpp>
#include <nlohmann/json.hpp>
@ -350,6 +351,45 @@ namespace hex::plugin::builtin {
return result;
});
/* Proxy */
static const std::string proxySetting { "hex.builtin.setting.proxy" };
// init hex::Net proxy url
hex::Net::setProxy(ContentRegistry::Settings::read(proxySetting, "hex.builtin.setting.proxy.url", ""));
ContentRegistry::Settings::addCategoryDescription(proxySetting, "hex.builtin.setting.proxy.description");
ContentRegistry::Settings::add(
proxySetting, "hex.builtin.setting.proxy.url", "", [](auto name, nlohmann::json &setting) {
static std::string proxyUrl = static_cast<std::string>(setting);
static bool enableProxy = !proxyUrl.empty();
bool result = false;
if (ImGui::Checkbox("hex.builtin.setting.proxy.enable"_lang, &enableProxy)) {
setting = enableProxy ? proxyUrl : "";
hex::Net::setProxy(enableProxy ? proxyUrl : "");
result = true;
}
ImGui::BeginDisabled(!enableProxy);
if (ImGui::InputText("##proxy_url", proxyUrl)) {
setting = proxyUrl;
hex::Net::setProxy(proxyUrl);
result = true;
}
ImGui::EndDisabled();
ImGui::InfoTooltip("hex.builtin.setting.proxy.url.tooltip"_lang);
ImGui::SameLine();
ImGui::TextFormatted("{}", name);
return result;
},
false);
}
}

View File

@ -696,6 +696,11 @@ namespace hex::plugin::builtin {
{ "hex.builtin.setting.font", "Schriftart" },
{ "hex.builtin.setting.font.font_path", "Eigene Schriftart" },
{ "hex.builtin.setting.font.font_size", "Schriftgrösse" },
//{ "hex.builtin.setting.proxy", "Proxy" },
//{ "hex.builtin.setting.proxy.description", "Proxy will take effect on store, wikipedia or any other plugin immediately." },
//{ "hex.builtin.setting.proxy.enable", "Enable Proxy" },
//{ "hex.builtin.setting.proxy.url", "Proxy URL" },
//{ "hex.builtin.setting.proxy.url.tooltip", "http(s):// or socks5:// (e.g., http://127.0.0.1:1080)" },
{ "hex.builtin.provider.file.path", "Dateipfad" },
{ "hex.builtin.provider.file.size", "Größe" },

View File

@ -698,6 +698,11 @@ namespace hex::plugin::builtin {
{ "hex.builtin.setting.font", "Font" },
{ "hex.builtin.setting.font.font_path", "Custom Font Path" },
{ "hex.builtin.setting.font.font_size", "Font Size" },
{ "hex.builtin.setting.proxy", "Proxy" },
{ "hex.builtin.setting.proxy.description", "Proxy will take effect on store, wikipedia or any other plugin immediately." },
{ "hex.builtin.setting.proxy.enable", "Enable Proxy" },
{ "hex.builtin.setting.proxy.url", "Proxy URL" },
{ "hex.builtin.setting.proxy.url.tooltip", "http(s):// or socks5:// (e.g., http://127.0.0.1:1080)" },
{ "hex.builtin.provider.file.path", "File path" },
{ "hex.builtin.provider.file.size", "Size" },

View File

@ -702,6 +702,11 @@ namespace hex::plugin::builtin {
//{ "hex.builtin.setting.font", "Font" },
//{ "hex.builtin.setting.font.font_path", "Custom Font Path" },
//{ "hex.builtin.setting.font.font_size", "Font Size" },
//{ "hex.builtin.setting.proxy", "Proxy" },
//{ "hex.builtin.setting.proxy.description", "Proxy will take effect on store, wikipedia or any other plugin immediately." },
//{ "hex.builtin.setting.proxy.enable", "Enable Proxy" },
//{ "hex.builtin.setting.proxy.url", "Proxy URL" },
//{ "hex.builtin.setting.proxy.url.tooltip", "http(s):// or socks5:// (e.g., http://127.0.0.1:1080)" },
{ "hex.builtin.provider.file.path", "Percorso del File" },
{ "hex.builtin.provider.file.size", "Dimensione" },

View File

@ -699,6 +699,11 @@ namespace hex::plugin::builtin {
//{ "hex.builtin.setting.font", "Font" },
//{ "hex.builtin.setting.font.font_path", "Custom Font Path" },
//{ "hex.builtin.setting.font.font_size", "Font Size" },
//{ "hex.builtin.setting.proxy", "Proxy" },
//{ "hex.builtin.setting.proxy.description", "Proxy will take effect on store, wikipedia or any other plugin immediately." },
//{ "hex.builtin.setting.proxy.enable", "Enable Proxy" },
//{ "hex.builtin.setting.proxy.url", "Proxy URL" },
//{ "hex.builtin.setting.proxy.url.tooltip", "http(s):// or socks5:// (e.g., http://127.0.0.1:1080)" },
{ "hex.builtin.provider.file.path", "ファイルパス" },
{ "hex.builtin.provider.file.size", "サイズ" },

View File

@ -696,6 +696,11 @@ namespace hex::plugin::builtin {
{ "hex.builtin.setting.font", "Fonte" },
{ "hex.builtin.setting.font.font_path", "Caminho da Fonte Customizada" },
{ "hex.builtin.setting.font.font_size", "Tamanho da Fonte" },
//{ "hex.builtin.setting.proxy", "Proxy" },
//{ "hex.builtin.setting.proxy.description", "Proxy will take effect on store, wikipedia or any other plugin immediately." },
//{ "hex.builtin.setting.proxy.enable", "Enable Proxy" },
//{ "hex.builtin.setting.proxy.url", "Proxy URL" },
//{ "hex.builtin.setting.proxy.url.tooltip", "http(s):// or socks5:// (e.g., http://127.0.0.1:1080)" },
{ "hex.builtin.provider.file.path", "Caminho do Arquivo" },
{ "hex.builtin.provider.file.size", "Tamanho" },

View File

@ -343,6 +343,8 @@ namespace hex::plugin::builtin {
{ "hex.builtin.view.strings.extract", "搜索" },
{ "hex.builtin.view.strings.regex_error", "非法正则" },
{ "hex.builtin.view.strings.results", "找到 {0} 个结果" },
{ "hex.builtin.view.strings.filter", "过滤" },
{ "hex.builtin.view.strings.extract", "提取" },
{ "hex.builtin.view.strings.searching", "搜索中..." },
{ "hex.builtin.view.strings.offset", "偏移" },
{ "hex.builtin.view.strings.size", "大小" },
@ -567,7 +569,7 @@ namespace hex::plugin::builtin {
{ "hex.builtin.tools.demangler", "Itanium/MSVC 名还原" },
{ "hex.builtin.tools.demangler.mangled", "修饰名" },
{ "hex.builtin.tools.demangler.demangled", "还原名" },
{ "hex.builtin.tools.ascii_table", "ASCII" },
{ "hex.builtin.tools.ascii_table", "ASCII " },
{ "hex.builtin.tools.ascii_table.octal", "显示八进制" },
{ "hex.builtin.tools.regex_replacer", "正则替换" },
{ "hex.builtin.tools.regex_replacer.pattern", "正则表达式" },
@ -689,7 +691,7 @@ namespace hex::plugin::builtin {
{ "hex.builtin.setting.hex_editor", "Hex 编辑器" },
{ "hex.builtin.setting.hex_editor.highlight_color", "选区高亮色" },
{ "hex.builtin.setting.hex_editor.bytes_per_row", "每行显示的字节数" },
{ "hex.builtin.setting.hex_editor.ascii", "显示ASCII栏" },
{ "hex.builtin.setting.hex_editor.ascii", "显示 ASCII " },
{ "hex.builtin.setting.hex_editor.advanced_decoding", "显示高级解码栏" },
{ "hex.builtin.setting.hex_editor.grey_zeros", "显示零字节为灰色" },
{ "hex.builtin.setting.hex_editor.uppercase_hex", "大写十六进制" },
@ -701,6 +703,11 @@ namespace hex::plugin::builtin {
{ "hex.builtin.setting.font", "字体" },
{ "hex.builtin.setting.font.font_path", "自定义字体路径" },
{ "hex.builtin.setting.font.font_size", "字体大小" },
{ "hex.builtin.setting.proxy", "网络代理" },
{ "hex.builtin.setting.proxy.description", "代理设置会立即在可下载内容、维基百科查询上生效。" },
{ "hex.builtin.setting.proxy.enable", "启用代理" },
{ "hex.builtin.setting.proxy.url", "代理 URL" },
{ "hex.builtin.setting.proxy.url.tooltip", "http(s):// 或 socks5://(如 http://127.0.0.1:1080" },
{ "hex.builtin.provider.file.path", "路径" },
{ "hex.builtin.provider.file.size", "大小" },