const char* fs_uae_base_dir(void) { static const char* path; if (path) { return path; } path = fs_config_get_const_string("base_dir"); if (path) { fs_log("base specified via base_dir option\n"); path = fs_uae_expand_path(path); } if (path == NULL) { // FIXME: deprecated const char *env_path = getenv("FS_UAE_BASE_DIR"); if (env_path && env_path[0]) { path = env_path; fs_log("base specified via FS_UAE_BASE_DIR\n"); fs_emu_deprecated("FS_UAE_BASE_DIR is deprecated"); } } if (path == NULL) { // check for portable dir char buffer[MAX_PATH]; fs_get_application_exe_dir(buffer, MAX_PATH); char *next = g_strdup(buffer); char *orig = g_strdup(":INVALID;"); while (strcmp(orig, next) != 0) { char *test = g_build_filename(next, "Portable.ini", NULL); fs_log("checking %s\n", test); if (fs_path_exists(test)) { path = next; fs_log("using portable base dir %s\n", path); g_free(orig); break; } g_free(test); g_free(orig); orig = next; next = g_path_get_dirname(next); } } if (path == NULL) { path = read_custom_path("base-dir"); } if (path == NULL) { fs_log("- using base dir $DOCUMENTS/FS-UAE\n"); path = g_build_filename(fs_uae_documents_dir(), "FS-UAE", NULL); } int result = g_mkdir_with_parents(path, 0755); if (result == -1) { fs_emu_warning("Could not create base directory " "at %s", path); path = fs_uae_documents_dir(); } fs_log("- using base ($BASE / $FSUAE) directory \"%s\"\n", path); return path; }
static char *get_or_create_default_dir(const char *name, const char *key1, const char *key2, const char *dashed_key, int create, int cache) { char *path = NULL; if (path == NULL && key1 != NULL) { path = fs_config_get_string(key1); } if (path == NULL && key2 != NULL) { path = fs_config_get_string(key2); } if (path == NULL && dashed_key != NULL) { path = read_custom_path(dashed_key); } if (path == NULL) { if (cache) { path = g_build_filename(fs_uae_cache_dir(), name, NULL); } else { path = g_build_filename(fs_uae_base_dir(), name, NULL); } } char *expanded_path = fs_uae_expand_path_and_free(path); path = fs_uae_resolve_path(expanded_path, FS_UAE_DIR_PATHS); free(expanded_path); if (create) { int result = g_mkdir_with_parents(path, 0755); if (result == -1) { fs_emu_warning("Could not create %s directory", name); free(path); path = g_strdup(fs_uae_base_dir()); } } fs_log("- using \"%s\" directory \"%s\"\n", name, path); return path; }