From ffe11c695e5d778f67b2844a152ca8f80e2268d9 Mon Sep 17 00:00:00 2001 From: kichikuou Date: Fri, 3 Jan 2025 12:27:41 +0900 Subject: [PATCH] Reorganize initialization error reporting - Invalid game id -> sys_error() in GameId::GameId() - Unknown crc32 -> SDL_ShowSimpleMessageBox() in GameId::GameId() - Cannot open ADISK.DAT -> sys_error() in NACT::NACT() --- src/sdlmain.cpp | 10 ---------- src/sys/dri.h | 1 + src/sys/game_id.cpp | 11 ++++++++++- src/sys/nact.cpp | 2 ++ src/sys/scenario.h | 1 + 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/sdlmain.cpp b/src/sdlmain.cpp index de6a9b4..e57813d 100644 --- a/src/sdlmain.cpp +++ b/src/sdlmain.cpp @@ -31,13 +31,6 @@ SDL_Window* create_window(const GameId& game_id) if (game_id.title) { title += ": "; title += game_id.title; - } else { - SDL_ShowSimpleMessageBox( - SDL_MESSAGEBOX_WARNING, "system3", - "Unable to determine game ID.\n" - "If you are running a modified game, please specify 'game = ' in system3.ini.\n" - "See README.md for more information.", - NULL); } SDL_Init(SDL_INIT_VIDEO); @@ -81,9 +74,6 @@ int main(int argc, char *argv[]) return 0; } GameId game_id(config); - if (!game_id.is_valid()) { - sys_error("No game files in the current directory."); - } g_window = create_window(game_id); g_renderer = SDL_CreateRenderer(g_window, -1, 0); diff --git a/src/sys/dri.h b/src/sys/dri.h index b40579d..e116421 100644 --- a/src/sys/dri.h +++ b/src/sys/dri.h @@ -17,6 +17,7 @@ class Dri { public: void open(const char* file_name); std::vector load(int page); + bool loaded() const { return !link_table.empty(); } static std::vector load_mda(const GameId& game_id, int page); diff --git a/src/sys/game_id.cpp b/src/sys/game_id.cpp index 637c736..71870fd 100644 --- a/src/sys/game_id.cpp +++ b/src/sys/game_id.cpp @@ -197,12 +197,21 @@ GameId::GameId(const Config& config) break; } } + if (!entry) + sys_error("Unknown game ID: %s", config.game_id.c_str()); } else { uint32_t crc32_a = calc_crc32("ADISK.DAT"); uint32_t crc32_b = calc_crc32("BDISK.DAT"); entry = lookup(crc32_a, crc32_b); - if (!entry) + if (crc32_a && !entry) { WARNING("Cannot determine game id. crc32_a: %08x, crc32_b: %08x", crc32_a, crc32_b); + SDL_ShowSimpleMessageBox( + SDL_MESSAGEBOX_WARNING, "system3", + "Unable to determine game ID.\n" + "If you are running a modified game, please specify 'game = ' in system3.ini.\n" + "See README.md for more information.", + NULL); + } } if (entry) { game = entry->game; diff --git a/src/sys/nact.cpp b/src/sys/nact.cpp index a959120..dd56539 100644 --- a/src/sys/nact.cpp +++ b/src/sys/nact.cpp @@ -53,6 +53,8 @@ NACT::NACT(const Config& config, const GameId& game_id) sco.open("AGAME.DAT"); else sco.open("ADISK.DAT"); + if (!sco.loaded()) + sys_error("Cannot open scenario file"); sco.page_jump(0, 2); // 各種クラス生成 diff --git a/src/sys/scenario.h b/src/sys/scenario.h index 8900fe3..45fe4a9 100644 --- a/src/sys/scenario.h +++ b/src/sys/scenario.h @@ -11,6 +11,7 @@ class Encoding; class Scenario { public: void open(const char* file_name) { adisk.open(file_name); } + bool loaded() const { return adisk.loaded(); } void page_jump(int page, int addr); int default_addr() { return data_[0] | data_[1] << 8; }