scenario_index_entry CreateNewScenarioEntry(const utf8 * path, uint64 timestamp, rct_s6_info * s6Info) { scenario_index_entry entry = { 0 }; // Set new entry String::Set(entry.path, sizeof(entry.path), path); entry.timestamp = timestamp; entry.category = s6Info->category; entry.objective_type = s6Info->objective_type; entry.objective_arg_1 = s6Info->objective_arg_1; entry.objective_arg_2 = s6Info->objective_arg_2; entry.objective_arg_3 = s6Info->objective_arg_3; entry.highscore = nullptr; String::Set(entry.name, sizeof(entry.name), s6Info->name); String::Set(entry.details, sizeof(entry.details), s6Info->details); // Normalise the name to make the scenario as recognisable as possible. ScenarioSources::NormaliseName(entry.name, sizeof(entry.name), entry.name); // Look up and store information regarding the origins of this scenario. source_desc desc; if (ScenarioSources::TryGetByName(entry.name, &desc)) { entry.sc_id = desc.id; entry.source_index = desc.index; entry.source_game = desc.source; entry.category = desc.category; } else { entry.sc_id = SC_UNIDENTIFIED; entry.source_index = -1; if (entry.category == SCENARIO_CATEGORY_REAL) { entry.source_game = SCENARIO_SOURCE_REAL; } else { entry.source_game = SCENARIO_SOURCE_OTHER; } } scenario_translate(&entry, &s6Info->entry); return entry; }
static void scenario_list_add(const utf8 *path, uint64 timestamp) { // Load the basic scenario information rct_s6_header s6Header; rct_s6_info s6Info; if (!scenario_load_basic(path, &s6Header, &s6Info)) { return; } scenario_index_entry *newEntry = NULL; const utf8 *filename = path_get_filename(path); scenario_index_entry *existingEntry = scenario_list_find_by_filename(filename); if (existingEntry != NULL) { bool bail = false; const utf8 *conflictPath; if (existingEntry->timestamp > timestamp) { // Existing entry is more recent conflictPath = existingEntry->path; // Overwrite existing entry with this one newEntry = existingEntry; } else { // This entry is more recent conflictPath = path; bail = true; } printf("Scenario conflict: '%s' ignored because it is newer.\n", conflictPath); if (bail) { return; } } if (newEntry == NULL) { // Increase list size if (gScenarioListCount == gScenarioListCapacity) { gScenarioListCapacity = max(8, gScenarioListCapacity * 2); gScenarioList = (scenario_index_entry*)realloc(gScenarioList, gScenarioListCapacity * sizeof(scenario_index_entry)); } newEntry = &gScenarioList[gScenarioListCount]; gScenarioListCount++; } // Set new entry safe_strcpy(newEntry->path, path, sizeof(newEntry->path)); newEntry->timestamp = timestamp; newEntry->category = s6Info.category; newEntry->objective_type = s6Info.objective_type; newEntry->objective_arg_1 = s6Info.objective_arg_1; newEntry->objective_arg_2 = s6Info.objective_arg_2; newEntry->objective_arg_3 = s6Info.objective_arg_3; newEntry->highscore = NULL; safe_strcpy(newEntry->name, s6Info.name, sizeof(newEntry->name)); safe_strcpy(newEntry->details, s6Info.details, sizeof(newEntry->details)); // Normalise the name to make the scenario as recognisable as possible. scenario_normalise_name(newEntry->name); // Look up and store information regarding the origins of this scenario. source_desc desc; if (scenario_get_source_desc(newEntry->name, &desc)) { newEntry->sc_id = desc.id; newEntry->source_index = desc.index; newEntry->source_game = desc.source; newEntry->category = desc.category; } else { newEntry->sc_id = SC_UNIDENTIFIED; newEntry->source_index = -1; if (newEntry->category == SCENARIO_CATEGORY_REAL) { newEntry->source_game = SCENARIO_SOURCE_REAL; } else { newEntry->source_game = SCENARIO_SOURCE_OTHER; } } scenario_translate(newEntry, &s6Info.entry); }