def install_nsp(nsp_file, usb_drive):
"""Installs an NSP game to a USB drive.
Args:
nsp_file: The path to the NSP file.
usb_drive: The path to the USB drive.
"""
# Create a temporary directory to store the extracted NSP files.
temp_dir = os.path.join(usb_drive, ".nsp_temp")
os.makedirs(temp_dir, exist_ok=True)
# Extract the NSP files to the temporary directory.
nx.archive.extract_nsp(nsp_file, temp_dir)
# Move the NSP files to the appropriate location on the USB drive.
nx.file.move(temp_dir, usb_drive)
# Delete the temporary directory.
os.rmdir(temp_dir)
def run_nsp(nsp_file, usb_drive):
"""Runs an NSP game from a USB drive.
Args:
nsp_file: The path to the NSP file.
usb_drive: The path to the USB drive.
"""
# Mount the USB drive.
nx.mount.mount_usb_drive(usb_drive)
# Start the NSP game.
nx.app.start_title(nsp_file)
# Unmount the USB drive.
nx.mount.unmount_usb_drive(usb_drive)
def main():
"""The main entry point for the homebrew app."""
# Get the path to the USB drive.
usb_drive = nx.interface.get_usb_drive_path()
# If the USB drive is not mounted, prompt the user to insert it.
if not nx.mount.is_usb_drive_mounted(usb_drive):
nx.console.log("Please insert a USB drive.")
nx.input.wait_for_button_press()
# Get the path to the NSP file.
nsp_file = nx.file.select_file()
# Install the NSP game to the USB drive.
install_nsp(nsp_file, usb_drive)
# Run the NSP game from the USB drive.
run_nsp(nsp_file, usb_drive)
if __name__ == "__main__":
main()
It just says:
To compile this Python application into a homebrew app, you can use the following command:
// Install an NSP game to an external USB drive.
void InstallNSPGameToUSB(const char* nsp_file, const char* usb_path) {
// Open the NSP game file.
FILE* file = fopen(nsp_file, "rb");
if (!file) {
return;
}
// Get the file size.
fseek(file, 0, SEEK_END);
size_t size = ftell(file);
fseek(file, 0, SEEK_SET);
// Allocate a buffer to store the NSP game file.
uint8_t* buffer = (uint8_t*)malloc(size);
if (!buffer) {
fclose(file);
return;
}
// Read the NSP game file into the buffer.
fread(buffer, 1, size, file);
fclose(file);
// Open the USB device.
handle_t usb_device;
swipc_usb_open(&usb_device, usb_path);
// Write the NSP game file to the USB device.
swipc_usb_write(usb_device, buffer, size);
// Close the USB device.
swipc_usb_close(usb_device);
// Free the buffer.
free(buffer);
}
// Uninstall an NSP game from an external USB drive.
void UninstallNSPGameFromUSB(const char* usb_path) {
// Open the USB device.
handle_t usb_device;
swipc_usb_open(&usb_device, usb_path);
// Remove the NSP game file from the USB device.
swipc_usb_remove(usb_device, "NSP");
// Close the USB device.
swipc_usb_close(usb_device);
}
// Run an NSP game from an external USB drive.
void RunNSPGameFromUSB(const char* usb_path) {
// Open the USB device.
handle_t usb_device;
swipc_usb_open(&usb_device, usb_path);
// Read the NSP game file from the USB device.
size_t size = swipc_usb_get_file_size(usb_device, "NSP");
uint8_t* buffer = (uint8_t*)malloc(size);
swipc_usb_read(usb_device, buffer, size, 0);
// Close the USB device.
swipc_usb_close(usb_device);
// Load the NSP game file into memory.
nx_applet_load_package_memory(buffer, size, 0);
// Start the NSP game.
nx_applet_start();
// Wait for the NSP game to exit.
nx_applet_wait();
// Free the buffer.
free(buffer);
}
int main(void) {
// Initialize the Nintendo Switch.
switch_init();
// Get the path to the NSP game file.
char* nsp_file = switch_select_file();
if (!nsp_file) {
switch_exit();
return 1;
}
// Get the path to the external USB drive.
char* usb_path = switch_select_path();
if (!usb_path) {
switch_exit();
return 1;
}
// Install the NSP game to the external USB drive.
InstallNSPGameToUSB(nsp_file, usb_path);
// Run the NSP game from the external USB drive.
RunNSPGameFromUSB(usb_path);
// Uninstall the NSP game from the external USB drive.
UninstallNSPGameFromUSB(usb_path);
Sony made a shocking announcement today, revealing that the company plans to move away from physical game releases in the future. Citing claims of how the industry is...
After much speculation, a lot of which being caused by dbrand's unceremonious reveal of their Companion Cube casing, the Steam Machine is finally available to order...
Nintendo's expected Summer showcase is here, offering up plenty of new announcements and exciting reveals. Let's see what they have in store in the latest Nintendo...
What once seemed like a far off dream, and after many, many community restarts throughout the years, the elusive Mother 1 / EarthBound Beginnings Remake, which is a...
Since being decompiled Super Mario 64 has seen a considerable amount of interest. We've had multiple PC ports, but the efforts beyond that are really astounding. It's...
Remember when you could get an Xbox Series S for $300? Those were the days. Microsoft has today announced the latest in their console price hikes, seeing their...
Happy June 15th! Well, this one was close enough. Atmosphere has been updated to add support for the latest Nintendo Switch firmware, 22.5.0. This means all of you...
The delays may be behind us, but the news isn't all good for Grand Theft Auto VI. Rockstar have today announced that pre-orders for the game will go live tomorrow, on...
It's that time again. Batten down the hatches and ride out the storm, because we've got another Switch update! And Switch 2, but that's somewhat less impactful given...
After being announced earlier this month, the first early access release for Pokemon Infinite Fusion 2: Hoenn is now live. This first release includes the first two...
Sony made a shocking announcement today, revealing that the company plans to move away from physical game releases in the future. Citing claims of how the industry is...
After much speculation, a lot of which being caused by dbrand's unceremonious reveal of their Companion Cube casing, the Steam Machine is finally available to order...
Remember when you could get an Xbox Series S for $300? Those were the days. Microsoft has today announced the latest in their console price hikes, seeing their...
The delays may be behind us, but the news isn't all good for Grand Theft Auto VI. Rockstar have today announced that pre-orders for the game will go live tomorrow, on...
Nintendo's expected Summer showcase is here, offering up plenty of new announcements and exciting reveals. Let's see what they have in store in the latest Nintendo...
The end has come for the PlayStation 3 and the PlayStation Vita. After supporting the PSN Store on the PS3 and PS Vita since 2006 and 2011 respectively, Sony has...
Last month we got confirmation of a new model of Switch 2 to better comply with upcoming EU regulations. With the legislation set to come into effect in February of...
Since being decompiled Super Mario 64 has seen a considerable amount of interest. We've had multiple PC ports, but the efforts beyond that are really astounding. It's...
What once seemed like a far off dream, and after many, many community restarts throughout the years, the elusive Mother 1 / EarthBound Beginnings Remake, which is a...
Apple have today announced price increases, primarily focused on their MacBook and iPad lines. These increases have already come into effect, with both prices and the...