void CDownloadDlg::OnCancel() { // TODO: Add extra cleanup here m_btnCancel.EnableWindow( FALSE ); AfxGetStkReceiver().RemoveRcvDataWnd( GetSafeHwnd() ); AfxReleaseDB(); char szErr[1024]; if( !AfxInitializeDB( szErr, sizeof(szErr) ) ) AfxMessageBox( szErr, MB_OK|MB_ICONINFORMATION ); CDialog::OnCancel( ); if( m_bDBModified ) { BOOL bRecalculate = FALSE; CSPTime tmLatest = 0; if( ( m_netdb.SetRootPath( AfxGetProfile().GetSelfDBPath(), IStStore::dbtypeSelfDB ) && m_netdb.GetTimeLocalRange( &tmLatest, NULL, NULL ) && tmLatest.GetTime() > m_tmLatestOld.GetTime() ) ) { bRecalculate = TRUE; } if( m_bAutoRun ) bRecalculate = FALSE; AfxGetStkUIApp()->OnDBChanged( FALSE /*bRecalculate*/ ); } if( !m_bAutoRun ) { CNetInfoDlg dlg; dlg.DoModal( ); if( AfxGetProfile().HasNewVersion() && IDYES == AfxMessageBox( IDS_DOWNLOAD_UPGRADENOW, MB_YESNO ) ) { CUpgradeDlg dlg; dlg.SetAutoRun( TRUE ); dlg.DoModal(); } } CXFDialog::PostNcDestroy(); }
void CMainFrame::OnAppUpgrade() { // TODO: Add your command handler code here CString myStr; BOOL myhasUpgrade = FALSE; CMyCommApp *myApp = (CMyCommApp *)AfxGetApp(); CMainFrame * myMain = (CMainFrame *) myApp->GetMainWnd(); CStdioFile myfile; CString vertext = myApp->m_AppDir + "\\version"; if(!myMain->m_IsNewVertxt || !IsFileExist(vertext)) { char s[256]; _tcscpy(s,vertext.GetBuffer(vertext.GetLength())) ; if(!DonwLoadFile("https://github.com/liquanhai/LSDComm/version/ver.txt",s)) { AfxMessageBox(_T("无法连接服务器。")); return; } myMain->m_IsNewVertxt = TRUE; } if(!myfile.Open(vertext,CFile::modeRead)) { AfxMessageBox(_T("打开升级文件出错。")); return; } else{ CString myverion; myfile.ReadString(myverion); //line:1 myverion.TrimLeft(); myverion.TrimRight(); if (atof(myApp->m_AppVersion)<atof(myverion)) { //new version myhasUpgrade = TRUE; CMyCommView * myview = (CMyCommView *) myMain->GetActiveView(); myStr = "最新版本:"+myverion+"\r\n"; CString strLine; myfile.ReadString(strLine); // downfilename line:2 myApp->m_downfileexefilename = strLine; while(myfile.ReadString(strLine)) { if(strLine.GetLength()>2) if ((strLine[0] == '>') && (strLine[1]=='>')) myStr += strLine+"\r\n"; } } else{ myStr = myApp->m_AppVersion + "版本已是最新了"; } } myfile.Close(); CUpgradeDlg dlg; dlg.m_strData = myStr; dlg.m_strdownfile = myApp->m_downfileexefilename; dlg.m_StrLocalfile = myApp->m_AppDir + "\\exe"; dlg.m_IsUpgrade = myhasUpgrade; if((dlg.DoModal()==IDOK) && myhasUpgrade) { if(!IsFileExist(myApp->m_AppDir + "\\exe")) return; CStdioFile batfile; CString mybatFile; CString myAppDir; mybatFile = myApp->m_AppDir+"\\update.bat"; if(!batfile.Open(mybatFile,CStdioFile::modeReadWrite|CStdioFile::modeCreate)) return; myAppDir = DoGetShortFileName(myApp->m_AppDir); batfile.WriteString("@echo off\n\r"); CString myexename; myexename = myAppDir + "\\LSDComm.exe"; batfile.WriteString("del "+ myexename + "\n\r"); batfile.WriteString("if exist "+ myexename +" goto loop" + "\n\r"); batfile.WriteString("copy "+ myAppDir + "\\exe" + " " + myexename + "\n\r"); batfile.WriteString("del "+ myAppDir + "\\exe" + "\n\r"); batfile.WriteString(myexename+"\n\r"); batfile.WriteString("del "+mybatFile+"\n\r"); batfile.Close(); ShellExecute(NULL,NULL,mybatFile,NULL,NULL,SW_HIDE); CFrameWnd::OnClose(); }; }