#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;
|
}
|
|
};
|