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; }
char *fs_uae_expand_path(const char* path) { char* lower = g_ascii_strdown(path, -1); int replace = 0; const char *replace_with = NULL; if (check_path_prefix(lower, "~", &replace)) { replace_with = fs_uae_home_dir(); } else if (check_path_prefix(lower, "$home", &replace)) { replace_with = fs_uae_home_dir(); } else if (check_path_prefix(lower, "$app", &replace)) { replace_with = fs_uae_app_dir(); } else if (check_path_prefix(lower, "$exe", &replace)) { replace_with = fs_uae_exe_dir(); } else if (check_path_prefix(lower, "$fsuae", &replace)) { replace_with = fs_uae_base_dir(); } else if (check_path_prefix(lower, "$base", &replace)) { replace_with = fs_uae_base_dir(); } else if (check_path_prefix(lower, "$documents", &replace)) { replace_with = fs_uae_documents_dir(); } else if (check_path_prefix(lower, "$config", &replace)) { replace_with = g_fs_uae_config_dir_path; } else if (check_path_prefix(lower, "$temp", &replace)) { replace_with = fs_uae_temp_dir(); } free(lower); if (replace_with) { const char *src = path + replace; return g_build_filename(replace_with, src, NULL); } else { return g_strdup(path); } }
char *fs_uae_expand_path(const char* path) { char* lower = g_ascii_strdown(path, -1); int replace = 0; const char *replace_with = NULL; if (g_str_has_prefix(lower, "~/") || g_str_has_prefix(lower, "~\\")) { replace = 2; replace_with = fs_uae_home_dir(); } if (g_str_has_prefix(lower, "$home/") || g_str_has_prefix(lower, "$home\\")) { replace = 6; replace_with = fs_uae_home_dir(); } if (g_str_has_prefix(lower, "$app/") || g_str_has_prefix(lower, "$app\\")) { replace = 5; replace_with = fs_uae_app_dir(); } if (g_str_has_prefix(lower, "$exe/") || g_str_has_prefix(lower, "$exe\\")) { replace = 5; replace_with = fs_uae_exe_dir(); } if (g_str_has_prefix(lower, "$fsuae/") || g_str_has_prefix(lower, "$fsuae\\")) { replace = 7; replace_with = fs_uae_base_dir(); } if (g_str_has_prefix(lower, "$base/") || g_str_has_prefix(lower, "$base\\")) { replace = 6; replace_with = fs_uae_base_dir(); } if (g_str_has_prefix(lower, "$documents/") || g_str_has_prefix(lower, "$documents\\")) { replace = 11; replace_with = fs_uae_documents_dir(); } if (g_str_has_prefix(lower, "$config/") || g_str_has_prefix(lower, "$config\\")) { replace = 8; replace_with = g_fs_uae_config_dir_path; } free(lower); if (replace && replace_with) { const char *src = path + replace; return g_build_filename(replace_with, src, NULL); } else { return g_strdup(path); } }