Skip to content

Commit

Permalink
Small fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
KostromDan committed Apr 17, 2024
1 parent 533be99 commit 6df4dfb
Show file tree
Hide file tree
Showing 19 changed files with 119 additions and 30 deletions.
2 changes: 1 addition & 1 deletion MDG.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
from MDGUtil.MDGLogger import MDGLogger

if __name__ == '__main__':
faulthandler.enable()
multiprocessing.freeze_support()

if not PathUtils.check_pyinstaller_env():
faulthandler.enable()
generate_ui()
"""generate_ui() can change ui so,we need to import MDGMainWindow only after that line"""
from MDGWindow.MDGMainWindow import MDGMainWindow
Expand Down
13 changes: 8 additions & 5 deletions MDGLogic/Decompilation/DecompilationMain.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def decomp_callback(self, thread_number: int, exception: Exception = None) -> No
thread.start()
thread.wait()

with self.lock:
with (self.lock):
thread_data = self.threads_data[thread_number]
mod_path = thread_data['mod_path']
mod_name = os.path.basename(mod_path)
Expand All @@ -75,10 +75,13 @@ def decomp_callback(self, thread_number: int, exception: Exception = None) -> No
logging.warning(f'Something happened while decompiling {mod_name}. stdout & stderr:', extra={
'debug': (not ((show_warn and 'WARN: ' in thread_data['stdall'].value) or
(show_err and 'ERROR: ' in thread_data['stdall'].value)))})
logging_func_warn = lambda e: logging.warning(e, extra={
'debug': not show_warn})
logging_func_err = lambda e: logging.error(e, extra={
'debug': not show_err})

def logging_func_warn(e):
logging.warning(e, extra={'debug': not show_warn})

def logging_func_err(e):
logging.error(e, extra={'debug': not show_err})

logging_func = logging_func_warn
for msg in thread_data['all_msgs']:
if 'ERROR: ' in msg:
Expand Down
1 change: 0 additions & 1 deletion MDGLogic/InitialisationThread.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os
import shutil
import subprocess
import time

from PySide6.QtCore import QThread

Expand Down
6 changes: 6 additions & 0 deletions MDGUi/forms/MDGMainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1844,6 +1844,7 @@
</property>
<addaction name="action_save"/>
<addaction name="action_reset"/>
<addaction name="action_open_log"/>
<addaction name="action_adjust_height"/>
</widget>
<addaction name="menuFile"/>
Expand All @@ -1863,6 +1864,11 @@
<string>adjust height</string>
</property>
</action>
<action name="action_open_log">
<property name="text">
<string>open log</string>
</property>
</action>
</widget>
<resources>
<include location="../resources.qrc"/>
Expand Down
21 changes: 16 additions & 5 deletions MDGUi/forms/MDGProgressWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,22 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="stop_button">
<property name="text">
<string>stop</string>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="open_log_button">
<property name="text">
<string>open full log</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="stop_button">
<property name="text">
<string>stop</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
Expand Down
10 changes: 9 additions & 1 deletion MDGUi/forms/MDGResultWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ li.checked::marker { content: &quot;\2612&quot;; }
&lt;li style=&quot; margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Open result folders you are interested in.&lt;/li&gt;
&lt;li style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Open in IntelliJ IDEA as project merged_mdk.&lt;/li&gt;
&lt;li style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Exit program using exit button.&lt;/li&gt;
&lt;li style=&quot; margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Return to previous window using close button.&lt;/li&gt;&lt;/ul&gt;
&lt;li style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Return to previous window using close button.&lt;/li&gt;
&lt;li style=&quot; margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Open complete log with open log button.&lt;/li&gt;&lt;/ul&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Errors:&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
Expand Down Expand Up @@ -120,6 +121,13 @@ li.checked::marker { content: &quot;\2612&quot;; }
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="open_log_button">
<property name="text">
<string>open log</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="close_button">
<property name="text">
Expand Down
4 changes: 4 additions & 0 deletions MDGUi/generated/Ui_MDGMainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def setupUi(self, MDGMainWindow):
self.action_save.setObjectName(u"action_save")
self.action_adjust_height = QAction(MDGMainWindow)
self.action_adjust_height.setObjectName(u"action_adjust_height")
self.action_open_log = QAction(MDGMainWindow)
self.action_open_log.setObjectName(u"action_open_log")
self.centralwidget = QWidget(MDGMainWindow)
self.centralwidget.setObjectName(u"centralwidget")
self.centralwidget.setEnabled(True)
Expand Down Expand Up @@ -905,6 +907,7 @@ def setupUi(self, MDGMainWindow):
self.menubar.addAction(self.menuFile.menuAction())
self.menuFile.addAction(self.action_save)
self.menuFile.addAction(self.action_reset)
self.menuFile.addAction(self.action_open_log)
self.menuFile.addAction(self.action_adjust_height)

self.retranslateUi(MDGMainWindow)
Expand All @@ -917,6 +920,7 @@ def retranslateUi(self, MDGMainWindow):
self.action_reset.setText(QCoreApplication.translate("MDGMainWindow", u"reset", None))
self.action_save.setText(QCoreApplication.translate("MDGMainWindow", u"save", None))
self.action_adjust_height.setText(QCoreApplication.translate("MDGMainWindow", u"adjust height", None))
self.action_open_log.setText(QCoreApplication.translate("MDGMainWindow", u"open log", None))
self.mods_path_label.setText(QCoreApplication.translate("MDGMainWindow", u"Mods folder path:", None))
self.select_mods_button.setText(QCoreApplication.translate("MDGMainWindow", u"select", None))
self.help_mods_button.setText(QCoreApplication.translate("MDGMainWindow", u"?", None))
Expand Down
13 changes: 12 additions & 1 deletion MDGUi/generated/Ui_MDGProgressWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,20 @@ def setupUi(self, MDGProgressWindow):

self.verticalLayout.addWidget(self.logger_text_edit)

self.horizontalLayout_2 = QHBoxLayout()
self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
self.open_log_button = QPushButton(self.centralwidget)
self.open_log_button.setObjectName(u"open_log_button")

self.horizontalLayout_2.addWidget(self.open_log_button)

self.stop_button = QPushButton(self.centralwidget)
self.stop_button.setObjectName(u"stop_button")

self.verticalLayout.addWidget(self.stop_button)
self.horizontalLayout_2.addWidget(self.stop_button)


self.verticalLayout.addLayout(self.horizontalLayout_2)

MDGProgressWindow.setCentralWidget(self.centralwidget)
self.menubar = QMenuBar(MDGProgressWindow)
Expand Down Expand Up @@ -178,6 +188,7 @@ def retranslateUi(self, MDGProgressWindow):
#if QT_CONFIG(accessibility)
self.logger_text_edit.setAccessibleName("")
#endif // QT_CONFIG(accessibility)
self.open_log_button.setText(QCoreApplication.translate("MDGProgressWindow", u"open full log", None))
self.stop_button.setText(QCoreApplication.translate("MDGProgressWindow", u"stop", None))
# retranslateUi

13 changes: 10 additions & 3 deletions MDGUi/generated/Ui_MDGResultWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ def setupUi(self, MDGResultWindow):

self.horizontalLayout_2 = QHBoxLayout()
self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
self.open_log_button = QPushButton(self.centralwidget)
self.open_log_button.setObjectName(u"open_log_button")

self.horizontalLayout_2.addWidget(self.open_log_button)

self.close_button = QPushButton(self.centralwidget)
self.close_button.setObjectName(u"close_button")

Expand Down Expand Up @@ -130,16 +135,18 @@ def retranslateUi(self, MDGResultWindow):
"<li style=\" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Open result folders you are interested in.</li>\n"
"<li style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Open in IntelliJ IDEA as project merged_mdk.</li>\n"
"<li style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Exit program using exit button.</li>\n"
"<li style=\" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Return to previous window using close button.</li></ul>\n"
"<li style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Return to previous window using close button.</li>\n"
"<li style=\" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Open complete log with open log button.</li></ul>\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Errors:</p>\n"
"<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><br /></p></body></ht"
"ml>", None))
""
"<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><br /></p></body></html>", None))
self.label.setText(QCoreApplication.translate("MDGResultWindow", u"Open folders:", None))
self.deobfuscated_mods_button.setText(QCoreApplication.translate("MDGResultWindow", u"deobfuscated_mods", None))
self.decompiled_mods_button.setText(QCoreApplication.translate("MDGResultWindow", u"decompiled_mods", None))
self.merged_mdk_button.setText(QCoreApplication.translate("MDGResultWindow", u"merged_mdk", None))
self.label_2.setText(QCoreApplication.translate("MDGResultWindow", u"Open in IntelliJ IDEA as project:", None))
self.intellij_idea_button.setText(QCoreApplication.translate("MDGResultWindow", u"merged_mdk", None))
self.open_log_button.setText(QCoreApplication.translate("MDGResultWindow", u"open log", None))
self.close_button.setText(QCoreApplication.translate("MDGResultWindow", u"close", None))
self.exit_button.setText(QCoreApplication.translate("MDGResultWindow", u"exit", None))
# retranslateUi
Expand Down
2 changes: 1 addition & 1 deletion MDGUi/generated/resources_rc.py
Original file line number Diff line number Diff line change
Expand Up @@ -56967,7 +56967,7 @@
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x02\x00\x00\x00\x02\
\x00\x00\x00\x00\x00\x00\x00\x00\
\x00\x00\x00\x12\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\
\x00\x00\x01\x8e\xe7\xae\xf71\
\x00\x00\x01\x8e\xeb\x0c\xedq\
\x00\x00\x00(\x00\x00\x00\x00\x00\x01\x00\x0b\xda5\
\x00\x00\x01\x8e\xaf\xe9\x8cJ\
"
Expand Down
1 change: 0 additions & 1 deletion MDGUtil/BON2Utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import time
from collections import OrderedDict

import jpype
Expand Down
12 changes: 8 additions & 4 deletions MDGUtil/MDGLogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,14 @@ def __init__(self) -> None:
return

if not PathUtils.check_pyinstaller_env():
FileUtils.remove_folder('logs')
FileUtils.remove_folder(PathUtils.LOGS_FOLDER)

self.logger_signal = LoggerSignal()

FileUtils.create_folder('logs')
FileUtils.create_folder(PathUtils.LOGS_FOLDER)

logging.basicConfig(level=logging.INFO, filename=os.path.join('logs', self.get_log_name()),
self.log_name = self.get_log_name()
logging.basicConfig(level=logging.INFO, filename=self.get_path_to_log(),
filemode='w',
format=LOGGER_FORMAT)

Expand All @@ -87,7 +88,10 @@ def __init__(self) -> None:
def get_log_name(self) -> str:
current_date = datetime.now().strftime('%Y-%m-%d')
current_date_count = 0
for file in os.listdir('logs'):
for file in os.listdir(PathUtils.LOGS_FOLDER):
if file.startswith(current_date):
current_date_count += 1
return f'{current_date}-{current_date_count}.log'

def get_path_to_log(self) -> str:
return os.path.join(PathUtils.LOGS_FOLDER, self.log_name)
33 changes: 31 additions & 2 deletions MDGUtil/PathUtils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import os
import platform
import re
import subprocess
import sys

from MDGUtil.MDGLogger import MDGLogger

MINECRAFT_FORGE_DOWNLOADS_PAGE = 'https://files.minecraftforge.net/net/minecraftforge/forge/'
ADOPTIUM_DOWNLOADS_PAGE = ('https://adoptium.net/temurin/releases/'
f"?version=18&package=jdk&arch=x{platform.architecture()[0].removesuffix('bit')}")

java_homes = None


def get_gradle_caches_path():
gradle_user_home = os.environ.get('GRADLE_USER_HOME')
Expand Down Expand Up @@ -50,6 +55,8 @@ def get_gradle_caches_path():
MERGED_MDK_RESOURCES_PATH = os.path.join(MERGED_MDK_SRC_PATH, 'resources')
MERGED_MDK_JAVA_PATH = os.path.join(MERGED_MDK_SRC_PATH, 'java')

LOGS_FOLDER = os.path.join('logs')

DEFAULT_DECOMPILER_CMD = rf'{{java}} -jar {DECOMPILER_JAR_PATH} -dgs=1 -din=1 -log=WARN {{path_to_jar}} {{out_path}}'
DEFAULT_BON2_CMD = (
r'{java} -jar {bon2_path} --inputJar {path_to_jar} --outputJar {out_path} --mcVer {mc_ver} '
Expand All @@ -61,6 +68,9 @@ def check_pyinstaller_env() -> bool:


def get_all_java_homes() -> list[str]:
global java_homes
if java_homes is not None:
return java_homes
java_homes = list()

"""JAVA_HOME"""
Expand All @@ -71,13 +81,13 @@ def get_all_java_homes() -> list[str]:
"""java cmd"""
try:
output = subprocess.check_output(['java', '-XshowSettings:properties', '-version'], stderr=subprocess.STDOUT)
output_lines = output.decode('utf-8').split('\n')
output_lines = output.decode('utf-8', errors='ignore').split('\n')
for line in output_lines:
if line.strip().startswith('java.home'):
java_path = line.split('=', 1)[1].strip().rstrip('/\\')
if java_path not in java_homes:
java_homes.append(java_path)
except subprocess.CalledProcessError:
except Exception:
pass

"""PATH"""
Expand All @@ -91,6 +101,21 @@ def get_all_java_homes() -> list[str]:
java_homes.append(java_home.rstrip('/\\'))
except KeyError:
pass

"""ftype"""
try:
output = subprocess.check_output(['ftype', ], shell=True, stderr=subprocess.STDOUT)
output_lines = output.decode('utf-8', errors='ignore').split('\n')
for line in output_lines:
line = line.strip()
line = re.sub(r'[/\\]+', r'\\', line)
line = line.replace('bin\\javaw.exe', 'bin\\java.exe')
if 'bin\\java.exe' in line:
java_path = line.split('=')[1].split('bin\\java.exe')[0].strip('"\\')
if java_path not in java_homes:
java_homes.append(java_path)
except Exception:
pass
return java_homes


Expand Down Expand Up @@ -137,3 +162,7 @@ def format_bon2_command(cmd: str,
out_path=f'"{os.path.abspath(out_path)}"',
mc_ver=version,
mappings_ver=mappings)


def open_log():
os.startfile(MDGLogger().get_path_to_log())
8 changes: 7 additions & 1 deletion MDGWindow/MDGHelpWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import webbrowser

from MDGUi.generated.Ui_MDGHelpWindow import Ui_MDGHelpWindow
from PySide6.QtWidgets import QMainWindow, QTextBrowser, QWidget
from PySide6.QtWidgets import QMainWindow, QTextBrowser, QWidget, QApplication

from MDGUtil import PathUtils
from MDGWindow.MDGMdkWindow import MDGMdkWindow
Expand All @@ -18,6 +18,12 @@ def __init__(self) -> None:
self.ui.mdk_button.clicked.connect(self.open_minecraft_forge)
self.ui.mdk_help_download_button.clicked.connect(self.open_mdk_help)
self.ui.close_button.clicked.connect(self.hide)
self.fit_window_to_screen()

def fit_window_to_screen(self):
if self.geometry().bottom() > QApplication.primaryScreen().geometry().bottom():
self.resize(self.width(),
self.height() - 100 - self.geometry().bottom() + QApplication.primaryScreen().geometry().bottom())

def start_help_window(self, help_about: QWidget) -> None:
self.show()
Expand Down
2 changes: 1 addition & 1 deletion MDGWindow/MDGMainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def __init__(self):
self.ui.action_reset.triggered.connect(self.action_reset)
self.ui.action_save.triggered.connect(self.save_ui_to_config)
self.ui.action_adjust_height.triggered.connect(self.adjust_min_height)
self.ui.action_open_log.triggered.connect(PathUtils.open_log)

self.ui.bon2_version_combo_box.currentTextChanged.connect(self.bon2_version_changed)
self.ui.bon2_version_combo_box.addItems(self.bon2_mappings.keys())
Expand Down Expand Up @@ -299,7 +300,6 @@ def help_button_clicked(self) -> None:
self.help_window.start_help_window(self.help_widget_pairs[self.sender()])

def start_button(self) -> None:
self.adjust_min_height()
self.save_ui_to_config()
mods_folder_path = self.ui.mods_path_line_edit.text()
if not os.path.exists(mods_folder_path):
Expand Down
3 changes: 2 additions & 1 deletion MDGWindow/MDGProgressWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from MDGLogic.InitialisationThread import InitialisationThread
from MDGLogic.MdkInitialisationThread import MdkInitialisationThread
from MDGLogic.MergingThread import MergingThread
from MDGUtil import FileUtils
from MDGUtil import FileUtils, PathUtils
from MDGUtil.MDGLogger import MDGLogger
from MDGWindow.MDGResultWindow import MDGResultWindow

Expand All @@ -41,6 +41,7 @@ def __init__(self, main_window) -> None:
self.current_progress_bar = self.ui.init_progress_bar

self.ui.stop_button.clicked.connect(self.stop_button)
self.ui.open_log_button.clicked.connect(PathUtils.open_log)

MDGLogger().logger_signal.append_logger_signal.connect(self.append_logger)

Expand Down
Loading

0 comments on commit 6df4dfb

Please sign in to comment.