summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornotaz2011-09-08 00:45:41 +0300
committernotaz2011-09-08 00:48:33 +0300
commitd40aa461c5267826ec092f80b9e4db6cc38466b1 (patch)
tree25b24db057ae4bd3b4ecfff4ebbe72c2f30b18f9
parent44cae4c585effb7c34c6636bc9802cd0bab58ac3 (diff)
downloadpicogpsp-d40aa461c5267826ec092f80b9e4db6cc38466b1.tar.gz
picogpsp-d40aa461c5267826ec092f80b9e4db6cc38466b1.tar.bz2
picogpsp-d40aa461c5267826ec092f80b9e4db6cc38466b1.zip
make romdir saving not GP2X specific
not using config as it's binary, this is intended to be user editable.
-rw-r--r--gp2x/gp2x.c36
-rw-r--r--main.c52
2 files changed, 48 insertions, 40 deletions
diff --git a/gp2x/gp2x.c b/gp2x/gp2x.c
index 7bef895..d03a548 100644
--- a/gp2x/gp2x.c
+++ b/gp2x/gp2x.c
@@ -244,28 +244,6 @@ u32 wiz_load_gamepak(char *name)
#endif
-static int get_romdir(char *buff, size_t size)
-{
- FILE *f;
- char *s;
- int r = -1;
-
- f = fopen("romdir.txt", "r");
- if (f == NULL)
- return -1;
-
- s = fgets(buff, size, f);
- if (s)
- {
- r = strlen(s);
- while (r > 0 && isspace(buff[r-1]))
- buff[--r] = 0;
- }
-
- fclose(f);
- return r;
-}
-
void gpsp_plat_init(void)
{
char buff[256];
@@ -281,9 +259,6 @@ void gpsp_plat_init(void)
fb_video_init();
#endif
- if (get_romdir(buff, sizeof(buff)) > 0)
- chdir(buff);
-
gp2x_sound_volume(1);
}
@@ -293,17 +268,6 @@ void gpsp_plat_quit(void)
getcwd(buff1, sizeof(buff1));
chdir(main_path);
- if (get_romdir(buff2, sizeof(buff2)) >= 0 &&
- strcmp(buff1, buff2) != 0)
- {
- FILE *f = fopen("romdir.txt", "w");
- if (f != NULL)
- {
- printf("writing romdir: %s\n", buff1);
- fprintf(f, "%s", buff1);
- fclose(f);
- }
- }
warm_finish();
#ifdef WIZ_BUILD
diff --git a/main.c b/main.c
index 967ac73..ecd529a 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)
+#ifdef PSP_BUILD
+static void ChangeWorkingDirectory(char *exe)
{
#ifndef _WIN32_WCE
char *s = strrchr(exe, '/');
@@ -145,6 +145,49 @@ 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];
+ int r = -1;
+
+ 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 +234,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);
@@ -282,6 +323,7 @@ int main(int argc, char *argv[])
if(argc > 1)
{
+ switch_to_romdir();
if(load_gamepak(argv[1]) == -1)
{
#ifndef PSP_BUILD
@@ -836,6 +878,8 @@ void synchronize()
void quit()
{
+ save_romdir();
+
if(!update_backup_flag)
update_backup_force();