summary refs log tree commit diff
path: root/freecell.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-03-28 20:41:12 -0400
committerJune McEnroe <june@causal.agency>2019-03-28 20:41:12 -0400
commit8edec29c784f2ac4d1ab276e4bc901af924ebd56 (patch)
tree71206c7e36a87969e1804798288a8fd24255dcff /freecell.c
parentSimplify (sort of) Cards API and add FreeCell loading (diff)
downloadwep-8edec29c784f2ac4d1ab276e4bc901af924ebd56.tar.gz
wep-8edec29c784f2ac4d1ab276e4bc901af924ebd56.zip
Factor out path searching
Diffstat (limited to '')
-rw-r--r--freecell.c31
1 files changed, 7 insertions, 24 deletions
diff --git a/freecell.c b/freecell.c
index e8b41f6..f480bda 100644
--- a/freecell.c
+++ b/freecell.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]))
@@ -274,7 +275,6 @@ static bool mouseButtonUp(SDL_MouseButtonEvent button) {
 	return false;
 }
 
-static SDL_Window *window;
 static SDL_Renderer *render;
 
 static void renderOutlines(void) {
@@ -309,7 +309,7 @@ static void renderList(SDL_Texture **textures, 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);
@@ -319,32 +319,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_Empty];
 	int error = Cards_LoadCards(
@@ -354,6 +336,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