int config_read(config_t* cfg, const char *dir, const char *file) { char path[BUFSIZ]; if (config_get_default_path(cfg, path, BUFSIZ, dir, file) < 0) return -1; return config_read_file(cfg, path); }
IPlatformEnvironment * SetupEnvironment() { utf8 userPath[MAX_PATH]; platform_resolve_openrct_data_path(); platform_resolve_user_data_path(); platform_get_user_directory(userPath, NULL, sizeof(userPath)); if (!platform_ensure_directory_exists(userPath)) { Console::Error::WriteLine("Could not create user directory (do you have write access to your documents folder?)"); return nullptr; } openrct2_set_exe_path(); config_set_defaults(); if (!config_open_default()) { if (!config_find_or_browse_install_directory()) { gConfigGeneral.last_run_version = String::Duplicate(OPENRCT2_VERSION); config_save_default(); utf8 path[MAX_PATH]; config_get_default_path(path, sizeof(path)); Console::Error::WriteLine("An RCT2 install directory must be specified! Please edit \"game_path\" in %s.", path); return nullptr; } config_save_default(); } if (!rct2_init_directories()) { return nullptr; } if (!rct2_startup_checks()) { return nullptr; } utf8 path[260]; std::string basePaths[4]; basePaths[(size_t)DIRBASE::RCT1] = String::ToStd(gConfigGeneral.rct1_path); basePaths[(size_t)DIRBASE::RCT2] = String::ToStd(gConfigGeneral.rct2_path); platform_get_openrct_data_path(path, sizeof(path)); basePaths[(size_t)DIRBASE::OPENRCT2] = std::string(path); platform_get_user_directory(path, nullptr, sizeof(path)); basePaths[(size_t)DIRBASE::USER] = std::string(path); IPlatformEnvironment * env = CreatePlatformEnvironment(basePaths); return env; }
int config_write(config_t* cfg, const char *dir, const char *file) { char path[BUFSIZ]; if (config_get_default_path(cfg,path, BUFSIZ, dir, file) < 0) { config_set_strerror(cfg,"config_create_default(): %s\n", strerror(errno)); return -1; } if (mkdirs(path, S_IRWXU) < 0) { config_set_strerror(cfg,"config_create_default(): \"%s\": %s\n", path, strerror(errno)); return -1; } return config_write_file(cfg, path); }
/* * get_session_name * * Return allocated string with the session name found in the config * directory. */ char *get_session_name(void) { char *path, *session_name = NULL; /* Get path to config file */ path = config_get_default_path(); if (path == NULL) { goto error; } /* Get session name from config */ session_name = config_read_session_name(path); if (session_name == NULL) { goto error; } DBG2("Config file path found: %s", path); DBG("Session name found: %s", session_name); return session_name; error: return NULL; }