#include "MakeSetup.h"
#include <Windows.h>
#include <tchar.h>
#include <QtWidgets/QApplication>
#include <QFile>
bool updateZipRes(const QString& exeFile)
{
BOOL ret = FALSE;
QString strErr;
DWORD fileSize = 0;
DWORD readSize = 0;
if (!QFile::exists(exeFile))
{
//strErr.Format(_T("File %s Does not Exist!"), m_strExe);
//AfxMessageBox(strErr);
return FALSE;
}
QFile file(exeFile);
if (file.open(QFile::ReadOnly) == FALSE)
{
//CString strErrMsg("Failed to Open ");
//strErrMsg += strRes;
//strErrMsg += " !";
//MessageBox(strErrMsg);
return FALSE;
}
char *pData = NULL;
fileSize = file.size();
if (fileSize==0)
{
file.close();
//strErr.Format(_T("File size 0!"));
//MessageBox(strErr);
return FALSE;
}
pData = new char[fileSize];
memset(pData,0,fileSize);
if(fileSize != file.read(pData, fileSize))
{
//strErr.Format(_T("Read File Failed"));
//MessageBox(strErr);
file.close();
return FALSE;
}
file.close();
std::wstring wstr = exeFile.toStdWString();
const wchar_t *wstrName = wstr.c_str();
HANDLE upResHandle = BeginUpdateResource(wstrName, FALSE);
if (upResHandle == NULL)
{
//strErr.Format(_T("Open file %s Failed"),m_strExe);
//AfxMessageBox(strErr);
return FALSE;
}
const int resourceID = 101;
ret = UpdateResource(upResHandle, L"ZIP",
MAKEINTRESOURCE(resourceID), MAKELANGID(LANG_CHINESE,0x2),pData, fileSize);
delete [] pData;
pData = NULL;
if (ret == FALSE)
{
//AfxMessageBox(_T("UpdateResource Failed!"));
return FALSE;
}
ret = EndUpdateResource(upResHandle, FALSE);
if (ret == FALSE)
{
//AfxMessageBox(_T("UpdateResource Failed!"));
return FALSE;
}
return TRUE;
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
updateZipRes("../Win32/Debug/Setup2.exe");
//MakeSetup w;
//w.show();
return a.exec();
}
#include <Windows.h>
#include <tchar.h>
#include <QtWidgets/QApplication>
#include <QFile>
bool updateZipRes(const QString& exeFile)
{
BOOL ret = FALSE;
QString strErr;
DWORD fileSize = 0;
DWORD readSize = 0;
if (!QFile::exists(exeFile))
{
//strErr.Format(_T("File %s Does not Exist!"), m_strExe);
//AfxMessageBox(strErr);
return FALSE;
}
QFile file(exeFile);
if (file.open(QFile::ReadOnly) == FALSE)
{
//CString strErrMsg("Failed to Open ");
//strErrMsg += strRes;
//strErrMsg += " !";
//MessageBox(strErrMsg);
return FALSE;
}
char *pData = NULL;
fileSize = file.size();
if (fileSize==0)
{
file.close();
//strErr.Format(_T("File size 0!"));
//MessageBox(strErr);
return FALSE;
}
pData = new char[fileSize];
memset(pData,0,fileSize);
if(fileSize != file.read(pData, fileSize))
{
//strErr.Format(_T("Read File Failed"));
//MessageBox(strErr);
file.close();
return FALSE;
}
file.close();
std::wstring wstr = exeFile.toStdWString();
const wchar_t *wstrName = wstr.c_str();
HANDLE upResHandle = BeginUpdateResource(wstrName, FALSE);
if (upResHandle == NULL)
{
//strErr.Format(_T("Open file %s Failed"),m_strExe);
//AfxMessageBox(strErr);
return FALSE;
}
const int resourceID = 101;
ret = UpdateResource(upResHandle, L"ZIP",
MAKEINTRESOURCE(resourceID), MAKELANGID(LANG_CHINESE,0x2),pData, fileSize);
delete [] pData;
pData = NULL;
if (ret == FALSE)
{
//AfxMessageBox(_T("UpdateResource Failed!"));
return FALSE;
}
ret = EndUpdateResource(upResHandle, FALSE);
if (ret == FALSE)
{
//AfxMessageBox(_T("UpdateResource Failed!"));
return FALSE;
}
return TRUE;
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
updateZipRes("../Win32/Debug/Setup2.exe");
//MakeSetup w;
//w.show();
return a.exec();
}