summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-03-24 00:57:52 -0400
committerJune McEnroe <june@causal.agency>2019-03-24 00:57:52 -0400
commite8de0eae2efc768032a47560ddcfe99609e3249f (patch)
tree3f643b8a6ea95929b5e2ca2143e71e8fc2291869
parentUse SDL_ShowSimpleMessageBox for errors (diff)
downloadwep-e8de0eae2efc768032a47560ddcfe99609e3249f.tar.gz
wep-e8de0eae2efc768032a47560ddcfe99609e3249f.zip
Search pref path, base path for CARDS.DLL, SOL.EXE
-rw-r--r--sol.c43
1 files changed, 33 insertions, 10 deletions
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;