mirror of https://github.com/OpenRCT2/OpenRCT2.git
use log functions instead of printf and RCT2_ERROR (now removed)
This commit is contained in:
parent
949d195c95
commit
beb2b23afb
|
@ -43,7 +43,7 @@ void *gTitleMusicChannel = 0;
|
|||
void audio_init(int i)
|
||||
{
|
||||
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
|
||||
RCT2_ERROR("SDL_Init %s", SDL_GetError());
|
||||
log_fatal("SDL_Init %s", SDL_GetError());
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ static int screenshot_get_next_path(char *path, int format)
|
|||
|
||||
platform_get_user_directory(screenshotPath, "screenshot");
|
||||
if (!platform_ensure_directory_exists(screenshotPath)) {
|
||||
fprintf(stderr, "Unable to save screenshots in OpenRCT2 screenshot directory.\n");
|
||||
log_error("Unable to save screenshots in OpenRCT2 screenshot directory.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -93,7 +93,7 @@ static int screenshot_get_next_path(char *path, int format)
|
|||
}
|
||||
}
|
||||
|
||||
fprintf(stderr, "You have too many saved screenshots.\n");
|
||||
log_error("You have too many saved screenshots.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -118,7 +118,7 @@ int platform_lock_single_instance()
|
|||
// Create new mutex
|
||||
status = CreateMutex(NULL, FALSE, SINGLE_INSTANCE_MUTEX_NAME);
|
||||
if (status == NULL)
|
||||
fprintf(stderr, "unable to create mutex\n");
|
||||
log_error("unable to create mutex\n");
|
||||
|
||||
return 1;
|
||||
} else {
|
||||
|
|
|
@ -378,7 +378,7 @@ const char *get_file_path(int pathId)
|
|||
{
|
||||
if (strlen(path) >= MAX_PATH - 1)
|
||||
{
|
||||
RCT2_ERROR("Path for %s too long", file_paths[pathId]);
|
||||
log_error("Path for %s too long", file_paths[pathId]);
|
||||
path[0] = '\0';
|
||||
return path;
|
||||
}
|
||||
|
@ -387,9 +387,8 @@ const char *get_file_path(int pathId)
|
|||
}
|
||||
|
||||
// Concatenate file path
|
||||
if (strlen(path) + strlen(file_paths[pathId]) > MAX_PATH)
|
||||
{
|
||||
RCT2_ERROR("Path for %s too long", file_paths[pathId]);
|
||||
if (strlen(path) + strlen(file_paths[pathId]) > MAX_PATH) {
|
||||
log_error("Path for %s too long", file_paths[pathId]);
|
||||
path[0] = '\0';
|
||||
return path;
|
||||
}
|
||||
|
|
|
@ -68,12 +68,6 @@ typedef utf16* utf16string;
|
|||
|
||||
#define countof(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define RCT2_ERROR(format,...) fprintf(stderr, "ERROR %s:%s():%d: " format "\n", __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__);
|
||||
#else
|
||||
#define RCT2_ERROR(format,...) fprintf(stderr, "ERROR %s:%s():%d: " format "\n", __FILE__, __func__, __LINE__, ## __VA_ARGS__);
|
||||
#endif
|
||||
|
||||
#ifndef _MSC_VER
|
||||
// use similar struct packing as MSVC for our structs
|
||||
#pragma pack(1)
|
||||
|
|
|
@ -184,7 +184,7 @@ static int scenario_scores_load()
|
|||
if (file == NULL) {
|
||||
file = fopen(get_file_path(PATH_ID_SCORES), "rb");
|
||||
if (file == NULL) {
|
||||
RCT2_ERROR("Unable to load scenario scores.");
|
||||
log_error("Unable to load scenario scores.");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ static int scenario_scores_load()
|
|||
rct_scenario_scores_header header;
|
||||
if (fread(&header, 16, 1, file) != 1) {
|
||||
fclose(file);
|
||||
RCT2_ERROR("Invalid header in scenario scores file.");
|
||||
log_error("Invalid header in scenario scores file.");
|
||||
return 0;
|
||||
}
|
||||
gScenarioListCount = header.scenario_count;
|
||||
|
@ -229,7 +229,7 @@ int scenario_scores_save()
|
|||
|
||||
file = fopen(scoresPath, "wb");
|
||||
if (file == NULL) {
|
||||
RCT2_ERROR("Unable to save scenario scores.");
|
||||
log_error("Unable to save scenario scores.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -89,7 +89,7 @@ int sawyercoding_read_chunk(FILE *file, uint8 *buffer)
|
|||
|
||||
// Read chunk header
|
||||
if (fread(&chunkHeader, sizeof(sawyercoding_chunk_header), 1, file) != 1) {
|
||||
RCT2_ERROR("Unable to read chunk header!");
|
||||
log_error("Unable to read chunk header!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -98,7 +98,7 @@ int sawyercoding_read_chunk(FILE *file, uint8 *buffer)
|
|||
// Read chunk data
|
||||
if (fread(src_buffer, chunkHeader.length, 1, file) != 1) {
|
||||
free(src_buffer);
|
||||
RCT2_ERROR("Unable to read chunk data!");
|
||||
log_error("Unable to read chunk data!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -120,7 +120,7 @@ int _type;
|
|||
static void window_loadsave_populate_list(int includeNewItem, bool browsable, const char *directory, const char *extension);
|
||||
static void window_loadsave_select(rct_window *w, const char *path);
|
||||
|
||||
static int hasExtension(char *path, char *extension);
|
||||
static int has_extension(char *path, char *extension);
|
||||
|
||||
static rct_window *window_overwrite_prompt_open(const char *name, const char *path);
|
||||
|
||||
|
@ -172,7 +172,7 @@ rct_window *window_loadsave_open(int type, char *defaultName)
|
|||
case LOADSAVETYPE_GAME:
|
||||
platform_get_user_directory(path, "save");
|
||||
if (!platform_ensure_directory_exists(path)) {
|
||||
fprintf(stderr, "Unable to create save directory.");
|
||||
log_error("Unable to create save directory.");
|
||||
window_close(w);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -182,7 +182,7 @@ rct_window *window_loadsave_open(int type, char *defaultName)
|
|||
case LOADSAVETYPE_LANDSCAPE:
|
||||
platform_get_user_directory(path, "landscape");
|
||||
if (!platform_ensure_directory_exists(path)) {
|
||||
fprintf(stderr, "Unable to create landscapes directory.");
|
||||
log_error("Unable to create landscapes directory.");
|
||||
window_close(w);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -195,7 +195,7 @@ rct_window *window_loadsave_open(int type, char *defaultName)
|
|||
|
||||
platform_get_user_directory(path, "scenario");
|
||||
if (!platform_ensure_directory_exists(path)) {
|
||||
fprintf(stderr, "Unable to create scenarios directory.");
|
||||
log_error("Unable to create scenarios directory.");
|
||||
window_close(w);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -214,7 +214,7 @@ rct_window *window_loadsave_open(int type, char *defaultName)
|
|||
|
||||
platform_get_user_directory(path, "tracks");
|
||||
if (!platform_ensure_directory_exists(path)) {
|
||||
fprintf(stderr, "Unable to create tracks directory.");
|
||||
log_error("Unable to create tracks directory.");
|
||||
window_close(w);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -245,8 +245,10 @@ static void window_loadsave_close()
|
|||
|
||||
static void window_loadsave_mouseup()
|
||||
{
|
||||
short widgetIndex;
|
||||
rct_window *w;
|
||||
short widgetIndex;
|
||||
int result;
|
||||
char filename[MAX_PATH], filter[MAX_PATH];
|
||||
|
||||
window_widget_get_registers(w, widgetIndex);
|
||||
|
||||
|
@ -254,16 +256,11 @@ static void window_loadsave_mouseup()
|
|||
case WIDX_CLOSE:
|
||||
window_close(w);
|
||||
break;
|
||||
|
||||
case WIDX_BROWSE:
|
||||
{
|
||||
char filename[MAX_PATH], filter[MAX_PATH];
|
||||
int result;
|
||||
|
||||
strcpy(filename, _directory);
|
||||
if (_type & LOADSAVETYPE_SAVE){
|
||||
if (_type & LOADSAVETYPE_SAVE)
|
||||
strcat(filename, (char*)RCT2_ADDRESS_SCENARIO_NAME);
|
||||
}
|
||||
|
||||
memset(filter, '\0', MAX_PATH);
|
||||
strncpy(filter, "*", MAX_PATH);
|
||||
strncat(filter, _extension, MAX_PATH);
|
||||
|
@ -288,24 +285,22 @@ static void window_loadsave_mouseup()
|
|||
result = platform_open_common_file_dialog(1, (char*)language_get_string(1039), filename, filter, _extension);
|
||||
break;
|
||||
}
|
||||
if (result){
|
||||
if (!hasExtension(filename, _extension)){
|
||||
|
||||
if (result) {
|
||||
if (!has_extension(filename, _extension)) {
|
||||
strncat(filename, _extension, MAX_PATH);
|
||||
puts("added extension");
|
||||
}
|
||||
window_loadsave_select(w, filename);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int hasExtension(char *path, char *extension)
|
||||
static int has_extension(char *path, char *extension)
|
||||
{
|
||||
int extensionLength = strlen(extension);
|
||||
int pathLength = strlen(path);
|
||||
for (int u = 0; u < extensionLength; u++){
|
||||
printf("%c, %c\n", tolower(path[pathLength - extensionLength + u]), tolower(extension[u]));
|
||||
for (int u = 0; u < extensionLength; u++) {
|
||||
if (tolower(path[pathLength - extensionLength + u]) != tolower(extension[u]))
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue