106 lines
2.8 KiB
C++
106 lines
2.8 KiB
C++
#include "stdafx.h"
|
|
#include "acdocman.h"
|
|
|
|
#define RES_ARX_TYPE MAKEINTRESOURCE(300)
|
|
#define RES_DWG_TYPE MAKEINTRESOURCE(301)
|
|
#define RES_ARX_NAME1 MAKEINTRESOURCE(1)
|
|
#define RES_ARX_NAME2 MAKEINTRESOURCE(2)
|
|
#define RES_ARX_NAME3 MAKEINTRESOURCE(3)
|
|
#define RES_DWG_NAME MAKEINTRESOURCE(1)
|
|
|
|
//添加、删除、替换可执行文件中的资源
|
|
//删除时使用默认参数。
|
|
bool UpdateResource(const TCHAR* sFile,LPCTSTR sType,LPCTSTR sName,LPVOID pData,DWORD size)
|
|
{
|
|
HANDLE hUpdateRes=BeginUpdateResource(sFile,FALSE);
|
|
if (hUpdateRes==NULL)
|
|
return false;
|
|
if (!UpdateResource(hUpdateRes,sType,sName,MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),pData,size))
|
|
return false;
|
|
if (!EndUpdateResource(hUpdateRes,FALSE))
|
|
return false;
|
|
return true;
|
|
}
|
|
//将文件数据添加到或替换到可执行文件的资源,数据文件不能空!
|
|
bool UpdateFileDataResource(const TCHAR* sDataFile,const TCHAR *sFileExe,LPCTSTR sType,LPCTSTR sName)
|
|
{
|
|
CFile file;
|
|
if (!file.Open(sDataFile,CFile::modeRead))
|
|
return false;
|
|
DWORD size=(DWORD)file.GetLength();
|
|
if (size<1)
|
|
{
|
|
file.Close();
|
|
return false;
|
|
}
|
|
LPVOID pData=new TCHAR[size];
|
|
file.Read(pData,size);
|
|
file.Close();
|
|
bool bRes=UpdateResource(sFileExe,sType,sName,pData,size);
|
|
delete[] pData;
|
|
return bRes;
|
|
}
|
|
//void SaveEx()
|
|
//{
|
|
// int bDwgTitled=0;
|
|
// xg_getvar(_T("DWGTITLED"), &bDwgTitled);
|
|
// if (!bDwgTitled)
|
|
// {
|
|
// AfxMessageBox(_T("请首先将当前文件保存为dwg文件!"));
|
|
// return;
|
|
// }
|
|
//
|
|
// XString sExe;
|
|
// if (!FindFile(_T("MySave.exe"),sExe))
|
|
// {
|
|
// AfxMessageBox(_T("保存失败!"));
|
|
// return;
|
|
// }
|
|
//
|
|
// CString temp=curDoc()->fileName();
|
|
// temp.Replace(_T(".dwg"),_T(".exe"));
|
|
// CFileDialog dlg(FALSE,_T("exe"),temp,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
|
|
// _T("包含上华解释器的图形文件(*.exe)|*.exe|"));
|
|
// if (dlg.DoModal()!=IDOK)
|
|
// return;
|
|
//
|
|
// if (!CopyFile(sExe,dlg.GetPathName(),FALSE))
|
|
// {
|
|
// AfxMessageBox(_T("保存失败!"));
|
|
// return;
|
|
// }
|
|
// SetFileAttributes(dlg.GetPathName(),0);
|
|
// XString sFileKernal;
|
|
// FindFile(_T("TPlugIn.exe"),sFileKernal);
|
|
// if (!UpdateFileDataResource(sFileKernal,dlg.GetPathName(),RES_ARX_TYPE,RES_ARX_NAME1))
|
|
// {
|
|
// AfxMessageBox(_T("保存失败!"));
|
|
// return;
|
|
// }
|
|
//
|
|
// temp.Replace(_T(".exe"),_T(".tmp"));
|
|
// if (!CopyFile(curDoc()->fileName(),temp,FALSE))
|
|
// {
|
|
// AfxMessageBox(_T("保存失败!"));
|
|
// return;
|
|
// }
|
|
// if (!UpdateFileDataResource(temp,dlg.GetPathName(),RES_DWG_TYPE,RES_DWG_NAME))
|
|
// AfxMessageBox(_T("保存失败!"));
|
|
// DeleteFile(temp);
|
|
//}
|
|
void SaveEx()
|
|
{
|
|
XString sFile;
|
|
if (!FindFile(_T("TPlugIn.exe"),sFile))
|
|
{
|
|
AfxMessageBox(_T("未找到TPlugIn.exe文件!"));
|
|
return;
|
|
}
|
|
CFileDialog dlg(FALSE,_T("exe"),_T("TPlugIn.exe"),OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
|
|
_T("上华图形插件(*.exe)|*.exe|"));
|
|
if (dlg.DoModal()!=IDOK)
|
|
return;
|
|
|
|
if (!CopyFile(sFile,dlg.GetPathName(),FALSE))
|
|
AfxMessageBox(_T("复制上华插件文件失败!"));
|
|
} |