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

📄 progressdlg.cpp

📁 手机数据备份软件
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// ProgressDlg.cpp: implementation of the CProgressDlg class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "ProgressDlg.h"
#include "Public.h"
#include "Registry_DB.h"
#include "eBackup2002Dialog.h"
#include "CeFileFind.h"
#include "XBzip.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
#define	PROGRESSRANGE			100
#define AVANTGO			        _T("\\windows\\avantgo")
CProgressDlg::CProgressDlg()
{
	m_BackupFlag = TRUE;
	m_TotalFlag = TRUE;
	m_BackupDBFlag = FALSE;
	m_BackupMailFlag = FALSE;
	m_TotalSize = 0;
	m_CurrentStep = 0;
	m_CurrentSize = 0;
	m_PreRate = 0;
	m_StorageType.Empty();
	if (m_ItemList.GetCount() > 0 )
		m_ItemList.RemoveAll();
}

CProgressDlg::~CProgressDlg()
{

}
LRESULT CProgressDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{ 
	// TODO : Add Code for message handler. Call DefWindowProc if necessary.
	m_hMenuBar = CreateMenuBarWnd(m_hWnd,IDR_ACTIONMENU);
	
	HWND hWnd = GetDlgItem(IDC_LIST1);
	m_ListCtrl.SubclassWindow(hWnd);
	SendDlgItemMessage(IDC_LIST1,WM_SETFOCUS,0,0);	
	
	m_ProCtrl.Attach(GetDlgItem(IDC_PROGRESS1));
	m_ProgressState.Attach(GetDlgItem(IDC_STATE));
	
	m_ProCtrl.SetRange(0,PROGRESSRANGE);
	m_ProCtrl.SetPos(0);
	m_ProCtrl.SetStep(1);
	m_ProgressState.SetWindowText(L"0%");

	CRect rect;
	m_ListCtrl.GetClientRect(&rect);

	//set font of listctrl	
/*	HFONT hFont = CreateItemFont(8,FW_NORMAL);
	m_ListCtrl.SetFont(hFont);
	hFont = CreateItemFont(10,FW_BOLD);
	CStatic TotalTitle,ShowTotal;
	TotalTitle.Attach(GetDlgItem(IDC_TOTALTITLE));
	ShowTotal.Attach(GetDlgItem(IDC_SHOWTOTALSIZE));
	TotalTitle.SetFont(hFont);
	ShowTotal.SetFont(hFont);
*/
	CString ItemStr,SizeStr;
	ItemStr.LoadString(ITEM_TXT);
	SizeStr.LoadString(SIZE_TXT);
	m_TotalSize = 0;
	CString MenuStr;
	if (m_BackupFlag)
	{
		// init backup interface		
		MenuStr.LoadString(BACKUPBUTTON_TXT);
		ModifyToolBarMenuItemText(m_hMenuBar,MenuStr.LockBuffer(),IDM_NEXT,FALSE);
		MenuStr.UnlockBuffer();		
		m_ListCtrl.InsertColumn(0,ItemStr,LVCFMT_LEFT,rect.Width()*4/5 - 25,-1);
		m_ListCtrl.InsertColumn(1,SizeStr,LVCFMT_LEFT,rect.Width()/5 + 25,-1);

//		SetWindowText(BACKUPTITLE);
		if (m_ItemList.GetCount() == 0)
		{
			CString Msg;
			Msg.LoadString(MSG_NOSELECTED);
			MessageBox(Msg,BACKUPTITLE,MB_OK|MB_ICONWARNING);
			EndDialog(IDCANCEL);
			return TRUE;
		}
		SetCursor(LoadCursor(NULL, IDC_WAIT));
		// init backup
		memset(m_BackupFileSize,0,sizeof(m_BackupFileSize));
		if (!BackupInit())
		{
			EndDialog(IDCANCEL);
			return TRUE;
		}
		SetCursor(LoadCursor(NULL, IDC_ARROW));	
	}
	else
	{
		// init restore interface
		MenuStr.LoadString(RESTOREBUTTON_TXT);
		ModifyToolBarMenuItemText(m_hMenuBar,MenuStr.LockBuffer(),IDM_NEXT,FALSE);
		MenuStr.UnlockBuffer();
		DWORD dwStyle = m_ListCtrl.GetExtendedListViewStyle();
		dwStyle |= LVS_EX_CHECKBOXES|LVS_EX_FULLROWSELECT ; 
		m_ListCtrl.SetExtendedListViewStyle(dwStyle) ;

		m_ListCtrl.SelectItem(0);
		m_ListCtrl.InsertColumn(0,ItemStr,LVCFMT_LEFT,rect.Width()*2/3,-1);
		m_ListCtrl.InsertColumn(1,SizeStr,LVCFMT_LEFT,rect.Width()/3,-1);
//		SetWindowText(RESTORETITLE);

		CCeFileFind FindRestore;
		// if backup doesn't exist, do nothing
		if (!FindRestore.FindFile(m_StorageType + BACKUPDIR))
		{
			CString Msg;
			Msg.Format(MSG_NODATATOUSE);
			MessageBox(Msg,RESTORETITLE,MB_OK|MB_ICONWARNING);
			EndDialog(IDCANCEL);
			return FALSE;
		}
		SetCursor(LoadCursor(NULL, IDC_WAIT));
		if (!RestoreInit())
		{
			SetCursor(LoadCursor(NULL, IDC_ARROW));
			EndDialog(IDCANCEL);
			return FALSE;
		}
		m_ListCtrl.SelectItem(0);
//		SendDlgItemMessage(IDC_LIST1,WM_KEYDOWN,VK_TDOWN,0);
//		SendDlgItemMessage(IDC_LIST1,WM_KEYDOWN,VK_TUP,0);

		SetCursor(LoadCursor(NULL, IDC_ARROW));
	}
	return 0;
}
LRESULT CProgressDlg::OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	CPaintDC dc(m_hWnd); // device context for painting
	
	// TODO: Add your message handler code here
	CPen pen;
	pen.CreatePen(PS_SOLID,2,RGB(0,0,0));
	dc.SelectPen(pen);
	CRect rect;
	m_ListCtrl.GetWindowRect(&rect);
	rect.top -= 20;
	rect.bottom -= 20;
	rect.InflateRect(1,1,1,1);
	dc.Draw3dRect(rect,RGB(0,0,0),GetSysColor(COLOR_3DFACE));//RGB(210,210,210));
	rect.InflateRect(1,1,1,1);
	dc.Draw3dRect(rect,RGB(70,70,70),RGB(200,200,200));
	rect.InflateRect(2,2,2,2);
	dc.Draw3dRect(rect,RGB(0,0,0),RGB(0,0,0));
	return 0;
}
LRESULT CProgressDlg::OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	EndDialog(IDCANCEL);  
	return 0;
}

LRESULT CProgressDlg::OnNext(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	int i = 0;
	int nRet = -1;	
	m_CurrentSize = 0;
	m_CurrentStep = 0;
	m_PreRate = 0;
	m_ListCtrl.SetFocus();
	if (m_BackupFlag)
	{
		CString Msg;
		Msg.LoadString(MSG_BACKUPWARNING);
		nRet = MessageBox(Msg ,BACKUPTITLE,MB_OKCANCEL | MB_ICONWARNING);
		if (nRet == IDNO)
			return 0;
//		ModifyToolBarMenuItemText(m_hMenuBar,BACKUPTITLE,IDM_NEXT,FALSE);
//		ModifyToolBarMenuItemText(m_hMenuBar,BACKUPTITLE,IDM_MENU,FALSE);
		RedrawWindow();
		SendMessage(m_hWnd,WM_ERASEBKGND,0,0);

		// if no enough space in storage to backup ,return 
		if (!CountStorageSpace(m_TotalSize))
			return 0 ;
		//if the backup dir doesn't exist, create it
		CCeFileFind FileFind;
		if (!FileFind.FindFile(m_StorageType + BACKUPDIR))
			if (!CreateDirectory(m_StorageType + BACKUPDIR,NULL))
			{
				FileFind.Close();
				CString Msg;
				Msg.LoadString(MSG_CREATEDIRERROR);
				MessageBox(Msg,BACKUPTITLE,MB_OK|MB_ICONERROR);
				return 0 ;
			}
/*		else
		{
			if (!CreateDirectory(m_StorageType + BACKUPTITLE + L"1",NULL))
			{
				FileFind.Close();
				MessageBox(CREATEDIRERROR,BACKUPTITLE,MB_OK|MB_ICONWARNING);
				return;
			}
		}
*/		
		SetCursor(LoadCursor(NULL, IDC_WAIT));
			
		//backup the datas on PDA
		EnableToolBarMenuItem(m_hMenuBar,IDM_NEXT,FALSE);
		EnableToolBarMenuItem(m_hMenuBar,IDM_MENU,FALSE);
		if (!BackupAll())
		{
			UpdateWindow();
			m_ProCtrl.SetPos(0);
			m_ProgressState.SetWindowText(L"0%");
			EnableToolBarMenuItem(m_hMenuBar,IDM_NEXT,TRUE);
			EnableToolBarMenuItem(m_hMenuBar,IDM_MENU,TRUE);
			return 0;
		}
		// backup completed
		SetCursor(LoadCursor(NULL, IDC_ARROW));
		EnableToolBarMenuItem(m_hMenuBar,IDM_NEXT,TRUE);
		EnableToolBarMenuItem(m_hMenuBar,IDM_MENU,TRUE);
		m_ProCtrl.SetPos(PROGRESSRANGE);
		m_ProgressState.SetWindowText(L"100%");	
		CString CompleteStr;
		CompleteStr.LoadString(MSG_BACKUPCOMPLETE);
		MessageBox(CompleteStr,BACKUPTITLE,MB_OK | MB_ICONASTERISK);
		EndDialog(IDOK);
		
	}
	else
	{   //restore datas
		CCeFileFind FileFind;
		//if backup dir doesn't exist,do nothing
		if (!FileFind.FindFile(m_StorageType + BACKUPDIR))
		{
			CString Msg;
			Msg.Format(MSG_NODATATOUSE);
			MessageBox(Msg,RESTORETITLE,MB_OK|MB_ICONASTERISK);
			FileFind.Close();
			return 0 ;
		}
		FileFind.Close();
		BOOL CheckFlag = FALSE;
		m_TotalFlag = TRUE;
		
		for(i = 0;i < m_ListCtrl.GetItemCount(); i++)
		{
			if (m_ListCtrl.GetCheckState(i))
				CheckFlag = TRUE;
			else
				m_TotalFlag = FALSE;
		}

		// if select nothing, return
		if (!CheckFlag)
		{
			CString Msg;
			Msg.LoadString(MSG_NOSELECTED);
			MessageBox(Msg,RESTORETITLE,MB_OK|MB_ICONWARNING);
			UpdateWindow();
			return 0 ;
		}
		CString Msg;
		Msg.LoadString(MSG_RESTOREWARNING);
		nRet = MessageBox(Msg,RESTORETITLE,MB_OKCANCEL | MB_ICONWARNING);
		if (nRet == IDNO)
			return 0 ;
		UpdateWindow();
		// get selected items
		SetCursor(LoadCursor(NULL, IDC_WAIT));
		if (m_SelectedList.GetCount())
			m_SelectedList.RemoveAll();
		if (!m_TotalFlag)
			GetSelected();
		else	
			m_SelectedList.AddTail(&m_ItemList);		
		//restore
		if (!RestoreAll())
		{
			UpdateWindow();
			m_ProCtrl.SetPos(0);
			m_ProgressState.SetWindowText(L"0%");
			return 0 ;			
		}
		SetCursor(LoadCursor(NULL, IDC_ARROW));
		m_ProCtrl.SetPos(PROGRESSRANGE);
		m_ProgressState.SetWindowText(L"100%");
		Msg.LoadString(MSG_RESTORECOMPLETE);
		MessageBox(Msg,RESTORETITLE,MB_OK | MB_ICONWARNING);
		EndDialog(IDOK);
	}	
	return 0;
}
LRESULT CProgressDlg::OnActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	m_ListCtrl.SetFocus();
	return 0;
}

void CProgressDlg::SetProgressPos(DWORD size)
{
	CString ProState;
	m_CurrentSize += size;
	if (m_CurrentSize > m_TotalSize)
		m_CurrentSize = m_TotalSize;
	m_CurrentStep = m_CurrentSize * PROGRESSRANGE /m_TotalSize;
	m_ProCtrl.SetPos(m_CurrentStep);

	if ((m_CurrentSize * 100 / m_TotalSize) > m_PreRate)
	{
		ProState.Format(L"%d%%",m_CurrentSize * 100 / m_TotalSize);
		m_ProgressState.SetWindowText(ProState);
	}
	m_PreRate = m_CurrentSize * 100 / m_TotalSize;
}

BOOL CProgressDlg::BackupInit()
{
	int i=0,j=0,line = 0;
	DWORD size = 0;
	CRegistry_DB db(m_StorageType);
	POSITION pos = 0;
	CString SizeStr,Msg;
	LPCTSTR ZipFileName[5] = {CHANNELDIR,NOTEDIR,VOICEDIR,USERAPPDIR};
	LPCTSTR MailDir[] = {_T("\\Program Files\\Connections\\Mail Attachments"),_T("\\Windows\\messaging")};
	// get size of  four files
	GetBackupFileSize(L"\\");
	DWORD InboxSize;
	for(i = 0 ; i < m_ItemList.GetCount();i++)
	{
		pos = m_ItemList.FindIndex(i);
		// init Inbox
		if (m_ItemList.GetAt(pos).IsMail)
		{
			size = 0;
			InboxSize = 0;
			CString MailStr;
			MailStr.Empty();
			POSITION DBPos;
			if (db.GetTotalBackupDB())
			{
				for(j = 0; j < db.m_DBItemList.GetCount(); j++)
				{
					m_BackupDBFlag = TRUE;
					DBPos = db.m_DBItemList.FindIndex(j);
					MailStr.Format(db.m_DBItemList.GetAt(DBPos).ItemName);
					if ((MailStr.Find(L"pmail") != -1) || (MailStr.Find(L"fldr") != -1))
					{
						size += db.m_DBItemList.GetAt(DBPos).ItemSize;
						if (size == -1)
						{
							SetCursor(LoadCursor(NULL, IDC_ARROW));
//							Msg.Format(MSG_READDBERR,m_ItemList.GetAt(pos).ItemName);
							Msg.Format(MSG_WRITE_ERROR);
							MessageBox(Msg,BACKUPTITLE,MB_OK|MB_ICONERROR);
							return FALSE;
						}
					}
					
				}
			}
			else
			{
				SetCursor(LoadCursor(NULL, IDC_ARROW));
//				Msg.Format(MSG_READDBERR,m_ItemList.GetAt(pos).ItemName);
				Msg.Format(MSG_WRITE_ERROR);
				MessageBox(Msg,BACKUPTITLE,MB_OK|MB_ICONERROR);
				return FALSE;
			}
			InboxSize +=size;
			for(j = 0; j < 2; j++)
			{
				size = 0;
				GetDirSize(MailDir[j],size);
				InboxSize += size;
			}
			m_BackupMailFlag = TRUE;
			m_ListCtrl.InsertItem(line,m_ItemList.GetAt(pos).ItemName);
			CountKB(InboxSize,SizeStr);
			m_ListCtrl.SetItemText(line++,1,SizeStr);
			m_TotalSize += InboxSize;
			continue;
		}
		//init database			
		if (m_ItemList.GetAt(pos).IsDB)
		{
			size = db.GetBackupDBSize(m_ItemList.GetAt(pos).DBNAME_ZIPDIR);		
			if (size == -1)
			{
				SetCursor(LoadCursor(NULL, IDC_ARROW));
//				Msg.Format(MSG_READDBERR,m_ItemList.GetAt(pos).ItemName);
				Msg.Format(MSG_WRITE_ERROR);
				MessageBox(Msg,BACKUPTITLE,MB_OK|MB_ICONERROR);
				return FALSE;
			}
			m_BackupDBFlag = TRUE;
			m_ItemList.GetAt(pos).ItemSize = size;			
			if (wcslen(m_ItemList.GetAt(pos).ItemName))
			{
				m_ListCtrl.InsertItem(line,m_ItemList.GetAt(pos).ItemName);
				CountKB(size,SizeStr);
				m_ListCtrl.SetItemText(line++,1,SizeStr);
			}				
			m_TotalSize += size;
		}
		else
		{
			//init files
			for ( j = 0 ;j < 4; j++)
				if (wcscmp(ZipFileName[j],m_ItemList.GetAt(pos).DBNAME_ZIPDIR) == 0)
				{
					m_ListCtrl.InsertItem(line,m_ItemList.GetAt(pos).ItemName);
					m_ItemList.GetAt(pos).ItemSize = m_BackupFileSize[j];					
					CountKB(m_BackupFileSize[j],SizeStr);
					m_ListCtrl.SetItemText(line++,1,SizeStr);
					m_TotalSize += m_BackupFileSize[j];					
					break;
				}
		}
	}
	// init totalsize
	if (m_TotalFlag)
	{
		if (db.GetBackupRegistrySize() == -1)
		{
			SetCursor(LoadCursor(NULL, IDC_ARROW));
			return FALSE;
		}
		else
			m_TotalSize += db.GetBackupRegistrySize();
	}
	CountKB(m_TotalSize,SizeStr);
	CStatic ShowTotal;
	ShowTotal.Attach(GetDlgItem(IDC_SHOWTOTALSIZE));
	ShowTotal.SetWindowText(SizeStr);
	return TRUE;
}

BOOL CProgressDlg::RestoreInit()
{
	int line = 0;
	DWORD MailDBSize = 0;
	CString SizeStr;
	BOOL FindFlag = FALSE;	
	if (m_ItemList.GetCount() >0)
		m_ItemList.RemoveAll();	

	// if any database exist,read it
	FindFlag = RestoreDBinit(line,MailDBSize);
	if (FindFlag == -1)
	{
		UpdateWindow();
		return FALSE;
	}
	// if any file exists, read it	
	BOOL FileFlag = RestoreFileInit(line,MailDBSize);
	if (FileFlag == -1)
	{
		UpdateWindow();
		return FALSE;
	}

	if (FileFlag)
		FindFlag = TRUE;

	// if no any database or file, do nothing
	if (FindFlag)
	{
		CountKB(m_TotalSize,SizeStr);
		CStatic ShowTotal;
		ShowTotal.Attach(GetDlgItem(IDC_SHOWTOTALSIZE));
		ShowTotal.SetWindowText(SizeStr);
	}
	else
	{
		CString Msg;
		Msg.Format(MSG_NODATATOUSE);
		MessageBox(Msg,RESTORETITLE,MB_OK|MB_ICONWARNING);
		return FALSE;
	}	
	return TRUE;
}

void CProgressDlg::GetBackupFileSize(CString DirName)
{
//	DWORD sysprogSize=0;
//	DWORD voiceSize=0;
//	DWORD noteSize=0;
//	DWORD avgoSize=0;
	CCeFileFind FileFind;
	int i,j,k,fnlen;
	CString path,ext,exta;
	BOOL bFound = TRUE;
	LPCTSTR Inbox[] = {_T("\\Program Files\\Connections\\Mail Attachments"),_T("\\Windows\\messaging")};
	// set and reset attributes of "save file" here

	bFound = FileFind.FindFile(DirName+"*.*");
	while (bFound)

⌨️ 快捷键说明

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