诸暨麻将添加redis
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

212 lines
5.2 KiB

  1. #include "StdAfx.h"
  2. #include "WHIniData.h"
  3. #include "WHEncrypt.h"
  4. //////////////////////////////////////////////////////////////////////////////////
  5. //构造函数
  6. CWHIniData::CWHIniData()
  7. {
  8. //设置变量
  9. ZeroMemory(m_szIniFile, sizeof(m_szIniFile));
  10. return;
  11. }
  12. //析构函数
  13. CWHIniData::~CWHIniData()
  14. {
  15. }
  16. //设置路径
  17. VOID CWHIniData::SetIniFilePath(LPCTSTR pszIniFile)
  18. {
  19. //设置变量
  20. lstrcpyn(m_szIniFile, pszIniFile, CountArray(m_szIniFile));
  21. return;
  22. }
  23. //读取数值
  24. UINT CWHIniData::ReadInt(LPCTSTR pszItem, LPCTSTR pszSubItem, INT nDefault)
  25. {
  26. //效验状态
  27. ASSERT(m_szIniFile[0] != 0);
  28. //读取数值
  29. UINT uReadData = GetPrivateProfileInt(pszItem, pszSubItem, nDefault, m_szIniFile);
  30. return uReadData;
  31. }
  32. //读取字符
  33. LPCTSTR CWHIniData::ReadString(LPCTSTR pszItem, LPCTSTR pszSubItem, LPCTSTR pszDefault, LPTSTR pszString, WORD wMaxCount)
  34. {
  35. //效验状态
  36. ASSERT(m_szIniFile[0] != 0);
  37. //读取字符
  38. GetPrivateProfileString(pszItem, pszSubItem, pszDefault, pszString, wMaxCount, m_szIniFile);
  39. return pszString;
  40. }
  41. //读取字符
  42. LPCTSTR CWHIniData::ReadEncryptString(LPCTSTR pszItem, LPCTSTR pszSubItem, LPCTSTR pszDefault, LPTSTR pszString, WORD wMaxCount)
  43. {
  44. //效验状态
  45. ASSERT(m_szIniFile[0] != 0);
  46. ASSERT(wMaxCount <= MAX_SOURCE_LEN);
  47. //设置结果
  48. if (wMaxCount > 0) pszString[0] = 0;
  49. //读取字符
  50. TCHAR szStringRead[MAX_ENCRYPT_LEN];
  51. DWORD dwReadCount = GetPrivateProfileString(pszItem, pszSubItem, NULL, szStringRead, MAX_ENCRYPT_LEN, m_szIniFile);
  52. //解密字符
  53. if ((dwReadCount > 0) && (dwReadCount<CountArray(szStringRead)))
  54. {
  55. CWHEncrypt WHEncrypt;
  56. WHEncrypt.XorCrevasse(szStringRead, pszString, wMaxCount);
  57. }
  58. //默认参数
  59. if ((wMaxCount>0) && (pszString[0] == 0)) lstrcpyn(pszString, pszDefault, wMaxCount);
  60. return pszString;
  61. }
  62. //读取矩形
  63. bool CWHIniData::ReadRect(RECT & ValueRect, LPCTSTR pszItem, LPCTSTR pszSubItem)
  64. {
  65. //效验状态
  66. ASSERT(m_szIniFile[0] != 0);
  67. //设置变量
  68. TCHAR szReadData[64] = TEXT("");
  69. ZeroMemory(&ValueRect, sizeof(ValueRect));
  70. //读取字符
  71. GetPrivateProfileString(pszItem, pszSubItem, TEXT(""), szReadData, CountArray(szReadData), m_szIniFile);
  72. //数据处理
  73. if (szReadData[0] != 0)
  74. {
  75. //读取变量
  76. LPCTSTR pszString = szReadData;
  77. ValueRect.left = SwitchStringToValue(pszString);
  78. ValueRect.top = SwitchStringToValue(pszString);
  79. ValueRect.right = SwitchStringToValue(pszString);
  80. ValueRect.bottom = SwitchStringToValue(pszString);
  81. return true;
  82. }
  83. return false;
  84. }
  85. //读取尺寸
  86. bool CWHIniData::ReadSize(SIZE & ValueSize, LPCTSTR pszItem, LPCTSTR pszSubItem)
  87. {
  88. //效验状态
  89. ASSERT(m_szIniFile[0] != 0);
  90. //设置变量
  91. TCHAR szReadData[64] = TEXT("");
  92. ZeroMemory(&ValueSize, sizeof(ValueSize));
  93. //读取字符
  94. GetPrivateProfileString(pszItem, pszSubItem, TEXT(""), szReadData, CountArray(szReadData), m_szIniFile);
  95. //数据处理
  96. if (szReadData[0] != 0)
  97. {
  98. //读取变量
  99. LPCTSTR pszString = szReadData;
  100. ValueSize.cx = SwitchStringToValue(pszString);
  101. ValueSize.cy = SwitchStringToValue(pszString);
  102. return true;
  103. }
  104. return false;
  105. }
  106. //读取坐标
  107. bool CWHIniData::ReadPoint(POINT & ValuePoint, LPCTSTR pszItem, LPCTSTR pszSubItem)
  108. {
  109. //效验状态
  110. ASSERT(m_szIniFile[0] != 0);
  111. //设置变量
  112. TCHAR szReadData[64] = TEXT("");
  113. ZeroMemory(&ValuePoint, sizeof(ValuePoint));
  114. //读取字符
  115. GetPrivateProfileString(pszItem, pszSubItem, TEXT(""), szReadData, CountArray(szReadData), m_szIniFile);
  116. //数据处理
  117. if (szReadData[0] != 0)
  118. {
  119. //读取变量
  120. LPCTSTR pszString = szReadData;
  121. ValuePoint.x = SwitchStringToValue(pszString);
  122. ValuePoint.y = SwitchStringToValue(pszString);
  123. return true;
  124. }
  125. return false;
  126. }
  127. //读取颜色
  128. bool CWHIniData::ReadColor(COLORREF & ValueColor, LPCTSTR pszItem, LPCTSTR pszSubItem)
  129. {
  130. //效验状态
  131. ASSERT(m_szIniFile[0] != 0);
  132. //设置变量
  133. TCHAR szReadData[64] = TEXT("");
  134. ZeroMemory(&ValueColor, sizeof(ValueColor));
  135. //读取字符
  136. GetPrivateProfileString(pszItem, pszSubItem, TEXT(""), szReadData, CountArray(szReadData), m_szIniFile);
  137. //数据处理
  138. if (szReadData[0] != 0)
  139. {
  140. //读取变量
  141. LPCTSTR pszString = szReadData;
  142. ValueColor = RGB(SwitchStringToValue(pszString), SwitchStringToValue(pszString), SwitchStringToValue(pszString));
  143. return true;
  144. }
  145. return false;
  146. }
  147. //转换数值
  148. LONG CWHIniData::SwitchStringToValue(LPCTSTR & pszSring)
  149. {
  150. //效验参数
  151. ASSERT((pszSring != NULL) && (pszSring[0] != 0));
  152. if ((pszSring == NULL) || (pszSring[0] == 0)) return 0L;
  153. //寻找开始
  154. while (((pszSring[0] > 0) && (pszSring[0]<TEXT('0'))) || (pszSring[0]>TEXT('9'))) pszSring++;
  155. //读取数值
  156. LONG lValue = 0L;
  157. while ((pszSring[0] >= TEXT('0')) && (pszSring[0] <= TEXT('9')))
  158. {
  159. lValue = lValue * 10L + pszSring[0] - TEXT('0');
  160. ++pszSring;
  161. }
  162. return lValue;
  163. }
  164. //////////////////////////////////////////////////////////////////////////////////