aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core.c43
-rw-r--r--core.h2
-rw-r--r--main.c2
-rw-r--r--menu.c20
4 files changed, 61 insertions, 6 deletions
diff --git a/core.c b/core.c
index 61a14b5..6f28d28 100644
--- a/core.c
+++ b/core.c
@@ -704,6 +704,49 @@ finish:
return ret;
}
+void core_load_last_opened(char *buf, size_t len) {
+ char filename[MAX_PATH];
+ FILE *file;
+ size_t count;
+
+ if (!len)
+ goto finish;
+
+ snprintf(filename, MAX_PATH, "%s%s", config_dir, "last_opened.txt");
+ file = fopen(filename, "r");
+
+ if (!file)
+ goto finish;
+
+ count = fread(buf, 1, len - 1, file);
+ buf[count] = '\0';
+
+finish:
+ if (file)
+ fclose(file);
+}
+
+void core_save_last_opened(struct content *content) {
+ char filename[MAX_PATH];
+ FILE *file;
+ size_t len = strlen(content->path);
+
+ if (!len)
+ goto finish;
+
+ snprintf(filename, MAX_PATH, "%s%s", config_dir, "last_opened.txt");
+ file = fopen(filename, "w");
+
+ if (!file)
+ goto finish;
+
+ fwrite(content->path, 1, len, file);
+
+finish:
+ if (file)
+ fclose(file);
+}
+
void core_apply_cheats(struct cheats *cheats) {
if (!cheats)
return;
diff --git a/core.h b/core.h
index a267b6e..8049aa7 100644
--- a/core.h
+++ b/core.h
@@ -64,6 +64,8 @@ void core_extract_name(const char* core_file, char *buf, size_t len);
int core_open(const char *corefile);
void core_load(void);
int core_load_content(struct content *content);
+void core_load_last_opened(char *buf, size_t len);
+void core_save_last_opened(struct content *content);
void core_apply_cheats(struct cheats *cheats);
void core_run_frame(void);
void core_unload_content(void);
diff --git a/main.c b/main.c
index 9b3c633..1408a46 100644
--- a/main.c
+++ b/main.c
@@ -673,6 +673,8 @@ int main(int argc, char **argv) {
quit(-1);
}
+ core_save_last_opened(content);
+
load_config_keys();
#ifdef MMENU
diff --git a/menu.c b/menu.c
index 66ee8ef..a76ea44 100644
--- a/menu.c
+++ b/menu.c
@@ -250,17 +250,25 @@ const char *select_content(void) {
if (content && strlen(content->path)) {
strncpy(content_path, content->path, sizeof(content_path) - 1);
- } else if (getenv("CONTENT_DIR")) {
- strncpy(content_path, getenv("CONTENT_DIR"), sizeof(content_path) - 1);
-#ifdef CONTENT_DIR
} else {
- strncpy(content_path, CONTENT_DIR, sizeof(content_path) - 1);
+ core_load_last_opened(content_path, sizeof(content_path));
+ }
+
+ if (!content_path[0]) {
+ if (getenv("CONTENT_DIR")) {
+ strncpy(content_path, getenv("CONTENT_DIR"), sizeof(content_path) - 1);
+#ifdef CONTENT_DIR
+ } else {
+ strncpy(content_path, CONTENT_DIR, sizeof(content_path) - 1);
#else
- } else if (getenv("HOME")) {
- strncpy(content_path, getenv("HOME"), sizeof(content_path) - 1);
+ } else if (getenv("HOME")) {
+ strncpy(content_path, getenv("HOME"), sizeof(content_path) - 1);
#endif
+ }
}
+ content_path[sizeof(content_path) - 1] = '\0';
+
if (extensions) {
for (size = 0; extensions[size]; size++)
;