}
CString CRescueSysDlg::toShortPath(CString m_inDir) //用来将长路径名转化为短路径名.
{
char strBuffer[_MAX_PATH];
GetShortPathName(m_inDir,strBuffer,_MAX_PATH);
CString m_toDir(strBuffer);
return m_toDir;
}
5.为"开始备份"按钮或菜单项生成一个响应函数:
void CRescueSysDlg::OnBeginBkup()
{
CInputName m_inNameDlg;
// CinputName是一个对话框类,用来将用户输入的备份名称保存在inNameDlg .m_strInputEdit中.
if(IDCANCEL==m_inNameDlg.DoModal())
return;
CFile f1;
CString m_allFileName[20];
int m_savedNum=0;
if(f1.Open(getMyDir()+"backedCab.mqy",CFile::modeRead))
//读出用户以前所有备份的名称.
{
CArchive ar1(&f1,CArchive::load);
ar1>>m_savedNum;
for(int i=0;i
ar1>>m_allFileName[i];
ar1.Close();
f1.Close();
}
CTime m_curTime=CTime::GetCurrentTime();
CString strInputAdded,strIsFileName;
strInputAdded.Format("_%d_%d_%d_%d_%d",m_curTime.GetYear(),m_curTime.GetMonth(),
m_curTime.GetDay(),m_curTime.GetHour(),m_curTime.GetMinute());
strIsFileName=m_inNameDlg.m_strInputEdit+strInputAdded;
CFile f2;
f2.Open(getMyDir()+"backedCab.mqy",CFile::modeCreate|CFile::modeWrite);
CArchive ar2(&f2,CArchive::store);
ar2<
for(int j=0;j
ar2<
ar2<
ar2.Close();
f2.Close();
m_savedNum++;
DeleteFile(toShortPath(m_strWinDir)+"\\sysbckup\\rb000.cab");
CStdioFile f; //建立包含系统备份命令的批处理文件并执行.
f.Open(getMyDir()+"myTemp.bat", CFile::modeCreate|CFile::modeWrite,NULL);
CString m_strCommand=toShortPath(m_strWinDir)+"\\command\\scanreg.exe/backup\n";
f.WriteString(m_strCommand);
f.Close();
WinExec(getMyDir()+"myTemp.bat",SW_HIDE);
CString m_toRbName;
m_toRbName.Format("rb0%d.cab", m_savedNum); //格式化存储文件名.
CTime m_beginTime=CTime::GetCurrentTime();
CTimeSpan m_timeSpan=CTime::GetCurrentTime()-m_beginTime;
SYSTEM_INFO sysInfo;
GetSystemInfo(&sysInfo);
int delayTime=150/sysInfo.wProcessorLevel; //根据
计算机的速度算出大致的完成时间.
while(!CopyFile(m_strWinDir+"\\sysbckup\\rb000.cab",getMyDir()+m_toRbName,0))
{
MSG msg;
if(::PeekMessage(&msg,m_hWnd,0,0,PM_REMOVE))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
if(!(m_progress.GetPos()>=100))
m_progress.SetPos(100*m_timeSpan.GetSeconds()/delayTime);
m_timeSpan=CTime::GetCurrentTime()-m_beginTime;
}
m_progress.SetPos(100);
AfxMessageBox("已经成功的备份了系统文件");
DeleteFile(getMyDir()+"myTemp.bat");
}
6.为"开始恢复"按钮或菜单项生成一个响应函数:
void CRescueSysDlg::OnBeginRestore()
{
CRestoreDlg m_restoreDlg;
// CRestor