mirror of
https://github.com/Artikash/Textractor.git
synced 2024-12-23 17:04:12 +08:00
small fixes
This commit is contained in:
parent
140c9057ea
commit
b5c319ee46
@ -107,7 +107,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
std::unique_ptr<LPWSTR[], Functor<LocalFree>> argv(CommandLineToArgvW(GetCommandLineW(), &argc));
|
std::unique_ptr<LPWSTR[], Functor<LocalFree>> argv(CommandLineToArgvW(GetCommandLineW(), &argc));
|
||||||
for (int i = 0; i < argc; ++i)
|
for (int i = 0; i < argc; ++i)
|
||||||
if (std::wstring arg = argv[i]; arg[0] == L'/' || arg[0] == L'-')
|
if (std::wstring arg = argv[i]; arg[0] == L'/' || arg[0] == L'-')
|
||||||
if (arg[1] == L'p')
|
if (arg[1] == L'p' || arg[1] == L'P')
|
||||||
if (DWORD processId = _wtoi(arg.substr(2).c_str())) Host::InjectProcess(processId);
|
if (DWORD processId = _wtoi(arg.substr(2).c_str())) Host::InjectProcess(processId);
|
||||||
else for (int i = 0; i < processIds.size(); ++i)
|
else for (int i = 0; i < processIds.size(); ++i)
|
||||||
if (processNames[i].find(L"\\" + arg.substr(2)) != std::wstring::npos) Host::InjectProcess(processIds[i]);
|
if (processNames[i].find(L"\\" + arg.substr(2)) != std::wstring::npos) Host::InjectProcess(processIds[i]);
|
||||||
|
@ -58,21 +58,14 @@ Synchronized<std::wstring> translateTo = L"en";
|
|||||||
std::pair<bool, std::wstring> Translate(const std::wstring& text)
|
std::pair<bool, std::wstring> Translate(const std::wstring& text)
|
||||||
{
|
{
|
||||||
std::wstring translateFrom;
|
std::wstring translateFrom;
|
||||||
if (HttpRequest httpRequest{
|
if (HttpRequest httpRequest{ L"Mozilla/5.0 Textractor", L"www.bing.com", L"POST", FormatString(L"/tdetect?text=%s", Escape(text)).c_str() }) translateFrom = httpRequest.response;
|
||||||
L"Mozilla/5.0 Textractor",
|
|
||||||
L"www.bing.com",
|
|
||||||
L"POST",
|
|
||||||
FormatString(L"/tdetect?text=%s", Escape(text)).c_str(),
|
|
||||||
WINHTTP_FLAG_ESCAPE_DISABLE | WINHTTP_FLAG_SECURE,
|
|
||||||
}) translateFrom = httpRequest.response;
|
|
||||||
else return { false, FormatString(L"%s (code=%u)", TRANSLATION_ERROR, httpRequest.errorCode) };
|
else return { false, FormatString(L"%s (code=%u)", TRANSLATION_ERROR, httpRequest.errorCode) };
|
||||||
|
|
||||||
if (HttpRequest httpRequest{
|
if (HttpRequest httpRequest{
|
||||||
L"Mozilla/5.0 Textractor",
|
L"Mozilla/5.0 Textractor",
|
||||||
L"www.bing.com",
|
L"www.bing.com",
|
||||||
L"POST",
|
L"POST",
|
||||||
FormatString(L"/ttranslate?from=%s&to=%s&text=%s", translateFrom, translateTo->c_str(), Escape(text)).c_str(),
|
FormatString(L"/ttranslate?from=%s&to=%s&text=%s", translateFrom, translateTo->c_str(), Escape(text)).c_str()
|
||||||
WINHTTP_FLAG_ESCAPE_DISABLE | WINHTTP_FLAG_SECURE,
|
|
||||||
})
|
})
|
||||||
// Response formatted as JSON: translation starts with :" and ends with "}
|
// Response formatted as JSON: translation starts with :" and ends with "}
|
||||||
if (std::wsmatch results; std::regex_search(httpRequest.response, results, std::wregex(L":\"(.+)\"\\}"))) return { true, results[1] };
|
if (std::wsmatch results; std::regex_search(httpRequest.response, results, std::wregex(L":\"(.+)\"\\}"))) return { true, results[1] };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user