KIniFile.h
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:5k
源码类别:

模拟服务器

开发平台:

C/C++

  1. //---------------------------------------------------------------------------
  2. // Sword3 Engine (c) 1999-2000 by Kingsoft
  3. //
  4. // File: KIniFile.h
  5. // Date: 2000.08.08
  6. // Code: WangWei(Daphnis)
  7. // Desc: Header File
  8. //---------------------------------------------------------------------------
  9. #ifndef KIniFile_H
  10. #define KIniFile_H
  11. //---------------------------------------------------------------------------
  12. #include "KMemStack.h"
  13. //---------------------------------------------------------------------------
  14. typedef struct tagKeyNode {
  15. DWORD dwID;
  16. LPSTR pKey;
  17. LPSTR pValue;
  18. tagKeyNode* pNextNode;
  19. } KEYNODE;
  20. //---------------------------------------------------------------------------
  21. typedef struct tagSecNode {
  22. DWORD dwID;
  23. LPSTR pSection;
  24. tagKeyNode pKeyNode;
  25. tagSecNode* pNextNode;
  26. } SECNODE;
  27. //---------------------------------------------------------------------------
  28. ENGINE_API void g_SetIniCodec(int nCodec);
  29. //---------------------------------------------------------------------------
  30. class ENGINE_API KIniFile
  31. {
  32. private:
  33. SECNODE m_Header;
  34. LONG m_Offset;
  35. KMemStack m_MemStack;
  36. private:
  37. void CreateIniLink(LPVOID Buffer,LONG Size);
  38. void ReleaseIniLink();
  39. DWORD String2Id(LPCSTR pString);
  40. BOOL ReadLine(LPSTR Buffer,LONG Size);
  41. BOOL IsKeyChar(char ch);
  42. LPSTR SplitKeyValue(LPSTR pString);
  43. BOOL SetKeyValue(LPCSTR pSection,LPCSTR pKey,LPCSTR pValue);
  44. BOOL GetKeyValue(LPCSTR pSection,LPCSTR pKey,LPSTR pValue,DWORD dwSize);
  45. public:
  46. KIniFile();
  47. ~KIniFile();
  48. BOOL Load(LPCSTR FileName);
  49. BOOL Save(LPCSTR FileName);
  50. BOOL LoadPack(LPCSTR FileName);
  51. BOOL SavePack(LPCSTR FileName);
  52. void Clear();
  53. BOOL IsSectionExist(LPCSTR lpSection);
  54. void EraseSection(LPCSTR lpSection);
  55. void EraseKey(LPCSTR lpSection, LPCSTR lpKey);
  56. BOOL GetString(
  57. LPCSTR lpSection, // points to section name
  58. LPCSTR lpKeyName, // points to key name
  59. LPCSTR lpDefault, // points to default string
  60. LPSTR lpRString, // points to destination buffer
  61. DWORD dwSize // size of string buffer
  62. );
  63. BOOL GetInteger(
  64. LPCSTR lpSection, // points to section name
  65. LPCSTR lpKeyName, // points to key name
  66. int nDefault, // default value
  67. int *pnValue        // return value
  68. );
  69. void GetInteger2(
  70. LPCSTR lpSection, // points to section name
  71. LPCSTR lpKeyName, // points to key name
  72. int *pnValue1, // value 1
  73. int *pnValue2       // value 2
  74. );
  75. BOOL GetFloat(
  76. LPCSTR lpSection, // points to section name
  77. LPCSTR lpKeyName, // points to key name
  78. float fDefault, // default value
  79. float *pfValue        // return value
  80. );
  81. void GetFloat2(
  82. LPCSTR lpSection, // points to section name
  83. LPCSTR lpKeyName, // points to key name
  84. float *pfValue1, // value 1
  85. float *pfValue2       // value 2
  86. );
  87. void GetStruct(
  88. LPCSTR lpSection, // pointer to section name
  89. LPCSTR lpKeyName, // pointer to key name
  90. LPVOID lpStruct, // pointer to buffer that contains data to add
  91. DWORD  dwSize // size, in bytes, of the buffer
  92. );
  93. void GetRect(
  94. LPCSTR lpSection,
  95. LPCSTR lpKeyName,
  96. RECT *pRect
  97. );
  98. void GetFloat3(
  99. LPCSTR lpSection,
  100. LPCSTR lpKeyName,
  101. float *pFloat
  102. );
  103. void GetFloat4(
  104. LPCSTR lpSection,
  105. LPCSTR lpKeyName,
  106. float *pRect
  107. );
  108. void GetBool(
  109. LPCSTR lpSection,
  110. LPCSTR lpKeyName,
  111. BOOL *pBool
  112. );
  113. void WriteString(
  114. LPCSTR lpSection, // pointer to section name
  115. LPCSTR lpKeyName, // pointer to key name
  116. LPCSTR lpString // pointer to string to add
  117. );
  118. void WriteInteger(
  119. LPCSTR lpSection, // pointer to section name
  120. LPCSTR lpKeyName, // pointer to key name
  121. int     Value // value to write
  122. );
  123. void WriteInteger2(
  124. LPCSTR lpSection, // pointer to section name
  125. LPCSTR lpKeyName, // pointer to key name
  126. int     Value1, // value 1 to write
  127. int Value2 // value 2 to write
  128. );
  129. void WriteFloat(
  130. LPCSTR lpSection, // pointer to section name
  131. LPCSTR lpKeyName, // pointer to key name
  132. float fValue // value to write
  133. );
  134. void WriteFloat2(
  135. LPCSTR lpSection, // pointer to section name
  136. LPCSTR lpKeyName, // pointer to key name
  137. float fValue1, // value 1 to write
  138. float fValue2 // value 2 to write
  139. );
  140. void WriteStruct(
  141. LPCSTR lpSection, // pointer to section name
  142. LPCSTR lpKeyName, // pointer to key name
  143. LPVOID lpStruct, // pointer to buffer that contains data to add
  144. DWORD  dwSize // size, in bytes, of the buffer
  145. );
  146. BOOL GetNextSection(LPCSTR pSection, LPSTR pNextSection);
  147. BOOL GetNextKey(LPCSTR pSection, LPCSTR pKey, LPSTR pNextKey);
  148. int GetSectionCount();
  149. };
  150. //---------------------------------------------------------------------------
  151. #endif