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

📄 progressdlg.cpp

📁 手机数据备份软件
💻 CPP
📖 第 1 页 / 共 3 页
字号:
		{	//backup files
			if (m_ItemList.GetAt(pos).ItemSize == 0)
				continue;
/*			if (firstFlag && (!m_BackupMailFlag))
			{
				CTestDlg testDlg;
				testDlg.DoModal();
				UpdateWindow();
				firstFlag = FALSE;
			}	
*/	
			if (!BackupFile(m_ItemList.GetAt(pos).DBNAME_ZIPDIR))
			{

				SetCursor(LoadCursor(NULL, IDC_ARROW));
				if (MountFlag)
					CeUnmountDBVol(pceguid);
				LocalFree((HLOCAL)pceguid);
				return FALSE;
			}
		}			
	}
	if (MountFlag)
		CeUnmountDBVol(pceguid);
	LocalFree((HLOCAL)pceguid);

	if (m_TotalFlag)
	{			
		BackupRegDB.SetProgressWnd(this);
		//backup registry
		if (!BackupRegDB.BackupRegistry())
		{
			SetCursor(LoadCursor(NULL, IDC_ARROW));		
			return FALSE;					
		}
	}
	return TRUE;
}

BOOL CProgressDlg::BackupInbox(PCEGUID pceguid)
{
	int j = 0 ;
	DWORD size = 0, totalsize = 0;
	CFile MailBackup;
	CCeFileFind cFileFind;
	CFileException Err;
	LPCTSTR MailDir[] = {_T("\\Windows\\messaging"),_T("\\Program Files\\Connections\\Mail Attachments")};
	if (MailBackup.Open(m_StorageType + INBOXDIR,CFile::modeCreate|CFile::modeWrite,&Err))
	{
		CXBzip bzip;	
		bzip.m_FirstDirFlag = TRUE;
		bzip.SetProgressWnd(this);
		for (j = 0; j < 2 ; j++)
		{
			if (cFileFind.FindFile(MailDir[j]))
			{
				size = 0;
				if (!bzip.AddDirToArchive(MailBackup,MailDir[j]))
				{
					CString Msg;
					Msg.LoadString(MSG_WRITE_ERROR);
					SetCursor(LoadCursor(NULL, IDC_ARROW));
					MessageBox(Msg,BACKUPTITLE,MB_OK|MB_ICONERROR);
					MailBackup.Close();
					return FALSE;
				}			
				GetDirSize(MailDir[j],size);
				totalsize += size;	
			}
		}
		char buf[] = {"OK"};	
		MailBackup.Write(&totalsize,sizeof(DWORD));
		MailBackup.Write(buf,2);
		MailBackup.Close();
	}
	else
	{
		SetCursor(LoadCursor(NULL, IDC_ARROW));
		Err.ReportError();
		return FALSE;
	}

	CRegistry_DB MailDB(m_StorageType);
	if (MailDB.GetTotalBackupDB())
	{
		POSITION DBpos;
		CString MailStr;
		for (j = 0; j < MailDB.m_DBItemList.GetCount(); j++)
		{
			DBpos = MailDB.m_DBItemList.FindIndex(j);
			MailStr.Format(MailDB.m_DBItemList.GetAt(DBpos).ItemName);
			if ((MailStr.Find(L"pmail") != -1) || (MailStr.Find(L"fldr") != -1))
			{
				if (!MailDB.BackupDB(MailDB.m_DBItemList.GetAt(DBpos).ItemName,pceguid))
				{
					SetCursor(LoadCursor(NULL, IDC_ARROW));
					CString Msg;
					Msg.LoadString(MSG_BACKUPDATABASEERROR);
					MessageBox(Msg,BACKUPTITLE,MB_OK|MB_ICONERROR);
					return FALSE;
				}
				SetProgressPos(MailDB.m_DBItemList.GetAt(DBpos).ItemSize);
			}
		}
	}	
	else
	{
		SetCursor(LoadCursor(NULL, IDC_ARROW));
		CString Msg;
		Msg.LoadString(MSG_BACKUPDATABASEERROR);
		MessageBox(Msg,BACKUPTITLE,MB_OK|MB_ICONERROR);
		return FALSE;
	}
	
	return TRUE;
}

BOOL CProgressDlg::BackupFile(LPCTSTR zipFileName)
{	
	CFile CBackupFile;
	if (!CBackupFile.Open(m_StorageType + zipFileName,CFile::modeCreate|CFile::modeWrite))
	{
		CString Msg;
		Msg.LoadString(MSG_WRITE_ERROR);
		MessageBox(Msg,BACKUPTITLE,MB_OK|MB_ICONERROR);
		return FALSE;
	}

	int i = 0, j = 0, k =0, fnlen = 0;
	BOOL bFound = TRUE;
	BOOL BackupFlag = FALSE;
	BOOL zipFlag = FALSE;
	CXBzip bzip;	
	BZFILEDATA bzipFileInfo;	
	CCeFileFind FileFind;
//	char FilePath[MAX_PATH]; 
	CString path,ext,exta;
	CString currentDir;
	currentDir = L"\\";
	CStringList dirList;
	dirList.RemoveAll();

	//Create the file for backup files
	LPWSTR  FILE_NAME[] = {CHANNELDIR,NOTEDIR,VOICEDIR,USERAPPDIR};
	LPCTSTR Inbox[] = {_T("\\Program Files\\Connections\\Mail Attachments"),_T("\\Windows\\messaging")};
	CeBackup2002Dialog mainDlg;
	mainDlg.Attach(GetTopLevelWindow());
	// set and reset attributes of "save file" here	
	do 
	{
		bFound = FileFind.FindFile(currentDir+"*.*");
		while(bFound)
		{
			bFound = FileFind.FindNextFile();
			BOOL NextFlag = FALSE;
			
			//do nothing with the storage media
			for (i = 0 ;i < 3; i++)
			{
				if (mainDlg.m_additionalstorage[i].IsEmpty())
					break;
				path = L"\\" + mainDlg.m_additionalstorage[i];
				if (FileFind.GetFilePath().Compare(path) == 0)
				{
					NextFlag = TRUE;
					break;
				}
			}
			if (NextFlag)
				continue;
if (FileFind.GetFilePath().Find(L"\\Backup") != -1)
	continue;
			if (FileFind.MatchesMask(FILE_ATTRIBUTE_INROM || FILE_ATTRIBUTE_ROMMODULE
				||FILE_ATTRIBUTE_SYSTEM))
				continue;
			
			// if dir,insert it into a list
			if (FileFind.IsDirectory()) 
			{
				//do nothing with the Inbox dir
				for (i = 0; i < 2; i++)
				{
					if (FileFind.GetFilePath().Compare(Inbox[i]) == 0)
					{
						NextFlag = TRUE;
						break;
					}
				}
				if (NextFlag)
					continue;
				
				// if dir is empty, backup it
				if (bzip.IsEmptyDirectory(FileFind.GetFilePath()))
				{
					if (wcscmp(FILE_NAME[3],zipFileName) == 0)
					{
						if (!bzip.AddDirToArchive(CBackupFile,FileFind.GetFilePath()))
						{
							ext.Format(MSG_BACKUPERROR,FileFind.GetFilePath());
							SetCursor(LoadCursor(NULL, IDC_ARROW));
							if (MessageBox(ext,BACKUPTITLE,MB_YESNO|MB_ICONWARNING) == IDNO)
							{
								CBackupFile.Close();
								UpdateWindow();
								return FALSE;
							}
							SetCursor(LoadCursor(NULL, IDC_WAIT));
							UpdateWindow();
						}
					}
				}
				else
					dirList.AddTail(FileFind.GetFilePath()+L"\\");					
				continue;
			}				
		
			//get file length
			fnlen = FileFind.GetLength();
			//get file path
			path = FileFind.GetFilePath();
			
			//set the structure of BZFILEDATA which prepare for backup file
			ZeroMemory(&bzipFileInfo,sizeof(bzipFileInfo));
//			memset(FilePath,0,sizeof(FilePath));
//			wcstombs(FilePath,path,path.GetLength());
//			strcpy(bzipFileInfo.szFilePathName,FilePath);
			wcscpy(bzipFileInfo.szFilePathName,path);
			bzipFileInfo.dwFileAttributes = FileFind.GetFileAttributes();
			bzipFileInfo.dwOriginFileSize = FileFind.GetLength();
			FileFind.GetCreationTime(&bzipFileInfo.ftCreateTime); 
			FileFind.GetLastAccessTime(&bzipFileInfo.ftLastAccessedTime);
			FileFind.GetLastWriteTime(&bzipFileInfo.ftLastModifiedTime);
			bzipFileInfo.wRealFilePathNameLen = FileFind.GetFilePath().GetLength() * 2;
			
			BackupFlag = FALSE;
			// find files under avantgo directory			
			i = j = k =0;
			while ((k = path.Find(L"\\",k+1)) != -1)
			{
				i = k;
				j++;
				if (j == 2)
					break;
			}
			path.MakeLower();
			path = path.Left(i);			
			if ((j == 2)&&(path.Compare(AVANTGO) == 0))
			{
				if (wcscmp(FILE_NAME[0],zipFileName) == 0)
					BackupFlag = TRUE;	
			}
			else
			{
				// get the type of file
				ext = FileFind.GetFileName();
				i = j = 0;
				while ((j = ext.Find(L".",j+1)) != -1)
					i = j;		
				if (i > 0)
					ext = ext.Right(ext.GetLength() - i -1);
				ext.MakeLower();
				//find "note" files
				exta.LoadString(NOTES_EXT);
				if (exta.Find(ext.GetBuffer(0)) != -1) 		
				{
					if (wcscmp(FILE_NAME[1],zipFileName) == 0)
						BackupFlag = TRUE;
				}		
				else
				{
					//backup "voice" files
					exta.LoadString(VOICE_EXT);
					if (exta.Find(ext.GetBuffer(0)) != -1)
					{
						if (wcscmp(FILE_NAME[2],zipFileName) == 0)
							BackupFlag = TRUE;
					}
					else
					{
						// backup "user application" files
						if (wcscmp(FILE_NAME[3],zipFileName) == 0)
							BackupFlag = TRUE;
					}
				}
			}
			
			if (BackupFlag)
			{
//				if (wcscmp(FILE_NAME[3],zipFileName) != 0)
					bzip.SetProgressWnd(this);

				CFile OpenFileTest;
				if (!OpenFileTest.Open(FileFind.GetFilePath(),CFile::modeRead))
				{
					if (GetLastError() == ERROR_SHARING_VIOLATION)
					{
						ext.Format(MSG_BACKUP_USING,FileFind.GetFilePath());
						if (MessageBox(ext,BACKUPTITLE,MB_YESNO|MB_ICONWARNING) == IDNO)
						{
							CBackupFile.Close();
							UpdateWindow();
							return FALSE;
						}
						UpdateWindow();
						SetProgressPos(fnlen);
						continue;
					}
					else
					{
//						ext.Format(MSG_BACKUPERROR,FileFind.GetFilePath());
//						if (MessageBox(ext,BACKUPTITLE,MB_YESNO|MB_ICONWARNING) == IDNO)
//						{
//							CBackupFile.Close();
//							UpdateWindow();
//							return FALSE;
//						}
						UpdateWindow();
						SetProgressPos(fnlen);
						continue;
					}
				}
				OpenFileTest.Close();

				zipFlag = bzip.AddToArchive(CBackupFile,bzipFileInfo);
				if (!zipFlag)
				{
					ext.Format(MSG_BACKUPERROR,FileFind.GetFilePath());
					SetCursor(LoadCursor(NULL,IDC_ARROW));
					if (MessageBox(ext,BACKUPTITLE,MB_YESNO|MB_ICONWARNING) == IDNO)
					{
						CBackupFile.Close();
						UpdateWindow();
						return FALSE;
					}
					SetCursor(LoadCursor(NULL, IDC_WAIT));
					UpdateWindow();
				}
				if (zipFlag == ERROR_SHARING_VIOLATION)
				{
					CString Msg;
					Msg.Format(MSG_BACKUP_USING,FileFind.GetFilePath());
					SetCursor(LoadCursor(NULL, IDC_ARROW));
					if (MessageBox(Msg ,BACKUPTITLE,MB_YESNO|MB_ICONWARNING) == IDNO)
					{
						CBackupFile.Close();
						UpdateWindow();
						return FALSE;
					}
					SetCursor(LoadCursor(NULL, IDC_WAIT));
					UpdateWindow();
				}
//				if (wcscmp(FILE_NAME[3],zipFileName) == 0)
//					SetProgressPos(fnlen);
			}
		}
		FileFind.Close();
		if (dirList.IsEmpty())
			break;
		currentDir = dirList.GetHead();
		
		dirList.RemoveHead();
	}while (1);

	char buf[] = {"OK"};
	for (k = 0 ;k < 4; k++)
	{
		if (wcscmp(zipFileName,FILE_NAME[k]) == 0)
		{
			CBackupFile.Write(&m_BackupFileSize[k],sizeof(DWORD));
			CBackupFile.Write(buf,2);
			break;
		}
	}	
	return TRUE;
}

BOOL CProgressDlg::RestoreAll()
{
	int i = 0;
	POSITION pos = 0;
	CXBzip RestoreFile;
	CRegistry_DB ResDB(m_StorageType);

	PCEGUID pceguid=0;
	pceguid = (PCEGUID) LocalAlloc (LPTR, sizeof (CEGUID));
	BOOL MountFlag = TRUE;
	if (!MountDBVol(pceguid,OPEN_EXISTING))
		MountFlag = FALSE;
	
	//restore
	for (i = 0; i < m_SelectedList.GetCount();i++)
	{
		pos = m_SelectedList.FindIndex(i);
//MessageBox(m_SelectedList.GetAt(pos).DBNAME_ZIPDIR);
		if (m_SelectedList.GetAt(pos).IsDB)
		{
			if (!MountFlag)
			{	// if can not mount volume,return false
				SetCursor(LoadCursor(NULL, IDC_ARROW));
				CString Msg;
				Msg.LoadString(MSG_BACKUPDATABASEERROR);
				MessageBox(Msg,RESTORETITLE,MB_OK|MB_ICONERROR);
				LocalFree((HLOCAL)pceguid); 
				return FALSE;
			}
			//restore database
			if (!ResDB.RestoreDB(m_SelectedList.GetAt(pos).DBNAME_ZIPDIR,pceguid))
			{
				SetCursor(LoadCursor(NULL, IDC_ARROW));
				CString Msg;
				Msg.LoadString(MSG_DATABASE_NOTFINISHED);
				MessageBox(Msg,RESTORETITLE,MB_OK|MB_ICONERROR);
				CeUnmountDBVol(pceguid);
				LocalFree((HLOCAL)pceguid); 
				return FALSE;
			}
			SetProgressPos(m_SelectedList.GetAt(pos).ItemSize);
			continue;
		}
		//restore registry
		if (m_SelectedList.GetAt(pos).IsReg)
		{
			ResDB.SetProgressWnd(this);
			if (!ResDB.RestoreRegistry())
			{
				SetCursor(LoadCursor(NULL, IDC_ARROW));
				if (MountFlag)
					CeUnmountDBVol(pceguid);
				LocalFree((HLOCAL)pceguid); 
				return FALSE;
			}
			continue;
		}
		//delete the files under Start Menu
		if (wcscmp(m_SelectedList.GetAt(pos).DBNAME_ZIPDIR,USERAPPDIR) == 0)
			DeleteDir(L"\\Windows\\Start Menu");

		//restore files
		if (wcscmp(m_SelectedList.GetAt(pos).DBNAME_ZIPDIR,INBOXDIR) == 0)
		{
			DeleteDir(_T("\\Windows\\messaging"));
		}
		RestoreFile.SetProgressWnd(this);
		if (!RestoreFile.ExtractArchive(m_StorageType + m_SelectedList.GetAt(pos).DBNAME_ZIPDIR))
		{	
			SetCursor(LoadCursor(NULL, IDC_ARROW));
			CString Msg;
			Msg.LoadString(MSG_BKFILE_ERROR);
//			MessageBox(Msg,RESTORETITLE,MB_OK|MB_ICONERROR);
			MessageBox(m_SelectedList.GetAt(pos).DBNAME_ZIPDIR);
			if (MountFlag)
				CeUnmountDBVol(pceguid);
			LocalFree((HLOCAL)pceguid); 
			return FALSE;
		}		
	}
	if (MountFlag)
		CeUnmountDBVol(pceguid);
	LocalFree((HLOCAL)pceguid); 
	return TRUE;
}

BOOL CProgressDlg::DeleteDir(LPCTSTR DirName)
{
	CCeFileFind SettingDir;
	CBzip bzip;
	CString FindDirStr(DirName);
	if (!bzip.IsExistedDirectory(DirName))
		return TRUE;
	if (bzip.IsEmptyDirectory(DirName))
	{
		RemoveDirectory(DirName);
		return TRUE;
	}
	if (FindDirStr.Right(1).Compare(L"\\") != 0)
		FindDirStr += L"\\";
	FindDirStr += L"*.*";
	BOOL findFlag = SettingDir.FindFile(FindDirStr);

	while (findFlag)
	{
		findFlag = SettingDir.FindNextFile();
		if (SettingDir.IsDirectory())
		{	
			if (bzip.IsEmptyDirectory(SettingDir.GetFilePath()))			
				RemoveDirectory(SettingDir.GetFilePath());
			else
			{
				DeleteDir(SettingDir.GetFilePath());
				RemoveDirectory(SettingDir.GetFilePath());
			}
		}
		else
		{
			if (SettingDir.GetFileName().Compare(L"eBackup.exe") == 0)
				continue;
			DeleteFile(SettingDir.GetFilePath());
		}
	}			
	return TRUE;

}

⌨️ 快捷键说明

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