ref: 6bd8b1185e7a9a1d80b4d9a10fbf6e04b767de4c
parent: 0184245d3352001a72bbc12386d7882cc23eb778
author: Snesrev <snesrev@protonmail.com>
date: Sun Sep 11 11:04:35 EDT 2022
Locate ini file and chdir
--- a/main.c
+++ b/main.c
@@ -9,6 +9,7 @@
#else
#include <sys/stat.h>
#include <sys/types.h>
+#include <unistd.h>
#endif
#include <math.h>
#include "snes/snes.h"
@@ -146,9 +147,35 @@
return rv;
}
+// Go some steps up and find zelda3.ini
+static void SwitchDirectory() {
+ char buf[4096];
+ if (!getcwd(buf, sizeof(buf) - 32))
+ return;
+ size_t pos = strlen(buf);
+ for (int step = 0; pos != 0 && step < 3; step++) {
+ memcpy(buf + pos, "/zelda3.ini", 12);
+ FILE *f = fopen(buf, "rb");
+ if (f) {
+ fclose(f);
+ buf[pos] = 0;
+ if (step != 0) {
+ printf("Found zelda3.ini in %s\n", buf);
+ chdir(buf);
+ }
+ return;
+ }
+ pos--;
+ while (pos != 0 && buf[pos] != '/' && buf[pos] != '\\')
+ pos--;
+ }
+}
+
+
#undef main
int main(int argc, char** argv) {
+ SwitchDirectory();
ParseConfigFile();
AfterConfigParse();
--- a/zelda3.vcxproj
+++ b/zelda3.vcxproj
@@ -91,7 +91,7 @@
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>D:\Lib\SDL2-2.0.20\include</AdditionalIncludeDirectories>
<LanguageStandard_C>stdc11</LanguageStandard_C>
- <DisableSpecificWarnings>4244;4018</DisableSpecificWarnings>
+ <DisableSpecificWarnings>4244;4018;4996</DisableSpecificWarnings>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
@@ -109,7 +109,7 @@
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<AdditionalIncludeDirectories>D:\Lib\SDL2-2.0.20\include</AdditionalIncludeDirectories>
<LanguageStandard_C>stdc11</LanguageStandard_C>
- <DisableSpecificWarnings>4244;4018</DisableSpecificWarnings>
+ <DisableSpecificWarnings>4244;4018;4996</DisableSpecificWarnings>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
@@ -128,7 +128,7 @@
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
<LanguageStandard_C>stdc11</LanguageStandard_C>
<WarningLevel>Level3</WarningLevel>
- <DisableSpecificWarnings>4244;4018</DisableSpecificWarnings>
+ <DisableSpecificWarnings>4244;4018;4996</DisableSpecificWarnings>
<TreatWarningAsError>true</TreatWarningAsError>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
</ClCompile>
@@ -142,7 +142,7 @@
</AdditionalIncludeDirectories>
<LanguageStandard_C>stdc11</LanguageStandard_C>
<WarningLevel>Level3</WarningLevel>
- <DisableSpecificWarnings>4244;4018</DisableSpecificWarnings>
+ <DisableSpecificWarnings>4244;4018;4996</DisableSpecificWarnings>
<TreatWarningAsError>true</TreatWarningAsError>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
</ClCompile>