by Gez » Tue Aug 17, 2010 10:43 am
Maybe if I say it a third time...
... and with a code excerpt...
Code: Select all
FString FGameConfigFile::GetConfigPath (bool tryProg)
{
const char *pathval;
FString path;
pathval = Args->CheckValue ("-config");
if (pathval != NULL)
{
return FString(pathval);
}
#ifdef _WIN32
path = NULL;
HRESULT hr;
TCHAR uname[UNLEN+1];
DWORD unamelen = countof(uname);
// Because people complained, try for a user-specific .ini in the program directory first.
// If that is not writeable, use the one in the home directory instead.
hr = GetUserName (uname, &unamelen);
if (SUCCEEDED(hr) && uname[0] != 0)
{
// Is it valid for a user name to have slashes?
// Check for them and substitute just in case.
char *probe = uname;
while (*probe != 0)
{
if (*probe == '\\' || *probe == '/')
*probe = '_';
++probe;
}
path = progdir;
path += "zdoom-";
path += uname;
path += ".ini";
if (tryProg)
{
if (!FileExists (path.GetChars()))
{
path = "";
}
}
else
{ // check if writeable
FILE *checker = fopen (path.GetChars(), "a");
if (checker == NULL)
{
path = "";
}
else
{
fclose (checker);
}
}
}
if (path.IsEmpty())
{
if (Args->CheckParm ("-cdrom"))
return CDROM_DIR "\\zdoom.ini";
path = progdir;
path += "zdoom.ini";
}
return path;
#elif defined(__APPLE__)
char cpath[PATH_MAX];
FSRef folder;
if (noErr == FSFindFolder(kUserDomain, kPreferencesFolderType, kCreateFolder, &folder) &&
noErr == FSRefMakePath(&folder, (UInt8*)cpath, PATH_MAX))
{
path = cpath;
path += "/zdoom.ini";
return path;
}
// Ungh.
return "zdoom.ini";
#else
return GetUserFile ("zdoom.ini");
#endif
}
... it'll be listened to.
The function that ZDoom uses to get the path for the config file will do lots of complicated stuff to append the username to "zdoom-" and then add ".ini".
But! If you use -config bluhbluhhugeconfig.ini, what happens in this magical function? That's right boys and girls, there's a return! It will read and write from that location!
Which means, for those of you following the score at home, that if you use the incredibly complicated batch files I have given to you above, it will do what you want, without the need for renaming and deleting.
Caligari's second batch file will only result in the config being deleted, and an error message about file zdoom-*.ini being not found.
Maybe if I say it a third time...
... and with a code excerpt...
[code]FString FGameConfigFile::GetConfigPath (bool tryProg)
{
const char *pathval;
FString path;
pathval = Args->CheckValue ("-config");
if (pathval != NULL)
{
return FString(pathval);
}
#ifdef _WIN32
path = NULL;
HRESULT hr;
TCHAR uname[UNLEN+1];
DWORD unamelen = countof(uname);
// Because people complained, try for a user-specific .ini in the program directory first.
// If that is not writeable, use the one in the home directory instead.
hr = GetUserName (uname, &unamelen);
if (SUCCEEDED(hr) && uname[0] != 0)
{
// Is it valid for a user name to have slashes?
// Check for them and substitute just in case.
char *probe = uname;
while (*probe != 0)
{
if (*probe == '\\' || *probe == '/')
*probe = '_';
++probe;
}
path = progdir;
path += "zdoom-";
path += uname;
path += ".ini";
if (tryProg)
{
if (!FileExists (path.GetChars()))
{
path = "";
}
}
else
{ // check if writeable
FILE *checker = fopen (path.GetChars(), "a");
if (checker == NULL)
{
path = "";
}
else
{
fclose (checker);
}
}
}
if (path.IsEmpty())
{
if (Args->CheckParm ("-cdrom"))
return CDROM_DIR "\\zdoom.ini";
path = progdir;
path += "zdoom.ini";
}
return path;
#elif defined(__APPLE__)
char cpath[PATH_MAX];
FSRef folder;
if (noErr == FSFindFolder(kUserDomain, kPreferencesFolderType, kCreateFolder, &folder) &&
noErr == FSRefMakePath(&folder, (UInt8*)cpath, PATH_MAX))
{
path = cpath;
path += "/zdoom.ini";
return path;
}
// Ungh.
return "zdoom.ini";
#else
return GetUserFile ("zdoom.ini");
#endif
}[/code]
... it'll be listened to.
The function that ZDoom uses to get the path for the config file will do lots of complicated stuff to append the username to "zdoom-" and then add ".ini".
But! If you use -config bluhbluhhugeconfig.ini, what happens in this magical function? That's right boys and girls, there's a return! It will read and write from that location!
Which means, for those of you following the score at home, that if you use the incredibly complicated batch files I have given to you above, it will do what you want, without the need for renaming and deleting.
Caligari's second batch file will only result in the config being deleted, and an error message about file zdoom-*.ini being not found.