2017-03-23 16:27:33 +00:00
|
|
|
/*
|
2019-01-22 14:58:29 +00:00
|
|
|
Copyright 2016-2019 Arisotura
|
2017-03-23 16:27:33 +00:00
|
|
|
|
|
|
|
This file is part of melonDS.
|
|
|
|
|
|
|
|
melonDS is free software: you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU General Public License as published by the Free
|
|
|
|
Software Foundation, either version 3 of the License, or (at your option)
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with melonDS. If not, see http://www.gnu.org/licenses/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "Config.h"
|
2019-03-27 03:23:03 +00:00
|
|
|
#include "Platform.h"
|
2017-03-23 16:27:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace Config
|
|
|
|
{
|
|
|
|
|
2018-12-11 20:34:05 +00:00
|
|
|
const char* kConfigFile = "melonDS.ini";
|
|
|
|
|
2017-05-25 20:50:36 +00:00
|
|
|
int Threaded3D;
|
|
|
|
|
2017-03-23 16:27:33 +00:00
|
|
|
ConfigEntry ConfigFile[] =
|
|
|
|
{
|
2017-05-25 20:50:36 +00:00
|
|
|
{"Threaded3D", 0, &Threaded3D, 1, NULL, 0},
|
|
|
|
|
2017-03-23 16:27:33 +00:00
|
|
|
{"", -1, NULL, 0, NULL, 0}
|
|
|
|
};
|
|
|
|
|
2019-03-14 23:58:29 +00:00
|
|
|
extern ConfigEntry PlatformConfigFile[];
|
|
|
|
|
2017-03-23 16:27:33 +00:00
|
|
|
|
|
|
|
void Load()
|
|
|
|
{
|
|
|
|
ConfigEntry* entry = &ConfigFile[0];
|
2019-03-14 23:58:29 +00:00
|
|
|
int c = 0;
|
2017-03-23 16:27:33 +00:00
|
|
|
for (;;)
|
|
|
|
{
|
2019-03-14 23:58:29 +00:00
|
|
|
if (!entry->Value)
|
|
|
|
{
|
|
|
|
if (c > 0) break;
|
|
|
|
entry = &PlatformConfigFile[0];
|
2019-03-26 14:11:32 +00:00
|
|
|
if (!entry->Value) break;
|
2019-03-14 23:58:29 +00:00
|
|
|
c++;
|
|
|
|
}
|
2017-03-23 16:27:33 +00:00
|
|
|
|
|
|
|
if (entry->Type == 0)
|
|
|
|
*(int*)entry->Value = entry->DefaultInt;
|
|
|
|
else
|
2018-12-14 03:25:39 +00:00
|
|
|
{
|
2017-03-23 16:27:33 +00:00
|
|
|
strncpy((char*)entry->Value, entry->DefaultStr, entry->StrLength);
|
2018-12-14 03:25:39 +00:00
|
|
|
((char*)entry->Value)[entry->StrLength] = '\0';
|
|
|
|
}
|
2017-03-23 16:27:33 +00:00
|
|
|
|
|
|
|
entry++;
|
|
|
|
}
|
|
|
|
|
2019-03-27 12:34:26 +00:00
|
|
|
FILE* f = Platform::OpenLocalFile(kConfigFile, "r");
|
2017-03-23 16:27:33 +00:00
|
|
|
if (!f) return;
|
|
|
|
|
|
|
|
char linebuf[1024];
|
|
|
|
char entryname[16];
|
|
|
|
char entryval[1024];
|
|
|
|
while (!feof(f))
|
|
|
|
{
|
|
|
|
fgets(linebuf, 1024, f);
|
|
|
|
int ret = sscanf(linebuf, "%15[A-Za-z_0-9]=%[^\t\n]", entryname, entryval);
|
|
|
|
if (ret < 2) continue;
|
|
|
|
|
|
|
|
ConfigEntry* entry = &ConfigFile[0];
|
2019-03-14 23:58:29 +00:00
|
|
|
c = 0;
|
2017-03-23 16:27:33 +00:00
|
|
|
for (;;)
|
|
|
|
{
|
2019-03-14 23:58:29 +00:00
|
|
|
if (!entry->Value)
|
|
|
|
{
|
|
|
|
if (c > 0) break;
|
|
|
|
entry = &PlatformConfigFile[0];
|
2019-03-26 14:11:32 +00:00
|
|
|
if (!entry->Value) break;
|
2019-03-14 23:58:29 +00:00
|
|
|
c++;
|
|
|
|
}
|
2017-03-23 16:27:33 +00:00
|
|
|
|
|
|
|
if (!strncmp(entry->Name, entryname, 15))
|
|
|
|
{
|
|
|
|
if (entry->Type == 0)
|
|
|
|
*(int*)entry->Value = strtol(entryval, NULL, 10);
|
|
|
|
else
|
|
|
|
strncpy((char*)entry->Value, entryval, entry->StrLength);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
entry++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Save()
|
|
|
|
{
|
2019-03-27 12:34:26 +00:00
|
|
|
FILE* f = Platform::OpenLocalFile(kConfigFile, "w");
|
2019-03-27 12:54:33 +00:00
|
|
|
if (!f) return;
|
2017-03-23 16:27:33 +00:00
|
|
|
|
|
|
|
ConfigEntry* entry = &ConfigFile[0];
|
2019-03-14 23:58:29 +00:00
|
|
|
int c = 0;
|
2017-03-23 16:27:33 +00:00
|
|
|
for (;;)
|
|
|
|
{
|
2019-03-14 23:58:29 +00:00
|
|
|
if (!entry->Value)
|
|
|
|
{
|
|
|
|
if (c > 0) break;
|
|
|
|
entry = &PlatformConfigFile[0];
|
2019-03-26 14:11:32 +00:00
|
|
|
if (!entry->Value) break;
|
2019-03-14 23:58:29 +00:00
|
|
|
c++;
|
|
|
|
}
|
2017-03-23 16:27:33 +00:00
|
|
|
|
|
|
|
if (entry->Type == 0)
|
|
|
|
fprintf(f, "%s=%d\n", entry->Name, *(int*)entry->Value);
|
|
|
|
else
|
|
|
|
fprintf(f, "%s=%s\n", entry->Name, entry->Value);
|
|
|
|
|
|
|
|
entry++;
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|