📄 config.h
字号:
/*
This file is part of KCeasy (http://www.kceasy.com)
Copyright (C) 2002-2004 Markus Kern <mkern@kceasy.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
//---------------------------------------------------------------------------
#ifndef ConfigH
#define ConfigH
#include <windows.h>
#include <map>
#include "istring.h"
//---------------------------------------------------------------------------
#ifdef CONFIG_STREAM_METHODS
# include <Classes.hpp>
#endif // CONFIG_STREAM_METHODS
namespace KCeasyEngine {
using std::map;
using std::list;
class TFileConfigValue
{
public:
TFileConfigValue(const string& Nam, const string& Val, int Position)
: Name(Nam), Value(Val), Pos(Position) {};
TFileConfigValue() : Pos(-1) {};
string Name;
string Value;
string Descr;
int Pos; // position in config file
};
class TFileConfigSection
{
public:
TFileConfigSection(const string& Nam, int Position) : Name(Nam), Pos(Position) {};
TFileConfigSection() : Pos(-1) {};
string Name;
string Descr;
map<string,TFileConfigValue> Values;
int Pos; // position in config file
};
class TFileConfig
{
public:
TFileConfig();
TFileConfig(const string& NFilePath);
~TFileConfig();
void SetFilePath(const string& NFilePath) { FilePath = NFilePath; }
string& GetFilePath() { return FilePath; }
void SetDefaults(unsigned int DefaultsResId = 0) { DefaultConfResId = DefaultsResId; }
// if ForceReload == false and the file time hasn't changed no loading occurs
bool Load(bool ForceReload = false, bool LoadDefaults = false);
bool Save();
// Key is in the form of "<section>/<name>"
bool ValueExists(const char* Key);
const string& GetValue(const char* Key);
int GetValueInt(const char* Key);
void SetValue(const char* Key, const char* Value);
void SetValueInt(const char* Key, int Value);
bool RemoveValue(const char* Key);
bool RemoveSection(const char* Section);
list<string> GetNames(const char* Section);
list<string> GetSections();
#ifdef CONFIG_STREAM_METHODS
bool SetValueStream(const char* Key, TStream* Stream);
bool GetValueStream(const char* Key, TStream* Stream);
#endif // CONFIG_STREAM_METHODS
bool ValueExists(const string& Key) { return ValueExists(Key.c_str()); }
const string& GetValue(const string& Key) { return GetValue(Key.c_str()); }
int GetValueInt(const string& Key) { return GetValueInt(Key.c_str()); }
void SetValue(const string& Key, const string& Value) { SetValue(Key.c_str(),Value.c_str()); }
void SetValueInt(const string& Key, int Value) { SetValueInt(Key.c_str(),Value); }
bool RemoveValue(const string& Key) { return RemoveValue(Key.c_str()); }
bool RemoveSection(const string& Section) { return RemoveSection(Section.c_str()); }
list<string> GetNames(const string& Section) { return GetNames(Section.c_str()); }
#ifdef CONFIG_INCLUDE_STREAM_METHODS
bool SetValueStream(const string& Key, TStream* Stream) { return SetValueStream(Key.c_str(), Stream); }
bool GetValueStream(const string& Key, TStream* Stream) { return GetValueStream(Key.c_str(), Stream); }
#endif // CONFIG_INCLUDE_STREAM_METHODS
private:
bool ParseString(const string& Config);
static string SectionFromKey(const char* Key);
static string NameFromKey(const char* Key);
const string EmptyString;
string FilePath;
FILETIME LastFileWriteTime;
unsigned int DefaultConfResId;
map<string,TFileConfigSection> Sections;
};
// reads string or dword (which gets converted to string)
// Key is of the form "HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Run\\foo"
// returns NULL on fail, caller frees returned string
char* ReadRegKey(const char* Key);
// writes string
// Key is of the form "HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Run\\foo"
// if Value is NULL value is removed
bool WriteRegKey(const char* Key, const char* Value);
// writes dword
// Key is of the form "HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Run\\foo"
// use WriteRegKey(NULL) to remove key
bool WriteRegKeyDWORD(const char* Key, DWORD Value);
// returns the installed physical ram in MB or 0 on failure
int GetPhysicalMem();
// return the cpu speed in MHz or 0 on filure
int GetCPUSpeed();
// returns true if OS is NT/2k/XP
bool RunningWindowsNT();
} // namespace KCeasyEngine
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -