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

📄 updatedlg.cpp

📁 该程序是mobile5.0 ppc2003系统下的
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// UpdateDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Update.h"
#include "UpdateDlg.h"
#include "XmlParse.h"
#include "StringFile.h"
#include <tlhelp32.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
CStringArray fileArray;
bool stop = false;
bool downloadversion = false;
bool downloadupdatefile = false;
CString info;
//CString fileName;
CGPRSConnection *m_pGPRSConnection;
CHttpDelegate * m_pHttpDelegate;
CXmlParse * m_XmlParse;
CStringArray m_OldFileArray;
CStringArray m_NewFileArray;
CString currentdirectory;
CStringArray downloadfile;

// CUpdateDlg dialog
CUpdateDlg::CUpdateDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CUpdateDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CUpdateDlg)
	//}}AFX_DATA_INIT
}

void CUpdateDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CUpdateDlg)
	DDX_Control(pDX, IDC_Static2, m_static);
	DDX_Control(pDX, IDC_BUTTON1, m_BtnOK);
	DDX_Control(pDX, IDC_LIST1, m_FileList);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CUpdateDlg, CDialog)
	//{{AFX_MSG_MAP(CUpdateDlg)
	ON_WM_VSCROLL()
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CUpdateDlg message handlers

void CUpdateDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	// TODO: Add your message handler code here and/or call default
	UpdateData(TRUE);
	int minpos;
	int maxpos;
	LPRECT rects=new RECT;
	CRect rect;
	CDC hdc,memDC;
	static int curpos = 0;
	const int vscolllen = 90;
  
	CDialog::SetScrollRange(SB_VERT,0,vscolllen,true); 
	CDialog::GetScrollRange(SB_VERT,&minpos, &maxpos); 
	maxpos = CDialog::GetScrollLimit(SB_VERT);

	curpos = CDialog::GetScrollPos(SB_VERT);
	SCROLLINFO  info;

	switch (nSBCode)
	{
		case SB_TOP:    // Scroll to far left.

			curpos = minpos;
	
			CDialog::ScrollWindowEx(0,nPos-curpos,NULL,NULL,NULL,NULL,SW_SCROLLCHILDREN);
			CDialog::UpdateWindow();
			CDialog::SetScrollPos(SB_VERT,curpos,true);
			break;

		case SB_BOTTOM:    // Scroll to far right.
			curpos = maxpos;
	
			CDialog::ScrollWindowEx(0,nPos-curpos,NULL,NULL,NULL,NULL,SW_SCROLLCHILDREN);
			CDialog::UpdateWindow();
			CDialog::SetScrollPos(SB_VERT,curpos,true);
			break;

		case SB_ENDSCROLL:  // End scroll.
			break;

		case SB_LINEUP:    // Scroll left.
			if (curpos > minpos)
			{
				curpos-=10;
	
				CDialog::ScrollWindowEx(0,nPos-curpos,NULL,NULL,NULL,NULL,SW_SCROLLCHILDREN);
				CDialog::UpdateWindow();
				CDialog::SetScrollPos(SB_VERT,curpos,true);
			}
			break;

		case SB_LINEDOWN:  // Scroll right.
			//if(maxpos==101){AfxMessageBox(_T("i am here"));}
			if (curpos < vscolllen)
			{
				curpos+=10;
				//AfxMessageBox(_T("ok here"));
	
				CDialog::ScrollWindowEx(0,nPos-curpos,NULL,NULL,NULL,NULL,SW_SCROLLCHILDREN);
				CDialog::UpdateWindow();
				CDialog::SetScrollPos(SB_VERT,curpos,true);
			}
			//AfxMessageBox(_T("linedown"));
			break;

		case SB_PAGEUP:   // Scroll one page left.
			// Get the page size. 
			
			//pScrollBar->GetScrollInfo(&info, SIF_ALL);
			CDialog::GetScrollInfo(SB_VERT,&info, SIF_ALL);
  
			if (curpos > 0)
			{
				//curpos = max(minpos, curpos - (int) info.nPage);
				curpos = max(minpos, curpos - 10);
	
				CDialog::ScrollWindowEx(0,10,NULL,NULL,NULL,NULL,SW_SCROLLCHILDREN);
				CDialog::UpdateWindow();
				CDialog::SetScrollPos(SB_VERT,curpos,true);
			}
			break;

		case SB_PAGEDOWN:    // Scroll one page right.
			//pScrollBar->GetScrollInfo(&info, SIF_ALL);
			CDialog::GetScrollInfo(SB_VERT,&info, SIF_ALL);
    
			if (curpos < vscolllen)
			{
				curpos = min(maxpos, curpos + (int) info.nPage);
				
				curpos = min(maxpos, curpos + 10);
				CDialog::ScrollWindowEx(0,-10,NULL,NULL,NULL,NULL,SW_SCROLLCHILDREN);
				CDialog::UpdateWindow();
				CDialog::SetScrollPos(SB_VERT,curpos,true);
			}
			break;

		case SB_THUMBPOSITION: // Scroll to absolute position. nPos is the position	
			/*postmp1=nPos;
			if(curpos<postmp1)
			{

			curpos = nPos;      // of the scroll box at the end of the drag 
								// operation.
			
			CDialog::ScrollWindowEx(0,-10,NULL,NULL,NULL,NULL,SW_SCROLLCHILDREN);
			CDialog::UpdateWindow();
			CDialog::SetScrollPos(SB_VERT,curpos,true);
			}
			if(curpos>postmp1)
			{

			 curpos = nPos;      // of the scroll box at the end of the drag 
								// operation.
			
			CDialog::ScrollWindowEx(0,10,NULL,NULL,NULL,NULL,SW_SCROLLCHILDREN);
			CDialog::UpdateWindow();
			CDialog::SetScrollPos(SB_VERT,curpos,true);
			}*/
			break;

		case SB_THUMBTRACK:   // Drag scroll box to specified position. nPos is 
			int postmp2=curpos;
			curpos = nPos;     // position that the scroll box has been dragged 
							  // to.
			if(postmp2<vscolllen){
					CDialog::ScrollWindowEx(0,postmp2-curpos,NULL,NULL,NULL,NULL,SW_SCROLLCHILDREN);
					CDialog::UpdateWindow();
					CDialog::SetScrollPos(SB_VERT,curpos,true);
			}
			else if (postmp2 == vscolllen && nPos<vscolllen){
				CDialog::ScrollWindowEx(0,postmp2-curpos,NULL,NULL,NULL,NULL,SW_SCROLLCHILDREN);
					CDialog::UpdateWindow();
					CDialog::SetScrollPos(SB_VERT,curpos,true);
			}
			break;
	}
	
	UpdateData(FALSE);
	Invalidate();
	CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}

void CUpdateDlg::OnButton2() 
{//取消升级
	// TODO: Add your control notification handler code here
	CDialog::OnCancel();
}

BOOL CUpdateDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
//获得最新版本;
    getFileName();

	TCHAR exeFullPath[MAX_PATH] ;// MAX_PATH在API中定义了吧,好象是
	GetModuleFileName(NULL,exeFullPath,MAX_PATH);
	//AfxMessageBox(exeFullPath);
	int pathlen=wcslen(exeFullPath);
	int i=0;
	int newlen=0;
	while(i<pathlen)
	{
	if(exeFullPath[i]=='\\')
	{
	newlen=i;
	}
	i++;
	}
	/*
	TCHAR currentfilepath[MAX_PATH];
	wcscpy(currentfilepath,_T(""));
	for(i=0;i<newlen+1;i++)
	{
	currentfilepath[i]=exeFullPath[i];
	}
	AfxMessageBox(currentfilepath);
	*/
	CString newfilepath;
	newfilepath=exeFullPath;
	newfilepath.TrimLeft(_T("\r\n"));
	newfilepath.TrimRight(_T("\r\n"));
	//newfilepath+=_T("config.txt");
	//AfxMessageBox(newfilepath.Left(newlen+1));

	currentdirectory=newfilepath.Left(newlen+1);

	m_FileList.InsertColumn(0,_T("文件"),LVCFMT_LEFT,200);
//	m_FileList.InsertColumn(1,_T("当前版本"),LVCFMT_LEFT,60);
//	m_FileList.InsertColumn(2,_T("最新版本"),LVCFMT_LEFT,60);
	m_FileList.SetExtendedStyle(LVS_EX_FULLROWSELECT);

/*
	m_XmlParse = CXmlParse::GetInstance();//得到旧版本的信息
	m_XmlParse->ParseVersion(m_OldFileArray,_T("zhifa"),currentdirectory+_T("version.xml"));
*/

	int nItem;
	int line = 0;
	for(i=0;i<fileArray.GetSize();i++)
	{
		nItem = m_FileList.InsertItem(line++,fileArray[i]);
		//m_FileList.SetItemText(nItem, 1, fileArray[++i]); 
	}

	info = _T("点击更新开始更新数据");
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

CString GetServerName()
{
	CString ServerName = _T("");;
	TCHAR exeFullPath[MAX_PATH] ;// MAX_PATH在API中定义了吧,好象是
	GetModuleFileName(NULL,exeFullPath,MAX_PATH);
	
	int pathlen=wcslen(exeFullPath);
	int i=0;
	int newlen=0;
	while(i<pathlen)
	{
		if(exeFullPath[i]=='\\')
		{
			newlen=i;
		}
		i++;
	}
	CString newfilepath;
	newfilepath=exeFullPath;
	newfilepath.TrimLeft(_T("\r\n"));
	newfilepath.TrimRight(_T("\r\n"));
	
	currentdirectory=newfilepath.Left(newlen+1);
	currentdirectory+=_T("config.txt");
	CStringFile M_StringFile;
	if(M_StringFile.OpenFile(currentdirectory) == FALSE ) 
	{
		AfxMessageBox(_T("配置打开文件失败"));
	}

	while(M_StringFile.ReadLine(ServerName) == TRUE )
	{
			
		//AfxMessageBox(ServerName);
	}
	M_StringFile.CloseFile();
	return ServerName;
}

void CUpdateDlg::Update()
{
	HttpParams  httpParams;
	CString ServerName = GetServerName();
	for(int curfile=0;curfile<fileArray.GetSize();curfile++)
	{
		httpParams.m_filename = _T("update\\")+fileArray[curfile];
		httpParams.m_pszURL = ServerName + _T("/fileDown?fileName=update\\") + m_NewFileArray[curfile];

		if(!m_pHttpDelegate->Update(&httpParams,currentdirectory))
			info = _T("下载文件") + m_NewFileArray[curfile] +_T("失败!");
			//GetDlgItem(IDC_status)->SetWindowText(_T("下载文件") + m_NewFileArray[curfile] +_T("失败!"));
		else //GetDlgItem(IDC_status)->SetWindowText(_T("下载文件") + m_NewFileArray[curfile] +_T("成功!"));
		{
			info = _T("下载文件") + m_NewFileArray[curfile] +_T("成功!");
			downloadfile.Add(m_NewFileArray[curfile]);
		}
			
	}
	SetDlgItemText(IDC_BUTTON1,_T("完成"));
}

DWORD CUpdateDlg::FindAppProcessID()
{
	HANDLE handle=CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);
	PROCESSENTRY32 Info;
	Info.dwSize = sizeof(PROCESSENTRY32);
	if(::Process32First(handle,&Info))
	{
		do{
			CString ss=Info.szExeFile;
			if(!ss.CompareNoCase(_T("数字城管.exe")))
			{
				::CloseHandle(handle);
				return Info.th32ProcessID;
			}
		}
		while(::Process32Next(handle,&Info));	
		::CloseHandle(handle);
	}
	return -1;
}

void RenameFile() 
{
	CString tmp;
	CStdioFile csf;
	for(int i=0;i<downloadfile.GetSize();i++)
	{
		tmp = downloadfile[i].Right(downloadfile[i].GetLength()-downloadfile[i].Find('\\')-1);
		if(csf.Open(currentdirectory+tmp,CFile::modeRead)){
			//判断要删除的文件是否存在
			csf.Close();
			CFile::Remove(currentdirectory+tmp);
		}
		CFile::Rename(currentdirectory+tmp+_T(".upd"),currentdirectory+tmp);
	}

⌨️ 快捷键说明

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