Skip to content

Commit

Permalink
Add Switch.FileSystem.openSdmc()
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed Nov 22, 2024
1 parent 43c6a1a commit a66c991
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/calm-carpets-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nx.js/runtime": patch
---

Add `Switch.FileSystem.openSdmc()`
1 change: 1 addition & 0 deletions packages/runtime/src/$.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ export interface Init {
fsInit(c: ClassOf<FileSystem>): void;
fsMount(fs: FileSystem, name: string): void;
fsOpenBis(id: number): FileSystem;
fsOpenSdmc(): FileSystem;
saveDataInit(c: ClassOf<SaveData>): void;
saveDataCreateSync(info: SaveDataCreationInfo, nacp?: ArrayBuffer): void;
saveDataMount(saveData: SaveData, name: string): void;
Expand Down
15 changes: 15 additions & 0 deletions packages/runtime/src/switch/file-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,20 @@ export class FileSystem {
static openBis(id: number): FileSystem {
return proto($.fsOpenBis(id), FileSystem);
}

/**
* Opens a file system partition for the SD card.
*
* @example
*
* ```typescript
* const fs = Switch.FileSystem.openSdmc();
* console.log(fs.freeSpace());
* console.log(fs.totalSpace());
* ```
*/
static openSdmc(): FileSystem {
return proto($.fsOpenSdmc(), FileSystem);
}
}
$.fsInit(FileSystem);
16 changes: 16 additions & 0 deletions source/fsdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,21 @@ static JSValue nx_fs_open_bis(JSContext *ctx, JSValueConst this_val, int argc,
return obj;
}

static JSValue nx_fs_open_sdmc(JSContext *ctx, JSValueConst this_val, int argc,
JSValueConst *argv) {
nx_file_system_t *file_system = js_mallocz(ctx, sizeof(nx_file_system_t));
if (!file_system) {
return JS_EXCEPTION;
}
Result rc = fsOpenSdCardFileSystem(&file_system->fs);
if (R_FAILED(rc)) {
return nx_throw_libnx_error(ctx, rc, "fsOpenSdCardFileSystem()");
}
JSValue obj = JS_NewObjectClass(ctx, nx_file_system_class_id);
JS_SetOpaque(obj, file_system);
return obj;
}

static JSValue nx_fs_free_space(JSContext *ctx, JSValueConst this_val, int argc,
JSValueConst *argv) {
nx_file_system_t *file_system =
Expand Down Expand Up @@ -774,6 +789,7 @@ static const JSCFunctionListEntry function_list[] = {
JS_CFUNC_DEF("fsInit", 1, nx_fs_init),
JS_CFUNC_DEF("fsMount", 1, nx_fs_mount),
JS_CFUNC_DEF("fsOpenBis", 1, nx_fs_open_bis),
JS_CFUNC_DEF("fsOpenSdmc", 1, nx_fs_open_sdmc),

JS_CFUNC_DEF("saveDataInit", 1, nx_save_data_init),
JS_CFUNC_DEF("saveDataMount", 1, nx_save_data_mount),
Expand Down

0 comments on commit a66c991

Please # to comment.