Is this proper code for external harddrive installing?

Mokiki

Active Member
OP
Newcomer
Joined
May 8, 2018
Messages
29
Trophies
0
Age
46
XP
373
Country
United States
C++
#include <switch.h>
#include <libnx.h>
#include <devkitpro.h>
#include <swipc.h>
#include <stratosphere.h>

// 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);

// Exit the Nintendo Switch.
switch_exit();

return 0;
}
Post automatically merged:

Or this

C++
#include <devkitA64.h>
#include <libnx.h>
#include <swIPC.h>
#include <stratosphere.h>

#include <string>
#include <vector>

using namespace std;

// The path to the USB drive
const char* usbPath = "/mnt/usb0";

// The title ID of the game to install
const char* titleId = "01003A600C2A0000";

// The path to the game file
const char* gamePath = "/path/to/game.xci";

// Installs the game to the USB drive
void installGame(const char* titleId, const char* gamePath) {
// Initialize the stratosphere library
stratosphereInit();

// Open the game file
FILE* gameFile = fopen(gamePath, "rb");
if (gameFile == nullptr) {
// Handle error
return;
}

// Get the size of the game file
fseek(gameFile, 0, SEEK_END);
size_t gameSize = ftell(gameFile);
fseek(gameFile, 0, SEEK_SET);

// Allocate a buffer for the game file
char* gameBuffer = (char*)malloc(gameSize);
if (gameBuffer == nullptr) {
// Handle error
return;
}

// Read the game file into the buffer
fread(gameBuffer, 1, gameSize, gameFile);
fclose(gameFile);

// Install the game to the USB drive
stratosphereInstallGame(titleId, gameBuffer, gameSize);

// Free the game buffer
free(gameBuffer);
}

// Runs the game from the USB drive
void runGame(const char* titleId) {
// Initialize the swIPC library
swIPCInit();

// Open the game process
Handle gameProcess = swIPCOpenProcess(titleId);
if (gameProcess == 0) {
// Handle error
return;
}

// Start the game process
swIPCStartProcess(gameProcess);

// Wait for the game process to exit
swIPCWaitProcess(gameProcess);
}

int main() {
// Initialize the devkitA64 library
devkitA64Init();

// Install the game to the USB drive
installGame(titleId, gamePath);

// Run the game from the USB drive
runGame(titleId);

// Finalize the devkitA64 library
devkitA64Exit();

return 0;
}
 
Last edited by Mokiki,

masagrator

The patches guy
Developer
Joined
Oct 14, 2018
Messages
6,307
Trophies
3
XP
12,100
Country
Poland
First of all, use code blocks.

Second, you could just compile code instead of asking? This way you will know.

And even if this would compile, you really expect that 3 GB of RAM will store any game that is bigger than 3GB? Because this is what you are trying to do, load whole xci/nsp to RAM instead of streaming.

There are already tools for that, why do you want to reinvent the wheel?

Edit: now when I'm looking at this code closer, do you use some ChatGPT or you are making this up yourself? There is ton of non existing shit and useless stuff in such small code snippets. WTF is "devkitA64Init" or "stratosphereInit"? Stratosphere is written in C++, so why header is ".h"? WTF is "libnx.h", "devkitA64.h" or "devkitpro.h"?

Are you mocking us or are you a bot? If you will answer with another code snippet, I will report you as bot since not only you have no idea what you are doing, you are also making shit up.
 
Last edited by masagrator,

barabanov

Member
Newcomer
Joined
Apr 23, 2021
Messages
18
Trophies
0
Age
34
XP
185
Country
Brazil
C++
#include <switch.h>
#include <libnx.h>
#include <devkitpro.h>
#include <swipc.h>
#include <stratosphere.h>

// 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);

// Exit the Nintendo Switch.
switch_exit();

return 0;
}
Post automatically merged:

Or this

C++
#include <devkitA64.h>
#include <libnx.h>
#include <swIPC.h>
#include <stratosphere.h>

#include <string>
#include <vector>

using namespace std;

// The path to the USB drive
const char* usbPath = "/mnt/usb0";

// The title ID of the game to install
const char* titleId = "01003A600C2A0000";

// The path to the game file
const char* gamePath = "/path/to/game.xci";

// Installs the game to the USB drive
void installGame(const char* titleId, const char* gamePath) {
// Initialize the stratosphere library
stratosphereInit();

// Open the game file
FILE* gameFile = fopen(gamePath, "rb");
if (gameFile == nullptr) {
// Handle error
return;
}

// Get the size of the game file
fseek(gameFile, 0, SEEK_END);
size_t gameSize = ftell(gameFile);
fseek(gameFile, 0, SEEK_SET);

// Allocate a buffer for the game file
char* gameBuffer = (char*)malloc(gameSize);
if (gameBuffer == nullptr) {
// Handle error
return;
}

// Read the game file into the buffer
fread(gameBuffer, 1, gameSize, gameFile);
fclose(gameFile);

// Install the game to the USB drive
stratosphereInstallGame(titleId, gameBuffer, gameSize);

// Free the game buffer
free(gameBuffer);
}

// Runs the game from the USB drive
void runGame(const char* titleId) {
// Initialize the swIPC library
swIPCInit();

// Open the game process
Handle gameProcess = swIPCOpenProcess(titleId);
if (gameProcess == 0) {
// Handle error
return;
}

// Start the game process
swIPCStartProcess(gameProcess);

// Wait for the game process to exit
swIPCWaitProcess(gameProcess);
}

int main() {
// Initialize the devkitA64 library
devkitA64Init();

// Install the game to the USB drive
installGame(titleId, gamePath);

// Run the game from the USB drive
runGame(titleId);

// Finalize the devkitA64 library
devkitA64Exit();

return 0;
}
what you want?
install games via usb? there are some tools for this

or

install in hdd/hard drive and play WITHOUT install on microsd/emunand? just like Wiiflow in Wii?
 

Jayinem

Well-Known Member
Member
Joined
Dec 16, 2021
Messages
707
Trophies
0
XP
1,686
Country
United States
I believe the option to play games off an external hdd has been dead since SX OS died 3 or so years ago. Unless there's a new way that I was unaware of.
 

Hayato213

Newcomer
Member
Joined
Dec 26, 2015
Messages
20,076
Trophies
1
XP
21,245
Country
United States
SX OS only support up to firmware 11.0.0 and the team behind it been dead for the last few years. Don't expect Atmosphere to get XCI mounting or install to HDD support.
 
  • Love
Reactions: impeeza

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
  • Jayro @ Jayro:
    Eventhough the New 3DS XL is more powerful, I still feel like the DS Lite was a more polished system. It's a real shame that it never got an XL variant keeping the GBA slot. You'd have to go on AliExpress and buy an ML shell to give a DS phat the unofficial "DS Lite" treatment, and that's the best we'll ever get I'm afraid.
    +1
  • Jayro @ Jayro:
    The phat model had amazingly loud speakers tho.
    +1
  • SylverReZ @ SylverReZ:
    @Jayro, I don't see whats so special about the DS ML, its just a DS lite in a phat shell. At least the phat model had louder speakers, whereas the lite has a much better screen.
    +1
  • SylverReZ @ SylverReZ:
    They probably said "Hey, why not we combine the two together and make a 'new' DS to sell".
  • Veho @ Veho:
    It's a DS Lite in a slightly bigger DS Lite shell.
    +1
  • Veho @ Veho:
    It's not a Nintendo / iQue official product, it's a 3rd party custom.
    +1
  • Veho @ Veho:
    Nothing special about it other than it's more comfortable than the Lite
    for people with beefy hands.
    +1
  • Jayro @ Jayro:
    I have yaoi anime hands, very lorge but slender.
  • Jayro @ Jayro:
    I'm Slenderman.
  • Veho @ Veho:
    I have hands.
  • BakerMan @ BakerMan:
    imagine not having hands, cringe
    +1
  • AncientBoi @ AncientBoi:
    ESPECIALLY for things I do to myself :sad:.. :tpi::rofl2: Or others :shy::blush::evil:
    +1
  • The Real Jdbye @ The Real Jdbye:
    @SylverReZ if you could find a v5 DS ML you would have the best of both worlds since the v5 units had the same backlight brightness levels as the DS Lite unlockable with flashme
  • The Real Jdbye @ The Real Jdbye:
    but that's a long shot
  • The Real Jdbye @ The Real Jdbye:
    i think only the red mario kart edition phat was v5
  • BigOnYa @ BigOnYa:
    A woman with no arms and no legs was sitting on a beach. A man comes along and the woman says, "I've never been hugged before." So the man feels bad and hugs her. She says "Well i've also never been kissed before." So he gives her a kiss on the cheek. She says "Well I've also never been fucked before." So the man picks her up, and throws her in the ocean and says "Now you're fucked."
    +1
  • BakerMan @ BakerMan:
    lmao
  • BakerMan @ BakerMan:
    anyways, we need to re-normalize physical media

    if i didn't want my games to be permanent, then i'd rent them
    +1
  • BigOnYa @ BigOnYa:
    Agreed, that why I try to buy all my games on disc, Xbox anyways. Switch games (which I pirate tbh) don't matter much, I stay offline 24/7 anyways.
  • AncientBoi @ AncientBoi:
    I don't pirate them, I Use Them :mellow:. Like I do @BigOnYa 's couch :tpi::evil::rofl2:
    +1
  • cearp @ cearp:
    @BakerMan - you can still "own" digital media, arguably easier and better than physical since you can make copies and backups, as much as you like.

    The issue is DRM
  • cearp @ cearp:
    You can buy drm free games / music / ebooks, and if you keep backups of your data (like documents and family photos etc), then you shouldn't lose the game. but with a disk, your toddler could put it in the toaster and there goes your $60

    :rofl2:
  • cearp @ cearp:
    still, I agree physical media is nice to have. just pointing out the issue is drm
    cearp @ cearp: still, I agree physical media is nice to have. just pointing out the issue is drm