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);
As each year passes, retro games become harder and harder to play, as the physical media begins to fall apart and becomes more difficult and expensive to obtain. The...
While rumors had been floating about rampantly as to the future plans of Nintendo, the President of the company, Shuntaro Furukawa, made a brief statement confirming...
Nintendo has officially announced that a successor to the beloved Switch console is on the horizon. As we eagerly anticipate what innovations this new device will...
DOOM is well-known for being ported to basically every device with some kind of input, and that list now includes the old retro game console in Persona 5 Royal...
With the vast success of Super Mario Maker and its Switch sequel Super Mario Maker 2, Nintendo fans have long been calling for "Maker" titles for other iconic genres...
Retro handheld manufacturer Anbernic has revealed its first clamshell device: the Anbernic RG35XXSP. As the suffix indicates, this handheld's design is inspired by...
After several months of work, the Harbour Masters 64 team have released their first public build of 2Ship2Harkinian, a feature-rich Majora's Mask PC port. This comes...
After rumour got out about an upcoming NES Edition release for the famed Nintendo World Championships, Nintendo has officially unveiled the new game, titled "Nintendo...
The number of layoffs and cuts in the videogame industry sadly continue to grow, with the latest huge layoffs coming from Microsoft, due to what MIcrosoft calls a...
Ubisoft has today officially revealed the next installment in the Assassin's Creed franchise: Assassin's Creed Shadows. This entry is set in late Sengoku-era Japan...
Nintendo has officially announced that a successor to the beloved Switch console is on the horizon. As we eagerly anticipate what innovations this new device will...
While rumors had been floating about rampantly as to the future plans of Nintendo, the President of the company, Shuntaro Furukawa, made a brief statement confirming...
As each year passes, retro games become harder and harder to play, as the physical media begins to fall apart and becomes more difficult and expensive to obtain. The...
After several months of work, the Harbour Masters 64 team have released their first public build of 2Ship2Harkinian, a feature-rich Majora's Mask PC port. This comes...
Ubisoft has today officially revealed the next installment in the Assassin's Creed franchise: Assassin's Creed Shadows. This entry is set in late Sengoku-era Japan...
After a little more than three years of exclusivity with the Epic Games Store, Square Enix has decided to bring their beloved Kingdom Hearts franchise to Steam. The...
After rumour got out about an upcoming NES Edition release for the famed Nintendo World Championships, Nintendo has officially unveiled the new game, titled "Nintendo...
DOOM is well-known for being ported to basically every device with some kind of input, and that list now includes the old retro game console in Persona 5 Royal...
Sony is once more attempting to reintroduce players to their older library of games by re-releasing classic PlayStation 2 titles onto the PlayStation Store. During...
The number of layoffs and cuts in the videogame industry sadly continue to grow, with the latest huge layoffs coming from Microsoft, due to what MIcrosoft calls a...