1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-24 00:03:11 +01:00

use native line endings for config.ini and themes, closes #2678

This commit is contained in:
IntelOrca
2016-01-09 22:43:12 +00:00
parent 4425693ba2
commit 5796cf3053
4 changed files with 55 additions and 32 deletions

View File

@@ -331,6 +331,11 @@ static void rwopswritec(SDL_RWops *file, char c)
SDL_RWwrite(file, &c, 1, 1); SDL_RWwrite(file, &c, 1, 1);
} }
static void rwopswritestr(SDL_RWops *file, const char *str)
{
SDL_RWwrite(file, str, strlen(str), 1);
}
static void rwopsprintf(SDL_RWops *file, const char *format, ...) static void rwopsprintf(SDL_RWops *file, const char *format, ...)
{ {
va_list args; va_list args;
@@ -344,6 +349,11 @@ static void rwopsprintf(SDL_RWops *file, const char *format, ...)
va_end(args); va_end(args);
} }
static void rwopswritenewline(SDL_RWops *file)
{
rwopswritestr(file, platform_get_new_line());
}
void config_set_defaults() void config_set_defaults()
{ {
int i, j; int i, j;
@@ -478,24 +488,24 @@ bool config_save(const utf8string path)
config_section_definition *section = &_sectionDefinitions[i]; config_section_definition *section = &_sectionDefinitions[i];
rwopswritec(file, '['); rwopswritec(file, '[');
SDL_RWwrite(file, section->section_name, strlen(section->section_name), 1); rwopswritestr(file, section->section_name);
rwopswritec(file, ']'); rwopswritec(file, ']');
rwopswritec(file, '\n'); rwopswritenewline(file);
for (j = 0; j < section->property_definitions_count; j++) { for (j = 0; j < section->property_definitions_count; j++) {
config_property_definition *property = &section->property_definitions[j]; config_property_definition *property = &section->property_definitions[j];
SDL_RWwrite(file, property->property_name, strlen(property->property_name), 1); rwopswritestr(file, property->property_name);
SDL_RWwrite(file, " = ", 3, 1); rwopswritestr(file, " = ");
value = (value_union*)((size_t)section->base_address + (size_t)property->offset); value = (value_union*)((size_t)section->base_address + (size_t)property->offset);
if (property->enum_definitions != NULL) if (property->enum_definitions != NULL)
config_write_enum(file, property->type, value, property->enum_definitions); config_write_enum(file, property->type, value, property->enum_definitions);
else else
config_save_property_value(file, property->type, value); config_save_property_value(file, property->type, value);
rwopswritec(file, '\n'); rwopswritenewline(file);
} }
rwopswritec(file, '\n'); rwopswritenewline(file);
} }
SDL_RWclose(file); SDL_RWclose(file);
@@ -506,8 +516,8 @@ static void config_save_property_value(SDL_RWops *file, uint8 type, value_union
{ {
switch (type) { switch (type) {
case CONFIG_VALUE_TYPE_BOOLEAN: case CONFIG_VALUE_TYPE_BOOLEAN:
if (value->value_boolean) SDL_RWwrite(file, "true", 4, 1); if (value->value_boolean) rwopswritestr(file, "true");
else SDL_RWwrite(file, "false", 5, 1); else rwopswritestr(file, "false");
break; break;
case CONFIG_VALUE_TYPE_UINT8: case CONFIG_VALUE_TYPE_UINT8:
rwopsprintf(file, "%u", value->value_uint8); rwopsprintf(file, "%u", value->value_uint8);
@@ -535,8 +545,9 @@ static void config_save_property_value(SDL_RWops *file, uint8 type, value_union
break; break;
case CONFIG_VALUE_TYPE_STRING: case CONFIG_VALUE_TYPE_STRING:
rwopswritec(file, '"'); rwopswritec(file, '"');
if (value->value_string != NULL) if (value->value_string != NULL) {
SDL_RWwrite(file, value->value_string, strlen(value->value_string), 1); rwopswritestr(file, value->value_string);
}
rwopswritec(file, '"'); rwopswritec(file, '"');
break; break;
} }
@@ -728,7 +739,7 @@ static void config_write_enum(SDL_RWops *file, uint8 type, value_union *value, c
uint32 enumValue = (value->value_uint32) & ((1 << (_configValueTypeSize[type] * 8)) - 1); uint32 enumValue = (value->value_uint32) & ((1 << (_configValueTypeSize[type] * 8)) - 1);
while (enumDefinitions->key != NULL) { while (enumDefinitions->key != NULL) {
if (enumDefinitions->value.value_uint32 == enumValue) { if (enumDefinitions->value.value_uint32 == enumValue) {
SDL_RWwrite(file, enumDefinitions->key, strlen(enumDefinitions->key), 1); rwopswritestr(file, enumDefinitions->key);
return; return;
} }
enumDefinitions++; enumDefinitions++;
@@ -1231,15 +1242,15 @@ static bool themes_save(const_utf8string path, int preset)
theme_section_definition *section = &_themeSectionDefinitions[i]; theme_section_definition *section = &_themeSectionDefinitions[i];
rwopswritec(file, '['); rwopswritec(file, '[');
SDL_RWwrite(file, section->section_name, strlen(section->section_name), 1); rwopswritestr(file, section->section_name);
rwopswritec(file, ']'); rwopswritec(file, ']');
rwopswritec(file, '\n'); rwopswritenewline(file);
for (j = 0; j < section->property_definitions_count; j++) { for (j = 0; j < section->property_definitions_count; j++) {
theme_property_definition *property = &section->property_definitions[j]; theme_property_definition *property = &section->property_definitions[j];
SDL_RWwrite(file, property->property_name, strlen(property->property_name), 1); rwopswritestr(file, property->property_name);
SDL_RWwrite(file, " = ", 3, 1); rwopswritestr(file, " = ");
value = (value_union*)((size_t)&gConfigThemes.presets[preset] + (size_t)section->offset + (size_t)property->offset); value = (value_union*)((size_t)&gConfigThemes.presets[preset] + (size_t)section->offset + (size_t)property->offset);
@@ -1247,24 +1258,24 @@ static bool themes_save(const_utf8string path, int preset)
config_write_enum(file, property->type, value, property->enum_definitions); config_write_enum(file, property->type, value, property->enum_definitions);
else else
config_save_property_value(file, property->type, value); config_save_property_value(file, property->type, value);
rwopswritec(file, '\n'); rwopswritenewline(file);
} }
rwopswritec(file, '\n'); rwopswritenewline(file);
} }
for (i = 0; i < (int)gNumThemeWindows; i++) { for (i = 0; i < (int)gNumThemeWindows; i++) {
theme_section_definition *section = &_themeSectionDefinitions[0]; theme_section_definition *section = &_themeSectionDefinitions[0];
rwopswritec(file, '['); rwopswritec(file, '[');
SDL_RWwrite(file, gThemeWindowDefinitions[i].section_name, strlen(gThemeWindowDefinitions[i].section_name), 1); rwopswritestr(file, gThemeWindowDefinitions[i].section_name);
rwopswritec(file, ']'); rwopswritec(file, ']');
rwopswritec(file, '\n'); rwopswritenewline(file);
for (j = 0; j < section->property_definitions_count; j++) { for (j = 0; j < section->property_definitions_count; j++) {
theme_property_definition *property = &section->property_definitions[j]; theme_property_definition *property = &section->property_definitions[j];
SDL_RWwrite(file, property->property_name, strlen(property->property_name), 1); rwopswritestr(file, property->property_name);
SDL_RWwrite(file, " = ", 3, 1); rwopswritestr(file, " = ");
value = (value_union*)((size_t)gConfigThemes.presets[preset].windows + (size_t)(sizeof(theme_window) * i) + (size_t)property->offset); value = (value_union*)((size_t)gConfigThemes.presets[preset].windows + (size_t)(sizeof(theme_window) * i) + (size_t)property->offset);
@@ -1272,7 +1283,7 @@ static bool themes_save(const_utf8string path, int preset)
config_write_enum(file, property->type, value, property->enum_definitions); config_write_enum(file, property->type, value, property->enum_definitions);
else else
config_save_property_value(file, property->type, value); config_save_property_value(file, property->type, value);
rwopswritec(file, '\n'); rwopswritenewline(file);
} }
} }
@@ -1627,33 +1638,34 @@ void title_sequence_save_preset_script(int preset)
switch (command->command) { switch (command->command) {
case TITLE_SCRIPT_LOAD: case TITLE_SCRIPT_LOAD:
if (command->saveIndex == 0xFF) if (command->saveIndex == 0xFF)
rwopsprintf(file, "LOAD <No save file>\r\n"); rwopsprintf(file, "LOAD <No save file>");
else else
rwopsprintf(file, "LOAD %s\r\n", gConfigTitleSequences.presets[preset].saves[command->saveIndex]); rwopsprintf(file, "LOAD %s", gConfigTitleSequences.presets[preset].saves[command->saveIndex]);
break; break;
case TITLE_SCRIPT_LOCATION: case TITLE_SCRIPT_LOCATION:
rwopsprintf(file, "LOCATION %i %i\r\n", command->x, command->y); rwopsprintf(file, "LOCATION %i %i", command->x, command->y);
break; break;
case TITLE_SCRIPT_ROTATE: case TITLE_SCRIPT_ROTATE:
rwopsprintf(file, "ROTATE %i\r\n", command->rotations); rwopsprintf(file, "ROTATE %i", command->rotations);
break; break;
case TITLE_SCRIPT_ZOOM: case TITLE_SCRIPT_ZOOM:
rwopsprintf(file, "ZOOM %i\r\n", command->zoom); rwopsprintf(file, "ZOOM %i", command->zoom);
break; break;
case TITLE_SCRIPT_SPEED: case TITLE_SCRIPT_SPEED:
rwopsprintf(file, "SPEED %i\r\n", command->speed); rwopsprintf(file, "SPEED %i", command->speed);
break; break;
case TITLE_SCRIPT_WAIT: case TITLE_SCRIPT_WAIT:
rwopsprintf(file, "WAIT %i\r\n\r\n", command->seconds); rwopsprintf(file, "WAIT %i", command->seconds);
rwopswritenewline(file);
break; break;
case TITLE_SCRIPT_RESTART: case TITLE_SCRIPT_RESTART:
rwopsprintf(file, "RESTART\r\n"); rwopsprintf(file, "RESTART");
break; break;
case TITLE_SCRIPT_END: case TITLE_SCRIPT_END:
rwopsprintf(file, "END\r\n"); rwopsprintf(file, "END");
break; break;
} }
rwopswritenewline(file);
} }
SDL_RWclose(file); SDL_RWclose(file);

View File

@@ -125,6 +125,7 @@ void platform_get_time(rct2_time *out_time);
// Platform specific definitions // Platform specific definitions
void platform_get_exe_path(utf8 *outPath); void platform_get_exe_path(utf8 *outPath);
const char *platform_get_new_line();
char platform_get_path_separator(); char platform_get_path_separator();
bool platform_file_exists(const utf8 *path); bool platform_file_exists(const utf8 *path);
bool platform_directory_exists(const utf8 *path); bool platform_directory_exists(const utf8 *path);

View File

@@ -91,6 +91,11 @@ char platform_get_path_separator()
return '/'; return '/';
} }
const char *platform_get_new_line()
{
return "\n";
}
bool platform_file_exists(const utf8 *path) bool platform_file_exists(const utf8 *path)
{ {
wchar_t *wPath = utf8_to_widechar(path); wchar_t *wPath = utf8_to_widechar(path);

View File

@@ -148,6 +148,11 @@ char platform_get_path_separator()
return '\\'; return '\\';
} }
const char *platform_get_new_line()
{
return "\r\n";
}
bool platform_file_exists(const utf8 *path) bool platform_file_exists(const utf8 *path)
{ {
wchar_t *wPath = utf8_to_widechar(path); wchar_t *wPath = utf8_to_widechar(path);