-
Notifications
You must be signed in to change notification settings - Fork 98
/
ConfigManager.h
135 lines (100 loc) · 3.96 KB
/
ConfigManager.h
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//========= Copyright © 1996-2005, 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"
// STEAM CLOUD FLAGS
#define STEAMREMOTESTORAGE_CLOUD_CONFIG (1<<0)
#define STEAMREMOTESTORAGE_CLOUD_ALL 0x7fff // all bits set, so any new items added will be on by default
struct defaultConfigInfo_t
{
char gameName[MAX_PATH];
char gameDir[MAX_PATH];
char FGD[MAX_PATH];
char steamPath[MAX_PATH];
char defaultPointEntity[MAX_PATH];
char exeName[MAX_PATH];
int steamAppID;
};
enum eSDKEpochs
{
SDK_EPOCH_HL2 = 1,
SDK_EPOCH_EP1 = 2,
SDK_EPOCH_EP2 = 3,
SDK_EPOCH_PORTAL2 = 4,
SDK_EPOCH_CSS15 = 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 *steamDir );
const char *GetRootDirectory( void );
void SetSDKEpoch( eSDKEpochs epoch ) { m_eSDKEpoch = epoch; };
static bool IsSDKDeployment()
{
static bool bRetVal = false;
static bool bInitialized = false;
if ( g_pFullFileSystem && !bInitialized )
{
char szBaseDirectory[MAX_PATH];
// Check to see whether 'steamapps/common' is part of the path to this EXE
g_pFullFileSystem->GetCurrentDirectory( szBaseDirectory, sizeof( szBaseDirectory ) );
V_FixSlashes( szBaseDirectory, '/' );
bRetVal = ( V_stristr( szBaseDirectory, "steamapps/common" ) != NULL );
bInitialized = true;
}
return ( bRetVal );
};
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