Luigi, I have written a very small program to parse the "SteamAppData.vdf" file (plain text) and retrieve the user name set as the "AutoLoginUser". I wanted to know if you could look at my code and tell me of a better way to search through and parse such a file as I feel my code is very inefficient, however it does work for me.
GetSteamUser.c
Code:
#include <stdio.h>
#include <windows.h>
FILE *hVDF;
HKEY hkey;
LONG lRet;
DWORD dwSize=128;
char szSteamUser[128], lpBuffer[128], lpLine[1024];
char szAppData[MAX_PATH];
int main(int argc, char *argv[]) {
SetConsoleTitle("GetSteamUser - by desxor 2008");
lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Valve\\Steam", 0, KEY_READ, &hkey);
if(RegQueryValueEx(hkey, "InstallPath", NULL, NULL, szAppData, &dwSize) != ERROR_SUCCESS)
{
printf("Could not find Steam installation path in registry, exiting.\n");
exit(-1);
}
else {
printf("Found InstallPath value in registry:\n%s\n\n", szAppData);
}
RegCloseKey(hkey);
strcat(szAppData,"\\config\\SteamAppData.vdf");
hVDF = fopen(szAppData,"r");
if(!hVDF) {
printf("Failed opening: %s\n", szAppData);
exit(-1);
}
while(fgets(lpLine,sizeof(lpLine),hVDF) != NULL)
{
int i,f;
for (i=0, f=1; lpLine[i] != '\0'; i++, f++)
{
char *end = strchr(&lpLine[i],'"');
if (end != NULL)
{
int length = end - &lpLine[i];
switch (f)
{
case 2:
sprintf(lpBuffer,"%*.*s", length, length, &lpLine[i]);
case 4:
if(strcmp(lpBuffer,"AutoLoginUser") == 0) sprintf(szSteamUser,"%*.*s", length, length, &lpLine[i]);
}
i += length;
}
}
}
fclose(hVDF);
printf("AutoLoginUser: %s\n", szSteamUser);
return(0);
}
Thank you for looking and maybe this will help others ;)