about summary refs log tree commit diff
path: root/sol.c
diff options
context:
space:
mode:
Diffstat (limited to 'sol.c')
-rw-r--r--sol.c31
1 files changed, 7 insertions, 24 deletions
diff --git a/sol.c b/sol.c
index a2bd7c3..f02e4a1 100644
--- a/sol.c
+++ b/sol.c
@@ -22,6 +22,7 @@
 
 #include "cards.h"
 #include "layout.h"
+#include "path.h"
 #include "stack.h"
 
 #define ARRAY_LEN(a) (sizeof(a) / sizeof((a)[0]))
@@ -301,7 +302,6 @@ static bool mouseMotion(SDL_MouseMotionEvent motion) {
 	return true;
 }
 
-static SDL_Window *window;
 static SDL_Renderer *render;
 static SDL_Texture *textures[Cards_CardCount];
 
@@ -315,7 +315,7 @@ static void renderList(const struct List *list) {
 
 static void err(const char *title) {
 	int error = SDL_ShowSimpleMessageBox(
-		SDL_MESSAGEBOX_ERROR, title, SDL_GetError(), window
+		SDL_MESSAGEBOX_ERROR, title, SDL_GetError(), NULL
 	);
 	if (error) fprintf(stderr, "%s\n", SDL_GetError());
 	exit(EXIT_FAILURE);
@@ -325,32 +325,14 @@ 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");
 
-	const char *paths[] = { prefPath, basePath, "" };
-	const char *names[] = { "CARDS.DLL", "SOL.EXE", "cards.dll" };
+	char *prefPath = SDL_GetPrefPath("Causal Agency", "Cards");
+	if (!prefPath) err("SDL_GetPrefPath");
 
-	SDL_RWops *rw = NULL;
-	for (uint i = 0; !rw && i < ARRAY_LEN(paths); ++i) {
-		for (uint j = 0; !rw && j < ARRAY_LEN(names); ++j) {
-			char path[1024];
-			snprintf(path, sizeof(path), "%s%s", paths[i], names[j]);
-			rw = SDL_RWFromFile(path, "rb");
-		}
-	}
-	if (!rw) {
-		char msg[4096];
-		snprintf(
-			msg, sizeof(msg), "CARDS.DLL or SOL.EXE not found in:\n%s\n%s",
-			prefPath, basePath
-		);
-		SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Cards", msg, NULL);
-		return EXIT_FAILURE;
-	}
+	SDL_RWops *rw = pathCards(basePath, prefPath);
+	if (!rw) return EXIT_FAILURE;
 
 	SDL_Surface *surfaces[Cards_CardCount];
 	int error = Cards_LoadCards(
@@ -360,6 +342,7 @@ int main(void) {
 	if (error) err("Cards_LoadCards");
 	SDL_RWclose(rw);
 
+	SDL_Window *window;
 	error = SDL_CreateWindowAndRenderer(
 		WindowWidth, WindowHeight, SDL_WINDOW_ALLOW_HIGHDPI,
 		&window, &render