diff options
-rw-r--r-- | core.c | 43 | ||||
-rw-r--r-- | core.h | 2 | ||||
-rw-r--r-- | main.c | 2 | ||||
-rw-r--r-- | menu.c | 20 |
4 files changed, 61 insertions, 6 deletions
@@ -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; @@ -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); @@ -673,6 +673,8 @@ int main(int argc, char **argv) { quit(-1); } + core_save_last_opened(content); + load_config_keys(); #ifdef MMENU @@ -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++) ; |