void FGameConfigFile::CreateStandardAutoExec(const char *section, bool start)
{
	if (!SetSection(section))
	{
		FString path;
#ifdef __APPLE__
		char cpath[PATH_MAX];
		FSRef folder;
		
		if (noErr == FSFindFolder(kUserDomain, kDocumentsFolderType, kCreateFolder, &folder) &&
			noErr == FSRefMakePath(&folder, (UInt8*)cpath, PATH_MAX))
		{
			path << cpath << "/" GAME_DIR "/autoexec.cfg";
		}
#elif !defined(unix)
		path = "$PROGDIR/autoexec.cfg";
#else
		path = GetUserFile ("autoexec.cfg");
#endif
		SetSection (section, true);
		SetValueForKey ("Path", path.GetChars());
	}
	if (start)
	{
		MoveSectionToStart(section);
	}
}
예제 #2
0
void FGameConfigFile::CreateStandardAutoExec(const char *section, bool start)
{
	if (!SetSection(section))
	{
		FString path = M_GetAutoexecPath();
		SetSection (section, true);
		SetValueForKey ("Path", path.GetChars());
	}
	if (start)
	{
		MoveSectionToStart(section);
	}
}
void FGameConfigFile::ArchiveGlobalData ()
{
	SetSection ("LastRun", true);
	ClearCurrentSection ();
	SetValueForKey ("Version", LASTRUNVERSION);

	SetSection ("GlobalSettings", true);
	ClearCurrentSection ();
	C_ArchiveCVars (this, 1);

	SetSection ("GlobalSettings.Unknown", true);
	ClearCurrentSection ();
	C_ArchiveCVars (this, 3);
}
예제 #4
0
void FGameConfigFile::ArchiveGlobalData ()
{
	SetSection ("LastRun", true);
	ClearCurrentSection ();
	SetValueForKey ("Version", LASTRUNVERSION);

	SetSection ("GlobalSettings", true);
	ClearCurrentSection ();
	C_ArchiveCVars (this, CVAR_ARCHIVE|CVAR_GLOBALCONFIG);

	SetSection ("GlobalSettings.Unknown", true);
	ClearCurrentSection ();
	C_ArchiveCVars (this, CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_AUTO);
}
void FGameConfigFile::AddAutoexec (DArgs *list, const char *game)
{
	char section[64];
	const char *key;
	const char *value;

	mysnprintf (section, countof(section), "%s.AutoExec", game);

	if (bMigrating)
	{
		FBaseCVar *autoexec = FindCVar ("autoexec", NULL);

		if (autoexec != NULL)
		{
			UCVarValue val;
			char *path;

			val = autoexec->GetGenericRep (CVAR_String);
			path = copystring (val.String);
			delete autoexec;
			SetSection (section, true);
			SetValueForKey ("Path", path);
			list->AppendArg (path);
			delete[] path;
		}
	}
	else
	{
		// If <game>.AutoExec section does not exist, create it
		// with a default autoexec.cfg file present.
		CreateStandardAutoExec(section, false);
		// Run any files listed in the <game>.AutoExec section
		if (!SectionIsEmpty())
		{
			while (NextInSection (key, value))
			{
				if (stricmp (key, "Path") == 0 && *value != '\0')
				{
					FString expanded_path = ExpandEnvVars(value);
					if (FileExists(expanded_path))
					{
						list->AppendArg (ExpandEnvVars(value));
					}
				}
			}
		}
	}
}
FGameConfigFile::FGameConfigFile ()
{
#ifdef __APPLE__
	FString user_docs, user_app_support, local_app_support;
#endif
	FString pathname;
	
	bMigrating = false;
	pathname = GetConfigPath (true);
	ChangePathName (pathname);
	LoadConfigFile (MigrateStub, NULL);

	if (!HaveSections ())
	{ // Config file not found; try the old one
		MigrateOldConfig ();
	}

	// If zdoom.ini was read from the program directory, switch
	// to the user directory now. If it was read from the user
	// directory, this effectively does nothing.
	pathname = GetConfigPath (false);
	ChangePathName (pathname);

	// Set default IWAD search paths if none present
	if (!SetSection ("IWADSearch.Directories"))
	{
		SetSection ("IWADSearch.Directories", true);
		SetValueForKey ("Path", ".", true);
		SetValueForKey ("Path", "$DOOMWADDIR", true);
#ifdef __APPLE__
		char cpath[PATH_MAX];
		FSRef folder;
		
		if (noErr == FSFindFolder(kUserDomain, kDocumentsFolderType, kCreateFolder, &folder) &&
			noErr == FSRefMakePath(&folder, (UInt8*)cpath, PATH_MAX))
		{
			user_docs << cpath << "/" GAME_DIR;
			SetValueForKey("Path", user_docs, true);
		}
		else
		{
			SetValueForKey("Path", "~/" GAME_DIR, true);
		}
		if (noErr == FSFindFolder(kUserDomain, kApplicationSupportFolderType, kCreateFolder, &folder) &&
			noErr == FSRefMakePath(&folder, (UInt8*)cpath, PATH_MAX))
		{
			user_app_support << cpath << "/" GAME_DIR;
			SetValueForKey("Path", user_app_support, true);
		}
		SetValueForKey ("Path", "$PROGDIR", true);
		if (noErr == FSFindFolder(kLocalDomain, kApplicationSupportFolderType, kCreateFolder, &folder) &&
			noErr == FSRefMakePath(&folder, (UInt8*)cpath, PATH_MAX))
		{
			local_app_support << cpath << "/" GAME_DIR;
			SetValueForKey("Path", local_app_support, true);
		}
#elif !defined(unix)
		SetValueForKey ("Path", "$HOME", true);
		SetValueForKey ("Path", "$PROGDIR", true);
#else
		SetValueForKey ("Path", "~/" GAME_DIR, true);
		SetValueForKey ("Path", SHARE_DIR, true);
#endif
	}

	// Set default search paths if none present
	if (!SetSection ("FileSearch.Directories"))
	{
		SetSection ("FileSearch.Directories", true);
#ifdef __APPLE__
		SetValueForKey ("Path", user_docs, true);
		SetValueForKey ("Path", user_app_support, true);
		SetValueForKey ("Path", "$PROGDIR", true);
		SetValueForKey ("Path", local_app_support, true);
#elif !defined(unix)
		SetValueForKey ("Path", "$PROGDIR", true);
#else
		SetValueForKey ("Path", SHARE_DIR, true);
#endif
		SetValueForKey ("Path", "$DOOMWADDIR", true);
	}

	// Create auto-load sections, so users know what's available.
	// Note that this totem pole is the reverse of the order that
	// they will appear in the file.
	CreateSectionAtStart("Chex3.Autoload");
	CreateSectionAtStart("Chex.Autoload");
	CreateSectionAtStart("Strife.Autoload");
	CreateSectionAtStart("HexenDemo.Autoload");
	CreateSectionAtStart("HexenDK.Autoload");
	CreateSectionAtStart("Hexen.Autoload");
	CreateSectionAtStart("Heretic.Autoload");
	CreateSectionAtStart("FreeDM.Autoload");
	CreateSectionAtStart("Freedoom1.Autoload");
	CreateSectionAtStart("Freedoom.Autoload");
	CreateSectionAtStart("Plutonia.Autoload");
	CreateSectionAtStart("TNT.Autoload");
	CreateSectionAtStart("Doom2.Autoload");
	CreateSectionAtStart("Doom1.Autoload");
	CreateSectionAtStart("Doom.Autoload");
	CreateSectionAtStart("Global.Autoload");

	// The same goes for auto-exec files.
	CreateStandardAutoExec("Chex.AutoExec", true);
	CreateStandardAutoExec("Strife.AutoExec", true);
	CreateStandardAutoExec("Hexen.AutoExec", true);
	CreateStandardAutoExec("Heretic.AutoExec", true);
	CreateStandardAutoExec("Doom.AutoExec", true);

	// Move search paths back to the top.
	MoveSectionToStart("FileSearch.Directories");
	MoveSectionToStart("IWADSearch.Directories");

	// Add some self-documentation.
	SetSectionNote("IWADSearch.Directories",
		"# These are the directories to automatically search for IWADs.\n"
		"# Each directory should be on a separate line, preceded by Path=\n");
	SetSectionNote("FileSearch.Directories",
		"# These are the directories to search for wads added with the -file\n"
		"# command line parameter, if they cannot be found with the path\n"
		"# as-is. Layout is the same as for IWADSearch.Directories\n");
	SetSectionNote("Doom.AutoExec",
		"# Files to automatically execute when running the corresponding game.\n"
		"# Each file should be on its own line, preceded by Path=\n\n");
	SetSectionNote("Global.Autoload",
		"# WAD files to always load. These are loaded after the IWAD but before\n"
		"# any files added with -file. Place each file on its own line, preceded\n"
		"# by Path=\n");
	SetSectionNote("Doom.Autoload",
		"# Wad files to automatically load depending on the game and IWAD you are\n"
		"# playing.  You may have have files that are loaded for all similar IWADs\n"
		"# (the game) and files that are only loaded for particular IWADs. For example,\n"
		"# any files listed under Doom.Autoload will be loaded for any version of Doom,\n"
		"# but files listed under Doom2.Autoload will only load when you are\n"
		"# playing Doom 2.\n\n");
}
void FGameConfigFile::DoGlobalSetup ()
{
	if (SetSection ("GlobalSettings.Unknown"))
	{
		ReadCVars (CVAR_GLOBALCONFIG);
	}
	if (SetSection ("GlobalSettings"))
	{
		ReadCVars (CVAR_GLOBALCONFIG);
	}
	if (SetSection ("LastRun"))
	{
		const char *lastver = GetValueForKey ("Version");
		if (lastver != NULL)
		{
			double last = atof (lastver);
			if (last < 123.1)
			{
				FBaseCVar *noblitter = FindCVar ("vid_noblitter", NULL);
				if (noblitter != NULL)
				{
					noblitter->ResetToDefault ();
				}
			}
			if (last < 202)
			{
				// Make sure the Hexen hotkeys are accessible by default.
				if (SetSection ("Hexen.Bindings"))
				{
					SetValueForKey ("\\", "use ArtiHealth");
					SetValueForKey ("scroll", "+showscores");
					SetValueForKey ("0", "useflechette");
					SetValueForKey ("9", "use ArtiBlastRadius");
					SetValueForKey ("8", "use ArtiTeleport");
					SetValueForKey ("7", "use ArtiTeleportOther");
					SetValueForKey ("6", "use ArtiEgg");
					SetValueForKey ("5", "use ArtiInvulnerability");
				}
			}
			if (last < 204)
			{ // The old default for vsync was true, but with an unlimited framerate
			  // now, false is a better default.
				FBaseCVar *vsync = FindCVar ("vid_vsync", NULL);
				if (vsync != NULL)
				{
					vsync->ResetToDefault ();
				}
			}
			if (last < 206)
			{ // spc_amp is now a float, not an int.
				if (spc_amp > 16)
				{
					spc_amp = spc_amp / 16.f;
				}
			}
			if (last < 207)
			{ // Now that snd_midiprecache works again, you probably don't want it on.
				FBaseCVar *precache = FindCVar ("snd_midiprecache", NULL);
				if (precache != NULL)
				{
					precache->ResetToDefault();
				}
			}
			if (last < 208)
			{ // Weapon sections are no longer used, so tidy up the config by deleting them.
				const char *name;
				size_t namelen;
				bool more;

				more = SetFirstSection();
				while (more)
				{
					name = GetCurrentSection();
					if (name != NULL && 
						(namelen = strlen(name)) > 12 &&
						strcmp(name + namelen - 12, ".WeaponSlots") == 0)
					{
						more = DeleteCurrentSection();
					}
					else
					{
						more = SetNextSection();
					}
				}
			}
			if (last < 209)
			{
				// menu dimming is now a gameinfo option so switch user override off
				FBaseCVar *dim = FindCVar ("dimamount", NULL);
				if (dim != NULL)
				{
					dim->ResetToDefault ();
				}
			}
		}
	}
}
예제 #8
0
FGameConfigFile::FGameConfigFile ()
{
#ifdef __APPLE__
	FString user_docs, user_app_support, local_app_support;
	M_GetMacSearchDirectories(user_docs, user_app_support, local_app_support);
#endif

	FString pathname;

	OkayToWrite = false;	// Do not allow saving of the config before DoGameSetup()
	bModSetup = false;
	pathname = GetConfigPath (true);
	ChangePathName (pathname);
	LoadConfigFile ();

	// If zdoom.ini was read from the program directory, switch
	// to the user directory now. If it was read from the user
	// directory, this effectively does nothing.
	pathname = GetConfigPath (false);
	ChangePathName (pathname);

	// Set default IWAD search paths if none present
	if (!SetSection ("IWADSearch.Directories"))
	{
		SetSection ("IWADSearch.Directories", true);
		SetValueForKey ("Path", ".", true);
		SetValueForKey ("Path", "$DOOMWADDIR", true);
#ifdef __APPLE__
		SetValueForKey ("Path", user_docs, true);
		SetValueForKey ("Path", user_app_support, true);
		SetValueForKey ("Path", "$PROGDIR", true);
		SetValueForKey ("Path", local_app_support, true);
#elif !defined(__unix__)
		SetValueForKey ("Path", "$HOME", true);
		SetValueForKey ("Path", "$PROGDIR", true);
#else
		SetValueForKey ("Path", "$HOME/" GAME_DIR, true);
		// Arch Linux likes them in /usr/share/doom
		// Debian likes them in /usr/share/games/doom
		// I assume other distributions don't do anything radically different
		SetValueForKey ("Path", "/usr/local/share/doom", true);
		SetValueForKey ("Path", "/usr/local/share/games/doom", true);
		SetValueForKey ("Path", "/usr/share/doom", true);
		SetValueForKey ("Path", "/usr/share/games/doom", true);
#endif
	}

	// Set default search paths if none present
	if (!SetSection ("FileSearch.Directories"))
	{
		SetSection ("FileSearch.Directories", true);
#ifdef __APPLE__
		SetValueForKey ("Path", user_docs, true);
		SetValueForKey ("Path", user_app_support, true);
		SetValueForKey ("Path", "$PROGDIR", true);
		SetValueForKey ("Path", local_app_support, true);
#elif !defined(__unix__)
		SetValueForKey ("Path", "$PROGDIR", true);
#else
		SetValueForKey ("Path", "$HOME/" GAME_DIR, true);
		SetValueForKey ("Path", SHARE_DIR, true);
		SetValueForKey ("Path", "/usr/local/share/doom", true);
		SetValueForKey ("Path", "/usr/local/share/games/doom", true);
		SetValueForKey ("Path", "/usr/share/doom", true);
		SetValueForKey ("Path", "/usr/share/games/doom", true);
#endif
		SetValueForKey ("Path", "$DOOMWADDIR", true);
	}

	// Set default search paths if none present
	if (!SetSection("SoundfontSearch.Directories"))
	{
		SetSection("SoundfontSearch.Directories", true);
#ifdef __APPLE__
		SetValueForKey("Path", user_docs + "/soundfonts", true);
		SetValueForKey("Path", user_docs + "/fm_banks", true);
		SetValueForKey("Path", user_app_support + "/soundfonts", true);
		SetValueForKey("Path", user_app_support + "/fm_banks", true);
		SetValueForKey("Path", "$PROGDIR/soundfonts", true);
		SetValueForKey("Path", "$PROGDIR/fm_banks", true);
		SetValueForKey("Path", local_app_support + "/soundfonts", true);
		SetValueForKey("Path", local_app_support + "/fm_banks", true);
#elif !defined(__unix__)
		SetValueForKey("Path", "$PROGDIR/soundfonts", true);
		SetValueForKey("Path", "$PROGDIR/fm_banks", true);
#else
		SetValueForKey("Path", "$HOME/" GAME_DIR "/soundfonts", true);
		SetValueForKey("Path", "$HOME/" GAME_DIR "/fm_banks", true);
		SetValueForKey("Path", "/usr/local/share/doom/soundfonts", true);
		SetValueForKey("Path", "/usr/local/share/doom/fm_banks", true);
		SetValueForKey("Path", "/usr/local/share/games/doom/soundfonts", true);
		SetValueForKey("Path", "/usr/local/share/games/doom/fm_banks", true);
		SetValueForKey("Path", "/usr/share/doom/soundfonts", true);
		SetValueForKey("Path", "/usr/share/doom/fm_banks", true);
		SetValueForKey("Path", "/usr/share/games/doom/soundfonts", true);
		SetValueForKey("Path", "/usr/share/games/doom/fm_banks", true);
#endif
	}

	// Add some self-documentation.
	SetSectionNote("IWADSearch.Directories",
		"# These are the directories to automatically search for IWADs.\n"
		"# Each directory should be on a separate line, preceded by Path=\n");
	SetSectionNote("FileSearch.Directories",
		"# These are the directories to search for wads added with the -file\n"
		"# command line parameter, if they cannot be found with the path\n"
		"# as-is. Layout is the same as for IWADSearch.Directories\n");
	SetSectionNote("SoundfontSearch.Directories",
		"# These are the directories to search for soundfonts that let listed in the menu.\n"
		"# Layout is the same as for IWADSearch.Directories\n");
}
예제 #9
0
void FGameConfigFile::DoGlobalSetup ()
{
	if (SetSection ("GlobalSettings.Unknown"))
	{
		ReadCVars (CVAR_GLOBALCONFIG);
	}
	if (SetSection ("GlobalSettings"))
	{
		ReadCVars (CVAR_GLOBALCONFIG);
	}
	if (SetSection ("LastRun"))
	{
		const char *lastver = GetValueForKey ("Version");
		if (lastver != NULL)
		{
			double last = atof (lastver);
			if (last < 123.1)
			{
				FBaseCVar *noblitter = FindCVar ("vid_noblitter", NULL);
				if (noblitter != NULL)
				{
					noblitter->ResetToDefault ();
				}
			}
			if (last < 202)
			{
				// Make sure the Hexen hotkeys are accessible by default.
				if (SetSection ("Hexen.Bindings"))
				{
					SetValueForKey ("\\", "use ArtiHealth");
					SetValueForKey ("scroll", "+showscores");
					SetValueForKey ("0", "useflechette");
					SetValueForKey ("9", "use ArtiBlastRadius");
					SetValueForKey ("8", "use ArtiTeleport");
					SetValueForKey ("7", "use ArtiTeleportOther");
					SetValueForKey ("6", "use ArtiPork");
					SetValueForKey ("5", "use ArtiInvulnerability2");
				}
			}
			if (last < 204)
			{ // The old default for vsync was true, but with an unlimited framerate
			  // now, false is a better default.
				FBaseCVar *vsync = FindCVar ("vid_vsync", NULL);
				if (vsync != NULL)
				{
					vsync->ResetToDefault ();
				}
			}
			if (last < 206)
			{ // spc_amp is now a float, not an int.
				if (spc_amp > 16)
				{
					spc_amp = spc_amp / 16.f;
				}
			}
			if (last < 207)
			{ // Now that snd_midiprecache works again, you probably don't want it on.
				FBaseCVar *precache = FindCVar ("snd_midiprecache", NULL);
				if (precache != NULL)
				{
					precache->ResetToDefault();
				}
			}
			if (last < 208)
			{ // Weapon sections are no longer used, so tidy up the config by deleting them.
				const char *name;
				size_t namelen;
				bool more;

				more = SetFirstSection();
				while (more)
				{
					name = GetCurrentSection();
					if (name != NULL && 
						(namelen = strlen(name)) > 12 &&
						strcmp(name + namelen - 12, ".WeaponSlots") == 0)
					{
						more = DeleteCurrentSection();
					}
					else
					{
						more = SetNextSection();
					}
				}
			}
			if (last < 209)
			{
				// menu dimming is now a gameinfo option so switch user override off
				FBaseCVar *dim = FindCVar ("dimamount", NULL);
				if (dim != NULL)
				{
					dim->ResetToDefault ();
				}
			}
			if (last < 210)
			{
				if (SetSection ("Hexen.Bindings"))
				{
					// These 2 were misnamed in earlier versions
					SetValueForKey ("6", "use ArtiPork");
					SetValueForKey ("5", "use ArtiInvulnerability2");
				}
			}
			if (last < 213)
			{
				auto var = FindCVar("snd_channels", NULL);
				if (var != NULL)
				{
					// old settings were default 32, minimum 8, new settings are default 128, minimum 64.
					UCVarValue v = var->GetGenericRep(CVAR_Int);
					if (v.Int < 64) var->ResetToDefault();
				}
			}
			if (last < 214)
			{
				FBaseCVar *var = FindCVar("hud_scale", NULL);
				if (var != NULL) var->ResetToDefault();
				var = FindCVar("st_scale", NULL);
				if (var != NULL) var->ResetToDefault();
				var = FindCVar("hud_althudscale", NULL);
				if (var != NULL) var->ResetToDefault();
				var = FindCVar("con_scale", NULL);
				if (var != NULL) var->ResetToDefault();
				var = FindCVar("con_scaletext", NULL);
				if (var != NULL) var->ResetToDefault();
				var = FindCVar("uiscale", NULL);
				if (var != NULL) var->ResetToDefault();
			}
			if (last < 215)
			{
				// Previously a true/false boolean. Now an on/off/auto tri-state with auto as the default.
				FBaseCVar *var = FindCVar("snd_hrtf", NULL);
				if (var != NULL) var->ResetToDefault();
			}
			if (last < 216)
			{
				FBaseCVar *var = FindCVar("gl_texture_hqresize", NULL);
				if (var != NULL)
				{
					auto v = var->GetGenericRep(CVAR_Int);
					switch (v.Int)
					{
					case 1:
						gl_texture_hqresizemode = 1; gl_texture_hqresizemult = 2;
						break;
					case 2:
						gl_texture_hqresizemode = 1; gl_texture_hqresizemult = 3;
						break;
					case 3:
						gl_texture_hqresizemode = 1; gl_texture_hqresizemult = 4;
						break;
					case 4:
						gl_texture_hqresizemode = 2; gl_texture_hqresizemult = 2;
						break;
					case 5:
						gl_texture_hqresizemode = 2; gl_texture_hqresizemult = 3;
						break;
					case 6:
						gl_texture_hqresizemode = 2; gl_texture_hqresizemult = 4;
						break;
					case 7:
						gl_texture_hqresizemode = 3; gl_texture_hqresizemult = 2;
						break;
					case 8:
						gl_texture_hqresizemode = 3; gl_texture_hqresizemult = 3;
						break;
					case 9:
						gl_texture_hqresizemode = 3; gl_texture_hqresizemult = 4;
						break;
					case 10:
						gl_texture_hqresizemode = 4; gl_texture_hqresizemult = 2;
						break;
					case 11:
						gl_texture_hqresizemode = 4; gl_texture_hqresizemult = 3;
						break;
					case 12:
						gl_texture_hqresizemode = 4; gl_texture_hqresizemult = 4;
						break;
					case 18:
						gl_texture_hqresizemode = 4; gl_texture_hqresizemult = 5;
						break;
					case 19:
						gl_texture_hqresizemode = 4; gl_texture_hqresizemult = 6;
						break;
					case 13:
						gl_texture_hqresizemode = 5; gl_texture_hqresizemult = 2;
						break;
					case 14:
						gl_texture_hqresizemode = 5; gl_texture_hqresizemult = 3;
						break;
					case 15:
						gl_texture_hqresizemode = 5; gl_texture_hqresizemult = 4;
						break;
					case 16:
						gl_texture_hqresizemode = 5; gl_texture_hqresizemult = 5;
						break;
					case 17:
						gl_texture_hqresizemode = 5; gl_texture_hqresizemult = 6;
						break;
					case 20:
						gl_texture_hqresizemode = 6; gl_texture_hqresizemult = 2;
						break;
					case 21:
						gl_texture_hqresizemode = 6; gl_texture_hqresizemult = 3;
						break;
					case 22:
						gl_texture_hqresizemode = 6; gl_texture_hqresizemult = 4;
						break;
					case 23:
						gl_texture_hqresizemode = 6; gl_texture_hqresizemult = 5;
						break;
					case 24:
						gl_texture_hqresizemode = 6; gl_texture_hqresizemult = 6;
						break;
					case 0:
					default:
						gl_texture_hqresizemode = 0; gl_texture_hqresizemult = 1;
						break;
					}
				}
			}
			if (last < 217)
			{
				auto var = FindCVar("vid_scalemode", NULL);
				UCVarValue newvalue;
				newvalue.Int = 2;
				if (var != NULL)
				{
					UCVarValue v = var->GetGenericRep(CVAR_Int);
					if (v.Int == 3) var->SetGenericRep(newvalue, CVAR_Int);
				}
			}
		}
	}
}