mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2025-01-15 00:43:59 +08:00
...
This commit is contained in:
parent
b7304003d0
commit
ac15a09471
6
.github/ISSUE_TEMPLATE/01_bug.yaml
vendored
6
.github/ISSUE_TEMPLATE/01_bug.yaml
vendored
@ -32,10 +32,10 @@ body:
|
|||||||
|
|
||||||
- type: textarea
|
- type: textarea
|
||||||
attributes:
|
attributes:
|
||||||
label: Log files 日志文件
|
label: Log file 日志文件
|
||||||
description: >
|
description: >
|
||||||
View log files in the "logs" directory. Please upload the log file as an attachment instead of copying its contents.
|
Run LunaTranslator_debug.exe to reproduce the error, and then upload the generated log_*.txt file.
|
||||||
|
|
||||||
在"logs"目录中获取日志文件。请将日志文件以附件的形式上传,而不是将其中的内容复制。
|
运行LunaTranslator_debug.exe复现错误,然后上传产生的log_*.txt文件。
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
@ -188,50 +188,6 @@ def switchdir():
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Lockedfile:
|
|
||||||
def __init__(self) -> None:
|
|
||||||
self.collect = queue.Queue()
|
|
||||||
threading.Thread(target=self.__write).start()
|
|
||||||
|
|
||||||
def __write(self):
|
|
||||||
data = self.collect.get()
|
|
||||||
os.makedirs("logs", exist_ok=True)
|
|
||||||
file = open(
|
|
||||||
f"logs/{time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime())}.txt",
|
|
||||||
"w",
|
|
||||||
encoding="utf8",
|
|
||||||
errors="ignore",
|
|
||||||
)
|
|
||||||
while True:
|
|
||||||
file.write(data)
|
|
||||||
file.flush()
|
|
||||||
data = self.collect.get()
|
|
||||||
|
|
||||||
def write(self, data):
|
|
||||||
self.collect.put(data)
|
|
||||||
|
|
||||||
|
|
||||||
lockedfile = Lockedfile()
|
|
||||||
|
|
||||||
|
|
||||||
class debugoutput(io.IOBase):
|
|
||||||
def __init__(self, file: io.TextIOBase) -> None:
|
|
||||||
super().__init__()
|
|
||||||
self.originfile = file
|
|
||||||
|
|
||||||
def write(self, data):
|
|
||||||
self.originfile.write(data)
|
|
||||||
lockedfile.write(data)
|
|
||||||
|
|
||||||
def flush(self):
|
|
||||||
self.originfile.flush()
|
|
||||||
|
|
||||||
|
|
||||||
def savelogs():
|
|
||||||
sys.stderr = debugoutput(sys.stderr)
|
|
||||||
sys.stdout = debugoutput(sys.stdout)
|
|
||||||
|
|
||||||
|
|
||||||
def urlprotocol():
|
def urlprotocol():
|
||||||
import argparse, gobject, sys
|
import argparse, gobject, sys
|
||||||
from urllib.parse import urlsplit
|
from urllib.parse import urlsplit
|
||||||
@ -239,9 +195,9 @@ def urlprotocol():
|
|||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("--URLProtocol", required=False)
|
parser.add_argument("--URLProtocol", required=False)
|
||||||
args = parser.parse_args()
|
|
||||||
URLProtocol: str = args.URLProtocol
|
|
||||||
try:
|
try:
|
||||||
|
args = parser.parse_args()
|
||||||
|
URLProtocol: str = args.URLProtocol
|
||||||
if URLProtocol:
|
if URLProtocol:
|
||||||
print(URLProtocol)
|
print(URLProtocol)
|
||||||
result = urlsplit(URLProtocol)
|
result = urlsplit(URLProtocol)
|
||||||
@ -266,7 +222,6 @@ if __name__ == "__main__":
|
|||||||
checklang()
|
checklang()
|
||||||
checkintegrity()
|
checkintegrity()
|
||||||
checkpermission()
|
checkpermission()
|
||||||
savelogs()
|
|
||||||
urlprotocol()
|
urlprotocol()
|
||||||
loadmainui()
|
loadmainui()
|
||||||
app.exit(app.exec())
|
app.exit(app.exec())
|
||||||
|
@ -348,7 +348,7 @@
|
|||||||
"button_color_close": "#D32424",
|
"button_color_close": "#D32424",
|
||||||
"button_color_normal": "#FFFFFF",
|
"button_color_normal": "#FFFFFF",
|
||||||
"textthreaddelay": 500,
|
"textthreaddelay": 500,
|
||||||
"maxBufferSize": 10000,
|
"maxBufferSize": 3000,
|
||||||
"maxHistorySize": 1000000,
|
"maxHistorySize": 1000000,
|
||||||
"yuanjiao_r": 5,
|
"yuanjiao_r": 5,
|
||||||
"qwebinspectgeo": [
|
"qwebinspectgeo": [
|
||||||
|
@ -10,15 +10,12 @@ Make sure not to download the source code by mistake!
|
|||||||
|
|
||||||
### Launch
|
### Launch
|
||||||
|
|
||||||
After unzipping, you can see the following files. Use **LunaTranslator.exe** to start.
|
|
||||||
|
|
||||||
![img](https://image.lunatranslator.org/zh/startup.png)
|
|
||||||
|
|
||||||
**LunaTranslator.exe** will start in normal mode.
|
**LunaTranslator.exe** will start in normal mode.
|
||||||
|
|
||||||
**LunaTranslator_admin.exe** will start with administrator privileges. Some games require administrator privileges to HOOK, so use this only when necessary; otherwise, start in normal mode.
|
**LunaTranslator_admin.exe** will start with administrator privileges. Some games require administrator privileges to HOOK, so use this only when necessary; otherwise, start in normal mode.
|
||||||
|
|
||||||
**LunaTranslator_debug.exe** will display the command line and show the log during runtime. If you encounter a bug, please run this program and attach the log.
|
**LunaTranslator_debug.exe** will generate log file. When submitting bug feedback, please be sure to run the program and reproduce the bug, and then submit the generated log file.
|
||||||
|
|
||||||
#### Note
|
#### Note
|
||||||
|
|
||||||
|
@ -10,15 +10,12 @@
|
|||||||
|
|
||||||
### Запуск
|
### Запуск
|
||||||
|
|
||||||
После распаковки вы увидите следующие файлы, запустите **LunaTranslator.exe**.
|
|
||||||
|
|
||||||
![img](https://image.lunatranslator.org/zh/startup.png)
|
|
||||||
|
|
||||||
**LunaTranslator.exe** запускается в обычном режиме
|
**LunaTranslator.exe** запускается в обычном режиме
|
||||||
|
|
||||||
**LunaTranslator_admin.exe** запускается с правами администратора, некоторые игры требуют прав администратора для HOOK, используйте его только в этом случае, в остальных случаях запускайте в обычном режиме.
|
**LunaTranslator_admin.exe** запускается с правами администратора, некоторые игры требуют прав администратора для HOOK, используйте его только в этом случае, в остальных случаях запускайте в обычном режиме.
|
||||||
|
|
||||||
**LunaTranslator_debug.exe** запускается с командной строкой и отображает логи во время работы. Если вы сталкиваетесь с ошибками, запустите этот программу и приложите логи.
|
**LunaTranslator_debug.exe** создаст файлы журналов. Отправляя отзыв об ошибке, обязательно используйте эту программу для запуска и воспроизведения ошибки, а затем отправьте созданный файл журнала.
|
||||||
|
|
||||||
#### Внимание
|
#### Внимание
|
||||||
|
|
||||||
|
@ -10,17 +10,12 @@
|
|||||||
|
|
||||||
### 启动
|
### 启动
|
||||||
|
|
||||||
解压后可以看到下列文件,使用**LunaTranslator.exe**启动即可
|
|
||||||
|
|
||||||
|
|
||||||
![img](https://image.lunatranslator.org/zh/startup.png)
|
|
||||||
|
|
||||||
|
|
||||||
**LunaTranslator.exe** 会以普通模式启动
|
**LunaTranslator.exe** 会以普通模式启动
|
||||||
|
|
||||||
**LunaTranslator_admin.exe** 会以管理员权限启动,部分游戏需要管理员权限才能HOOK,仅这时需要使用这个,其他时候普通模式启动即可。
|
**LunaTranslator_admin.exe** 会以管理员权限启动,部分游戏需要管理员权限才能HOOK,仅这时需要使用这个,其他时候普通模式启动即可。
|
||||||
|
|
||||||
**LunaTranslator_debug.exe** 会显示命令行启动,并显示运行时的log。如果遇到有bug,请运行这个程序并附上log。
|
**LunaTranslator_debug.exe** 会生成log文件。提交bug反馈时,务必请使用该程序运行并复现bug,然后提交生成的log文件。
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,11 +15,11 @@ generate_product_version(
|
|||||||
|
|
||||||
set(sources PyStand.cpp luna.rc ${versioninfo})
|
set(sources PyStand.cpp luna.rc ${versioninfo})
|
||||||
|
|
||||||
#add_executable(LunaTranslator_debug ${sources})
|
add_executable(LunaTranslator_debug ${sources})
|
||||||
#target_compile_definitions(LunaTranslator_debug PRIVATE PYSTAND_CONSOLE)
|
target_compile_definitions(LunaTranslator_debug PRIVATE PYSTAND_CONSOLE)
|
||||||
add_executable(LunaTranslator WIN32 ${sources})
|
add_executable(LunaTranslator WIN32 ${sources})
|
||||||
add_executable(LunaTranslator_admin WIN32 ${sources})
|
add_executable(LunaTranslator_admin WIN32 ${sources})
|
||||||
set_target_properties(LunaTranslator_admin PROPERTIES LINK_FLAGS " /MANIFESTUAC:\"level='requireAdministrator' uiAccess='false'\" ")
|
set_target_properties(LunaTranslator_admin PROPERTIES LINK_FLAGS " /MANIFESTUAC:\"level='requireAdministrator' uiAccess='false'\" ")
|
||||||
#target_precompile_headers(LunaTranslator_debug REUSE_FROM pch)
|
target_precompile_headers(LunaTranslator_debug REUSE_FROM pch)
|
||||||
target_precompile_headers(LunaTranslator_admin REUSE_FROM pch)
|
target_precompile_headers(LunaTranslator_admin REUSE_FROM pch)
|
||||||
target_precompile_headers(LunaTranslator REUSE_FROM pch)
|
target_precompile_headers(LunaTranslator REUSE_FROM pch)
|
@ -1,6 +1,11 @@
|
|||||||
|
|
||||||
#include "PyStand.h"
|
#include "PyStand.h"
|
||||||
|
|
||||||
|
#include <iomanip>
|
||||||
|
#include <sstream>
|
||||||
|
#include <chrono>
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
// dtor
|
// dtor
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
@ -250,52 +255,63 @@ int PyStand::DetectScript()
|
|||||||
// init script
|
// init script
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
const auto init_script =
|
const auto init_script =
|
||||||
L"import sys\n"
|
LR"(
|
||||||
L"import os\n"
|
import sys
|
||||||
L"PYSTAND = os.environ['PYSTAND']\n"
|
import os
|
||||||
L"PYSTAND_HOME = os.environ['PYSTAND_HOME']\n"
|
PYSTAND = os.environ['PYSTAND']
|
||||||
L"PYSTAND_RUNTIME = os.environ['PYSTAND_RUNTIME']\n"
|
PYSTAND_HOME = os.environ['PYSTAND_HOME']
|
||||||
L"PYSTAND_SCRIPT = os.environ['PYSTAND_SCRIPT']\n"
|
PYSTAND_RUNTIME = os.environ['PYSTAND_RUNTIME']
|
||||||
L"sys.path_origin = [n for n in sys.path]\n"
|
PYSTAND_SCRIPT = os.environ['PYSTAND_SCRIPT']
|
||||||
L"sys.PYSTAND = PYSTAND\n"
|
sys.path_origin = [n for n in sys.path]
|
||||||
L"sys.PYSTAND_HOME = PYSTAND_HOME\n"
|
sys.PYSTAND = PYSTAND
|
||||||
L"sys.PYSTAND_SCRIPT = PYSTAND_SCRIPT\n"
|
sys.PYSTAND_HOME = PYSTAND_HOME
|
||||||
L"def MessageBox(msg, info = 'Message'):\n"
|
sys.PYSTAND_SCRIPT = PYSTAND_SCRIPT
|
||||||
L" import ctypes\n"
|
def MessageBox(msg, info = 'Message'):
|
||||||
L" ctypes.windll.user32.MessageBoxW(None, str(msg), str(info), 0)\n"
|
import ctypes
|
||||||
L" return 0\n"
|
ctypes.windll.user32.MessageBoxW(None, str(msg), str(info), 0)
|
||||||
L"os.MessageBox = MessageBox\n"
|
return 0
|
||||||
|
os.MessageBox = MessageBox
|
||||||
|
sys.stdout=sys.stderr
|
||||||
|
)"
|
||||||
#ifndef PYSTAND_CONSOLE
|
#ifndef PYSTAND_CONSOLE
|
||||||
L"try:\n"
|
LR"(
|
||||||
L" fd = os.open('CONOUT$', os.O_RDWR | os.O_BINARY)\n"
|
try:
|
||||||
L" fp = os.fdopen(fd, 'w')\n"
|
fd = os.open('CONOUT$', os.O_RDWR | os.O_BINARY)
|
||||||
L" sys.stdout = fp\n"
|
fp = os.fdopen(fd, 'w')
|
||||||
L" sys.stderr = fp\n"
|
sys.stdout = fp
|
||||||
L" attached = True\n"
|
sys.stderr = fp
|
||||||
L"except Exception as e:\n"
|
attached = True
|
||||||
L" fp = open(os.devnull, 'w', errors='ignore')\n"
|
except Exception as e:
|
||||||
L" sys.stdout = fp\n"
|
fp = open(os.devnull, 'w', errors='ignore')
|
||||||
L" sys.stderr = fp\n"
|
sys.stdout = fp
|
||||||
L" attached = False\n"
|
sys.stderr = fp
|
||||||
|
attached = False
|
||||||
|
)"
|
||||||
#endif
|
#endif
|
||||||
L"sys.argv = [PYSTAND_SCRIPT] + sys.argv[1:]\n"
|
LR"(
|
||||||
L"text = open(PYSTAND_SCRIPT, 'rb').read()\n"
|
sys.argv = [PYSTAND_SCRIPT] + sys.argv[1:]
|
||||||
L"environ = {'__file__': PYSTAND_SCRIPT, '__name__': '__main__'}\n"
|
text = open(PYSTAND_SCRIPT, 'rb').read()
|
||||||
L"environ['__package__'] = None\n"
|
environ = {'__file__': PYSTAND_SCRIPT, '__name__': '__main__'}
|
||||||
|
environ['__package__'] = None
|
||||||
|
)"
|
||||||
#ifndef PYSTAND_CONSOLE
|
#ifndef PYSTAND_CONSOLE
|
||||||
L"try:\n"
|
LR"(
|
||||||
L" code = compile(text, PYSTAND_SCRIPT, 'exec')\n"
|
try:
|
||||||
L" exec(code, environ)\n"
|
code = compile(text, PYSTAND_SCRIPT, 'exec')
|
||||||
L"except Exception:\n"
|
exec(code, environ)
|
||||||
L" if attached:\n"
|
except Exception:
|
||||||
L" raise\n"
|
if attached:
|
||||||
L" import traceback, io\n"
|
raise
|
||||||
L" sio = io.StringIO()\n"
|
import traceback, io
|
||||||
L" traceback.print_exc(file = sio)\n"
|
sio = io.StringIO()
|
||||||
L" os.MessageBox(sio.getvalue(), 'Error')\n"
|
traceback.print_exc(file = sio)
|
||||||
|
os.MessageBox(sio.getvalue(), 'Error')
|
||||||
|
)"
|
||||||
#else
|
#else
|
||||||
L"code = compile(text, PYSTAND_SCRIPT, 'exec')\n"
|
LR"(
|
||||||
L"exec(code, environ)\n"
|
code = compile(text, PYSTAND_SCRIPT, 'exec')
|
||||||
|
exec(code, environ)
|
||||||
|
)"
|
||||||
#endif
|
#endif
|
||||||
"";
|
"";
|
||||||
|
|
||||||
@ -310,12 +326,7 @@ const auto init_script =
|
|||||||
//! mode: win
|
//! mode: win
|
||||||
//! int: objs
|
//! int: objs
|
||||||
|
|
||||||
#ifdef PYSTAND_CONSOLE
|
|
||||||
int main()
|
int main()
|
||||||
#else
|
|
||||||
int WINAPI
|
|
||||||
WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR args, int show)
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
// 当更新进行时,禁止启动
|
// 当更新进行时,禁止启动
|
||||||
@ -330,6 +341,7 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR args, int show)
|
|||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
#ifndef PYSTAND_CONSOLE
|
#ifndef PYSTAND_CONSOLE
|
||||||
|
// winmain下的stderr没有任何卵用,对于崩溃时的stderr根本显示不出来,所以还是用控制台来保存log吧。
|
||||||
if (AttachConsole(ATTACH_PARENT_PROCESS))
|
if (AttachConsole(ATTACH_PARENT_PROCESS))
|
||||||
{
|
{
|
||||||
freopen("CONOUT$", "w", stdout);
|
freopen("CONOUT$", "w", stdout);
|
||||||
@ -347,8 +359,27 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR args, int show)
|
|||||||
SetEnvironmentVariableA("PYSTAND_STDIN", fn.c_str());
|
SetEnvironmentVariableA("PYSTAND_STDIN", fn.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
{
|
||||||
|
auto getCurrentTimestamp = []
|
||||||
|
{
|
||||||
|
auto now = std::chrono::system_clock::now();
|
||||||
|
std::time_t now_time_t = std::chrono::system_clock::to_time_t(now);
|
||||||
|
std::tm now_tm = *std::localtime(&now_time_t);
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << std::put_time(&now_tm, "log_%Y-%m-%d-%H-%M-%S.txt");
|
||||||
|
return oss.str();
|
||||||
|
};
|
||||||
|
auto curr = getCurrentTimestamp();
|
||||||
|
freopen(curr.c_str(), "a", stderr);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
int hr = ps.RunString(init_script);
|
int hr = ps.RunString(init_script);
|
||||||
// printf("finalize\n");
|
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int WINAPI
|
||||||
|
WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR args, int show)
|
||||||
|
{
|
||||||
|
return main();
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user