Skip to content

Commit

Permalink
Fast-fail when user forgets to extract from zip
Browse files Browse the repository at this point in the history
  • Loading branch information
th3w1zard1 committed Apr 9, 2024
1 parent 29f778b commit 71c85a1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
8 changes: 8 additions & 0 deletions Tools/BatchPatcher/src/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pathlib
import platform
import sys
import tempfile
import tkinter as tk
import traceback

Expand Down Expand Up @@ -1388,8 +1389,15 @@ def start_patching(self):
self.install_button.config(state=tk.DISABLED)
return None

def is_running_from_temp():
app_path = Path(sys.executable)
temp_dir = tempfile.gettempdir()
return str(app_path).startswith(temp_dir)

if __name__ == "__main__":
if is_running_from_temp():
messagebox.showerror("Error", "This application cannot be run from within a zip or temporary directory. Please extract it to a permanent location before running.")
sys.exit("Exiting: Application was run from a temporary or zip directory.")
try:
root = tk.Tk()
APP = KOTORPatchingToolUI(root)
Expand Down
18 changes: 12 additions & 6 deletions Tools/HoloPatcher/src/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1473,19 +1473,25 @@ def onAppCrash(
sys.excepthook = onAppCrash


def main():
app = App()
app.root.mainloop()
atexit.register(lambda: my_cleanup_function(app))


def my_cleanup_function(app: App):
"""Prevents the patcher from running in the background after sys.exit is called."""
#print("Fully shutting down Holo Patcher...")
#kill_self_pid()
#app.root.destroy()


def main():
app = App()
app.root.mainloop()
atexit.register(lambda: my_cleanup_function(app))

def is_running_from_temp():
app_path = Path(sys.executable)
temp_dir = tempfile.gettempdir()
return str(app_path).startswith(temp_dir)

if __name__ == "__main__":
if is_running_from_temp():
messagebox.showerror("Error", "This application cannot be run from within a zip or temporary directory. Please extract it to a permanent location before running.")
sys.exit("Exiting: Application was run from a temporary or zip directory.")
main()
14 changes: 13 additions & 1 deletion Tools/HolocronToolset/src/toolset/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from typing import TYPE_CHECKING

from PyQt5.QtCore import QThread
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWidgets import QApplication, QMessageBox

if TYPE_CHECKING:
from types import TracebackType
Expand Down Expand Up @@ -76,6 +76,10 @@ def update_sys_path(path: pathlib.Path):
update_sys_path(toolset_path.parent)
os.chdir(toolset_path)

def is_running_from_temp():
app_path = Path(sys.executable)
temp_dir = tempfile.gettempdir()
return str(app_path).startswith(temp_dir)

if __name__ == "__main__":
if os.name == "nt":
Expand Down Expand Up @@ -107,6 +111,14 @@ def update_sys_path(path: pathlib.Path):
app.thread().setPriority(QThread.HighestPriority)

sys.excepthook = onAppCrash
if is_running_from_temp():
# Show error message using PyQt5's QMessageBox
msgBox = QMessageBox()
msgBox.setIcon(QMessageBox.Critical)
msgBox.setWindowTitle("Error")
msgBox.setText("This application cannot be run from within a zip or temporary directory. Please extract it to a permanent location before running.")
msgBox.exec_()
sys.exit("Exiting: Application was run from a temporary or zip directory.")

from toolset.gui.windows.main import ToolWindow

Expand Down

0 comments on commit 71c85a1

Please sign in to comment.