Skip to content

Commit

Permalink
loader: add -cwd option to change working directory when app starts
Browse files Browse the repository at this point in the history
  • Loading branch information
AKuHAK committed Oct 18, 2024
1 parent c8c265f commit 9ed63a8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ Options:
- 5: IOP: Emulate DVD-DL
Multiple options possible, for example -gc=23
-cwd=<file> Change working directory
-cfg=<file> Load extra user/game specific config file (without .toml extension)
-dbc Enable debug colors
Expand Down
1 change: 1 addition & 0 deletions ee/loader/config/system.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ default_dvd = "no"
default_elf = "auto"
#default_mt = "dvd"
#default_gc = "12"
#default_cwd = "mc0:neutrino"
#default_cfg = ""
default_dbc = false
default_logo = false
Expand Down
16 changes: 16 additions & 0 deletions ee/loader/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ void print_usage()
printf(" - 5: IOP: Emulate DVD-DL\n");
printf(" Multiple options possible, for example -gc=23\n");
printf("\n");
printf(" -cwd=<path> Change working directory\n");
printf("\n");
printf(" -cfg=<file> Load extra user/game specific config file (without .toml extension)\n");
printf("\n");
printf(" -dbc Enable debug colors\n");
Expand Down Expand Up @@ -165,6 +167,7 @@ struct SSystemSettings {
char *sELFFile;
char *sMT;
char *sGC;
char *sCWDpath;
char *sCFGFile;
int bDebugColors;
int bLogo;
Expand Down Expand Up @@ -730,6 +733,7 @@ int load_driver(const char * type, const char * subtype)
toml_string_in_overwrite(tbl_root, "default_elf", &sys.sELFFile);
toml_string_in_overwrite(tbl_root, "default_mt", &sys.sMT);
toml_string_in_overwrite(tbl_root, "default_gc", &sys.sGC);
toml_string_in_overwrite(tbl_root, "default_cwd", &sys.sCWDpath);
toml_string_in_overwrite(tbl_root, "default_cfg", &sys.sCFGFile);
toml_bool_in_overwrite (tbl_root, "default_dbc", &sys.bDebugColors);
toml_bool_in_overwrite (tbl_root, "default_logo", &sys.bLogo);
Expand Down Expand Up @@ -938,6 +942,8 @@ int main(int argc, char *argv[])
sys.sMT = &argv[i][4];
else if (!strncmp(argv[i], "-gc=", 4))
sys.sGC = &argv[i][4];
else if (!strncmp(argv[i], "-cwd", 5))
sys.sCWDpath = &argv[i][5];
else if (!strncmp(argv[i], "-cfg=", 5))
sys.sCFGFile = &argv[i][5];
else if (!strncmp(argv[i], "-dbc", 4))
Expand All @@ -955,6 +961,16 @@ int main(int argc, char *argv[])
}
}

/*
* Change working directory
*/
if (sys.sCWDpath != NULL) {
if (chdir(sys.sCWDpath) != 0) {
printf("ERROR: failed to change working directory\n");
return -1;
}
}

/*
* Load user/game settings
*/
Expand Down

0 comments on commit 9ed63a8

Please sign in to comment.