static void window_themes_textinput(rct_window* w, rct_widgetindex widgetIndex, char* text) { if (text == nullptr || text[0] == 0) return; switch (widgetIndex) { case WIDX_THEMES_DUPLICATE_BUTTON: case WIDX_THEMES_RENAME_BUTTON: if (filename_valid_characters(text)) { if (theme_get_index_for_name(text) == SIZE_MAX) { if (widgetIndex == WIDX_THEMES_DUPLICATE_BUTTON) { theme_duplicate(text); } else { theme_rename(text); } window_invalidate(w); } else { context_show_error(STR_THEMES_ERR_NAME_ALREADY_EXISTS, STR_NONE); } } else { context_show_error(STR_ERROR_INVALID_CHARACTERS, STR_NONE); } break; } }
static void window_title_editor_rename_park(size_t index, const utf8 * name) { if (!filename_valid_characters(name)) { context_show_error(STR_ERROR_INVALID_CHARACTERS, STR_NONE); return; } for (size_t i = 0; i < _editingTitleSequence->NumSaves; i++) { if (i != index) { const utf8 * savePath = _editingTitleSequence->Saves[i]; if (_strcmpi(savePath, name) == 0) { context_show_error(STR_ERROR_EXISTING_NAME, STR_NONE); return; } } } if (TitleSequenceRenamePark(_editingTitleSequence, index, name)) { TitleSequenceSave(_editingTitleSequence); } }
static void window_themes_textinput(rct_window *w, rct_widgetindex widgetIndex, char *text) { if (text == NULL || text[0] == 0) return; switch (widgetIndex) { case WIDX_THEMES_DUPLICATE_BUTTON: case WIDX_THEMES_RENAME_BUTTON: if (filename_valid_characters(text)) { bool nameTaken = false; sint32 numAvailableThemes = (sint32)theme_manager_get_num_available_themes(); for (sint32 i = 0; i < numAvailableThemes; i++) { const utf8 * themeName = theme_manager_get_available_theme_name(i); if (strcmp(themeName, text) == 0) { if (widgetIndex != WIDX_THEMES_RENAME_BUTTON) { window_error_open(STR_THEMES_ERR_NAME_ALREADY_EXISTS, STR_NONE); } nameTaken = true; break; } } if (!nameTaken) { if (widgetIndex == WIDX_THEMES_DUPLICATE_BUTTON) { theme_duplicate(text); } else { theme_rename(text); } window_invalidate(w); } } else { window_error_open(STR_ERROR_INVALID_CHARACTERS, STR_NONE); } break; } }
void title_sequence_create_preset(const char *name) { if (filename_valid_characters(name) && !title_sequence_name_exists(name)) { int preset = gConfigTitleSequences.num_presets; gConfigTitleSequences.num_presets++; gConfigTitleSequences.presets = realloc(gConfigTitleSequences.presets, sizeof(title_sequence) * (size_t)gConfigTitleSequences.num_presets); safe_strncpy(gConfigTitleSequences.presets[preset].name, name, TITLE_SEQUENCE_NAME_SIZE); gConfigTitleSequences.presets[preset].path[0] = 0; gConfigTitleSequences.presets[preset].saves = malloc(0); gConfigTitleSequences.presets[preset].commands = malloc(0); gConfigTitleSequences.presets[preset].num_saves = 0; gConfigTitleSequences.presets[preset].num_commands = 0; // Create the folder utf8 path[MAX_PATH]; platform_get_user_directory(path, "title sequences"); strcat(path, gConfigTitleSequences.presets[preset].name); platform_file_delete(path); platform_ensure_directory_exists(path); title_sequence_save_preset_script(preset); gCurrentTitleSequence = preset; } }
void title_sequence_rename_save(int preset, int index, const char *newName) { if (preset >= TITLE_SEQUENCE_DEFAULT_PRESETS && preset < gConfigTitleSequences.num_presets && index >= 0 && index < gConfigTitleSequences.presets[preset].num_saves && filename_valid_characters(newName) && !title_sequence_save_exists(preset, newName)) { // Rename the save file char separator = platform_get_path_separator(); utf8 src[MAX_PATH], dest[MAX_PATH]; platform_get_user_directory(src, "title sequences"); platform_get_user_directory(dest, "title sequences"); strcat(src, gConfigTitleSequences.presets[preset].name); strcat(dest, gConfigTitleSequences.presets[preset].name); strncat(src, &separator, 1); strncat(dest, &separator, 1); strcat(src, gConfigTitleSequences.presets[preset].saves[index]); strcat(dest, newName); // Add the appropriate extension if needed char *extension = (char*)path_get_extension(newName); if (_stricmp(extension, ".sv6") != 0 && _stricmp(extension, ".sc6") != 0) strcat(dest, ".sv6"); platform_file_move(src, dest); safe_strncpy(gConfigTitleSequences.presets[preset].saves[index], 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[index], ".sv6"); title_sequence_save_preset_script(preset); } }
static void window_title_editor_textinput(rct_window * w, rct_widgetindex widgetIndex, char * text) { if (str_is_null_or_empty(text)) return; switch (widgetIndex) { case WIDX_TITLE_EDITOR_NEW_BUTTON: case WIDX_TITLE_EDITOR_DUPLICATE_BUTTON: case WIDX_TITLE_EDITOR_RENAME_BUTTON: if (filename_valid_characters(text)) { if (title_sequence_manager_get_index_for_name(text) == SIZE_MAX) { if (!title_sequence_manager_is_name_reserved(text)) { if (widgetIndex == WIDX_TITLE_EDITOR_NEW_BUTTON) { size_t newIndex = title_sequence_manager_create(text); window_title_editor_load_sequence(newIndex); } else if (widgetIndex == WIDX_TITLE_EDITOR_DUPLICATE_BUTTON) { size_t newIndex = title_sequence_manager_duplicate(_selectedTitleSequence, text); window_title_editor_load_sequence(newIndex); } else { size_t newIndex = title_sequence_manager_rename(_selectedTitleSequence, text); window_title_editor_load_sequence(newIndex); } config_save_default(); window_invalidate(w); } else { context_show_error(STR_ERROR_RESERVED_NAME, STR_NONE); } } else { context_show_error(STR_ERROR_EXISTING_NAME, STR_NONE); } } else { context_show_error(STR_ERROR_INVALID_CHARACTERS, STR_NONE); } break; case WIDX_TITLE_EDITOR_RENAME_SAVE: window_title_editor_rename_park(w->selected_list_item, text); break; } }
static void window_loadsave_textinput(rct_window *w, int widgetIndex, char *text) { char path[MAX_PATH]; int i, overwrite; if (text == NULL || text[0] == 0) return; if (gLoadSaveTitleSequenceSave) { if (filename_valid_characters(text)) { if (!title_sequence_save_exists(gCurrentTitleSequence, text)) { title_sequence_add_save(gCurrentTitleSequence, path, text); } else { window_error_open(5404, STR_NONE); } } else { window_error_open(5243, STR_NONE); } return; } safe_strcpy(path, _directory, sizeof(path)); strncat(path, text, sizeof(path) - strnlen(path, MAX_PATH) - 1); strncat(path, _extension, sizeof(path) - strnlen(path, MAX_PATH) - 1); overwrite = 0; for (i = 0; i < _listItemsCount; i++) { if (_stricmp(_listItems[i].path, path) == 0) { overwrite = 1; break; } } if (overwrite) window_overwrite_prompt_open(text, path); else window_loadsave_select(w, path); }
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"); } }
void title_sequence_rename_preset(int preset, const char *newName) { if (preset >= TITLE_SEQUENCE_DEFAULT_PRESETS && preset < gConfigTitleSequences.num_presets && filename_valid_characters(newName) && !title_sequence_name_exists(newName)) { // Rename the folder utf8 src[MAX_PATH], dest[MAX_PATH]; platform_get_user_directory(src, "title sequences"); platform_get_user_directory(dest, "title sequences"); strcat(src, gConfigTitleSequences.presets[preset].name); strcat(dest, newName); platform_file_move(src, dest); safe_strncpy(gConfigTitleSequences.presets[preset].name, newName, TITLE_SEQUENCE_NAME_SIZE); // Rename the config preset name if needed if (preset == gCurrentPreviewTitleSequence) { gConfigInterface.current_title_sequence_preset = gConfigTitleSequences.presets[preset].name; } } }
void title_sequence_duplicate_preset(int duplicate, const char *name) { if (duplicate >= 0 && duplicate < gConfigTitleSequences.num_presets && filename_valid_characters(name) && !title_sequence_name_exists(name)) { int preset = gConfigTitleSequences.num_presets; gConfigTitleSequences.num_presets++; gConfigTitleSequences.presets = realloc(gConfigTitleSequences.presets, sizeof(title_sequence) * (size_t)gConfigTitleSequences.num_presets); safe_strncpy(gConfigTitleSequences.presets[preset].name, name, TITLE_SEQUENCE_NAME_SIZE); gConfigTitleSequences.presets[preset].path[0] = 0; size_t savesSize = sizeof(char[TITLE_SEQUENCE_MAX_SAVE_LENGTH]) * gConfigTitleSequences.presets[duplicate].num_saves; size_t commandsSize = sizeof(title_command) * gConfigTitleSequences.presets[duplicate].num_commands; gConfigTitleSequences.presets[preset].saves = malloc(savesSize); gConfigTitleSequences.presets[preset].commands = malloc(commandsSize); memcpy(gConfigTitleSequences.presets[preset].saves, gConfigTitleSequences.presets[duplicate].saves, savesSize); memcpy(gConfigTitleSequences.presets[preset].commands, gConfigTitleSequences.presets[duplicate].commands, commandsSize); gConfigTitleSequences.presets[preset].num_saves = gConfigTitleSequences.presets[duplicate].num_saves; gConfigTitleSequences.presets[preset].num_commands = gConfigTitleSequences.presets[duplicate].num_commands; bool loadmm = false; for (int i = 0; i < gConfigTitleSequences.presets[preset].num_commands; i++) { if (gConfigTitleSequences.presets[preset].commands[i].command == TITLE_SCRIPT_LOADMM) { loadmm = true; gConfigTitleSequences.presets[preset].commands[i].command = TITLE_SCRIPT_LOAD; gConfigTitleSequences.presets[preset].commands[i].saveIndex = gConfigTitleSequences.presets[duplicate].num_saves; } } // Create the folder utf8 path[MAX_PATH], srcPath[MAX_PATH]; platform_get_user_directory(path, "title sequences"); strcat(path, gConfigTitleSequences.presets[preset].name); platform_file_delete(path); platform_ensure_directory_exists(path); // Copy the saves char separator = platform_get_path_separator(); for (int i = 0; i < gConfigTitleSequences.presets[preset].num_saves; i++) { if (gConfigTitleSequences.presets[duplicate].path[0]) { safe_strncpy(srcPath, gConfigTitleSequences.presets[duplicate].path, MAX_PATH); strcat(srcPath, gConfigTitleSequences.presets[duplicate].saves[i]); } else { platform_get_user_directory(srcPath, "title sequences"); strcat(srcPath, gConfigTitleSequences.presets[duplicate].name); strncat(srcPath, &separator, 1); strcat(srcPath, gConfigTitleSequences.presets[duplicate].saves[i]); } platform_get_user_directory(path, "title sequences"); strcat(path, gConfigTitleSequences.presets[preset].name); strncat(path, &separator, 1); strcat(path, gConfigTitleSequences.presets[preset].saves[i]); platform_file_copy(srcPath, path, false); } if (loadmm) { title_sequence_add_save(preset, get_file_path(PATH_ID_SIXFLAGS_MAGICMOUNTAIN), "Six Flags Magic Mountain.SC6"); } title_sequence_save_preset_script(preset); gCurrentTitleSequence = preset; } }