X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=main.c;h=96e6bb67050ef00f7981012bf9aa027cfc77e708;hb=e38fee1b96c0b904d7f221a349fb2492258d5789;hp=967ac737e187bb76534265ec82784918173ea5e5;hpb=d0944fc942fad418aed45245e4259780f2fc0697;p=gpsp.git diff --git a/main.c b/main.c index 967ac73..96e6bb6 100644 --- a/main.c +++ b/main.c @@ -133,8 +133,8 @@ void trigger_ext_event(); static const char *file_ext[] = { ".gba", ".bin", ".zip", NULL }; -#ifdef ARM_ARCH -void ChangeWorkingDirectory(char *exe) +#ifndef PSP_BUILD +static void ChangeWorkingDirectory(char *exe) { #ifndef _WIN32_WCE char *s = strrchr(exe, '/'); @@ -145,6 +145,48 @@ void ChangeWorkingDirectory(char *exe) } #endif } + +static void switch_to_romdir(void) +{ + char buff[256]; + int r; + + file_open(romdir_file, "romdir.txt", read); + + if(file_check_valid(romdir_file)) + { + r = file_read(romdir_file, buff, sizeof(buff) - 1); + if (r > 0) + { + buff[r] = 0; + while (r > 0 && isspace(buff[r-1])) + buff[--r] = 0; + chdir(buff); + } + file_close(romdir_file); + } +} + +static void save_romdir(void) +{ + char buff[512]; + + snprintf(buff, sizeof(buff), "%s" PATH_SEPARATOR "romdir.txt", main_path); + file_open(romdir_file, buff, write); + + if(file_check_valid(romdir_file)) + { + if (getcwd(buff, sizeof(buff))) + { + file_write(romdir_file, buff, strlen(buff)); + } + file_close(romdir_file); + } +} +#else +void ChangeWorkingDirectory(char *exe) {} +static void switch_to_romdir(void) {} +static void save_romdir(void) {} #endif void init_main() @@ -191,10 +233,8 @@ int main(int argc, char *argv[]) // Copy the directory path of the executable into main_path -#ifdef ARM_ARCH // ChangeWorkingDirectory will null out the filename out of the path ChangeWorkingDirectory(argv[0]); -#endif getcwd(main_path, 512); @@ -229,7 +269,7 @@ int main(int argc, char *argv[]) debug_screen_printl(" "); debug_screen_printl("When you do get it name it gba_bios.bin and put it"); #ifdef PND_BUILD - debug_screen_printl("in /pandora/appdata/gpsp/ . "); + debug_screen_printl("in /pandora/appdata/gpsp/ . "); #else debug_screen_printl("in the same directory as gpSP. "); #endif @@ -299,6 +339,7 @@ int main(int argc, char *argv[]) else { char load_filename[512]; + switch_to_romdir(); if(load_file(file_ext, load_filename) == -1) { menu(copy_screen()); @@ -836,6 +877,8 @@ void synchronize() void quit() { + save_romdir(); + if(!update_backup_flag) update_backup_force();