bool cfgOpen() { const char* filename = "/emu.cfg"; string config_path_read = get_readonly_config_path(filename); cfgPath = get_writable_config_path(filename); FILE* cfgfile = fopen(config_path_read.c_str(),"r"); if(cfgfile != NULL) { cfgdb.parse(cfgfile); fclose(cfgfile); } else { // Config file can't be opened int error_code = errno; printf("Warning: Unable to open the config file '%s' for reading (%s)\n", config_path_read.c_str(), strerror(error_code)); if (error_code == ENOENT || cfgPath != config_path_read) { // Config file didn't exist printf("Creating new empty config file at '%s'\n", cfgPath.c_str()); savecfgf(); } else { // There was some other error (may be a permissions problem or something like that) save_config = false; } } return true; }
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_config(JNIEnv *env,jobject obj,jstring dirName) { // Set home directory based on User config const char* D = dirName? env->GetStringUTFChars(dirName,0):0; set_user_config_dir(D); set_user_data_dir(D); printf("Config dir is: %s\n", get_writable_config_path("/").c_str()); printf("Data dir is: %s\n", get_writable_data_path("/").c_str()); env->ReleaseStringUTFChars(dirName,D); }
string get_readonly_config_path(const string& filename) { string user_filepath = get_writable_config_path(filename); if(file_exists(user_filepath)) { return user_filepath; } string filepath; for (unsigned int i = 0; i < system_config_dirs.size(); i++) { filepath = system_config_dirs[i] + filename; if (file_exists(filepath)) { return filepath; } } // Not found, so we return the user variant return user_filepath; }