diff --git a/src/main.c b/src/main.c index a67f506..a18cb9b 100644 --- a/src/main.c +++ b/src/main.c @@ -664,6 +664,9 @@ static LSAppWindow* ls_app_window_new(LSApp* app) static void ls_app_window_open(LSAppWindow* win, const char* file) { + char* error_msg = NULL; + GtkWidget* error_popup; + if (win->timer) { ls_app_window_clear_game(win); ls_timer_release(win->timer); @@ -673,8 +676,22 @@ static void ls_app_window_open(LSAppWindow* win, const char* file) ls_game_release(win->game); win->game = 0; } - if (ls_game_create(&win->game, file)) { + if (ls_game_create(&win->game, file, &error_msg)) { win->game = 0; + if (error_msg) { + error_popup = gtk_message_dialog_new( + GTK_WINDOW(win), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_INFO, + GTK_BUTTONS_OK, + "JSON parse error: %s\n%s", + error_msg, + file); + gtk_dialog_run(GTK_DIALOG(error_popup)); + + free(error_msg); + gtk_widget_destroy(error_popup); + } } else if (ls_timer_create(&win->timer, win->game)) { win->timer = 0; } else { diff --git a/src/timer.c b/src/timer.c index b86415b..a3c4888 100644 --- a/src/timer.c +++ b/src/timer.c @@ -154,7 +154,7 @@ void ls_game_release(ls_game* game) } } -int ls_game_create(ls_game** game_ptr, const char* path) +int ls_game_create(ls_game** game_ptr, const char* path, char** error_msg) { int error = 0; ls_game* game; @@ -178,6 +178,9 @@ int ls_game_create(ls_game** game_ptr, const char* path) json = json_load_file(game->path, 0, &json_error); if (!json) { error = 1; + size_t msg_len = snprintf(NULL, 0, "%s (%d:%d)", json_error.text, json_error.line, json_error.column); + *error_msg = calloc(msg_len + 1, sizeof(char)); + sprintf(*error_msg, "%s (%d:%d)", json_error.text, json_error.line, json_error.column); goto game_create_done; } // copy title diff --git a/src/timer.h b/src/timer.h index f6e7ef4..1b290f3 100644 --- a/src/timer.h +++ b/src/timer.h @@ -59,7 +59,7 @@ void ls_split_string(char* string, long long time); void ls_delta_string(char* string, long long time); -int ls_game_create(ls_game** game_ptr, const char* path); +int ls_game_create(ls_game** game_ptr, const char* path, char** error_msg); void ls_game_update_splits(ls_game* game, const ls_timer* timer);