mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-27 15:44:12 +08:00
.
This commit is contained in:
parent
ddbe526e27
commit
f982f96af6
@ -531,6 +531,28 @@ wchar_t *TranslateFullLog(wchar_t *otext)
|
|||||||
|
|
||||||
struct AtlasConfig atlcfg;
|
struct AtlasConfig atlcfg;
|
||||||
|
|
||||||
|
static void writestring(wchar_t *text, HANDLE hPipe)
|
||||||
|
{
|
||||||
|
DWORD _;
|
||||||
|
auto len = text ? (2 * wcslen(text)) : 0;
|
||||||
|
if (!WriteFile(hPipe, &len, 4, &_, NULL))
|
||||||
|
return;
|
||||||
|
if (text)
|
||||||
|
if (!WriteFile(hPipe, text, len, &_, NULL))
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
static wchar_t *readstring(HANDLE hPipe)
|
||||||
|
{
|
||||||
|
DWORD _;
|
||||||
|
int len;
|
||||||
|
if (!ReadFile(hPipe, &len, 4, &_, NULL))
|
||||||
|
return nullptr;
|
||||||
|
wchar_t *otext = new wchar_t[len / 2 + 1];
|
||||||
|
if (!ReadFile(hPipe, otext, len, &_, NULL))
|
||||||
|
return nullptr;
|
||||||
|
otext[len / 2] = 0;
|
||||||
|
return otext;
|
||||||
|
}
|
||||||
HANDLE mutex = NULL;
|
HANDLE mutex = NULL;
|
||||||
int atlaswmain(int argc, wchar_t *argv[])
|
int atlaswmain(int argc, wchar_t *argv[])
|
||||||
{
|
{
|
||||||
@ -542,9 +564,8 @@ int atlaswmain(int argc, wchar_t *argv[])
|
|||||||
return 0;
|
return 0;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
wchar_t src[4096] = {0};
|
wchar_t *src = readstring(hPipe);
|
||||||
DWORD _;
|
if (!src)
|
||||||
if (!ReadFile(hPipe, src, 4096 * 2, &_, NULL))
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (!mutex)
|
if (!mutex)
|
||||||
@ -583,14 +604,13 @@ int atlaswmain(int argc, wchar_t *argv[])
|
|||||||
if (!AtlasIsLoaded())
|
if (!AtlasIsLoaded())
|
||||||
{
|
{
|
||||||
ReleaseMutex(mutex);
|
ReleaseMutex(mutex);
|
||||||
auto text = L"Atlas Load Failed";
|
writestring(0, hPipe);
|
||||||
WriteFile(hPipe, text, wcslen(text) * 2, &_, NULL);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wchar_t *text = TranslateFull(src, 0, NULL, NULL);
|
wchar_t *text = TranslateFull(src, 0, NULL, NULL);
|
||||||
|
writestring(text, hPipe);
|
||||||
WriteFile(hPipe, text, wcslen(text) * 2, &_, NULL);
|
free(src);
|
||||||
free(text);
|
free(text);
|
||||||
ReleaseMutex(mutex);
|
ReleaseMutex(mutex);
|
||||||
}
|
}
|
||||||
|
@ -152,11 +152,12 @@ void SetUpLEC()
|
|||||||
static void writestring(wchar_t *text, HANDLE hPipe)
|
static void writestring(wchar_t *text, HANDLE hPipe)
|
||||||
{
|
{
|
||||||
DWORD _;
|
DWORD _;
|
||||||
auto len = 2 * wcslen(text);
|
auto len = text ? (2 * wcslen(text)) : 0;
|
||||||
if (!WriteFile(hPipe, &len, 4, &_, NULL))
|
if (!WriteFile(hPipe, &len, 4, &_, NULL))
|
||||||
return;
|
return;
|
||||||
if (!WriteFile(hPipe, text, len, &_, NULL))
|
if (text)
|
||||||
return;
|
if (!WriteFile(hPipe, text, len, &_, NULL))
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
static wchar_t *readstring(HANDLE hPipe)
|
static wchar_t *readstring(HANDLE hPipe)
|
||||||
{
|
{
|
||||||
@ -195,7 +196,6 @@ int lecwmain(int argc, wchar_t *argv[])
|
|||||||
PATH = "Nova\\JaEn\\EngineDll_je.dll";
|
PATH = "Nova\\JaEn\\EngineDll_je.dll";
|
||||||
}
|
}
|
||||||
DWORD _;
|
DWORD _;
|
||||||
wchar_t __[] = L"not installed";
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
wchar_t *otext = readstring(hPipe);
|
wchar_t *otext = readstring(hPipe);
|
||||||
@ -207,14 +207,14 @@ int lecwmain(int argc, wchar_t *argv[])
|
|||||||
SetUpLEC();
|
SetUpLEC();
|
||||||
if (lecState < 0)
|
if (lecState < 0)
|
||||||
{
|
{
|
||||||
writestring(__, hPipe);
|
writestring(0, hPipe);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lecState < 0)
|
if (lecState < 0)
|
||||||
{
|
{
|
||||||
writestring(__, hPipe);
|
writestring(0, hPipe);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
wchar_t *text = LECTranslateFull(otext);
|
wchar_t *text = LECTranslateFull(otext);
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
from myutils.subproc import subproc_w, autoproc
|
from myutils.subproc import subproc_w, autoproc
|
||||||
from translator.basetranslator import basetrans
|
from translator.basetranslator import basetrans
|
||||||
import os, time
|
import ctypes, time
|
||||||
from myutils.config import _TR
|
|
||||||
import windows
|
import windows
|
||||||
|
|
||||||
|
|
||||||
@ -47,9 +46,13 @@ class TS(basetrans):
|
|||||||
def x64(self, content):
|
def x64(self, content):
|
||||||
self.checkpath()
|
self.checkpath()
|
||||||
|
|
||||||
windows.WriteFile(self.hPipe, content.encode("utf-16-le"))
|
l = content.encode("utf-16-le")
|
||||||
|
windows.WriteFile(self.hPipe, bytes(ctypes.c_int(len(l))))
|
||||||
return windows.ReadFile(self.hPipe, 4096).decode("utf-16-le")
|
windows.WriteFile(self.hPipe, l)
|
||||||
|
size = ctypes.c_int.from_buffer_copy(windows.ReadFile(self.hPipe, 4)).value
|
||||||
|
if not size:
|
||||||
|
raise Exception("not installed")
|
||||||
|
return windows.ReadFile(self.hPipe, size).decode("utf-16-le")
|
||||||
|
|
||||||
def translate(self, content):
|
def translate(self, content):
|
||||||
return self.x64(content)
|
return self.x64(content)
|
||||||
|
@ -56,6 +56,8 @@ class TS(basetrans):
|
|||||||
windows.WriteFile(self.hPipe, bytes(ctypes.c_int(len(l))))
|
windows.WriteFile(self.hPipe, bytes(ctypes.c_int(len(l))))
|
||||||
windows.WriteFile(self.hPipe, l)
|
windows.WriteFile(self.hPipe, l)
|
||||||
size = ctypes.c_int.from_buffer_copy(windows.ReadFile(self.hPipe, 4)).value
|
size = ctypes.c_int.from_buffer_copy(windows.ReadFile(self.hPipe, 4)).value
|
||||||
|
if not size:
|
||||||
|
raise Exception("not installed")
|
||||||
return windows.ReadFile(self.hPipe, size).decode("utf-16-le")
|
return windows.ReadFile(self.hPipe, size).decode("utf-16-le")
|
||||||
|
|
||||||
def translate(self, content):
|
def translate(self, content):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user