This commit is contained in:
恍兮惚兮 2024-12-23 14:39:45 +08:00
parent ddbe526e27
commit f982f96af6
4 changed files with 43 additions and 18 deletions

View File

@ -531,6 +531,28 @@ wchar_t *TranslateFullLog(wchar_t *otext)
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;
int atlaswmain(int argc, wchar_t *argv[])
{
@ -542,9 +564,8 @@ int atlaswmain(int argc, wchar_t *argv[])
return 0;
while (true)
{
wchar_t src[4096] = {0};
DWORD _;
if (!ReadFile(hPipe, src, 4096 * 2, &_, NULL))
wchar_t *src = readstring(hPipe);
if (!src)
break;
if (!mutex)
@ -583,14 +604,13 @@ int atlaswmain(int argc, wchar_t *argv[])
if (!AtlasIsLoaded())
{
ReleaseMutex(mutex);
auto text = L"Atlas Load Failed";
WriteFile(hPipe, text, wcslen(text) * 2, &_, NULL);
writestring(0, hPipe);
return false;
}
}
wchar_t *text = TranslateFull(src, 0, NULL, NULL);
WriteFile(hPipe, text, wcslen(text) * 2, &_, NULL);
writestring(text, hPipe);
free(src);
free(text);
ReleaseMutex(mutex);
}

View File

@ -152,9 +152,10 @@ void SetUpLEC()
static void writestring(wchar_t *text, HANDLE hPipe)
{
DWORD _;
auto len = 2 * wcslen(text);
auto len = text ? (2 * wcslen(text)) : 0;
if (!WriteFile(hPipe, &len, 4, &_, NULL))
return;
if (text)
if (!WriteFile(hPipe, text, len, &_, NULL))
return;
}
@ -195,7 +196,6 @@ int lecwmain(int argc, wchar_t *argv[])
PATH = "Nova\\JaEn\\EngineDll_je.dll";
}
DWORD _;
wchar_t __[] = L"not installed";
while (true)
{
wchar_t *otext = readstring(hPipe);
@ -207,14 +207,14 @@ int lecwmain(int argc, wchar_t *argv[])
SetUpLEC();
if (lecState < 0)
{
writestring(__, hPipe);
writestring(0, hPipe);
continue;
}
}
if (lecState < 0)
{
writestring(__, hPipe);
writestring(0, hPipe);
continue;
}
wchar_t *text = LECTranslateFull(otext);

View File

@ -1,7 +1,6 @@
from myutils.subproc import subproc_w, autoproc
from translator.basetranslator import basetrans
import os, time
from myutils.config import _TR
import ctypes, time
import windows
@ -47,9 +46,13 @@ class TS(basetrans):
def x64(self, content):
self.checkpath()
windows.WriteFile(self.hPipe, content.encode("utf-16-le"))
return windows.ReadFile(self.hPipe, 4096).decode("utf-16-le")
l = content.encode("utf-16-le")
windows.WriteFile(self.hPipe, bytes(ctypes.c_int(len(l))))
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):
return self.x64(content)

View File

@ -56,6 +56,8 @@ class TS(basetrans):
windows.WriteFile(self.hPipe, bytes(ctypes.c_int(len(l))))
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):