Skip to content

Commit

Permalink
<feature> improve the speed of unpack with multi-threads and fix enco…
Browse files Browse the repository at this point in the history
…ding problem

update version to v2.3.2
  • Loading branch information
anonymousException committed Jun 3, 2024
1 parent eaad4ab commit 54c5359
Show file tree
Hide file tree
Showing 41 changed files with 211 additions and 76 deletions.
2 changes: 1 addition & 1 deletion src/engine_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def on_custom_button_clicked(self):
if os.path.isfile('openai_model.txt'):
command = 'notepad ' + 'openai_model.txt'
p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
creationflags=0x08000000)
creationflags=0x08000000, text=True, encoding='utf-8')
p.wait()
self.init_openai_model_combobox()

Expand Down
2 changes: 1 addition & 1 deletion src/extract_runtime_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def run(self):
command = 'start "" /wait /d "' + dir + '" "' + path + '"'
self.path = path
p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
creationflags=0x08000000)
creationflags=0x08000000, text=True, encoding='utf-8')
p.wait()

target = dir + '/' + hooked_result
Expand Down
2 changes: 1 addition & 1 deletion src/extraction_official_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,5 @@ def exec_official_translate(game_path, tl_name, is_gen_empty):
command = command + ' --empty'
log_print(command)
p = subprocess.Popen(command, shell=True, stdout=my_log.f, stderr=my_log.f,
creationflags=0x08000000)
creationflags=0x08000000, text=True, encoding='utf-8')
p.wait()
2 changes: 1 addition & 1 deletion src/font_replace_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def openFontStyleFile(self):
select_dir = select_dir + '/'
command = 'notepad ' + select_dir + 'gui.rpy'
p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
creationflags=0x08000000)
creationflags=0x08000000, text=True, encoding='utf-8')
p.wait()

def update(self):
Expand Down
15 changes: 12 additions & 3 deletions src/game_unpacker.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
QImage, QKeySequence, QLinearGradient, QPainter,
QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QApplication, QCheckBox, QDialog, QLabel,
QPushButton, QSizePolicy, QTextEdit, QWidget)
QLineEdit, QPushButton, QSizePolicy, QTextEdit,
QWidget)

class Ui_GameUnpackerDialog(object):
def setupUi(self, GameUnpackerDialog):
if not GameUnpackerDialog.objectName():
GameUnpackerDialog.setObjectName(u"GameUnpackerDialog")
GameUnpackerDialog.resize(661, 217)
GameUnpackerDialog.resize(661, 260)
self.label = QLabel(GameUnpackerDialog)
self.label.setObjectName(u"label")
self.label.setGeometry(QRect(20, 40, 71, 61))
Expand All @@ -38,8 +39,16 @@ def setupUi(self, GameUnpackerDialog):
self.unpackBtn.setGeometry(QRect(100, 130, 491, 24))
self.autoCheckBox = QCheckBox(GameUnpackerDialog)
self.autoCheckBox.setObjectName(u"autoCheckBox")
self.autoCheckBox.setGeometry(QRect(100, 180, 551, 20))
self.autoCheckBox.setGeometry(QRect(100, 220, 551, 20))
self.autoCheckBox.setChecked(True)
self.label_2 = QLabel(GameUnpackerDialog)
self.label_2.setObjectName(u"label_2")
self.label_2.setGeometry(QRect(20, 190, 161, 16))
self.label_2.setText(u"MAX_UNPACK_THREADS : ")
self.maxThreadsLineEdit = QLineEdit(GameUnpackerDialog)
self.maxThreadsLineEdit.setObjectName(u"maxThreadsLineEdit")
self.maxThreadsLineEdit.setGeometry(QRect(200, 188, 391, 20))
self.maxThreadsLineEdit.setPlaceholderText(u"")

self.retranslateUi(GameUnpackerDialog)

Expand Down
30 changes: 28 additions & 2 deletions src/game_unpacker.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>661</width>
<height>217</height>
<height>260</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -75,7 +75,7 @@
<property name="geometry">
<rect>
<x>100</x>
<y>180</y>
<y>220</y>
<width>551</width>
<height>20</height>
</rect>
Expand All @@ -87,6 +87,32 @@
<bool>true</bool>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>20</x>
<y>190</y>
<width>161</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string notr="true">MAX_UNPACK_THREADS : </string>
</property>
</widget>
<widget class="QLineEdit" name="maxThreadsLineEdit">
<property name="geometry">
<rect>
<x>200</x>
<y>188</y>
<width>391</width>
<height>20</height>
</rect>
</property>
<property name="placeholderText">
<string notr="true"/>
</property>
</widget>
</widget>
<resources/>
<connections/>
Expand Down
30 changes: 26 additions & 4 deletions src/game_unpacker_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def __init__(self, dir, p, is_auto_close):
def run(self):
try:
if self.is_auto_close and self.p is not None:
subprocess.Popen("taskkill /F /T /PID " + self.p, shell=False,
creationflags=0x08000000, text=True)
subprocess.Popen("taskkill /F /T /PID " + self.p, shell=True,
creationflags=0x08000000, text=True, encoding='utf-8')
dir = self.dir
bat = '"' + os.getcwd() + '/UnRen-forall.bat' + '"'
command = bat
Expand All @@ -74,6 +74,15 @@ def __init__(self, parent=None):
self.parent_hwnd = None
self.path = None
self.dir = None
f = io.open(hook_script, mode='r', encoding='utf-8')
_read_lines = f.readlines()
f.close()
max_thread_num = 12
for idx, _line in enumerate(_read_lines):
if _line.startswith(' MAX_UNPACK_THREADS = '):
max_thread_num = _line[len(' MAX_UNPACK_THREADS = '):].strip().strip('\n')
break
self.maxThreadsLineEdit.setText(str(max_thread_num))
_thread.start_new_thread(self.update, ())

def closeEvent(self, event):
Expand Down Expand Up @@ -101,15 +110,28 @@ def unpack(self):
if os.path.isfile(path):
if path.endswith('.exe'):
dir = os.path.dirname(path)
shutil.copyfile(hook_script, dir + '/game/' + hook_script)
#shutil.copyfile(hook_script, dir + '/game/' + hook_script)
f = io.open(hook_script, mode='r', encoding='utf-8')
_read_lines = f.readlines()
f.close()
for idx, _line in enumerate(_read_lines):
if _line.startswith(' MAX_UNPACK_THREADS = '):
_read_lines[idx] = f' MAX_UNPACK_THREADS = {self.maxThreadsLineEdit.text()}\n'
break
f = io.open(dir + '/game/' + hook_script, mode='w', encoding='utf-8')
f.writelines(_read_lines)
f.close()
f = io.open( hook_script, mode='w', encoding='utf-8')
f.writelines(_read_lines)
f.close()
command = path
self.path = path
f = io.open(dir + finish_flag, 'w')
f.write('waiting')
f.close()
self.setDisabled(True)
log_print('start unpacking...')
p = subprocess.Popen(command, shell=False, stdout=my_log.f, stderr=my_log.f,
p = subprocess.Popen(command, shell=True, stdout=my_log.f, stderr=my_log.f,
creationflags=0x08000000, text=True, cwd=dir, encoding='utf-8')
self.p = p
self.hwnd = win32gui.GetForegroundWindow()
Expand Down
30 changes: 26 additions & 4 deletions src/hook_unrpa.rpy
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ init python early hide:
import importlib
import inspect
import os
import re
from renpy.loader import archives

unpack_file_threads = []
MAX_UNPACK_THREADS = 12
unpack_semaphore = threading.Semaphore(MAX_UNPACK_THREADS)
non_ascii_file_list = []

def check_function_exists(module_name, function_name):
try:
module = importlib.import_module(module_name)
Expand All @@ -24,6 +30,19 @@ init python early hide:
#print(f"The function '{function_name}' does not exist in the module '{module_name}'.")
return False

def is_ascii(string):
return all(ord(char) < 128 for char in string)

def write_out_to_file(semaphore, name, write_path, _write_data):
with semaphore:
if is_ascii(name):
print(write_path)
else:
#print(write_path)
non_ascii_file_list.append(write_path)
with open(write_path, 'wb') as file:
file.write(_write_data)

def my_load_from_archive(name):
load_packed_file_source = None
if check_function_exists('renpy.loader','load_from_archive'):
Expand Down Expand Up @@ -61,10 +80,9 @@ init python early hide:
os.makedirs(target_dir,exist_ok=True)
else:
os.makedirs(target_dir)
with open(path, 'wb') as file:
file.write(_read)
print(path)

thread = threading.Thread(target=write_out_to_file, args=([unpack_semaphore, name, path, _read]))
thread.start()
unpack_file_threads.append(thread)
rv = load_packed_file(name)
return rv

Expand All @@ -73,6 +91,10 @@ init python early hide:
#print(name)
my_load_from_archive(name)

for t in unpack_file_threads:
t.join()
for non_ascii_file in non_ascii_file_list:
print('The file name is not ascii : ' + non_ascii_file)
finish_flag = 'unpack.finish'
pid_flag = 'game.pid'
f = io.open(pid_flag, 'w',encoding='utf-8')
Expand Down
34 changes: 21 additions & 13 deletions src/one_key_translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Ui_OneKeyTranslateDialog(object):
def setupUi(self, OneKeyTranslateDialog):
if not OneKeyTranslateDialog.objectName():
OneKeyTranslateDialog.setObjectName(u"OneKeyTranslateDialog")
OneKeyTranslateDialog.resize(1039, 600)
OneKeyTranslateDialog.resize(1039, 623)
self.selectFileBtn = QPushButton(OneKeyTranslateDialog)
self.selectFileBtn.setObjectName(u"selectFileBtn")
self.selectFileBtn.setGeometry(QRect(520, 25, 81, 91))
Expand Down Expand Up @@ -58,17 +58,17 @@ def setupUi(self, OneKeyTranslateDialog):
self.label_10.setGeometry(QRect(30, 280, 41, 31))
self.localGlossaryCheckBox = QCheckBox(OneKeyTranslateDialog)
self.localGlossaryCheckBox.setObjectName(u"localGlossaryCheckBox")
self.localGlossaryCheckBox.setGeometry(QRect(30, 370, 571, 20))
self.localGlossaryCheckBox.setGeometry(QRect(30, 400, 571, 20))
self.selectFontBtn = QPushButton(OneKeyTranslateDialog)
self.selectFontBtn.setObjectName(u"selectFontBtn")
self.selectFontBtn.setGeometry(QRect(520, 490, 81, 91))
self.selectFontBtn.setGeometry(QRect(520, 520, 81, 91))
self.label_4 = QLabel(OneKeyTranslateDialog)
self.label_4.setObjectName(u"label_4")
self.label_4.setGeometry(QRect(30, 520, 71, 31))
self.label_4.setGeometry(QRect(30, 550, 71, 31))
self.label_4.setWordWrap(True)
self.selectFontText = QTextEdit(OneKeyTranslateDialog)
self.selectFontText.setObjectName(u"selectFontText")
self.selectFontText.setGeometry(QRect(110, 490, 411, 91))
self.selectFontText.setGeometry(QRect(110, 520, 411, 91))
self.unpackCheckBox = QCheckBox(OneKeyTranslateDialog)
self.unpackCheckBox.setObjectName(u"unpackCheckBox")
self.unpackCheckBox.setGeometry(QRect(620, 30, 411, 20))
Expand All @@ -95,41 +95,49 @@ def setupUi(self, OneKeyTranslateDialog):
self.translateCheckBox.setChecked(True)
self.filterCheckBox = QCheckBox(OneKeyTranslateDialog)
self.filterCheckBox.setObjectName(u"filterCheckBox")
self.filterCheckBox.setGeometry(QRect(30, 400, 261, 20))
self.filterCheckBox.setGeometry(QRect(30, 430, 261, 20))
self.filterCheckBox.setChecked(True)
self.filterLengthLineEdit = QLineEdit(OneKeyTranslateDialog)
self.filterLengthLineEdit.setObjectName(u"filterLengthLineEdit")
self.filterLengthLineEdit.setGeometry(QRect(500, 400, 101, 20))
self.filterLengthLineEdit.setGeometry(QRect(500, 430, 101, 20))
self.filterLengthLineEdit.setText(u"8")
self.filterLengthLineEdit.setAlignment(Qt.AlignCenter)
self.label_14 = QLabel(OneKeyTranslateDialog)
self.label_14.setObjectName(u"label_14")
self.label_14.setGeometry(QRect(290, 402, 201, 16))
self.label_14.setGeometry(QRect(290, 432, 201, 16))
self.label_14.setAlignment(Qt.AlignCenter)
self.startButton = QPushButton(OneKeyTranslateDialog)
self.startButton.setObjectName(u"startButton")
self.startButton.setGeometry(QRect(620, 420, 401, 161))
self.startButton.setGeometry(QRect(620, 420, 401, 191))
self.officialExtractionCheckBox = QCheckBox(OneKeyTranslateDialog)
self.officialExtractionCheckBox.setObjectName(u"officialExtractionCheckBox")
self.officialExtractionCheckBox.setGeometry(QRect(620, 150, 411, 20))
self.officialExtractionCheckBox.setChecked(True)
self.filterCheckBox_2 = QCheckBox(OneKeyTranslateDialog)
self.filterCheckBox_2.setObjectName(u"filterCheckBox_2")
self.filterCheckBox_2.setGeometry(QRect(30, 460, 261, 20))
self.filterCheckBox_2.setGeometry(QRect(30, 490, 261, 20))
self.filterCheckBox_2.setChecked(True)
self.filterLengthLineEdit_2 = QLineEdit(OneKeyTranslateDialog)
self.filterLengthLineEdit_2.setObjectName(u"filterLengthLineEdit_2")
self.filterLengthLineEdit_2.setGeometry(QRect(500, 458, 101, 20))
self.filterLengthLineEdit_2.setGeometry(QRect(500, 488, 101, 20))
self.filterLengthLineEdit_2.setText(u"3")
self.filterLengthLineEdit_2.setAlignment(Qt.AlignCenter)
self.label_15 = QLabel(OneKeyTranslateDialog)
self.label_15.setObjectName(u"label_15")
self.label_15.setGeometry(QRect(290, 460, 201, 16))
self.label_15.setGeometry(QRect(290, 490, 201, 16))
self.label_15.setAlignment(Qt.AlignCenter)
self.underlineCheckBox = QCheckBox(OneKeyTranslateDialog)
self.underlineCheckBox.setObjectName(u"underlineCheckBox")
self.underlineCheckBox.setGeometry(QRect(30, 430, 581, 20))
self.underlineCheckBox.setGeometry(QRect(30, 460, 581, 20))
self.underlineCheckBox.setChecked(True)
self.maxThreadsLineEdit = QLineEdit(OneKeyTranslateDialog)
self.maxThreadsLineEdit.setObjectName(u"maxThreadsLineEdit")
self.maxThreadsLineEdit.setGeometry(QRect(210, 370, 391, 20))
self.maxThreadsLineEdit.setPlaceholderText(u"")
self.label_2 = QLabel(OneKeyTranslateDialog)
self.label_2.setObjectName(u"label_2")
self.label_2.setGeometry(QRect(30, 372, 161, 16))
self.label_2.setText(u"MAX_UNPACK_THREADS : ")

self.retranslateUi(OneKeyTranslateDialog)

Expand Down
Loading

0 comments on commit 54c5359

Please sign in to comment.