mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2025-01-13 07:33:53 +08:00
.
This commit is contained in:
parent
3a0f44449c
commit
32766a4dce
@ -1,4 +1,7 @@
|
||||
|
||||
wchar_t SPCAT_VOICES_7[] = LR"(HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices)";
|
||||
wchar_t SPCAT_VOICES_10[] = LR"(HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech_OneCore\Voices)";
|
||||
|
||||
std::optional<std::vector<byte>> _Speak(std::wstring &Content, const wchar_t *token, int voiceid, int rate, int volume)
|
||||
{
|
||||
std::optional<std::vector<byte>> ret = {};
|
||||
|
@ -39,7 +39,7 @@ std::wstring stolower(const std::wstring &s1)
|
||||
std::vector<DWORD> EnumerateProcesses(const std::wstring &exe)
|
||||
{
|
||||
|
||||
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
||||
AutoHandle hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
||||
if (hSnapshot == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
return {};
|
||||
@ -50,7 +50,6 @@ std::vector<DWORD> EnumerateProcesses(const std::wstring &exe)
|
||||
|
||||
if (!Process32First(hSnapshot, &pe32))
|
||||
{
|
||||
CloseHandle(hSnapshot);
|
||||
return {};
|
||||
}
|
||||
std::vector<DWORD> pids;
|
||||
@ -60,7 +59,6 @@ std::vector<DWORD> EnumerateProcesses(const std::wstring &exe)
|
||||
pids.push_back(pe32.th32ProcessID);
|
||||
} while (Process32Next(hSnapshot, &pe32));
|
||||
|
||||
CloseHandle(hSnapshot);
|
||||
return pids;
|
||||
}
|
||||
enum
|
||||
|
@ -1,10 +1,11 @@
|
||||
std::optional<std::vector<byte>> _Speak(std::wstring &Content, const wchar_t *token, int voiceid, int rate, int volume);
|
||||
|
||||
std::vector<std::wstring> _List(const wchar_t *token);
|
||||
extern wchar_t SPCAT_VOICES_7[];
|
||||
extern wchar_t SPCAT_VOICES_10[];
|
||||
int neospeechlist(int argc, wchar_t *argv[])
|
||||
{
|
||||
FILE *f = _wfopen(argv[1], L"wb");
|
||||
for (auto key : {L"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Speech\\Voices", L"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Speech_OneCore\\Voices"})
|
||||
for (auto key : {SPCAT_VOICES_7, SPCAT_VOICES_10})
|
||||
{
|
||||
auto speechs = _List(key);
|
||||
for (int i = 0; i < speechs.size(); i++)
|
||||
|
@ -1,7 +1,7 @@
|
||||
|
||||
set(VERSION_MAJOR 6)
|
||||
set(VERSION_MINOR 16)
|
||||
set(VERSION_PATCH 3)
|
||||
set(VERSION_PATCH 4)
|
||||
set(VERSION_REVISION 0)
|
||||
set(LUNA_VERSION "{${VERSION_MAJOR},${VERSION_MINOR},${VERSION_PATCH},${VERSION_REVISION}}")
|
||||
add_library(VERSION_DEF ${CMAKE_CURRENT_LIST_DIR}/version_def.cpp)
|
||||
|
@ -163,15 +163,9 @@ IWebBrowser2 *MWebBrowser::GetIWebBrowser2()
|
||||
return m_web_browser2;
|
||||
}
|
||||
|
||||
IHTMLDocument2 *MWebBrowser::GetIHTMLDocument2()
|
||||
HRESULT MWebBrowser::GetIHTMLDocument2(IHTMLDocument2 **p)
|
||||
{
|
||||
IDispatch *pDisp;
|
||||
m_web_browser2->get_Document(&pDisp);
|
||||
if (pDisp)
|
||||
{
|
||||
return static_cast<IHTMLDocument2 *>(pDisp);
|
||||
}
|
||||
return NULL;
|
||||
return m_web_browser2->get_Document((IDispatch **)p);
|
||||
}
|
||||
|
||||
HWND MWebBrowser::GetControlWindow()
|
||||
@ -221,7 +215,7 @@ HRESULT MWebBrowser::CreateBrowser(HWND hwndParent)
|
||||
RECT rc;
|
||||
::SetRectEmpty(&rc);
|
||||
CHECK_FAILURE(m_ole_object->DoVerb(OLEIVERB_INPLACEACTIVATE, NULL, this, 0,
|
||||
m_hwndParent, &rc));
|
||||
m_hwndParent, &rc));
|
||||
|
||||
CHECK_FAILURE(m_ole_object.QueryInterface(&m_web_browser2));
|
||||
HWND hwnd = GetControlWindow();
|
||||
@ -1002,30 +996,20 @@ HRESULT MWebBrowser::GetTypeInfoCount(UINT *pctinfo) { return E_FAIL; }
|
||||
HRESULT MWebBrowser::GetTypeInfo(UINT, LCID, ITypeInfo **) { return E_FAIL; }
|
||||
HRESULT MWebBrowser::GetIDsOfNames(REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId) { return E_FAIL; }
|
||||
|
||||
void AddCustomObject(IHTMLDocument2 *doc, IDispatch *custObj, std::wstring name)
|
||||
HRESULT MWebBrowser::AddCustomObject(IDispatch *custObj, std::wstring name)
|
||||
{
|
||||
CComPtr<IHTMLDocument2> _doc = doc;
|
||||
if (doc == NULL)
|
||||
return;
|
||||
CComPtr<IHTMLDocument2> doc;
|
||||
CHECK_FAILURE(GetIHTMLDocument2(&doc));
|
||||
|
||||
CComPtr<IHTMLWindow2> win = NULL;
|
||||
_doc->get_parentWindow(&win);
|
||||
|
||||
if (!win)
|
||||
return;
|
||||
CHECK_FAILURE(doc->get_parentWindow(&win));
|
||||
|
||||
CComPtr<IDispatchEx> winEx;
|
||||
HRESULT hr = win.QueryInterface(&winEx);
|
||||
|
||||
if (FAILED(hr) || !winEx)
|
||||
return;
|
||||
CHECK_FAILURE(win.QueryInterface(&winEx));
|
||||
|
||||
DISPID dispid;
|
||||
CComBSTR bname = name.c_str();
|
||||
hr = winEx->GetDispID(bname, fdexNameEnsure, &dispid);
|
||||
|
||||
if (FAILED(hr))
|
||||
return;
|
||||
CHECK_FAILURE(winEx->GetDispID(bname, fdexNameEnsure, &dispid));
|
||||
|
||||
DISPID namedArgs[] = {DISPID_PROPERTYPUT};
|
||||
DISPPARAMS params;
|
||||
@ -1036,10 +1020,7 @@ void AddCustomObject(IHTMLDocument2 *doc, IDispatch *custObj, std::wstring name)
|
||||
params.cArgs = 1;
|
||||
params.cNamedArgs = 1;
|
||||
|
||||
hr = winEx->InvokeEx(dispid, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPUT, ¶ms, NULL, NULL, NULL);
|
||||
|
||||
if (FAILED(hr))
|
||||
return;
|
||||
return winEx->InvokeEx(dispid, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPUT, ¶ms, NULL, NULL, NULL);
|
||||
}
|
||||
HRESULT MWebBrowser::Invoke(DISPID dispIdMember, REFIID, LCID, WORD,
|
||||
DISPPARAMS *pDispParams, VARIANT *pVarResult,
|
||||
@ -1048,9 +1029,8 @@ HRESULT MWebBrowser::Invoke(DISPID dispIdMember, REFIID, LCID, WORD,
|
||||
if (dispIdMember == DISPID_DOCUMENTCOMPLETE)
|
||||
return OnCompleted(pDispParams);
|
||||
else if (dispIdMember == DISPID_NAVIGATECOMPLETE2)
|
||||
return AddCustomObject(GetIHTMLDocument2(), jsobj, L"LUNAJSObject"), S_OK;
|
||||
else
|
||||
return S_OK;
|
||||
return AddCustomObject(jsobj, L"LUNAJSObject"), S_OK;
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT MWebBrowser::OnCompleted(DISPPARAMS *args)
|
||||
{
|
||||
|
@ -78,10 +78,10 @@ public:
|
||||
void Destroy();
|
||||
BOOL TranslateAccelerator(LPMSG pMsg);
|
||||
IWebBrowser2 *GetIWebBrowser2();
|
||||
IHTMLDocument2 *GetIHTMLDocument2();
|
||||
HRESULT GetIHTMLDocument2(IHTMLDocument2**);
|
||||
void AllowInsecure(BOOL bAllow);
|
||||
HRESULT Quit();
|
||||
|
||||
HRESULT AddCustomObject(IDispatch *custObj, std::wstring name);
|
||||
HRESULT get_Application(IDispatch **ppApplication) const;
|
||||
HRESULT get_LocationURL(BSTR *bstrURL) const;
|
||||
HRESULT put_Silent(VARIANT_BOOL bSilent);
|
||||
|
@ -12,23 +12,13 @@
|
||||
|
||||
BOOL GetIEVersion(LPWSTR pszVersion, DWORD cchVersionMax)
|
||||
{
|
||||
pszVersion[0] = 0;
|
||||
HKEY hKey = NULL;
|
||||
RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Internet Explorer", 0,
|
||||
KEY_READ, &hKey);
|
||||
if (hKey)
|
||||
{
|
||||
DWORD cb = cchVersionMax * sizeof(WCHAR);
|
||||
LONG ret = RegQueryValueExW(hKey, L"svcVersion", NULL, NULL, (LPBYTE)pszVersion, &cb);
|
||||
if (ret != ERROR_SUCCESS)
|
||||
{
|
||||
ret = RegQueryValueExW(hKey, L"Version", NULL, NULL, (LPBYTE)pszVersion, &cb);
|
||||
}
|
||||
RegCloseKey(hKey);
|
||||
|
||||
return ret == ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
CRegKey hKey;
|
||||
if (ERROR_SUCCESS != hKey.Open(HKEY_LOCAL_MACHINE, LR"(SOFTWARE\Microsoft\Internet Explorer)", KEY_READ))
|
||||
return FALSE;
|
||||
DWORD cb = cchVersionMax * sizeof(WCHAR);
|
||||
if ((ERROR_SUCCESS == hKey.QueryStringValue(L"svcVersion", pszVersion, &cb)) ||
|
||||
(ERROR_SUCCESS == hKey.QueryStringValue(L"Version", pszVersion, &cb)))
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
static DWORD getemulation()
|
||||
@ -69,42 +59,29 @@ static DWORD getemulation()
|
||||
BOOL DoSetBrowserEmulation(DWORD dwValue)
|
||||
{
|
||||
static const TCHAR s_szFeatureControl[] =
|
||||
TEXT("SOFTWARE\\Microsoft\\Internet Explorer\\Main\\FeatureControl");
|
||||
TEXT(R"(SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl)");
|
||||
|
||||
TCHAR szPath[MAX_PATH], *pchFileName;
|
||||
GetModuleFileName(NULL, szPath, ARRAYSIZE(szPath));
|
||||
pchFileName = PathFindFileName(szPath);
|
||||
|
||||
BOOL bOK = FALSE;
|
||||
HKEY hkeyControl = NULL;
|
||||
RegOpenKeyEx(HKEY_CURRENT_USER, s_szFeatureControl, 0, KEY_ALL_ACCESS, &hkeyControl);
|
||||
if (hkeyControl)
|
||||
CRegKey hkeyControl;
|
||||
if (ERROR_SUCCESS != hkeyControl.Open(HKEY_CURRENT_USER, s_szFeatureControl, KEY_ALL_ACCESS))
|
||||
return FALSE;
|
||||
|
||||
CRegKey hkeyEmulation;
|
||||
if (ERROR_SUCCESS != hkeyEmulation.Create(hkeyControl, TEXT("FEATURE_BROWSER_EMULATION"), 0, 0, KEY_ALL_ACCESS, NULL, NULL))
|
||||
return FALSE;
|
||||
|
||||
if (dwValue)
|
||||
{
|
||||
HKEY hkeyEmulation = NULL;
|
||||
RegCreateKeyEx(hkeyControl, TEXT("FEATURE_BROWSER_EMULATION"), 0, NULL, 0,
|
||||
KEY_ALL_ACCESS, NULL, &hkeyEmulation, NULL);
|
||||
if (hkeyEmulation)
|
||||
{
|
||||
if (dwValue)
|
||||
{
|
||||
DWORD value = dwValue, size = sizeof(value);
|
||||
LONG result = RegSetValueEx(hkeyEmulation, pchFileName, 0,
|
||||
REG_DWORD, (LPBYTE)&value, size);
|
||||
bOK = (result == ERROR_SUCCESS);
|
||||
}
|
||||
else
|
||||
{
|
||||
RegDeleteValue(hkeyEmulation, pchFileName);
|
||||
bOK = TRUE;
|
||||
}
|
||||
|
||||
RegCloseKey(hkeyEmulation);
|
||||
}
|
||||
|
||||
RegCloseKey(hkeyControl);
|
||||
return ERROR_SUCCESS == hkeyEmulation.SetValue(dwValue, pchFileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
hkeyEmulation.DeleteValue(pchFileName);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return bOK;
|
||||
}
|
||||
class MWebBrowserEx : public MWebBrowser
|
||||
{
|
||||
@ -215,14 +192,14 @@ DECLARE_API void html_release(void *web)
|
||||
// ww->Release(); Destroy减少引用计数,自动del
|
||||
}
|
||||
|
||||
DECLARE_API const wchar_t *html_get_current_url(void *web)
|
||||
DECLARE_API void html_get_current_url(void *web, void (*cb)(LPCWSTR))
|
||||
{
|
||||
if (!web)
|
||||
return L"";
|
||||
return;
|
||||
auto ww = static_cast<MWebBrowserEx *>(web);
|
||||
wchar_t *_u;
|
||||
ww->get_LocationURL(&_u);
|
||||
return _u;
|
||||
CComBSTR _u;
|
||||
CHECK_FAILURE_NORET(ww->get_LocationURL(&_u));
|
||||
cb(_u);
|
||||
}
|
||||
|
||||
DECLARE_API void html_set_html(void *web, wchar_t *html)
|
||||
@ -243,40 +220,20 @@ DECLARE_API void html_add_menu(void *web, int index, int command, const wchar_t
|
||||
auto ptr = ww->menuitems.begin() + index;
|
||||
ww->menuitems.insert(ptr, {_label, command});
|
||||
}
|
||||
BSTR GetSelectedText(IHTMLDocument2 *pHTMLDoc2)
|
||||
{
|
||||
CComPtr<IHTMLSelectionObject> pSelectionObj = nullptr;
|
||||
HRESULT hr = pHTMLDoc2->get_selection(&pSelectionObj);
|
||||
if (FAILED(hr) || pSelectionObj == nullptr)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CComPtr<IHTMLTxtRange> pTxtRange = nullptr;
|
||||
hr = pSelectionObj->createRange((IDispatch **)&pTxtRange);
|
||||
if (FAILED(hr) || pTxtRange == nullptr)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
BSTR selectedText = nullptr;
|
||||
hr = pTxtRange->get_text(&selectedText);
|
||||
|
||||
return selectedText;
|
||||
}
|
||||
DECLARE_API const wchar_t *html_get_select_text(void *web)
|
||||
DECLARE_API void html_get_select_text(void *web, void (*cb)(LPCWSTR))
|
||||
{
|
||||
if (!web)
|
||||
return L"";
|
||||
return;
|
||||
auto ww = static_cast<MWebBrowserEx *>(web);
|
||||
|
||||
if (CComPtr<IHTMLDocument2> pDocument = ww->GetIHTMLDocument2())
|
||||
{
|
||||
auto text = GetSelectedText(pDocument);
|
||||
// 不需要free,free会崩溃
|
||||
return text;
|
||||
}
|
||||
return L"";
|
||||
CComPtr<IHTMLDocument2> pDocument;
|
||||
CHECK_FAILURE_NORET(ww->GetIHTMLDocument2(&pDocument));
|
||||
CComPtr<IHTMLSelectionObject> pSelectionObj;
|
||||
CHECK_FAILURE_NORET(pDocument->get_selection(&pSelectionObj));
|
||||
CComPtr<IHTMLTxtRange> pTxtRange;
|
||||
CHECK_FAILURE_NORET(pSelectionObj->createRange((IDispatch **)&pTxtRange));
|
||||
CComBSTR selectedText;
|
||||
CHECK_FAILURE_NORET(pTxtRange->get_text(&selectedText));
|
||||
cb(selectedText);
|
||||
}
|
||||
|
||||
DECLARE_API void html_bind_function(void *web, const wchar_t *name, void (*function)(wchar_t **, int))
|
||||
@ -300,18 +257,14 @@ DECLARE_API void html_eval(void *web, const wchar_t *js)
|
||||
if (!web)
|
||||
return;
|
||||
auto ww = static_cast<MWebBrowserEx *>(web);
|
||||
CComPtr<IHTMLDocument2> pDocument = ww->GetIHTMLDocument2();
|
||||
if (!pDocument)
|
||||
return;
|
||||
CComPtr<IHTMLDocument2> pDocument;
|
||||
CHECK_FAILURE_NORET(ww->GetIHTMLDocument2(&pDocument));
|
||||
CComPtr<IDispatch> scriptDispatch;
|
||||
if (FAILED(pDocument->get_Script(&scriptDispatch)))
|
||||
return;
|
||||
CHECK_FAILURE_NORET(pDocument->get_Script(&scriptDispatch));
|
||||
DISPID dispid;
|
||||
CComBSTR evalStr = L"eval";
|
||||
if (scriptDispatch->GetIDsOfNames(IID_NULL, &evalStr, 1,
|
||||
LOCALE_SYSTEM_DEFAULT, &dispid) != S_OK)
|
||||
|
||||
return;
|
||||
CHECK_FAILURE_NORET(scriptDispatch->GetIDsOfNames(IID_NULL, &evalStr, 1,
|
||||
LOCALE_SYSTEM_DEFAULT, &dispid) != S_OK);
|
||||
|
||||
DISPPARAMS params;
|
||||
VARIANT arg;
|
||||
|
@ -1,15 +1,11 @@
|
||||
|
||||
|
||||
std::optional<std::vector<byte>> _Speak(std::wstring &Content, const wchar_t *token, int voiceid, int rate, int volume);
|
||||
|
||||
std::vector<std::wstring> _List(const wchar_t *token);
|
||||
|
||||
extern wchar_t SPCAT_VOICES_7[];
|
||||
extern wchar_t SPCAT_VOICES_10[];
|
||||
namespace SAPI
|
||||
{
|
||||
|
||||
constexpr wchar_t SPCAT_VOICES_7[] = L"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Speech\\Voices";
|
||||
constexpr wchar_t SPCAT_VOICES_10[] = L"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Speech_OneCore\\Voices";
|
||||
|
||||
std::vector<std::wstring> List(int version)
|
||||
{
|
||||
if (version == 7)
|
||||
|
@ -200,19 +200,14 @@ DECLARE_API void _SetTheme(
|
||||
DECLARE_API bool isDark()
|
||||
{
|
||||
#ifndef WINXP
|
||||
HKEY hKey;
|
||||
const char *subKey = "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize";
|
||||
if (RegOpenKeyExA(HKEY_CURRENT_USER, subKey, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
|
||||
{
|
||||
DWORD value;
|
||||
DWORD dataSize = sizeof(DWORD);
|
||||
if (RegQueryValueExA(hKey, "AppsUseLightTheme", 0, NULL, (LPBYTE)&value, &dataSize) == ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey(hKey);
|
||||
return 1 - value;
|
||||
}
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
constexpr auto subKey = LR"(Software\Microsoft\Windows\CurrentVersion\Themes\Personalize)";
|
||||
CRegKey hKey;
|
||||
if (ERROR_SUCCESS != hKey.Open(HKEY_CURRENT_USER, subKey, KEY_READ))
|
||||
return false;
|
||||
|
||||
DWORD value;
|
||||
if (ERROR_SUCCESS != hKey.QueryDWORDValue(L"AppsUseLightTheme", value))
|
||||
return false;
|
||||
return 1 - value;
|
||||
#endif
|
||||
return false;
|
||||
}
|
@ -126,16 +126,32 @@ html_resize = utilsdll.html_resize
|
||||
html_resize.argtypes = c_void_p, c_uint, c_uint, c_uint, c_uint
|
||||
html_release = utilsdll.html_release
|
||||
html_release.argtypes = (c_void_p,)
|
||||
html_get_current_url = utilsdll.html_get_current_url
|
||||
html_get_current_url.argtypes = (c_void_p,)
|
||||
html_get_current_url.restype = c_wchar_p
|
||||
_html_get_current_url = utilsdll.html_get_current_url
|
||||
_html_get_current_url.argtypes = (c_void_p, c_void_p)
|
||||
html_set_html = utilsdll.html_set_html
|
||||
html_set_html.argtypes = (c_void_p, c_wchar_p)
|
||||
html_add_menu = utilsdll.html_add_menu
|
||||
html_add_menu.argtypes = (c_void_p, c_int, c_int, c_wchar_p)
|
||||
html_get_select_text = utilsdll.html_get_select_text
|
||||
html_get_select_text.argtypes = (c_void_p,)
|
||||
html_get_select_text.restype = c_wchar_p
|
||||
_html_get_select_text = utilsdll.html_get_select_text
|
||||
_html_get_select_text.argtypes = (c_void_p, c_void_p)
|
||||
|
||||
|
||||
def html_get_current_url(__):
|
||||
_ = []
|
||||
_html_get_current_url(__, CFUNCTYPE(None, c_wchar_p)(_.append))
|
||||
if _:
|
||||
return _[0]
|
||||
return ""
|
||||
|
||||
|
||||
def html_get_select_text(__):
|
||||
_ = []
|
||||
_html_get_select_text(__, CFUNCTYPE(None, c_wchar_p)(_.append))
|
||||
if _:
|
||||
return _[0]
|
||||
return ""
|
||||
|
||||
|
||||
html_bind_function_FT = CFUNCTYPE(None, POINTER(c_wchar_p), c_int)
|
||||
html_bind_function = utilsdll.html_bind_function
|
||||
html_bind_function.argtypes = c_void_p, c_wchar_p, html_bind_function_FT
|
||||
|
Loading…
x
Reference in New Issue
Block a user