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

📄 mirrorguidedlg.cpp

📁 VC—网络与通信
💻 CPP
字号:
// MirrorGuideDlg.cpp : implementation file
//

#include "stdafx.h"
#include "MirrorGuide.h"
#include "MirrorGuideDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMirrorGuideDlg dialog

CMirrorGuideDlg::CMirrorGuideDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMirrorGuideDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMirrorGuideDlg)
	m_SourceDir = _T("");
	m_year = _T("2000");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_day = m_month = 0 ;
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	pResultFile = NULL;
	pDirFile = NULL;
}

void CMirrorGuideDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMirrorGuideDlg)
	DDX_Control(pDX, IDC_SPIN3, m_DayCtrl);
	DDX_Control(pDX, IDC_SPIN2, m_MonthCtrl);
	DDX_Control(pDX, IDC_SPIN1, m_YearCtrl);
	DDX_Text(pDX, IDC_EDIT1, m_SourceDir);
	DDX_Text(pDX, IDC_EDITDAY, m_day);
	DDX_Text(pDX, IDC_EDITMONTH, m_month);
	DDX_Text(pDX, IDC_EDITYEAR, m_year);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMirrorGuideDlg, CDialog)
	//{{AFX_MSG_MAP(CMirrorGuideDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDOK, OnOk)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMirrorGuideDlg message handlers

BOOL CMirrorGuideDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	COleDateTime now = COleDateTime::GetCurrentTime ();
	m_day = now.GetDay ();
	m_month = now.GetMonth ();
	char s[5];
	itoa ( now.GetYear(), s, 10 );
	m_year = s;
	UpdateData ( FALSE );
	m_YearCtrl.SetRange ( 1900, 2200 );
	m_MonthCtrl.SetRange ( 1, 12 );
	m_DayCtrl.SetRange ( 1, 31 );
	SetTimer ( 2, 4500, NULL );
	CDialogTimer dt;
	autorun = dt.DoModal();
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMirrorGuideDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CMirrorGuideDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMirrorGuideDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CMirrorGuideDlg::OnOk()
{
	UpdateData ( TRUE );
	int year = GetValue ( m_year );
	COleDateTime t( year, m_month, m_day, 0,0,0 );
	MinimumTime = t;
	InitSourceDir ( m_SourceDir );

	CString thisDir,newDir,toFind;
	HANDLE Hand = NULL;
	if ( m_SourceDir != "" )
	{
		chdir ( m_SourceDir );
		mkdir ( "$$_Mirror123_$$" );
		chdir ( ".." );
	}
	else
		mkdir ( "$$_Mirror123_$$" );
	queue.InQueue ( m_SourceDir );
	while ( !queue.IsEmpty () )
	{
		queue.GetHead ( thisDir );
		toFind = thisDir;
		if ( thisDir == "" || thisDir == "/" )
			toFind += "*.*";
		else
			toFind += "/*.*";
		

		Hand = FindFirstFile ( toFind, &FileState );
		if ( Hand != INVALID_HANDLE_VALUE )
		do
		{
			if ( !strcmp ( FileState.cFileName, "." ) || !strcmp ( FileState.cFileName, ".." ) )
				continue;
			int aaa = FILE_ATTRIBUTE_DIRECTORY ;
			if ( ( FileState.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) == FILE_ATTRIBUTE_DIRECTORY )
			{
//				MessageBox ( FileState.cFileName );
				if ( thisDir != "" && thisDir != "/" )
					newDir = thisDir + '/' + FileState.cFileName ;
				else
					newDir = FileState.cFileName ;
				CheckDir ( newDir );

				queue.InQueue ( newDir );
			}
			else
				CheckFile ( thisDir, FileState );
		}
		while (	FindNextFile ( Hand, &FileState ) );
		
	}
	if ( Hand != NULL )
		CloseHandle ( Hand );
	CDialog::OnCancel();

}

BOOL CMirrorGuideDlg::CheckFile( CString thisDir, WIN32_FIND_DATA FileState )
{
	if ( pResultFile == NULL )
		pResultFile = fopen ( GenerateFilename( FILETYPE ), "wb" );
	COleDateTime CreateTime ( FileState.ftCreationTime );
	COleDateTime LastWriteTime ( FileState.ftLastWriteTime );
	if ( LastWriteTime < CreateTime )
		LastWriteTime = CreateTime;
	if ( LastWriteTime > MinimumTime )
	{
		if ( thisDir != "" && thisDir != "/" )
			thisDir += "/";
		thisDir += FileState.cFileName;
		fputs ( thisDir, pResultFile );
		fputs ( "\r\n", pResultFile );

		CString FileLength;
		FileLength.Format ( "%u", FileState.nFileSizeLow );
		fputs ( FileLength, pResultFile );
		fputs ( "\r\n", pResultFile );
		fflush ( pResultFile );
	}
							
	return TRUE;
}

CString CMirrorGuideDlg::GenerateFilename( BOOL flag )
{
	COleDateTime t = COleDateTime::GetCurrentTime ();
	CString filename = m_SourceDir;
	if ( filename != "" && filename != "/" )
		filename += "/";
	filename +=	"$$_Mirror123_$$/";
	char s[5]; int i;
	itoa ( t.GetYear(), s, 10 );
	filename += s;
	i = t.GetMonth();
	if ( i < 10 )
		filename += "0";
	itoa ( i, s, 10 );
	filename += s;
	i = t.GetDay ();
	if ( i < 10 )
		filename += "0";
	itoa ( i, s, 10 );
	filename += s;
	if ( flag == FILETYPE )
		filename += ".rlt";
	else
		filename += ".dir";
	return filename;
	
}

BOOL CMirrorGuideDlg::CheckDir( CString thisDir )
{
	if ( pDirFile == NULL )
		pDirFile = fopen ( GenerateFilename( DIRTYPE ), "wb" );
	fputs ( thisDir, pDirFile );
	fputs ( "\r\n", pDirFile );
	fflush ( pDirFile );
	return TRUE;
}

void CMirrorGuideDlg::OnCancel() 
{
	if ( pResultFile != NULL )
		fclose ( pResultFile );
	if ( pDirFile != NULL )
		fclose ( pDirFile );
		CDialog::OnCancel();
}

void CMirrorGuideDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	KillTimer ( 2 );
	if ( autorun == IDOK )
	{
		PostMessage ( WM_COMMAND, IDOK, 0 );
		ShowWindow ( SW_SHOWMINIMIZED );
	}

	CDialog::OnTimer(nIDEvent);
}

int CMirrorGuideDlg::GetValue( CString string )
{
	int value;
	string.Remove ( ',' );
	value = atoi ( string );
	return value;
}

void CMirrorGuideDlg::InitSourceDir(CString &dir)
{
	dir.Replace ( "\\", "/" );
	if ( dir != "/" && dir.Right( 1 ) == "/" )
		dir.Delete ( dir.GetLength() - 1, 1 );
}

⌨️ 快捷键说明

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