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
#include "stdafx.h"
#include "ConfigVision.h"
#include <iostream>
#include <atlstr.h> // °üº¬CStringÍ·Îļþ
#include <time.h>
#include <stdarg.h>
#include <direct.h>
#include <vector>
#include <Dbghelp.h>
#include "FileRecipe.h"
#pragma comment(lib,"Dbghelp.lib")
 
CConfigVision::CConfigVision(){
    /* code */
}
 
CConfigVision::~CConfigVision(){
    /* code */
}
 
void CConfigVision::SetWorkDir(const char *pszPath, const char *pszName) {
    /* code */
    std::string filePath = pszPath;
    std::string strName = pszName;
    init(filePath, pszName);
}
 
void CConfigVision::init(std::string filePath, std::string strName) {
    /* code */
    std::string fileName = filePath + "\\" + strName;
    if (!CFileRecipe::fileIsExist(fileName)) {
        MakeSureDirectoryPathExists(fileName.c_str());
    }
 
    std::string str = fileName + "\\Config.ini";
    m_strFileName = CA2T(str.c_str());
    CStdioFile file;
    if (!file.Open(m_strFileName, CFile::modeCreate | CFile::modeReadWrite | CFile::modeNoTruncate)) return;
    file.Close();
}
 
bool CConfigVision::WriteText(const char *pszSection, const char *pszName, const char *pszValue) {
    /* code */
    CString strSection = CString(pszSection);
    CString strName = CString(pszName);
    CString strValue = CString(pszValue);
    BOOL isRes = WritePrivateProfileString(strSection, strName, strValue, m_strFileName);
    if (!isRes) return false;
 
    return true;
}
 
std::string CConfigVision::ReadText(const char *pszSection, const char *pszName, const char *pszDefault) {
    /* code */
    std::string strRes = pszDefault;
    CString strValue;
    CString strSection = CString(pszSection);
    CString strName = CString(pszName);
    CString strDefault = CString(pszName);
    GetPrivateProfileString(strSection, strName, strDefault, strValue.GetBuffer(MAX_PATH), MAX_PATH, m_strFileName);
    strRes = CT2A(strValue);
    return strRes;
}
 
bool CConfigVision::WriteInt(const char *pszSection, const char *pszName, int intValue) {
    /* code */
    CString strSection = CString(pszSection);
    CString strName = CString(pszName);
    CString strValue;
    strValue.Format(_T("%d"), intValue);
    BOOL isRes = WritePrivateProfileString(strSection, strName, strValue, m_strFileName);
    if (!isRes) return false;
 
    return true;
}
 
int CConfigVision::ReadInt(const char *pszSection, const char *pszName, int defaultValue) {
    /* code */
    int intRes = defaultValue;
    CString strSection = CString(pszSection);
    CString strName = CString(pszName);
    intRes = GetPrivateProfileInt(strSection, strName, defaultValue, m_strFileName);
    return intRes;
}
 
bool CConfigVision::WriteBool(const char *pszSection, const char *pszName, int bValue) {
    /* code */
    int iValue = 0;
    if (bValue) iValue = 1;
    
    return WriteInt(pszSection, pszName, iValue);
}
 
bool CConfigVision::ReadBool(const char *pszSection, const char *pszName, bool deaultBool) {
    /* code */
    int defaultInt = 0;
    if (deaultBool)  defaultInt = 1;
    int nRet = ReadInt(pszSection, pszName, defaultInt);
    
    bool res = (1 == nRet);
    return res;
}
 
bool CConfigVision::WriteFloat(const char *pszSection, const char *pszName, double fValue) {
    /* code */
    CString strSection = CString(pszSection);
    CString strName = CString(pszName);
    CString strValue;
    strValue.Format(_T("%.6f"), fValue);
    BOOL isRes = WritePrivateProfileString(strSection, strName, strValue, m_strFileName);
    if (!isRes) return false;
 
    return true;
}
 
double CConfigVision::ReadFloat(const char *pszSection, const char *pszName, double defaultValue) {
    /* code */
    CString strSection = CString(pszSection);
    CString strName = CString(pszName);
    CString strDefault;
    strDefault.Format(_T("%.6f"), defaultValue);
    CString strValue;
    GetPrivateProfileString(strSection, strName, strDefault, strValue.GetBuffer(MAX_PATH), MAX_PATH, m_strFileName);
    std::string strRes = CT2A(strValue);
    double fValue = atof(strRes.c_str());
    return fValue;
}