Last active
November 3, 2024 07:46
-
-
Save parkerlreed/7c9fd093cab94e4cf10e6d2485036e0b to your computer and use it in GitHub Desktop.
Lists ISOs in given folder and allows you to turn the Steam Deck into a flash drive - Currently requires passwordless sudo for rmmod and modprobe to be setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import subprocess | |
from PyQt6.QtWidgets import ( | |
QApplication, QMainWindow, QVBoxLayout, QPushButton, QWidget, QMessageBox, QScrollArea, QVBoxLayout | |
) | |
class IsoLoaderApp(QMainWindow): | |
def __init__(self, iso_directory): | |
super().__init__() | |
self.iso_directory = iso_directory | |
self.setWindowTitle('ISO/IMG Loader') | |
# Maximize the window on launch | |
self.showMaximized() | |
# Main layout | |
self.central_widget = QWidget() | |
self.scroll_area = QScrollArea() | |
self.button_container = QWidget() | |
self.layout = QVBoxLayout(self.button_container) | |
# Populate the container with buttons for ISO/IMG files | |
self.populate_iso_buttons() | |
self.scroll_area.setWidgetResizable(True) | |
self.scroll_area.setWidget(self.button_container) | |
# Add the scroll area to the central widget | |
main_layout = QVBoxLayout(self.central_widget) | |
main_layout.addWidget(self.scroll_area) | |
self.setCentralWidget(self.central_widget) | |
def populate_iso_buttons(self): | |
"""Create buttons for each ISO and IMG file in the directory.""" | |
if os.path.isdir(self.iso_directory): | |
iso_img_files = sorted( | |
[f for f in os.listdir(self.iso_directory) if f.endswith(('.iso', '.img'))] | |
) | |
for file_name in iso_img_files: | |
button = QPushButton(file_name) | |
button.setMinimumHeight(50) # Set button height here | |
button.clicked.connect(lambda checked, fn=file_name: self.load_iso(fn)) | |
self.layout.addWidget(button) | |
else: | |
self.show_message("Error", f"Directory '{self.iso_directory}' not found", is_error=True) | |
def load_iso(self, file_name): | |
"""Load the selected ISO or IMG using the g_mass_storage module.""" | |
iso_path = os.path.join(self.iso_directory, file_name) | |
try: | |
# Unload the g_mass_storage module before loading a new file | |
subprocess.run( | |
["sudo", "rmmod", "g_mass_storage"], | |
check=False | |
) | |
# Command to load the ISO/IMG using g_mass_storage | |
subprocess.run( | |
["sudo", "modprobe", "g_mass_storage", f"file={iso_path}"], | |
check=True | |
) | |
self.show_message("Success", f"Loaded {file_name}") | |
except subprocess.CalledProcessError as e: | |
self.show_message("Error", f"Failed to load ISO/IMG: {e}", is_error=True) | |
except Exception as e: | |
self.show_message("Error", f"Unexpected error: {e}", is_error=True) | |
def show_message(self, title, text, is_error=False): | |
"""Display a customized QMessageBox with a larger 'Ok' button.""" | |
msg_box = QMessageBox(self) | |
msg_box.setWindowTitle(title) | |
msg_box.setText(text) | |
msg_box.setIcon(QMessageBox.Icon.Critical if is_error else QMessageBox.Icon.Information) | |
# Customize the Ok button | |
ok_button = msg_box.addButton(QMessageBox.StandardButton.Ok) | |
ok_button.setMinimumHeight(50) # Set button height here | |
ok_button.setMinimumWidth(200) # Optionally set the button width | |
# Show the message box | |
msg_box.exec() | |
if __name__ == "__main__": | |
import sys | |
app = QApplication(sys.argv) | |
iso_directory = "/home/deck/iso" | |
window = IsoLoaderApp(iso_directory) | |
window.show() | |
sys.exit(app.exec()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# PyQt6 is used which requires us to do some setup in a virtual environment | |
# Create the venv with | |
# python -m venv ~/.local/share/usb-host | |
# source ~/.local/share/usb-host/bin/activate | |
# pip install PyQt6 | |
source ~/.local/share/usb-host/bin/activate | |
python /home/deck/path/to/loader.py |
20241101_230242.mp4
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For the passwordless sudo
/etc/sudoers.d/wheel
Make sure DRD is enabled in the BIOS and that the
/sys/class/udc/dwc3.1.auto
exists before loading this up (I'll likely add this as a check later on)