shithub: cstory

Download patch

ref: 00d016183268476ec6be3572af26d7349e5a92bc
parent: 657b586cd1091074b74ec929fdb981165d15beb5
author: Clownacy <Clownacy@users.noreply.github.com>
date: Tue Sep 10 09:27:44 EDT 2019

Make DoConfig use the Config.dat in its directory

This is accurate to how the original DoConfig does it.

--- a/DoConfig/DoConfig.cpp
+++ b/DoConfig/DoConfig.cpp
@@ -4,7 +4,9 @@
  * To Public License, Version 2, as published by Sam Hocevar. See
  * http://sam.zoy.org/wtfpl/COPYING for more details. */
 
+#include <cstdio>
 #include <cstdlib>
+#include <cstring>
 #include <fstream>
 #include "FL/Fl.H"
 #include "FL/Fl_Window.H"
@@ -42,6 +44,8 @@
 		Fl_Group *label;
 };
 
+static char config_path[FILENAME_MAX];
+
 static data config = {MAGIC, FONT};
 
 static unsigned long CharsToLong(unsigned char *chars)
@@ -113,7 +117,7 @@
 
 void read_Config(){
 	std::fstream fd;
-	fd.open("Config.dat", std::ios::in | std::ios::binary);
+	fd.open(config_path, std::ios::in | std::ios::binary);
 	fd.read((char*)&config, sizeof(config));
 	fd.close();
 	if (CharsToLong(config.move) == 0){
@@ -157,12 +161,29 @@
 		LongToChars(button_lookup[joyRows[i]->value()]+1, config.buttons[i]);
 	}
 	std::fstream fd;
-	fd.open("Config.dat", std::ios::out | std::ios::binary);
+	fd.open(config_path, std::ios::out | std::ios::binary);
 	fd.write((char*)&config, sizeof(config));
 	fd.close();
 	exit(0);
 }
 int main(int argc, char* argv[]){
+	strcpy(config_path, argv[0]);
+
+	for (size_t i = strlen(config_path); ; --i)
+	{
+		if (i == 0)
+		{
+			strcpy(config_path, "Config.dat");
+			break;
+		}
+		else if (config_path[i] == '\\' || config_path[i] == '/')
+		{
+			config_path[i] = '\0';
+			strcat(config_path, "/Config.dat");
+			break;
+		}
+	}
+
 	Fl_Window *mainw = new Fl_Window(400, 380, "DoConfig - Doukutsu Monogatari Settings");
 
 	Fl_Group *movegroup = new Fl_Group(10, 10, 185, 50);
--