admin
2023-03-07 8b06b1cbf112d55307ea8a6efe711db4e7506d89
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
#pragma once
#include <tchar.h>
#include <string>
#include <stringapiset.h>
#include <fstream>
 
class Tool {
 
public:
    static std::string cstring2String(CString getbuf) {
        int iLen = WideCharToMultiByte(CP_ACP, 0, getbuf, -1, NULL, 0, NULL, NULL);   //Ê×ÏȼÆËãTCHAR ³¤¶È¡£
        char* chRtn = new char[iLen * sizeof(char)];  //¶¨ÒåÒ»¸ö TCHAR ³¤¶È´óСµÄ CHAR ÀàÐÍ¡£
        WideCharToMultiByte(CP_ACP, 0, getbuf, -1, chRtn, iLen, NULL, NULL);  //½«TCHAR ÀàÐ͵ÄÊý¾Ýת»»Îª CHAR ÀàÐÍ¡£
        std::string str(chRtn);
        return str;
    }
 
    static bool UnicodeToChinese(string str, CString& cstr)
    {
        int i = 0;
        int j = 0;
        int len = 0;
 
        len = str.length();
        if (len <= 0)
        {
            return false;
        }
 
        int nValue = 0;
        WCHAR* pWchar;
        wchar_t* szHex;
        char strchar[6] = { '0','x','\0' };
 
        for (i = 0; i < len; i++)
        {
            if (str[i] == 'u')
            {
                for (j = 2; j < 6; j++)
                {
                    i++;
                    strchar[j] = str[i];
                }
 
                USES_CONVERSION;
                szHex = A2W(strchar);
 
                StrToIntExW(szHex, STIF_SUPPORT_HEX, &nValue);
                pWchar = (WCHAR*)&nValue;
 
                cstr = cstr + pWchar;
            }
        }
        return true;
    }
 
 
    static void saveSettings(string path,list<string> contentList) {
        ofstream ofs;
        ofs.open(path, ios::trunc);
 
        int index = 0;
        for (list<string>::iterator ele = contentList.begin();ele != contentList.end();++ele)
        {
            index++;
            ofs << *ele;
            if(index<contentList.size())
            ofs << "\n";
        }
        ofs.close();
    }
 
    static void saveText(string path, string text) {
        ofstream ofs;
        ofs.open(path, ios::trunc);
        ofs << text;
        ofs.close();
    }
 
    static list<string> getSettings(string path) {
        list<string> mList;
        try {
            ifstream  ifs;
            ifs.open(path, ios::in);
            char buf[1024] = { 0 };
            while (ifs.getline(buf, sizeof(buf))) {
                cout << buf << endl;
                string content = string(buf);
                if(content.length()>0)
                    mList.push_back(string(buf));
            }
        }
        catch (...) {
        }
        return mList;
    }
 
};