Skip to content

Commit

Permalink
添加原文/译文jar不存在时的提示,暂时禁用jar翻译功能(因为词条对照表尚未更新,等待渡鸦更新)
Browse files Browse the repository at this point in the history
  • Loading branch information
jnxyp committed May 20, 2024
1 parent 91ce459 commit c925581
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# 忽略IDE文件
.idea/
.vscode/

# 忽略 para_tranz 输出的数据文件
para_tranz/output/*
Expand Down
3 changes: 1 addition & 2 deletions para_tranz/jar_loader/class_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
from typing import Union, Set, Optional, List, Tuple, Dict

from para_tranz.jar_loader.constant_table import ConstantTable, Utf8Constant
from para_tranz.utils.config import MAGIC, MIN_CLASS_VER, MAX_CLASS_VER, ORIGINAL_TEXT_MATCH_IGNORE_WHITESPACE_CHARS, \
PARA_TRANZ_PROJECT_ID
from para_tranz.utils.config import MAGIC, MIN_CLASS_VER, MAX_CLASS_VER, ORIGINAL_TEXT_MATCH_IGNORE_WHITESPACE_CHARS
from para_tranz.utils.util import make_logger, String, contains_chinese, contains_english, url_encode


Expand Down
16 changes: 10 additions & 6 deletions para_tranz/jar_loader/jar_file.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
import pdb
import re
import zipfile
from dataclasses import asdict
Expand All @@ -11,9 +12,6 @@
from para_tranz.utils.util import DataFile, String, make_logger, normalize_class_path


# Java设置


class JavaJarFile(DataFile):
"""
用于表示游戏文件中可以提取原文和译文的jar文件
Expand Down Expand Up @@ -64,7 +62,7 @@ def load_class_file(self, path: str, include_strings: List[str] = None,
class_file = JavaClassFile(self, path, include_strings, exclude_strings)
self.class_files[path] = class_file
except Exception as e:
self.logger.debug(f'在 {self.path} 中读取 class 文件 {path} 时出错:{e}')
self.logger.warn(f'在 {self.path} 中读取 class 文件 {path} 时出错:{e}')
return None

return class_file
Expand Down Expand Up @@ -219,10 +217,16 @@ def load_from_file(self) -> None:
class_file.load_from_file()

def read_original_class_file(self, class_file_path: str) -> bytes:
return zipfile.Path(self.original_file, class_file_path).read_bytes()
path = zipfile.Path(self.original_file, class_file_path)
if not path.exists():
raise FileNotFoundError(f'在原始jar文件 {self.original_path} 中找不到class文件 {class_file_path}')
return path.read_bytes()

def read_translation_class_file(self, class_file_path: str) -> bytes:
return zipfile.Path(self.translation_file, class_file_path).read_bytes()
path = zipfile.Path(self.translation_file, class_file_path)
if not path.exists():
raise FileNotFoundError(f'在译文jar文件 {self.translation_path} 中找不到class文件 {class_file_path}')
return path.read_bytes()

def load_all_classes_in_jar(self, from_translation: bool = False, override_loaded: bool = False) -> None:
jar_path = ORIGINAL_PATH / self.path if not from_translation else TRANSLATION_PATH / self.path
Expand Down
8 changes: 7 additions & 1 deletion para_tranz/para_tranz_script.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 将父级目录加入到环境变量中,以便从命令行中运行本脚本
import sys
from os.path import abspath, dirname

sys.path.append(dirname(dirname(abspath(__file__))))

from para_tranz.csv_loader.csv_file import CsvFile
from para_tranz.jar_loader.jar_file import JavaJarFile
from para_tranz.utils.util import make_logger
Expand All @@ -6,7 +12,7 @@

# 选择要处理的文件类型
# loaders = [JavaJarFile]
loaders = [JavaJarFile, CsvFile]
loaders = [CsvFile]


def game_to_paratranz():
Expand Down
1 change: 0 additions & 1 deletion para_tranz/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
MAP_PATH = PROJECT_DIRECTORY / 'para_tranz' / 'para_tranz_map.json'

# [通用配置]
PARA_TRANZ_PROJECT_ID = 3489
# 在导出字符串时是否覆盖已导出字符串的翻译stage状态
OVERRIDE_STRING_STATUS = False

Expand Down

0 comments on commit c925581

Please sign in to comment.