Exemplo n.º 1
0
void ThreadCheckVersion()
{
	//app dir
	CString myAppDir;
	CMyCommApp *myApp = (CMyCommApp *)AfxGetApp();
	CMainFrame * myMain = (CMainFrame *) myApp->GetMainWnd();
	CStdioFile myfile;
	myAppDir = myApp->m_AppDir;
	CString vertext = myAppDir + "\\version";
	if(!myfile.Open(vertext,CFile::modeRead))
	{
		
		CString myver;
		char s[256];
		_tcscpy(s,vertext.GetBuffer(vertext.GetLength())) ;
		if(myMain->DonwLoadFile("https://github.com/liquanhai/LSDComm/version/ver.txt",
			s))
			myMain->m_IsNewVertxt = TRUE;
		return;
	}
	else{
	   CString myverion;
	   myfile.ReadString(myverion); //line:1
	   myverion.TrimLeft();  myverion.TrimRight();
       if (atof(myApp->m_AppVersion)<atof(myverion))
	   {
			//new version
			CMyCommView * myview = (CMyCommView *) myMain->GetActiveView();
			//myview->m_EditLogger.AddText(vertext);
			//myview->m_EditLogger.AddText(myApp->m_AppVersion+"\r\n");
			myview->m_EditLogger.AddText(">>最新版本:"+myverion+"\r\n");
			CString strLine;
			myfile.ReadString(strLine); // downfilename line:2
			myApp->m_downfileexefilename = strLine;
			myfile.ReadString(strLine); //line:3
			myview->m_EditLogger.AddText(">>"+strLine +"\r\n");
			myview->m_EditLogger.AddText(">>升级点击主菜单的[帮助]->[在线升级]\r\n");

			myfile.Close();
			myMain->m_IsNewVertxt = TRUE;
	   }
	   else{
		   
		   char s[256];
		   _tcscpy(s,vertext.GetBuffer(vertext.GetLength())) ;
		   if(myMain->DonwLoadFile("https://github.com/liquanhai/LSDComm/version/ver.txt",
			   s))
				myMain->m_IsNewVertxt = TRUE;
		   myfile.Close();
		   
		   return;
	   }
	}
	
}
Exemplo n.º 2
0
void ThreadCheckVersion()
{
#if 1
	//app dir
	CString myAppDir;
	CMyCommApp *myApp = (CMyCommApp *)AfxGetApp();
	CMainFrame * myMain = (CMainFrame *) myApp->GetMainWnd();
	CStdioFile myfile;
	myAppDir = myApp->m_AppDir;
	CString vertext = myAppDir + "\\version";
	if(!myfile.Open(vertext,CFile::modeRead))
	{
		
		CString myver;
		char s[256];
		_tcscpy(s,vertext.GetBuffer(vertext.GetLength())) ;
		if(myMain->DonwLoadFile("http://git.oschina.net/yihui/lsdcomm/raw/master/release/version.txt",
			s))
			myMain->m_IsNewVertxt = TRUE;
		return;
	}
	else{
	   CString myverion;
	   myfile.ReadString(myverion); //line:1
	   myverion.TrimLeft();  myverion.TrimRight();
       if (atof(myApp->m_AppVersion)<atof(myverion))
	   {
			//new version
			CMyCommView * myview = (CMyCommView *) myMain->GetActiveView();
			//myview->m_EditLogger.AddText(vertext);
			//myview->m_EditLogger.AddText(myApp->m_AppVersion+"\r\n");
			myview->m_EditLogger.AddText(">>Latest Version:"+myverion+"\r\n");
			CString strLine;
			myfile.ReadString(strLine); // downfilename line:2
			myApp->m_downfileexefilename = strLine;
			myfile.ReadString(strLine); //line:3
			myview->m_EditLogger.AddText(">>"+strLine +"\r\n");
			myview->m_EditLogger.AddText(">>Click menu[Help]->[Upgrade]\r\n");

			myfile.Close();
			myMain->m_IsNewVertxt = TRUE;
	   }
	   else{
		   char s[256];
		   _tcscpy(s,vertext.GetBuffer(vertext.GetLength())) ;
		   if(myMain->DonwLoadFile("http://git.oschina.net/yihui/lsdcomm/raw/master/release/version.txt",
			   s))
				myMain->m_IsNewVertxt = TRUE;
		   myfile.Close();
		   
		   return;
	   }
	}
#endif
}
Exemplo n.º 3
0
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();
	};

}