Page 1 of 1

(G)ZDoom ini file for any user

Posted: Tue Aug 17, 2010 12:15 am
by Mazed_Band
Hello there. I want to create a portable copy (on USB flash drive) of both ZDoom 2.5.0 & GZDoom 1.5.0. So the only thing I need is an ini file that will work on any user. Is it possible to create such file or to force ZDoom to load specific ini file instead of the one with username in it?

Re: (G)ZDoom ini file for any user

Posted: Tue Aug 17, 2010 12:36 am
by wildweasel
Yes there is - start the game normally and make sure your settings are all in order, then quit the game and rename the resulting zdoom-USERNAMEHERE.ini to zdoom.ini. Any time G/ZDoom would create a new ini file for a new user, it will use the zdoom.ini as a base and load all settings from that.

Re: (G)ZDoom ini file for any user

Posted: Tue Aug 17, 2010 2:40 am
by Mazed_Band
Ok, and is there a way to prevent ZDoom from creating user-specific ini and write settings into zdoom.ini file only?

Re: (G)ZDoom ini file for any user

Posted: Tue Aug 17, 2010 2:55 am
by Graf Zahl
No. It will always write to the user specific file.

Re: (G)ZDoom ini file for any user

Posted: Tue Aug 17, 2010 3:07 am
by Gez
You could use a .bat file which calls ZDoom with the -config zdoom.ini parameter.

e.g.: ZDoom.bat:

Code: Select all

zdoom -config zdoom.ini %*
GZDoom.bat:

Code: Select all

gzdoom -config zdoom.ini %*

The %* is to transmit all parameters to (G)ZDoom, so that drag'n'drop is retained. (Just drag and drop on the .bat file rather than the exe.)

Re: (G)ZDoom ini file for any user

Posted: Tue Aug 17, 2010 9:48 am
by Xaser
Hmm, a while back I intended to make a feature suggestion somewhere along this regard -- a 'nocopy' line or something you could add to the zdoom.ini file to make ZDoom use and write to that particular config (treating it as global or some such). It would be handy for putting ZDoom on a flash drive or similar, at least.

Re: (G)ZDoom ini file for any user

Posted: Tue Aug 17, 2010 9:56 am
by Gez
If you do just like I explained, it'll work just as well. Unless your religion forbids you from using batch files, that is. But even then you can probably give them the .cmd extension instead and call them "command scripts", and maybe perform a cleansing ritual afterwards.

Re: (G)ZDoom ini file for any user

Posted: Tue Aug 17, 2010 10:30 am
by Caligari87
nevermind.

Re: (G)ZDoom ini file for any user

Posted: Tue Aug 17, 2010 10:43 am
by Gez
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.

Re: (G)ZDoom ini file for any user

Posted: Tue Aug 17, 2010 10:50 am
by Caligari87
You gave no indication that it would continue writing to the same file specified in -config. As I have no access to the source code, nor understanding of it, and have no experience using the -config parameter (similar to most people posting in this thread apparently, or it wouldn't exist), I was operating under the assumption that it would work as it always does, creating a new .ini file for whatever user is playing, regardless.
Remember how Graf Zahl wrote:No. It will always write to the user specific file.
A simple "it doesn't work that way" would have sufficed.

8-)

Re: (G)ZDoom ini file for any user

Posted: Tue Aug 17, 2010 10:58 am
by Xaser
Hmm, I really wish people would stop mentally substituting "your method is wrong" for posts that are in no way saying such. :|

Having said that, is it possible to associate file extensions with batch files (i.e. double-clicking action.wad would run the game using zdoom.bat instead of zdoom.exe)? Not that it would matter in the flash drive situation since the two intentions are mutually exclusive, but it's an interesting thought.

Re: (G)ZDoom ini file for any user

Posted: Tue Aug 17, 2010 11:00 am
by Caligari87
To the best of my knowledge, yes. It would require some mucking around in the file types box (something I've come to lothe), but it's possible.

8-)

Re: (G)ZDoom ini file for any user

Posted: Tue Aug 17, 2010 11:04 am
by Demolisher
Caligari_87 wrote:To the best of my knowledge, yes. It would require some mucking around in the file types box (something I've come to lothe), but it's possible.

8-)
Or the registry. Very fun.