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

📄 copyvcfiledlg.cpp

📁 自己写的加密 Asp源码的工具
💻 CPP
字号:
// CopyVCFileDlg.cpp : implementation file
//

#include "stdafx.h"
#include "CopyVCFile.h"
#include "CopyVCFileDlg.h"
#include "windows.h"
#include "afxwin.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()

/////////////////////////////////////////////////////////////////////////////
// CCopyVCFileDlg dialog

CCopyVCFileDlg::CCopyVCFileDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCopyVCFileDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCopyVCFileDlg)
	m_strNoCopyDir	= _T("");
	m_strNoCopyFile = _T("");
	m_strCopying	= _T("");
	m_strIncludeFile = _T("");
	m_strScrencPath = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

	m_strDesPathName = _T("");
	m_strSourcePathName = _T("");
	m_strNoCopyDir = _T("Debug,Release");
}

void CCopyVCFileDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCopyVCFileDlg)
	DDX_Control(pDX, IDC_COPYING, m_ctlCopying);
	DDX_Control(pDX, IDC_SOURPATHNAME, m_ctlSourcePathName);
	DDX_Control(pDX, IDC_DESPATHNAME, m_ctlDesPathName);
	DDX_Text(pDX, IDC_NOCOPYDIR, m_strNoCopyDir);
	DDX_Text(pDX, IDC_NOCOPYFILE, m_strNoCopyFile);
	DDX_Text(pDX, IDC_COPYING, m_strCopying);
	DDX_Text(pDX, IDC_INCLUDEFILE, m_strIncludeFile);
	DDX_Text(pDX, IDC_SCRENCPATH, m_strScrencPath);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CCopyVCFileDlg, CDialog)
	//{{AFX_MSG_MAP(CCopyVCFileDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_DELSOURCE, OnDelsource)
	ON_BN_CLICKED(IDC_BN_SOURCE, OnBnSource)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCopyVCFileDlg message handlers

BOOL CCopyVCFileDlg::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
	InitDlg();
	
	UpdateData( false );
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CCopyVCFileDlg::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 CCopyVCFileDlg::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 CCopyVCFileDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CCopyVCFileDlg::OnOK() 
{
	CString		strTemp;

	UpdateData();

	m_ctlDesPathName.GetWindowText( m_strDesPathName );
	m_ctlSourcePathName.GetWindowText( m_strSourcePathName );

	if( m_strDesPathName.IsEmpty() || m_strSourcePathName.IsEmpty()|| m_strScrencPath.IsEmpty() )
	{
		MessageBox( "请输入路径!","提示", MB_OK | MB_ICONINFORMATION );
		return;
	}

	InitCopyData();
	SaveSet();

	if(	CopyVCFile( m_strSourcePathName, m_strDesPathName ) )
	{
		m_ctlCopying.SetWindowText( "拷贝完毕" );
		MessageBox( "恭喜您,加密成功了!!\n\n谢谢使用本软件!!","成功信息",MB_OK | MB_ICONINFORMATION );
	}

	CDialog::OnOK();
}

BOOL CCopyVCFileDlg::CopyVCFile(CString strSourcePathName, CString strDesPathName  )
{
	HANDLE				hNextFile;
	CString				strTemp;
	CFileFind			filefind;
	FILETIME			fileTime;
	CString				strFind;
	BOOL				bReturn;
	CString				strFileEx;
	CString				strScrencPath;

	if( !CreateDirectory( strDesPathName, NULL ) )
	{
		if( GetLastError() != ERROR_ALREADY_EXISTS )
		{
			strTemp.Format( "不能创建目录%s!!", strDesPathName );
			MessageBox( strTemp,"提示",MB_OK | MB_ICONINFORMATION );
			return false;
		}
	}
	
	strFind.Format("%s\\*.*", strSourcePathName ); 
	bReturn	= filefind.FindFile( strFind );
	while( bReturn  )
	{
		bReturn = filefind.FindNextFile();	
		if( filefind.IsDots() )
			continue;

		strTemp = filefind.GetFileName();
		if( filefind.IsDirectory() )
		{
			// Copy 目录
			if( !IsNoCopyFolder( strTemp ))
			{
				CopyVCFile( strSourcePathName + "\\" + strTemp, strDesPathName + "\\" + strTemp );
			}
		}
		else
		{
			// Copy 文件
			if( !IsNoCopyFile(strTemp) )
			{
				if( m_ctlNoOverNewWrite )
				{
					//...
				}
				strFileEx = GetFileExtName( strTemp );
				if( strFileEx.CompareNoCase("asp") != 0 )
				{
					CopyFile( strSourcePathName + "\\" + strTemp, strDesPathName + "\\" + strTemp, true );
				}
				else if( IsIncludeFile( strSourcePathName + "\\" + strTemp , strTemp ) ) 
				{
					strScrencPath = " /f /xl "+strSourcePathName+"\\"+strTemp+ " "+strDesPathName +"\\" +strTemp;
					ShellExecute( GetSafeHwnd(),NULL,m_strScrencPath,strScrencPath,NULL,0);
				}
				else
				{
					strScrencPath = " /f "+strSourcePathName+"\\"+strTemp+ " "+strDesPathName +"\\" +strTemp;
					ShellExecute( GetSafeHwnd(),NULL,m_strScrencPath,strScrencPath,NULL,0);
				}
				CString		str;
				str.Format( "正在拷贝 从%s 到 %s",strSourcePathName + "\\" + strTemp, strDesPathName + "\\" + strTemp );
				m_ctlCopying.SetWindowText( str );
			}
		}
	}
	filefind.Close();

	int n= GetLastError();

	return true;
}

void CCopyVCFileDlg::InitDlg()
{
	CRegKey1	regKey;
	CString		str,strTemp;
	CString		strRegkey = "SOFTWARE\\EnCodeAspFile";
	int			nCount;
	int			nNum;
	DWORD		dwTemp;

	if( regKey.Open( HKEY_LOCAL_MACHINE, strRegkey ))
	{
		regKey.GetStringValue( "strScrencPath", str );
		m_strScrencPath = str;
		regKey.GetStringValue( "NoCopyDir", str );
		m_strNoCopyDir = str;
		regKey.GetStringValue( "NoCopyFile", str );
		m_strNoCopyFile = str;
		regKey.GetStringValue( "IncludeFile", str );
		m_strIncludeFile = str;
		if( regKey.Open( HKEY_LOCAL_MACHINE, strRegkey + "\\SourcePathName") )
		{
			regKey.GetIntValue( "Count", nCount );
			for( nNum = 1; nNum <= nCount; nNum ++ )
			{
				strTemp.Format( "%d", nNum );
				regKey.GetStringValue( strTemp, str );
				m_ctlSourcePathName.AddString( str );
			}
		}

		if( regKey.Open( HKEY_LOCAL_MACHINE, strRegkey + "\\DesPathName" ))
		{
			regKey.GetIntValue( "Count", nCount );
			for( nNum = 1; nNum <= nCount; nNum ++ )
			{
				strTemp.Format( "%d", nNum );
				regKey.GetStringValue( strTemp, str );
				m_ctlDesPathName.AddString( str );
			}
		}

		if(regKey.Open( HKEY_LOCAL_MACHINE, strRegkey + "\\ScrencPathName" ))
		{
			regKey.GetIntValue( "Count", nCount );
			for( nNum = 1; nNum <= nCount; nNum ++ )
			{
				strTemp.Format( "%d", nNum );
				regKey.GetStringValue( strTemp, str );
				m_ctlSourcePathName.AddString( str );
			}
		}
	} 
	else
	{
		regKey.Create( HKEY_LOCAL_MACHINE, strRegkey );
		
		regKey.Create( HKEY_LOCAL_MACHINE, strRegkey + "\\SourcePathName" );
		regKey.SetIntValue( "Count", 0 );

		regKey.Create( HKEY_LOCAL_MACHINE, strRegkey + "\\DesPathName" );
		regKey.SetIntValue( "Count", 0 );

		regKey.Create( HKEY_LOCAL_MACHINE, strRegkey + "\\ScrencPathName" );
		regKey.SetIntValue( "Count", 0 );

		regKey.Create( HKEY_LOCAL_MACHINE, strRegkey + "\\HostName" );
		regKey.SetIntValue( "Count", 0 );

		regKey.SetStringValue( "NoCopyDir", "Debug,Release");
		regKey.SetDWordValue( "DelSourceDebug", 0 );
		regKey.SetDWordValue( "NoOverNewWrite", 0 );
	}
}

//============================================
// 保存当前设置
//============================================
void CCopyVCFileDlg::SaveSet()
{
	CRegKey1	regKey;
	CString		str,strTemp;
	CString		strRegkey = "SOFTWARE\\EnCodeAspFile";
	int			nCount;

	if( regKey.Open( HKEY_LOCAL_MACHINE, strRegkey ))
	{
		regKey.SetStringValue( "strScrencPath", m_strScrencPath );
		regKey.SetStringValue( "NoCopyDir", m_strNoCopyDir );
		regKey.SetStringValue( "NoCopyFile", m_strNoCopyFile );
		regKey.SetStringValue( "IncludeFile", m_strIncludeFile );
		if( regKey.Open( HKEY_LOCAL_MACHINE, strRegkey + "\\SourcePathName") )
		{
			regKey.GetIntValue( "Count", nCount );
			if( !m_strSourcePathName.IsEmpty() )
			{
				if( m_ctlSourcePathName.FindString( 0,m_strSourcePathName ) < 0 )
				{
					regKey.SetIntValue( "Count", nCount + 1 );
					strTemp.Format( "%d", nCount + 1 );
					regKey.SetStringValue( strTemp, m_strSourcePathName );
				}
			}
		}

		if( regKey.Open( HKEY_LOCAL_MACHINE, strRegkey + "\\DesPathName" ))
		{
			regKey.GetIntValue( "Count", nCount );
			if( !m_strDesPathName.IsEmpty() )
			{
				if( m_ctlDesPathName.FindString( 0,m_strDesPathName ) < 0 )
				{
					regKey.SetIntValue( "Count", nCount + 1 );
					strTemp.Format( "%d", nCount + 1 );
					regKey.SetStringValue( strTemp, m_strDesPathName );
				}
			}
		}
	}
}

//=========================================
// 初始化不 Copy 的文件夹
//=========================================
void CCopyVCFileDlg::InitCopyData()
{
	CString strTemp,strNoCopyDir;
	BOOL	bOver = true;

	UpdateData();

	m_asNoCopyDir.RemoveAll();
	if( !m_strNoCopyDir.IsEmpty() )
		StringToArray( m_strNoCopyDir , m_asNoCopyDir , "," );

	m_asNoCopyFile.RemoveAll();
	if( !m_strNoCopyFile.IsEmpty() )
		StringToArray( m_strNoCopyFile , m_asNoCopyFile , "," );

	m_asIncFile.RemoveAll();
	if( !m_strIncludeFile.IsEmpty() )
		StringToArray( m_strIncludeFile , m_asIncFile , "," );
}

//=========================================================
// 判断是不是不 Copy 的文件夹
//=========================================================
BOOL CCopyVCFileDlg::IsNoCopyFolder(CString strFolderName)
{
	int		nIndex, nCount;
	CString	strTemp;

	nCount = m_asNoCopyDir.GetSize();
	for( nIndex = 0; nIndex < nCount; nIndex ++ )
	{
		strTemp = m_asNoCopyDir.GetAt( nIndex );
		if( strTemp.CompareNoCase( strFolderName ) == 0 )
			return true;
	}
	return false;
}


//=========================================================
// 判断是不是不 Include 的文件
//=========================================================
BOOL CCopyVCFileDlg::IsIncludeFile(CString strPathName , CString strFileName )
{
	int			nIndex, nCount;
	CString		strTemp,strCurExt;

	if( strFileName.GetLength() > 3 )
	{
		if( strFileName.Left(3).CompareNoCase( _T("In_") ) == 0 )
			return true;
	}

	nCount = m_asIncFile.GetSize();
	for( nIndex = 0; nIndex < nCount; nIndex ++ )
	{
		strTemp = m_asIncFile.GetAt( nIndex );
		strTemp = m_strSourcePathName + "\\" + strTemp;
		if( strTemp.CompareNoCase( strPathName ) == 0 )
			return true;
	}
	return false;
}

//=========================================================
// 判断是不是不 Copy 的文件
//=========================================================
BOOL CCopyVCFileDlg::IsNoCopyFile(CString strFileName)
{
	int			nIndex, nCount;
	CString		strTemp,strCurExt;

	nCount = m_asNoCopyFile.GetSize();
	for( nIndex = 0; nIndex < nCount; nIndex ++ )
	{
		strTemp = m_asNoCopyFile.GetAt( nIndex );
		if( strTemp.Find("*.") == 0 )
		{
			strCurExt = GetFileExtName( strFileName );
			if( GetFileExtName( strTemp ).CompareNoCase( strCurExt ) == 0 )
				return true;
		}
		else if( strTemp.CompareNoCase( strFileName ) == 0 )
			return true;
	}
	return false;
}

//=========================================
// 得到文件的扩展名
//=========================================
CString CCopyVCFileDlg::GetFileExtName( CString strFileName )
{
	CString		strExt;
	int			nPos;

	nPos		= strFileName.ReverseFind('.');
	if( nPos > 0 )
		strExt = strFileName.Mid( nPos + 1 ); 

	return strExt;

}

void CCopyVCFileDlg::OnDelsource() 
{
}

void CCopyVCFileDlg::OnBnSource() 
{
	
}

void CCopyVCFileDlg::StringToArray( CString strStuff , CStringArray &asArray , CString strApart )
{
	CString		strItem;

	asArray.RemoveAll(); 
	while( GetElementItem( strStuff, strItem, strApart) )
	{
		asArray.Add( strItem );
	}
}

BOOL CCopyVCFileDlg::GetElementItem(CString &strStuff, CString &strItem,CString strApart)
{
	if( strStuff.GetLength() == 0 )
		return FALSE;

	int pos = strStuff.Find(strApart);
	if( pos >= 0 )
	{
		strItem = strStuff.Left(pos);
		strStuff = strStuff.Right( strStuff.GetLength() - pos - strApart.GetLength() );
	}
	else
	{
		strItem		= strStuff;
		strStuff	= "";
	}
	return TRUE;
}

⌨️ 快捷键说明

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