bool platform_original_game_data_exists(const utf8 *path) { char buffer[MAX_PATH]; platform_utf8_to_multibyte(path, buffer, MAX_PATH); char checkPath[MAX_PATH]; safe_strcpy(checkPath, buffer, MAX_PATH); safe_strcat_path(checkPath, "Data", MAX_PATH); safe_strcat_path(checkPath, "g1.dat", MAX_PATH); return platform_file_exists(checkPath); }
static void openrct2_copy_files_over(const utf8 *originalDirectory, const utf8 *newDirectory, const utf8 *extension) { utf8 *ch, filter[MAX_PATH], oldPath[MAX_PATH], newPath[MAX_PATH]; int fileEnumHandle; file_info fileInfo; if (!platform_ensure_directory_exists(newDirectory)) { log_error("Could not create directory %s.", newDirectory); return; } // Create filter path safe_strncpy(filter, originalDirectory, MAX_PATH); ch = strchr(filter, '*'); if (ch != NULL) *ch = 0; strcat(filter, "*"); strcat(filter, extension); fileEnumHandle = platform_enumerate_files_begin(filter); while (platform_enumerate_files_next(fileEnumHandle, &fileInfo)) { safe_strncpy(newPath, newDirectory, MAX_PATH); strcat(newPath, fileInfo.path); safe_strncpy(oldPath, originalDirectory, MAX_PATH); ch = strchr(oldPath, '*'); if (ch != NULL) *ch = 0; strcat(oldPath, fileInfo.path); if (!platform_file_exists(newPath)) platform_file_copy(oldPath, newPath, false); } platform_enumerate_files_end(fileEnumHandle); fileEnumHandle = platform_enumerate_directories_begin(originalDirectory); while (platform_enumerate_directories_next(fileEnumHandle, filter)) { safe_strncpy(newPath, newDirectory, MAX_PATH); strcat(newPath, filter); safe_strncpy(oldPath, originalDirectory, MAX_PATH); ch = strchr(oldPath, '*'); if (ch != NULL) *ch = 0; strcat(oldPath, filter); if (!platform_ensure_directory_exists(newPath)) { log_error("Could not create directory %s.", newPath); return; } openrct2_copy_files_over(oldPath, newPath, extension); } platform_enumerate_directories_end(fileEnumHandle); }
bool platform_original_game_data_exists(const utf8 *path) { wchar_t *wPath = utf8_to_widechar(path); int len = min(MAX_PATH, utf8_length(path)); char buffer[MAX_PATH]; wcstombs(buffer, wPath, len); buffer[len] = '\0'; free(wPath); char checkPath[MAX_PATH]; sprintf(checkPath, "%s%c%s%c%s", buffer, platform_get_path_separator(), "Data", platform_get_path_separator(), "g1.dat"); return platform_file_exists(checkPath); }
static int cmdline_for_none(const char **argv, int argc) { assert(argc >= 1); if (platform_file_exists(argv[0])) { gOpenRCT2StartupAction = STARTUP_ACTION_OPEN; safe_strncpy(gOpenRCT2StartupActionPath, argv[0], 512); return 0; } else { fprintf(stderr, "error: %s does not exist\n", argv[0]); return -1; } }
static int cmdline_for_bench_sprite_sort(int argc, const char** argv) { { // Register some basic "baseline" benchmark std::vector<paint_session> sessions(1); for (auto& ps : sessions[0].PaintStructs) { ps.basic.next_quadrant_ps = (paint_struct*)(std::size(sessions[0].PaintStructs)); } for (auto& quad : sessions[0].Quadrants) { quad = (paint_struct*)(std::size(sessions[0].Quadrants)); } benchmark::RegisterBenchmark("baseline", BM_paint_session_arrange, sessions); } // Google benchmark does stuff to argv. It doesn't modify the pointees, // but it wants to reorder the pointers, so present a copy of them. std::vector<char*> argv_for_benchmark; // argv[0] is expected to contain the binary name. It's only for logging purposes, don't bother. argv_for_benchmark.push_back(nullptr); // Extract file names from argument list. If there is no such file, consider it benchmark option. for (int i = 0; i < argc; i++) { if (platform_file_exists(argv[i])) { // Register benchmark for sv6 if valid std::vector<paint_session> sessions = extract_paint_session(argv[i]); if (!sessions.empty()) benchmark::RegisterBenchmark(argv[i], BM_paint_session_arrange, sessions); } else { argv_for_benchmark.push_back((char*)argv[i]); } } // Update argc with all the changes made argc = (int)argv_for_benchmark.size(); ::benchmark::Initialize(&argc, &argv_for_benchmark[0]); if (::benchmark::ReportUnrecognizedArguments(argc, &argv_for_benchmark[0])) return -1; ::benchmark::RunSpecifiedBenchmarks(); return 0; }
static exitcode_t HandleCommandSetRCT2(CommandLineArgEnumerator * enumerator) { exitcode_t result = CommandLine::HandleCommandDefault(); if (result != EXITCODE_CONTINUE) { return result; } // Get the path that was passed const utf8 * rawPath; if (!enumerator->TryPopString(&rawPath)) { Console::Error::WriteLine("Expected a path."); return EXITCODE_FAIL; } utf8 path[MAX_PATH]; Path::GetAbsolute(path, sizeof(path), rawPath); // Check if path exists Console::WriteLine("Checking path..."); if (!platform_directory_exists(path)) { Console::Error::WriteLine("The path '%s' does not exist", path); return EXITCODE_FAIL; } // Check if g1.dat exists (naive but good check) Console::WriteLine("Checking g1.dat..."); utf8 pathG1Check[MAX_PATH]; String::Set(pathG1Check, sizeof(pathG1Check), path); Path::Append(pathG1Check, sizeof(pathG1Check), "Data"); Path::Append(pathG1Check, sizeof(pathG1Check), "g1.dat"); if (!platform_file_exists(pathG1Check)) { Console::Error::WriteLine("RCT2 path not valid."); Console::Error::WriteLine("Unable to find %s.", pathG1Check); return EXITCODE_FAIL; } // Check user path that will contain the config utf8 userPath[MAX_PATH]; platform_resolve_user_data_path(); platform_get_user_directory(userPath, NULL, sizeof(userPath)); if (!platform_ensure_directory_exists(userPath)) { Console::Error::WriteLine("Unable to access or create directory '%s'.", userPath); return EXITCODE_FAIL; } // Update RCT2 path in config config_set_defaults(); config_open_default(); String::DiscardDuplicate(&gConfigGeneral.rct2_path, path); if (config_save_default()) { Console::WriteFormat("Updating RCT2 path to '%s'.", path); Console::WriteLine(); Console::WriteLine("Updated config.ini"); return EXITCODE_OK; } else { Console::Error::WriteLine("Unable to update config.ini"); return EXITCODE_FAIL; } }
void LoadLegacyScores(const std::string &path) { if (!platform_file_exists(path.c_str())) { return; } bool highscoresDirty = false; try { auto fs = FileStream(path, FILE_MODE_OPEN); if (fs.GetLength() <= 4) { // Initial value of scores for RCT2, just ignore return; } // Load header auto header = fs.ReadValue<rct_scenario_scores_header>(); for (uint32 i = 0; i < header.scenario_count; i++) { // Read legacy entry auto scBasic = fs.ReadValue<rct_scenario_basic>(); // Ignore non-completed scenarios if (scBasic.flags & SCENARIO_FLAGS_COMPLETED) { bool notFound = true; for (size_t i = 0; i < _highscores.size(); i++) { scenario_highscore_entry * highscore = _highscores[i]; if (String::Equals(scBasic.path, highscore->fileName, true)) { notFound = false; // Check if legacy highscore is better if (scBasic.company_value > highscore->company_value) { SafeFree(highscore->name); highscore->name = win1252_to_utf8_alloc(scBasic.completed_by, Util::CountOf(scBasic.completed_by)); highscore->company_value = scBasic.company_value; highscore->timestamp = DATETIME64_MIN; break; } } } if (notFound) { scenario_highscore_entry * highscore = InsertHighscore(); highscore->fileName = String::Duplicate(scBasic.path); highscore->name = win1252_to_utf8_alloc(scBasic.completed_by, Util::CountOf(scBasic.completed_by)); highscore->company_value = scBasic.company_value; highscore->timestamp = DATETIME64_MIN; } } } } catch (Exception ex) { Console::Error::WriteLine("Error reading legacy scenario scores file: '%s'", path.c_str()); } if (highscoresDirty) { SaveHighscores(); } }
void title_sequence_add_save(int preset, const char *path, const char *newName) { utf8 newPath[MAX_PATH]; char *extension = (char*)path_get_extension(newName); safe_strncpy(newPath, newName, MAX_PATH); if (_stricmp(extension, ".sv6") != 0 && _stricmp(extension, ".sc6") != 0) strcat(newPath, ".sv6"); if (preset >= TITLE_SEQUENCE_DEFAULT_PRESETS && preset < gConfigTitleSequences.num_presets && filename_valid_characters(newPath) && !title_sequence_save_exists(preset, newPath) && platform_file_exists(path)) { // Copy the save file char separator = platform_get_path_separator(); platform_get_user_directory(newPath, "title sequences"); strcat(newPath, gConfigTitleSequences.presets[preset].name); strncat(newPath, &separator, 1); strcat(newPath, newName); // Add the appropriate extension if needed if (_stricmp(extension, ".sv6") != 0 && _stricmp(extension, ".sc6") != 0) strcat(newPath, ".sv6"); platform_file_copy(path, newPath, false); gConfigTitleSequences.presets[preset].num_saves++; gConfigTitleSequences.presets[preset].saves = realloc(gConfigTitleSequences.presets[preset].saves, sizeof(char[TITLE_SEQUENCE_MAX_SAVE_LENGTH]) * (size_t)gConfigTitleSequences.presets[preset].num_saves); safe_strncpy(gConfigTitleSequences.presets[preset].saves[gConfigTitleSequences.presets[preset].num_saves - 1], newName, TITLE_SEQUENCE_MAX_SAVE_LENGTH); // Add the appropriate extension if needed if (_stricmp(extension, ".sv6") != 0 && _stricmp(extension, ".sc6") != 0) strcat(gConfigTitleSequences.presets[preset].saves[gConfigTitleSequences.presets[preset].num_saves - 1], ".sv6"); } }