Skip to content

Commit

Permalink
<feature> support error repair by renpy lint
Browse files Browse the repository at this point in the history
update version to v2.5.7
  • Loading branch information
anonymousException committed Sep 12, 2024
1 parent a706bcc commit 46874ef
Show file tree
Hide file tree
Showing 41 changed files with 2,643 additions and 1,458 deletions.
8 changes: 8 additions & 0 deletions src/call_game_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,11 @@ def get_py_path(game_path):
def copy_files_under_directory_to_directory(src_dir, desc_dir):
shutil.copytree(src_dir, desc_dir, dirs_exist_ok=True)


def get_game_path_from_game_dir(game_dir):
for item in os.listdir(game_dir):
full_path = os.path.join(game_dir, item)
if os.path.isfile(full_path) and item.lower().endswith('.exe'):
if os.path.isfile(full_path[:-len('.exe')] + '.py'):
return full_path
return None
65 changes: 65 additions & 0 deletions src/error_repair.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# -*- coding: utf-8 -*-

################################################################################
## Form generated from reading UI file 'error_repair.ui'
##
## Created by: Qt User Interface Compiler version 6.6.1
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################

from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
QMetaObject, QObject, QPoint, QRect,
QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
QFont, QFontDatabase, QGradient, QIcon,
QImage, QKeySequence, QLinearGradient, QPainter,
QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QApplication, QDialog, QLabel, QLineEdit,
QPushButton, QSizePolicy, QTextEdit, QWidget)

class Ui_ErrorRepairDialog(object):
def setupUi(self, ErrorRepairDialog):
if not ErrorRepairDialog.objectName():
ErrorRepairDialog.setObjectName(u"ErrorRepairDialog")
ErrorRepairDialog.resize(666, 250)
self.selectFileBtn = QPushButton(ErrorRepairDialog)
self.selectFileBtn.setObjectName(u"selectFileBtn")
self.selectFileBtn.setGeometry(QRect(530, 30, 81, 91))
self.selectFileBtn.setText(u"...")
self.label = QLabel(ErrorRepairDialog)
self.label.setObjectName(u"label")
self.label.setGeometry(QRect(40, 45, 71, 61))
self.label.setWordWrap(True)
self.selectFileText = QTextEdit(ErrorRepairDialog)
self.selectFileText.setObjectName(u"selectFileText")
self.selectFileText.setGeometry(QRect(120, 30, 411, 91))
self.selectFileText.setPlaceholderText(u"Example:F:/DemoGame.exe")
self.label_2 = QLabel(ErrorRepairDialog)
self.label_2.setObjectName(u"label_2")
self.label_2.setGeometry(QRect(40, 150, 211, 61))
self.label_2.setWordWrap(True)
self.maxRecursionLineEdit = QLineEdit(ErrorRepairDialog)
self.maxRecursionLineEdit.setObjectName(u"maxRecursionLineEdit")
self.maxRecursionLineEdit.setGeometry(QRect(260, 170, 351, 20))
self.maxRecursionLineEdit.setAlignment(Qt.AlignCenter)
self.repairBtn = QPushButton(ErrorRepairDialog)
self.repairBtn.setObjectName(u"repairBtn")
self.repairBtn.setGeometry(QRect(120, 220, 491, 24))

self.retranslateUi(ErrorRepairDialog)

QMetaObject.connectSlotsByName(ErrorRepairDialog)
# setupUi

def retranslateUi(self, ErrorRepairDialog):
ErrorRepairDialog.setWindowTitle(QCoreApplication.translate("ErrorRepairDialog", u"Error Repair", None))
self.label.setText(QCoreApplication.translate("ErrorRepairDialog", u"file", None))
#if QT_CONFIG(tooltip)
self.selectFileText.setToolTip("")
#endif // QT_CONFIG(tooltip)
self.label_2.setText(QCoreApplication.translate("ErrorRepairDialog", u"max repair count", None))
self.maxRecursionLineEdit.setText(QCoreApplication.translate("ErrorRepairDialog", u"4", None))
self.repairBtn.setText(QCoreApplication.translate("ErrorRepairDialog", u"repair errors", None))
# retranslateUi

109 changes: 109 additions & 0 deletions src/error_repair.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ErrorRepairDialog</class>
<widget class="QDialog" name="ErrorRepairDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>666</width>
<height>250</height>
</rect>
</property>
<property name="windowTitle">
<string>Error Repair</string>
</property>
<widget class="QPushButton" name="selectFileBtn">
<property name="geometry">
<rect>
<x>530</x>
<y>30</y>
<width>81</width>
<height>91</height>
</rect>
</property>
<property name="text">
<string notr="true">...</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>40</x>
<y>45</y>
<width>71</width>
<height>61</height>
</rect>
</property>
<property name="text">
<string>file</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
<widget class="QTextEdit" name="selectFileText">
<property name="geometry">
<rect>
<x>120</x>
<y>30</y>
<width>411</width>
<height>91</height>
</rect>
</property>
<property name="toolTip">
<string/>
</property>
<property name="placeholderText">
<string notr="true">Example:F:/DemoGame.exe</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>40</x>
<y>150</y>
<width>211</width>
<height>61</height>
</rect>
</property>
<property name="text">
<string>max repair count</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
<widget class="QLineEdit" name="maxRecursionLineEdit">
<property name="geometry">
<rect>
<x>260</x>
<y>170</y>
<width>351</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string notr="true">4</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QPushButton" name="repairBtn">
<property name="geometry">
<rect>
<x>120</x>
<y>220</y>
<width>491</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>repair errors</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>
87 changes: 87 additions & 0 deletions src/error_repair_form.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import _thread
import os
import threading
import time
import traceback

from PySide6.QtCore import QCoreApplication, QThread, Signal
from PySide6.QtGui import QIntValidator
from PySide6.QtWidgets import QDialog, QFileDialog

from error_repair import Ui_ErrorRepairDialog
from my_log import log_print
from renpy_lint import fix_translation_by_lint_recursion


class repairThread(threading.Thread):
def __init__(self, path, max_recursion_depth):
threading.Thread.__init__(self)
self.path = path
self.max_recursion_depth = max_recursion_depth

def run(self):
try:
log_print('start repairing ...')
fix_translation_by_lint_recursion(self.path, self.max_recursion_depth)
except Exception as e:
msg = traceback.format_exc()
log_print(msg)


class MyErrorRepairForm(QDialog, Ui_ErrorRepairDialog):
def __init__(self, parent=None):
super(MyErrorRepairForm, self).__init__(parent)
self.setupUi(self)
self.setFixedHeight(self.height())
self.setFixedWidth(self.width())
self.selectFileBtn.clicked.connect(self.select_file)
self.repairBtn.clicked.connect(self.repair)
self.maxRecursionLineEdit.setValidator(QIntValidator(1, 65535, self))
self.repair_thread = None
_thread.start_new_thread(self.update, ())

def repair(self):
path = self.selectFileText.toPlainText()
path = path.replace('file:///', '')
if os.path.isfile(path):
if path.endswith('.exe'):
t = repairThread(path, int(self.maxRecursionLineEdit.text()))
self.repair_thread = t
t.start()
self.setDisabled(True)
self.repairBtn.setText(QCoreApplication.translate('ErrorRepairDialog', 'is repairing...', None))

def select_file(self):
file, filetype = QFileDialog.getOpenFileName(self, 'select the game file', '', "Game Files (*.exe)")
self.selectFileText.setText(file)

def update(self):
thread = self.UpdateThread()
thread.update_date.connect(self.update_progress)
while True:
thread.start()
time.sleep(0.5)

def update_progress(self):
try:
if self.repair_thread is not None:
if not self.repair_thread.is_alive():
self.repairBtn.setText(QCoreApplication.translate('ErrorRepairDialog', 'repair errors', None))
self.setEnabled(True)
self.repair_thread = None
log_print('error repair complete!')
except Exception:
msg = traceback.format_exc()
log_print(msg)

class UpdateThread(QThread):
update_date = Signal()

def __init__(self):
super().__init__()

def __del__(self):
self.wait()

def run(self):
self.update_date.emit()
21 changes: 15 additions & 6 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from one_key_translate_form import MyOneKeyTranslateForm
from pack_game_form import MyPackGameForm
from format_form import MyFormationForm
from error_repair_form import MyErrorRepairForm
from renpy_translate import translateThread, translate_threads, engineList, engineDic, language_header, \
get_translated_dic, web_brower_export_name, get_rpy_info, rpy_info_dic, get_translated, web_brower_translate
from proxy import Ui_ProxyDialog
Expand All @@ -55,7 +56,8 @@
sourceDic = dict()
translator = QTranslator()

VERSION = '2.5.6'
VERSION = '2.5.7'


class MyProxyForm(QDialog, Ui_ProxyDialog):
def __init__(self, parent=None):
Expand Down Expand Up @@ -171,6 +173,7 @@ def __init__(self, parent=None):
self.myPackGameForm = None
self.myDefaultLanuageForm = None
self.myFormationForm = None
self.myErrorRepairForm = None
self.actioncopyright.triggered.connect(lambda: self.show_copyright_form())
self.proxySettings.triggered.connect(lambda: self.show_proxy_settings())
self.engineSettings.triggered.connect(lambda: self.show_engine_settings())
Expand All @@ -179,6 +182,7 @@ def __init__(self, parent=None):
self.actionextract_translation.triggered.connect(lambda: self.show_extraction_form())
self.actionruntime_extraction.triggered.connect(lambda: self.show_extraction_runtime_form())
self.actionreplace_font.triggered.connect(lambda: self.replace_font())
self.actionerror_repair.triggered.connect(lambda: self.show_error_repair_form())
self.actionunpack_game.triggered.connect(lambda: self.unpack_game())
self.actionadd_change_langauge_entrance.triggered.connect(lambda: self.show_add_entrance_form())
self.actionone_key_translate.triggered.connect(lambda: self.show_one_key_translate_form())
Expand Down Expand Up @@ -225,21 +229,26 @@ def __init__(self, parent=None):

_thread.start_new_thread(self.update_log, ())

def show_error_repair_form(self):
if self.myErrorRepairForm is None:
self.myErrorRepairForm = MyErrorRepairForm(parent=self)
self.myErrorRepairForm.parent = self
self.myErrorRepairForm.exec()

def show_formation_form(self):
if self.myFormationForm is None:
self.myFormationForm = MyFormationForm(parent=self)
self.myFormationForm.parent = self
self.myFormationForm.exec()


def show_default_langauge_form(self):
if self.myDefaultLanuageForm is None:
self.myDefaultLanuageForm = MyDefaultLanguageForm(parent=self)
self.myDefaultLanuageForm.exec()

def on_combobox_changed(self):
if os.path.isfile('engine.txt'):
json_file = open('engine.txt', 'r',encoding='utf-8')
json_file = open('engine.txt', 'r', encoding='utf-8')
ori = json.load(json_file)
json_file.close()
current_engine = ori['engine']
Expand All @@ -250,7 +259,6 @@ def on_combobox_changed(self):
json_file = open('engine.txt', 'w', encoding='utf-8')
json.dump(ori, json_file)


def on_version_label_clicked(self):
try:
latest_release = get_latest_release('anonymousException', 'renpy-translator')
Expand Down Expand Up @@ -589,7 +597,7 @@ def init_combobox(self):

@staticmethod
def locate_log():
open_directory_and_select_file(os.getcwd()+'/'+log_path)
open_directory_and_select_file(os.getcwd() + '/' + log_path)

@staticmethod
def clear_log():
Expand Down Expand Up @@ -683,7 +691,8 @@ def update_progress(self, data):
self.myFormationForm.formatBtn.setDisabled(True)
else:
if self.myFormationForm is not None:
self.myFormationForm.formatBtn.setText(QCoreApplication.translate('FormatDialog', 'format rpy files', None))
self.myFormationForm.formatBtn.setText(
QCoreApplication.translate('FormatDialog', 'format rpy files', None))
self.myFormationForm.formatBtn.setEnabled(True)

class UpdateThread(QThread):
Expand Down
Loading

0 comments on commit 46874ef

Please sign in to comment.