From e8de0eae2efc768032a47560ddcfe99609e3249f Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Sun, 24 Mar 2019 00:57:52 -0400 Subject: Search pref path, base path for CARDS.DLL, SOL.EXE --- sol.c | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) (limited to 'sol.c') diff --git a/sol.c b/sol.c index 1f791c2..3aba0c5 100644 --- a/sol.c +++ b/sol.c @@ -369,6 +369,39 @@ int main(void) { if (SDL_Init(SDL_INIT_VIDEO) < 0) err("SDL_Init"); atexit(SDL_Quit); + char *prefPath = SDL_GetPrefPath("Causal Agency", "Cards"); + if (!prefPath) err("SDL_GetPrefPath"); + + char *basePath = SDL_GetBasePath(); + if (!basePath) err("SDL_GetBasePath"); + + char paths[4][1024]; + snprintf(paths[0], sizeof(paths[0]), "%sCARDS.DLL", prefPath); + snprintf(paths[1], sizeof(paths[1]), "%sSOL.EXE", prefPath); + snprintf(paths[2], sizeof(paths[2]), "%sCARDS.DLL", basePath); + snprintf(paths[3], sizeof(paths[3]), "%sSOL.EXE", basePath); + + SDL_RWops *rw; + for (uint i = 0; i < 4; ++i) { + rw = SDL_RWFromFile(paths[i], "rb"); + if (rw) break; + } + if (!rw) { + char buf[4096]; + snprintf( + buf, sizeof(buf), "CARDS.DLL not found in:\n%s\n%s", + prefPath, basePath + ); + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Cards", buf, NULL); + return EXIT_FAILURE; + } + + struct Cards *cards = Cards_Load( + rw, Cards_ColorKey | Cards_AlphaCorners | Cards_BlackBorders + ); + if (!cards) err("Cards_Load"); + SDL_RWclose(rw); + int error = SDL_CreateWindowAndRenderer( WindowWidth, WindowHeight, SDL_WINDOW_ALLOW_HIGHDPI, &window, &render @@ -388,16 +421,6 @@ int main(void) { ); } - // TODO: Path search. - SDL_RWops *rw = SDL_RWFromFile("CARDS.DLL", "rb"); - if (!rw) err("CARDS.DLL"); - - struct Cards *cards = Cards_Load( - rw, Cards_ColorKey | Cards_AlphaCorners | Cards_BlackBorders - ); - if (!cards) err("Cards_Load"); - SDL_RWclose(rw); - for (uint i = 0; i < Cards_Count; ++i) { textures[i] = NULL; if (!cards->surfaces[i]) continue; -- cgit 1.4.1