⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 updatedlg.cpp

📁 该程序是mobile5.0 ppc2003系统下的
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	CFile::Remove(currentdirectory+_T("version.xml"));
	CFile::Rename(currentdirectory+_T("version.xml.upd"),currentdirectory+_T("version.xml"));
}

DWORD WINAPI DownLoadUpdateFile(void* pv)
{
//	downloadfile.RemoveAll();
	HttpParams  httpParams;
	CString ServerName = GetServerName();
	int j=0;
	::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
	for(int curfile=0;curfile<fileArray.GetSize();curfile++)
	{
//		for(j=0;j<m_OldFileArray.GetSize();j+=2)
//		{//找到相同的文件
//			if(m_OldFileArray[j] == m_NewFileArray[curfile])
//				break;
//		}
	/*
		if(j<m_OldFileArray.GetSize())//找到同名的文件
				if(m_NewFileArray[curfile+1] <= m_OldFileArray[j+1])//当前版本已是最新
					continue;*/
	

		httpParams.m_filename = _T("update\\")+fileArray[curfile];
		httpParams.m_pszURL = ServerName + _T("CityManage/servlet/DataSynchronizationServlet?fileName=") + fileArray[curfile];
		//打印出url
		AfxMessageBox(httpParams.m_pszURL);
		info = _T("正在下载")+fileArray[curfile];
		if(!m_pHttpDelegate->Update(&httpParams,currentdirectory))
			info = _T("下载文件") + fileArray[curfile] +_T("失败!");
			//GetDlgItem(IDC_status)->SetWindowText(_T("下载文件") + m_NewFileArray[curfile] +_T("失败!"));
		else //GetDlgItem(IDC_status)->SetWindowText(_T("下载文件") + m_NewFileArray[curfile] +_T("成功!"));
		{
			info = _T("下载文件") + fileArray[curfile] +_T("成功!");
			//downloadfile.Add(m_NewFileArray[curfile]);
		}
			
	}
	::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));

	downloadupdatefile = true;
	stop = true;
	return 0;
}



DWORD WINAPI DownLoadVersion(void* pv)
{
	info = _T("正在连接服务器...");
	HttpParams  httpParams;;
	httpParams.m_filename = _T("update\\version.xml");
	CString ServerName = GetServerName();
	httpParams.m_pszURL = ServerName + _T("/fileDown?fileName=") + _T("update\\version.xml");
	info = _T("正在下载版本文件,请稍候...");
	::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
	if(!m_pHttpDelegate->Update(&httpParams,currentdirectory))
	{
		::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
		info = _T("下载版本文件出错!");
		stop = true;
		return -1;
	}
	::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
	downloadversion = 1;
	stop = true;
////////////////////////////////////////////////////////////////////////////////////////////////////////
//	WinExec("\"C:\\Program   Files\\Microsoft   Office\\OFFICE10\\WINWORD.EXE\"   mydoc.doc",SW_SHOW);   
////////////////////////////////////////////////////////////////////////////////////////////////////////
	return 0;
}

void CUpdateDlg::OnButton1() 
{//下一步,更新,完成的事件
	// TODO: Add your control notification handler code here
//	CString str;
//	GetDlgItemText(IDC_BUTTON1,str);
//
//	if(str==_T("更新"))
//	{	
//		downloadversion = false;
//		info = _T("开始升级系统,请稍候...");
//		//GetDlgItem(IDC_status)->SetWindowText(_T("开始升级系统,请稍候..."));
//		DWORD id=FindAppProcessID();
//		if(id!=-1)
//		{
//			if(AfxMessageBox(_T("执法通系统已在运行!\n请先关闭程序才能进行更新!\n如果选择确定将强行关闭程序!"),MB_OKCANCEL)==IDOK)
//			{
//				HANDLE ProcessHandle=OpenProcess(PROCESS_ALL_ACCESS,FALSE,id);
//				if(ProcessHandle)TerminateProcess(ProcessHandle,0);
//			}
//			
//		}
//		m_BtnOK.EnableWindow(false);
//		stop = false;
//		SetTimer(1,100,NULL);
//		DWORD ThreadId;
//		::CreateThread(NULL,0,DownLoadUpdateFile,NULL,0,&ThreadId);
//		//Update();
//		//RenameFile();
//		//GetDlgItem(IDC_status)->SetWindowText(_T("系统升级完成。"));
//		//return;
//	}
//	else if(str==_T("完成"))
//	{
//		CDialog::OnOK();
//		return;
//	}
//	else
//	{
//		if(GetConnection()==FALSE)
//		{
//			AfxMessageBox(L"对不起,不能建立GPRS连接!");
//			return;
//		}
//
//		m_BtnOK.EnableWindow(false);
//		SetTimer(1,100,NULL);
//		DWORD id;
//		::CreateThread(NULL,0,DownLoadVersion,NULL,0,&id);
//	}

downLoadAllFile();

}

BOOL CUpdateDlg::GetConnection()
{
	m_pGPRSConnection = CGPRSConnection::GetInstance();
	if(m_pGPRSConnection->BuildConnect()==TRUE)
	{
		return TRUE;
	}
	return FALSE;
}


//void CUpdateDlg::OnTimer(UINT nIDEvent) 
//{
//	// TODO: Add your message handler code here and/or call default
//	GetDlgItem(IDC_status)->SetWindowText(info);
//	if(downloadversion)
//	{
//		GetDlgItem(IDC_status)->SetWindowText(_T("读取版本信息..."));
//		m_XmlParse = CXmlParse::GetInstance();//得到新版本的信息
//		m_XmlParse->ParseVersion(m_NewFileArray,_T("zhifa"),currentdirectory+_T("version.xml.upd"));
//		
//		int position = -1;
//		LVFINDINFO info;
//		info.flags = LVFI_PARTIAL|LVFI_STRING;
//		for(int i=0;i<m_NewFileArray.GetSize();i+=2)
//		{
//			info.psz = m_NewFileArray[i];
//			position = m_FileList.FindItem(&info,-1);//找到同名的节点,即表示相同的文件
//			if(position != -1)		//找到就更新最新版本栏
//				m_FileList.SetItemText(position, 2, m_NewFileArray[i+1]); 
//			else//没找到就新增一行
//			{
//				position = m_FileList.InsertItem(m_FileList.GetItemCount(),m_NewFileArray[i]);
//				m_FileList.SetItemText(position, 2, m_NewFileArray[i+1]); 
//			}
//		}
//		GetDlgItem(IDC_status)->SetWindowText(_T("读取版本信息完毕!"));
//		SetDlgItemText(IDC_BUTTON1,_T("更新"));
//		m_BtnOK.EnableWindow(true);
//	}
//	if(downloadupdatefile)
//	{	
//		RenameFile();//文件改名
//		GetDlgItem(IDC_status)->SetWindowText(_T("系统升级完成。"));
//		SetDlgItemText(IDC_BUTTON1,_T("完成"));
//		m_BtnOK.EnableWindow(true);
//	}
//	if(stop)
//		KillTimer(1);
//	CDialog::OnTimer(nIDEvent);
//}

//void CUpdateDlg::OnButton4() 
//{
	// TODO: Add your control notification handler code here
  //  ShExecInfo.lpFile   =   TEXT("http://www.163.com");	

	//自动启动一个程序
/*
SHELLEXECUTEINFO   ShExecInfo   =   {0};   
  ShExecInfo.cbSize   =   sizeof(SHELLEXECUTEINFO);   
  ShExecInfo.fMask   =   SEE_MASK_NOCLOSEPROCESS;   
  ShExecInfo.hwnd   =   NULL;   
  ShExecInfo.lpVerb   =   NULL;   
  ShExecInfo.lpFile   =  TEXT("\\数字城管\\数字城管.exe");                    
  ShExecInfo.lpParameters   =NULL;           
  ShExecInfo.lpDirectory   = TEXT("\\数字城管") ;   
  ShExecInfo.nShow   =   SW_SHOWNORMAL;           
  ShellExecuteEx(&ShExecInfo);   
*/

//getFileName();
	//getFileName();
//	downLoadAllFile();

//}

void CUpdateDlg::DownLoadfile()
{
	CString m_Url;
		m_Url +=currentdirectory+ _T("CityManage/servlet/FileUploadServlet?taskId=");
		//m_Url += PicTaskId;
		m_Url +=_T("&fileName=");
	//	m_Url += m_caFiles[selList];
		m_Url +=_T("&uploadType=1");
//注意,url要带路径
		HttpParams  httpParams;	
		httpParams.m_filename =_T(""); //m_caFiles[selList];
		httpParams.m_pszURL = m_Url;
		AfxMessageBox(m_Url);
		if(GetConnection()==FALSE)
		{
			AfxMessageBox(L"对不起,不能建立连接!");
			return;
		}
	
	//	::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));	

		m_HttpDelegate = CHttpDelegate::GetInstance();
	//	m_HttpDelegate->path = currentdirectory;
		m_HttpDelegate->InitialHttp();
		if(!m_HttpDelegate->DownloadPic(&httpParams)) 
		{
			::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
			AfxMessageBox(_T("下载图片出错!"));
			return;
		}
}
//取最新的版本号
void CUpdateDlg::getNewVersion() //取版本号
{
	    CString m_Url;
		CString ServerName = GetServerName();
		AfxMessageBox(ServerName);
		m_Url +=ServerName+ _T("CityManage/servlet/DataSynchronizationServlet?active=0");
		
//注意,url要带路径
		HttpParams  httpParams;	
	//	httpParams.m_filename =_T(""); //m_caFiles[selList];
	//	httpParams.m_pszURL =_T("http://192.168.1.50:8080/CityManage/servlet/DataSynchronizationServlet?active=0"); //m_Url;
	     httpParams.m_pszURL = m_Url;
		//	AfxMessageBox(m_Url);
		if(GetConnection()==FALSE)
		{
			AfxMessageBox(L"对不起,不能建立连接!");
			return;
		}
	
	//	::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));	
        CString tmpResult = _T("0");
		m_HttpDelegate = CHttpDelegate::GetInstance();
        m_HttpDelegate->InitialHttp();
		if(!m_HttpDelegate->PostAndGetData(&httpParams, m_pGPRSConnection->bLinked))
		{
			AfxMessageBox(_T("发生错误!"));
			return;
		}
	
		m_XmlParse = CXmlParse::GetInstance();

        m_XmlParse->ParseCityAdminVersion(httpParams.m_Contents,fileArray,newVersion,tmpResult);
		AfxMessageBox(tmpResult);
}
//获取旧版本信息
void CUpdateDlg::getOldVersion()
{
	m_XmlParse = CXmlParse::GetInstance();
	m_XmlParse->ParseMyVersion(arr);
}
//取文件名称
void CUpdateDlg::getFileName()
{
	CString m_Url;
		CString ServerName = GetServerName();
		//AfxMessageBox(ServerName);
		m_Url +=ServerName+ _T("CityManage/servlet/DataSynchronizationServlet?active=1");
		
//注意,url要带路径
		HttpParams  httpParams;	
	//	httpParams.m_filename =_T(""); //m_caFiles[selList];
		//httpParams.m_pszURL =_T("http://192.168.1.50:8080/CityManage/servlet/DataSynchronizationServlet?active=1"); //m_Url;
		httpParams.m_pszURL = m_Url;
	//	AfxMessageBox(m_Url);
		if(GetConnection()==FALSE)
		{
			AfxMessageBox(L"对不起,不能建立连接!");
			return;
		}
	
	//	::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));	
        CString tmpResult = _T("0");
		m_HttpDelegate = CHttpDelegate::GetInstance();
        m_HttpDelegate->InitialHttp();
		if(!m_HttpDelegate->PostAndGetData(&httpParams, m_pGPRSConnection->bLinked))
		{
			AfxMessageBox(_T("发生错误!"));
			return;
		}
	
		m_XmlParse = CXmlParse::GetInstance();

        m_XmlParse->ParseCityAdminVersion(httpParams.m_Contents,fileArray,newVersion,tmpResult);
	//	AfxMessageBox(tmpResult);
	
}

void CUpdateDlg::downLoadAllFile()
{
HttpParams  httpParams;
	CString ServerName = GetServerName();
	int j=0;
	::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
	for(int curfile=0;curfile<fileArray.GetSize();curfile++)
	{

	

		httpParams.m_filename = _T("update\\")+fileArray[curfile];
		httpParams.m_pszURL = ServerName + _T("CityManage/servlet/DataSynchronizationServlet?fileName=") + fileArray[curfile];
		//打印出url
		//AfxMessageBox(httpParams.m_pszURL);
		info = _T("正在下载")+fileArray[curfile];
		if(!m_pHttpDelegate->Update(&httpParams,currentdirectory))
		{
			//info = _T("下载文件") + fileArray[curfile] +_T("失败!");
			//GetDlgItem(IDC_STATIC)->SetWindowText(_T("下载文件") + fileArray[curfile] +_T("失败!"));
			m_static.SetWindowText(_T("下载文件") + fileArray[curfile] +_T("失败!"));
		}
		else //GetDlgItem(IDC_status)->SetWindowText(_T("下载文件") + m_NewFileArray[curfile] +_T("成功!"));
		{
			info = _T("下载文件") + fileArray[curfile] +_T("成功!");
			//GetDlgItem(IDC_STATIC)->SetWindowText(_T("下载文件") + fileArray[curfile] +_T("成功!"));
			m_static.SetWindowText(_T("下载文件") + fileArray[curfile] +_T("成功!"));
	     // AfxMessageBox(_T("success0"));
			//downloadfile.Add(m_NewFileArray[curfile]);
		}
	//	AfxMessageBox(_T("success1"));	
	}
	::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
	m_static.SetWindowText(_T("下载文件成功") );
    AfxMessageBox(_T("数据更新成功"));
	startFile();
	this->OnOK();
	downloadupdatefile = true;
	stop = true;
//	return 0;
}
void CUpdateDlg::startFile()
{

//	AfxMessageBox(currentdirectory);

  SHELLEXECUTEINFO   ShExecInfo   =   {0};   
  ShExecInfo.cbSize   =   sizeof(SHELLEXECUTEINFO);   
  ShExecInfo.fMask   =   SEE_MASK_NOCLOSEPROCESS;   
  ShExecInfo.hwnd   =   NULL;   
  ShExecInfo.lpVerb   =   NULL;   
  ShExecInfo.lpFile   =  TEXT("\\存储卡\\数字城管\\数字城管.exe");                    
  ShExecInfo.lpParameters   =NULL;           
  ShExecInfo.lpDirectory   = TEXT("\\存储卡\\数字城管") ;   
  ShExecInfo.nShow   =   SW_SHOWNORMAL;           
  ShellExecuteEx(&ShExecInfo);   
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -