summaryrefslogtreecommitdiff
path: root/common/ConfigManager.h
blob: 887cfdcfc9b246cd34fd56f32657318eeb697c13 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================//

#ifndef CONFIGMANAGER_H
#define CONFIGMANAGER_H
#ifdef _WIN32
#pragma once
#endif

#include "KeyValues.h"
#include "utlvector.h"
#include "filesystem_init.h"


// See filesystem_init for the vconfig registry values.


#define	TOKEN_GAMES				"Games"
#define	TOKEN_GAME_DIRECTORY	"GameDir"
#define	TOKEN_TOOLS				"Tools"

struct defaultConfigInfo_t
{
	char	gameName[MAX_PATH];
	char	gameDir[MAX_PATH];
	char	FGD[MAX_PATH];
	char	defaultPointEntity[MAX_PATH];
	char	exeName[MAX_PATH];
	int		steamAppID;
};

enum eSDKEpochs
{
	HL2 = 1,
	EP1 = 2,
	EP2 = 3,
	SP2009 = 4,
	MP2009 = 5,
};

extern defaultConfigInfo_t *gDefaultConfigs[];

class CGameConfigManager
{
public:

	enum loadStatus_t
	{
		LOADSTATUS_NONE = 0,	// Configs were loaded with no error
		LOADSTATUS_CONVERTED,	// GameConfig.txt did not exist and was created by converting GameCfg.INI
		LOADSTATUS_CREATED,		// GameCfg.INI was not found, the system created the default configuration based on found GameInfo.txt resources
		LOADSTATUS_ERROR,		// File was not loaded and was unable to perform the above fail-safe procedures
	};

			CGameConfigManager( void );
			CGameConfigManager( const char *fileName );

			~CGameConfigManager( void );

	bool	LoadConfigs( const char *baseDir = NULL );
	bool	SaveConfigs( const char *baseDir = NULL );
	bool	ResetConfigs( const char *baseDir = NULL );
	
	int		GetNumConfigs( void );

	KeyValues	*GetGameBlock( void );
	KeyValues	*GetGameSubBlock( const char *keyName );
	bool		GetDefaultGameBlock( KeyValues *pIn );

	bool	IsLoaded( void ) const { return m_pData != NULL; }

	bool	WasConvertedOnLoad( void ) const { return m_LoadStatus == LOADSTATUS_CONVERTED; }
	bool	WasCreatedOnLoad( void ) const { return m_LoadStatus == LOADSTATUS_CREATED; }
	
	bool	AddDefaultConfig( const defaultConfigInfo_t &info, KeyValues *out, const char *rootDirectory, const char *gameExeDir );

	void	SetBaseDirectory( const char *pDirectory );

	void	GetRootGameDirectory( char *out, size_t outLen, const char *rootDir );

	const char *GetRootDirectory( void );
	void	SetSDKEpoch( eSDKEpochs epoch ) { m_eSDKEpoch = epoch; };

private:

	void	GetRootContentDirectory( char *out, size_t outLen, const char *rootDir );

	const char *GetBaseDirectory( void );
	const char *GetIniFilePath( void );

	bool	LoadConfigsInternal( const char *baseDir, bool bRecursiveCall );
	void	UpdateConfigsInternal( void );
	void	VersionConfig( void );
	bool	IsConfigCurrent( void );

	bool	ConvertGameConfigsINI( void );
	bool	CreateAllDefaultConfigs( void );
	bool	IsAppSubscribed( int nAppID );

	loadStatus_t	m_LoadStatus;	// Holds various state about what occured while loading
	KeyValues		*m_pData;		// Data as read from configuration file
	char			m_szBaseDirectory[MAX_PATH];	// Default directory
	eSDKEpochs		m_eSDKEpoch;    // Holds the "working version" of the SDK for times when we need to create an older set of game configurations.
									// This is required now that the SDK is deploying the tools for both the latest and previous versions of the engine.
};

#endif // CONFIGMANAGER_H