From b05c068e40adde4aa3712c54f44137c65f0a56b6 Mon Sep 17 00:00:00 2001 From: D-Pyro Date: Wed, 10 Jan 2024 19:34:34 -0500 Subject: [PATCH] Add config.ini to remember output folder --- host/config.ini | 2 + host/nxdt_host.py | 9 +++- ...bat => windows_make_standalone_Nuitka.bat} | 48 +++++++++---------- host/windows_make_standalone_PyInstaller.bat | 39 +++++++++++++++ 4 files changed, 73 insertions(+), 25 deletions(-) create mode 100644 host/config.ini rename host/{windows_make_standalone.bat => windows_make_standalone_Nuitka.bat} (95%) create mode 100644 host/windows_make_standalone_PyInstaller.bat diff --git a/host/config.ini b/host/config.ini new file mode 100644 index 0000000..2beb897 --- /dev/null +++ b/host/config.ini @@ -0,0 +1,2 @@ +[Directories] +Output = /path/to/directory diff --git a/host/nxdt_host.py b/host/nxdt_host.py index 860a67f..954134e 100644 --- a/host/nxdt_host.py +++ b/host/nxdt_host.py @@ -49,6 +49,8 @@ import usb.util import warnings import base64 +import configparser + import tkinter as tk import tkinter.ttk as ttk from tkinter import filedialog, messagebox, font, scrolledtext @@ -136,9 +138,14 @@ COPYRIGHT_TEXT = f'Copyright (c) {COPYRIGHT_YEAR}, {USB_DEV_MANUFACTURER}' SERVER_START_MSG = f'Please connect a Nintendo Switch console running {USB_DEV_PRODUCT}.' SERVER_STOP_MSG = f'Exit {USB_DEV_PRODUCT} on your console or disconnect it at any time to stop the server.' +# Load the configuration from the INI file +config = configparser.ConfigParser() +config.read('config.ini') + # Default directory paths. INITIAL_DIR = os.path.dirname(os.path.abspath(os.path.expanduser(os.path.expandvars(sys.argv[0])))) -DEFAULT_DIR = os.path.join(INITIAL_DIR, USB_DEV_PRODUCT) +# Get the default directory from the INI file or use a fallback if not present +DEFAULT_DIR = config.get('Directories', 'Output', fallback=os.path.join(INITIAL_DIR, USB_DEV_PRODUCT)) # Application icon (PNG). # Embedded to load it as the icon for all windows using PhotoImage (which doesn't support ICO files) + wm_iconphoto. diff --git a/host/windows_make_standalone.bat b/host/windows_make_standalone_Nuitka.bat similarity index 95% rename from host/windows_make_standalone.bat rename to host/windows_make_standalone_Nuitka.bat index 3651777..526d559 100644 --- a/host/windows_make_standalone.bat +++ b/host/windows_make_standalone_Nuitka.bat @@ -1,24 +1,24 @@ -@echo off - -set scriptdir=%~dp0 -set scriptdir=%scriptdir:~0,-1% - -set venvname=standalone -set venvscripts=%scriptdir%\%venvname%\Scripts - -set venvpython=%venvscripts%\python.exe - -cd /D "%scriptdir%" - -python -m venv "%venvname%" - -"%venvpython%" -m pip install --upgrade nuitka -r requirements-win32.txt - -"%venvpython%" -m nuitka --standalone --onefile --deployment --disable-console --windows-icon-from-ico=nxdt.ico --enable-plugin=tk-inter nxdt_host.py - -rmdir /s /q nxdt_host.build -rmdir /s /q nxdt_host.dist -rmdir /s /q nxdt_host.onefile-build -rmdir /s /q standalone - -pause +@echo off + +set scriptdir=%~dp0 +set scriptdir=%scriptdir:~0,-1% + +set venvname=standalone +set venvscripts=%scriptdir%\%venvname%\Scripts + +set venvpython=%venvscripts%\python.exe + +cd /D "%scriptdir%" + +python -m venv "%venvname%" + +"%venvpython%" -m pip install --upgrade nuitka -r requirements-win32.txt + +"%venvpython%" -m nuitka --standalone --onefile --deployment --disable-console --windows-icon-from-ico=nxdt.ico --enable-plugin=tk-inter nxdt_host.py + +rmdir /s /q nxdt_host.build +rmdir /s /q nxdt_host.dist +rmdir /s /q nxdt_host.onefile-build +rmdir /s /q standalone + +pause diff --git a/host/windows_make_standalone_PyInstaller.bat b/host/windows_make_standalone_PyInstaller.bat new file mode 100644 index 0000000..670da03 --- /dev/null +++ b/host/windows_make_standalone_PyInstaller.bat @@ -0,0 +1,39 @@ +@echo off + +rem Get the directory of the script +set scriptdir=%~dp0 +set scriptdir=%scriptdir:~0,-1% + +rem Set up virtual environment variables +set venvname=standalone +set venvdir=%scriptdir%\%venvname% + +rem Create a virtual environment +python -m venv "%venvdir%" + +rem Activate the virtual environment +call "%venvdir%\Scripts\activate" + +rem Install PyInstaller +pip install --upgrade pyinstaller + +rem Install additional requirements +pip install -r requirements-win32.txt + +rem Use PyInstaller to create a standalone executable +pyinstaller --onefile --noconsole --icon=nxdt.ico nxdt_host.py + +rem Deactivate the virtual environment +call deactivate + +rem Move the executable to the script directory +move "%scriptdir%\dist\nxdt_host.exe" "%scriptdir%" +timeout /t 1 /nobreak > nul + +rem Clean up temporary files +rmdir /s /q "%scriptdir%\dist" +rmdir /s /q "%scriptdir%\build" +rmdir /s /q "%venvdir%" + +rem Pause to keep the console window open for viewing output +pause