mirror of
https://github.com/FunkyFr3sh/cnc-ddraw.git
synced 2025-03-14 22:03:27 +01:00
improve ini performance
This commit is contained in:
parent
7517611992
commit
9256899b20
@ -49,6 +49,7 @@
|
||||
<ClCompile Include="src\IDirect3D\IDirect3D7.c" />
|
||||
<ClCompile Include="src\IAMMediaStream\IAMMediaStream.c" />
|
||||
<ClCompile Include="src\IDirectDraw\IDirectDrawGammaControl.c" />
|
||||
<ClCompile Include="src\ini.c" />
|
||||
<ClCompile Include="src\utils.c" />
|
||||
<ClCompile Include="src\hook.c" />
|
||||
<ClCompile Include="src\IDirectDraw\IDirectDraw.c" />
|
||||
@ -82,6 +83,7 @@
|
||||
<ClInclude Include="inc\IDirect3D.h" />
|
||||
<ClInclude Include="inc\IAMMediaStream.h" />
|
||||
<ClInclude Include="inc\IDirectDrawGammaControl.h" />
|
||||
<ClInclude Include="inc\ini.h" />
|
||||
<ClInclude Include="inc\patch.h" />
|
||||
<ClInclude Include="inc\utils.h" />
|
||||
<ClInclude Include="inc\hook.h" />
|
||||
|
@ -156,6 +156,9 @@
|
||||
<ClCompile Include="src\blt.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\ini.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="inc\debug.h">
|
||||
@ -269,6 +272,9 @@
|
||||
<ClInclude Include="inc\version.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="inc\ini.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="ddraw.rc">
|
||||
|
6
inc/ini.h
Normal file
6
inc/ini.h
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef INI_H
|
||||
#define INI_H
|
||||
|
||||
BOOL ini_section_exists(char* section);
|
||||
|
||||
#endif
|
40
src/config.c
40
src/config.c
@ -10,6 +10,7 @@
|
||||
#include "hook.h"
|
||||
#include "debug.h"
|
||||
#include "dllmain.h"
|
||||
#include "ini.h"
|
||||
|
||||
static void cfg_init();
|
||||
static void cfg_create_ini();
|
||||
@ -1098,37 +1099,42 @@ static DWORD cfg_get_string(LPCSTR key, LPCSTR default_value, LPSTR out_string,
|
||||
if (!g_config.ini_path[0])
|
||||
cfg_init();
|
||||
|
||||
DWORD s = GetPrivateProfileStringA(
|
||||
g_config.process_file_name, key, "", out_string, out_size, g_config.ini_path);
|
||||
|
||||
char buf[MAX_PATH] = { 0 };
|
||||
|
||||
if (s > 0)
|
||||
if (ini_section_exists(g_config.process_file_name))
|
||||
{
|
||||
if (GetPrivateProfileStringA(
|
||||
g_config.process_file_name, "checkfile", "", buf, sizeof(buf), g_config.ini_path) > 0)
|
||||
DWORD s = GetPrivateProfileStringA(
|
||||
g_config.process_file_name, key, "", out_string, out_size, g_config.ini_path);
|
||||
|
||||
if (s > 0)
|
||||
{
|
||||
if (FILE_EXISTS(buf))
|
||||
if (GetPrivateProfileStringA(
|
||||
g_config.process_file_name, "checkfile", "", buf, sizeof(buf), g_config.ini_path) > 0)
|
||||
{
|
||||
if (FILE_EXISTS(buf))
|
||||
return s;
|
||||
}
|
||||
else
|
||||
return s;
|
||||
}
|
||||
else
|
||||
return s;
|
||||
}
|
||||
|
||||
/* Only checking 1 additional section for now (it may be too slow otherwise) */
|
||||
for (int i = 2; i < 3; i++)
|
||||
for (int i = 2; i < 10; i++)
|
||||
{
|
||||
char section[MAX_PATH] = { 0 };
|
||||
_snprintf(section, sizeof(section) - 1, "%s/%d", g_config.process_file_name, i);
|
||||
|
||||
s = GetPrivateProfileStringA(section, key, "", out_string, out_size, g_config.ini_path);
|
||||
|
||||
if (s > 0)
|
||||
if (ini_section_exists(section))
|
||||
{
|
||||
if (GetPrivateProfileStringA(section, "checkfile", "", buf, sizeof(buf), g_config.ini_path) > 0)
|
||||
DWORD s = GetPrivateProfileStringA(section, key, "", out_string, out_size, g_config.ini_path);
|
||||
|
||||
if (s > 0)
|
||||
{
|
||||
if (FILE_EXISTS(buf))
|
||||
return s;
|
||||
if (GetPrivateProfileStringA(section, "checkfile", "", buf, sizeof(buf), g_config.ini_path) > 0)
|
||||
{
|
||||
if (FILE_EXISTS(buf))
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
49
src/ini.c
Normal file
49
src/ini.c
Normal file
@ -0,0 +1,49 @@
|
||||
#include <windows.h>
|
||||
#include "debug.h"
|
||||
#include "config.h"
|
||||
#include "crc32.h"
|
||||
|
||||
static unsigned long g_ini_section_hashes[1024];
|
||||
|
||||
BOOL ini_section_exists(char* section)
|
||||
{
|
||||
if (!g_ini_section_hashes[0])
|
||||
{
|
||||
char* buf = calloc(8192, 1);
|
||||
if (buf)
|
||||
{
|
||||
if (GetPrivateProfileSectionNamesA(buf, 8192, g_config.ini_path) > 0)
|
||||
{
|
||||
for (int i = 0; *buf && i < sizeof(g_ini_section_hashes) / sizeof(g_ini_section_hashes[0]); i++)
|
||||
{
|
||||
size_t len = strlen(buf);
|
||||
|
||||
for (char* p = buf; *p; ++p)
|
||||
*p = tolower(*p);
|
||||
|
||||
g_ini_section_hashes[i] = Crc32_ComputeBuf(0, buf, len);
|
||||
|
||||
buf += len + 1;
|
||||
}
|
||||
}
|
||||
|
||||
free(buf);
|
||||
}
|
||||
}
|
||||
|
||||
char s[MAX_PATH];
|
||||
strncpy(s, section, sizeof(s) - 1);
|
||||
|
||||
for (char* p = s; *p; ++p)
|
||||
*p = tolower(*p);
|
||||
|
||||
unsigned long hash = Crc32_ComputeBuf(0, s, strlen(s));
|
||||
|
||||
for (int i = 0; i < sizeof(g_ini_section_hashes) / sizeof(g_ini_section_hashes[0]) && g_ini_section_hashes[i]; i++)
|
||||
{
|
||||
if (g_ini_section_hashes[i] == hash)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user