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

📄 equalitypage.cpp

📁 对文件进行处理。 包括文件复制、分割、连接、查看等。
💻 CPP
字号:
// EqualityPage.cpp : implementation file
//

#include "stdafx.h"
#include "made.h"
#include "EqualityPage.h"

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

/////////////////////////////////////////////////////////////////////////////
// CEqualityPage property page
UINT EqualityPro(LPVOID pParam)
{
	int i=0;
	CEqualityPage * dlg=(CEqualityPage * )pParam;
	dlg->Equality();
	dlg->GetDlgItem(IDC_EQUALITY)->EnableWindow(1);
	dlg->GetDlgItem(IDC_EQUALITY_STOP)->EnableWindow(0);
	dlg->GetDlgItem(IDC_EQUALITY_LOOK)->EnableWindow(1);
	dlg->GetDlgItem(IDC_EQUALITY_FILE)->EnableWindow(1);
	return 0;
}

IMPLEMENT_DYNCREATE(CEqualityPage, CPropertyPage)

CEqualityPage::CEqualityPage() : CPropertyPage(CEqualityPage::IDD)
{
	//{{AFX_DATA_INIT(CEqualityPage)
	m_Count = _T("");
	m_Out = 0;
	m_Unit = 0;
	m_Size = _T("");
	Pfile=NULL;
	//}}AFX_DATA_INIT
}

CEqualityPage::~CEqualityPage()
{
}

void CEqualityPage::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CEqualityPage)
	DDX_Control(pDX, IDC_EQUALITY_PROGRESS, m_Progress);
	DDX_Text(pDX, IDC_EQUALITY_COUNT, m_Count);
	DDX_Control(pDX, IDC_EQUALITY_FILE, m_File);
	DDX_Control(pDX, IDC_EQUALITY_OUT_PATH, m_Outpath);
	DDX_Radio(pDX, IDC_EQUALITY_OLDOUT, m_Out);
	DDX_Radio(pDX, IDC_EQUALITY_RADIO1, m_Unit);
	DDX_Text(pDX, IDC_EQUALITY_SIZE, m_Size);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CEqualityPage, CPropertyPage)
	//{{AFX_MSG_MAP(CEqualityPage)
	ON_BN_CLICKED(IDC_EQUALITY, OnEquality)
	ON_EN_CHANGE(IDC_EQUALITY_COUNT, OnChangeEqualityCount)
	ON_BN_CLICKED(IDC_EQUALITY_LOOK, OnEqualityLook)
	ON_BN_CLICKED(IDC_EQUALITY_LOOK_DIR, OnEqualityLookDir)
	ON_BN_CLICKED(IDC_EQUALITY_NEWOUT, OnEqualityNewout)
	ON_BN_CLICKED(IDC_EQUALITY_OLDOUT, OnEqualityOldout)
	ON_BN_CLICKED(IDC_EQUALITY_RADIO1, OnEqualityRadio1)
	ON_BN_CLICKED(IDC_EQUALITY_RADIO2, OnEqualityRadio2)
	ON_BN_CLICKED(IDC_EQUALITY_RADIO3, OnEqualityRadio3)
	ON_EN_CHANGE(IDC_EQUALITY_SIZE, OnChangeEqualitySize)
	ON_BN_CLICKED(IDC_EQUALITY_STOP, OnEqualityStop)
	ON_EN_CHANGE(IDC_EQUALITY_FILE, OnChangeEqualityFile)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CEqualityPage message handlers


void CEqualityPage::OnChangeEqualityCount() 
{
	CString filename;
	m_File.GetWindowText(filename);
	if((Pfile=fopen(filename,"rb"))==NULL)
		MessageBox(filename+"  不存在!","错误",MB_ICONERROR);
	else
	{
		UpdateData();
		m_FileLenth=filelength(Pfile->_file);
		int piece=atoi(m_Count);
		if(piece>0)
		{
			switch(m_Unit)
			{
			case 0:
				m_PieceLenth=(m_FileLenth-1)/piece+1;
				m_Size.Format("%ld",m_PieceLenth);
				break;
			case 1:
				m_PieceLenth=((m_FileLenth/1024-1)/piece+1)*1024;
				m_Size.Format("%ld",m_PieceLenth/1024);
				break;
			case 2:
				m_PieceLenth=((m_FileLenth/1048576-1)/piece+1)*1048576;
				m_Size.Format("%ld",m_PieceLenth/1048576);
				break;
			}
		}
		GetDlgItem(IDC_EQUALITY)->EnableWindow();
		fclose(Pfile);
	}
	UpdateData(0);
}

void CEqualityPage::OnChangeEqualityFile() 
{
	m_File.GetWindowText(m_Dir);
	if(m_Out==0)
		m_Outpath.SetWindowText(m_Dir+".?");
	GetDlgItem(IDC_EQUALITY_SIZE)->EnableWindow();
	GetDlgItem(IDC_EQUALITY_COUNT)->EnableWindow();
	GetDlgItem(IDC_EQUALITY_RADIO1)->EnableWindow();
	GetDlgItem(IDC_EQUALITY_RADIO2)->EnableWindow();
	GetDlgItem(IDC_EQUALITY_RADIO3)->EnableWindow();
}

void CEqualityPage::OnEqualityLook() 
{
	CFileDialog m_file_dlg(1);
	m_file_dlg.m_ofn.lpstrInitialDir=m_Dir;
	if(m_file_dlg.DoModal()==IDOK)
	{
		m_File.SetWindowText(m_file_dlg.GetPathName());
		m_Dir=m_file_dlg.GetPathName();
		GetDlgItem(IDC_EQUALITY_SIZE)->EnableWindow();
		GetDlgItem(IDC_EQUALITY_COUNT)->EnableWindow();
		m_Size="";
		m_Count="";
		m_Dir=m_file_dlg.GetPathName();
	}
	if(m_Out==0)
		m_Outpath.SetWindowText(m_Dir+".?");
	UpdateData(0);	
}

void CEqualityPage::OnEqualityLookDir() 
{
	CFileDialog m_file_dlg(0,0,0,0,0,0);
	m_file_dlg.m_ofn.lpstrInitialDir=m_Dir;
	if(m_file_dlg.DoModal()==IDOK)
	{
		m_Outpath.SetWindowText(m_file_dlg.GetPathName());
	}
	UpdateData(0);
}

void CEqualityPage::OnEqualityNewout() 
{
	UpdateData();
	GetDlgItem(IDC_EQUALITY_OUT_PATH)->EnableWindow(1);
	GetDlgItem(IDC_EQUALITY_LOOK_DIR)->EnableWindow(1);
}

void CEqualityPage::OnEqualityOldout() 
{
	UpdateData();
	m_Outpath.SetWindowText(m_Dir+".?");
	GetDlgItem(IDC_EQUALITY_OUT_PATH)->EnableWindow(0);
	GetDlgItem(IDC_EQUALITY_LOOK_DIR)->EnableWindow(0);
}

void CEqualityPage::OnEqualityRadio1() 
{
	switch(m_Unit)
	{
	case 0:
		break;
	case 1:
		UpdateData();
		m_Size.Format("%ld",atol(m_Size)*1024);
		break;
	case 2:
		UpdateData();
		m_Size.Format("%ld",atol(m_Size)*1048576);
		break;
	}
	UpdateData(0);
	OnChangeEqualitySize();
}

void CEqualityPage::OnEqualityRadio2() 
{
	DWORD temp=0;
	switch(m_Unit)
	{
	case 0:
		temp=atol(m_Size)/1024;
		if(temp>0)
		{
			UpdateData();
			m_Size.Format("%ld",temp);
			UpdateData(0);
		}
		break;
	case 1:
		break;
	case 2:
		UpdateData();
		m_Size.Format("%ld",atol(m_Size)*1024);
		break;
	}
	UpdateData(0);
	OnChangeEqualitySize();
}

void CEqualityPage::OnEqualityRadio3() 
{
	DWORD temp=0;
	switch(m_Unit)
	{
	case 0:
		temp=atol(m_Size)/1048576;
		if(temp>0)
		{
			UpdateData();
			m_Size.Format("%ld",temp);
			UpdateData(0);
		}
		break;
	case 1:
		temp=atol(m_Size)/1024;
		if(temp>0)
		{
			UpdateData();
			m_Size.Format("%ld",temp);
			UpdateData(0);
		}
		break;
	case 2:
		break;
	}
	UpdateData(0);
	OnChangeEqualitySize();
}

void CEqualityPage::OnChangeEqualitySize() 
{
	CString filename;
	m_File.GetWindowText(filename);
	if((Pfile=fopen(filename,"rb"))==NULL)
		MessageBox(filename+"  不存在!","错误",MB_ICONERROR);
	else
	{
		UpdateData();
		m_FileLenth=filelength(Pfile->_file);
		switch(m_Unit)
		{
		case 0:
			m_PieceLenth=atol(m_Size);
			break;
		case 1:
			m_PieceLenth=atol(m_Size)*1024;
			break;
		case 2:
			m_PieceLenth=atol(m_Size)*1024*1024;
			break;
		}
		if(m_PieceLenth)
			m_Count.Format("%d",(m_FileLenth-1)/m_PieceLenth+1);
		GetDlgItem(IDC_EQUALITY)->EnableWindow();
		fclose(Pfile);
	}
	UpdateData(0);
}

void CEqualityPage::OnEqualityStop() 
{
	m_BreakFlag=1;
}

void CEqualityPage::OnEquality() 
{
	m_BreakFlag=0;
	GetDlgItem(IDC_EQUALITY)->EnableWindow(0);
	GetDlgItem(IDC_EQUALITY_STOP)->EnableWindow(1);
	GetDlgItem(IDC_EQUALITY_LOOK)->EnableWindow(0);
	GetDlgItem(IDC_EQUALITY_FILE)->EnableWindow(0);
	AfxBeginThread(EqualityPro,this);
}

void CEqualityPage::Equality()
{
	CString filename;
	m_File.GetWindowText(filename);
	if((Pfile=fopen(filename,"rb"))==NULL)
	{
		MessageBox(filename+" 文件不能被打开!","错误",MB_ICONERROR);
		return;
	}
	m_FileLenth=filelength(Pfile->_file);
	if(atol(m_Size)<1)
	{
		MessageBox("非法定义文件长度!","错误",MB_ICONERROR);
		return;
	}
	long piece;
	switch(m_Unit)
	{
	case 0:
		piece=atol(m_Size);
		break;
	case 1:
		piece=atol(m_Size)*1024;
		break;
	case 2:
		piece=atol(m_Size)*1048576;
	}
	char buf[NUM];
	CString piecename;
	m_Outpath.GetWindowText(piecename);
	if(piecename.GetAt(piecename.GetLength()-1)=='?')
		piecename.Delete(piecename.GetLength()-1);
	int index=1;CString name;FILE * p;
	SetTimer(IDD_EQUALITY,100,NULL);
	while(!feof(Pfile))
	{
		name.Format("%s%d",piecename,index);
		if((p=fopen(name,"rb")))
		{
			fclose(p);
			if(MessageBox(name+" 文件已经存在,如果要继续,必须修改文件名,\n继续吗?","文件存在",MB_ICONERROR|MB_OKCANCEL)==IDOK)
				continue;
			else
			{
				fclose(Pfile);
				KillTimer(IDD_EQUALITY);
				return;
			}
		}
		if((p=fopen(name,"wb"))==NULL)
		{
			MessageBox(name+" 无法建立","错误",MB_ICONERROR);
			{
				fclose(Pfile);
				KillTimer(IDD_EQUALITY);
				return;
			}
		}
		index++;
		long fl=m_FileLenth-ftell(Pfile);
		if(piece>fl)
			piece=fl;
		for(int i=0;i<(int)(piece/NUM);i++)
		{
			if(m_BreakFlag)
			{
				fclose(Pfile);
				fclose(p);
				return;
			}
			fread(buf,NUM,1,Pfile);
			fwrite(buf,NUM,1,p);
		}
		fread(buf,piece-NUM*i,1,Pfile);
		fwrite(buf,piece-NUM*i,1,p);
		fclose(p);
		if(ftell(Pfile)>=m_FileLenth)
		{
			fclose(Pfile);
			KillTimer(IDD_EQUALITY);
			return;
		}
	}
	KillTimer(IDD_EQUALITY);
}


BOOL CEqualityPage::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
	
	char dir[256];
	getcwd(dir,256);
	m_Dir=dir;
	m_Progress.SetRange(0,NUM);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CEqualityPage::OnTimer(UINT nIDEvent) 
{
	int sit;
	if(m_FileLenth>NUM)
		sit=ftell(Pfile)/(m_FileLenth/NUM);
	else
		sit=ftell(Pfile)*NUM/m_FileLenth;
	m_Progress.SetPos(sit);
	
	CPropertyPage::OnTimer(nIDEvent);
}

⌨️ 快捷键说明

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