📄 a2pshelldlg.cpp
字号:
// a2pshellDlg.cpp : implementation file
//
#include "stdafx.h"
#include "a2pshell.h"
#include "a2pshellDlg.h"
#include "xsbrowsefolder.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()
/////////////////////////////////////////////////////////////////////////////
// CA2PShellDlg dialog
CA2PShellDlg::CA2PShellDlg(CWnd* pParent /*=NULL*/)
: CDialog(CA2PShellDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CA2PShellDlg)
m_case = 0;
m_dbtype = 0;
m_dsn = _T("");
m_file_ext = 0;
m_gif2png = FALSE;
m_globalasa = FALSE;
m_html = FALSE;
m_includes = FALSE;
m_ip = _T("");
m_nomagick = FALSE;
m_noty2k = FALSE;
m_paths = FALSE;
m_pngs = FALSE;
m_pw = _T("");
m_sid = _T("");
m_spacer = FALSE;
m_userid = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CA2PShellDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CA2PShellDlg)
DDX_Control(pDX, IDC_SOURCE, mc_source);
DDX_Control(pDX, IDC_REQDEXT, mc_reqdext);
DDX_Control(pDX, IDC_EXTS, mc_exts);
DDX_CBIndex(pDX, IDC_CASE, m_case);
DDX_CBIndex(pDX, IDC_DBTYPE, m_dbtype);
DDX_Text(pDX, IDC_DSN, m_dsn);
DDX_CBIndex(pDX, IDC_FILE_EXT, m_file_ext);
DDX_Check(pDX, IDC_GIF2PNG, m_gif2png);
DDX_Check(pDX, IDC_GLOBALASA, m_globalasa);
DDX_Check(pDX, IDC_HTML, m_html);
DDX_Check(pDX, IDC_INCLUDES, m_includes);
DDX_Text(pDX, IDC_IP, m_ip);
DDX_Check(pDX, IDC_NOMAGICK, m_nomagick);
DDX_Check(pDX, IDC_NOTY2K, m_noty2k);
DDX_Check(pDX, IDC_PATHS, m_paths);
DDX_Check(pDX, IDC_PNGS, m_pngs);
DDX_Text(pDX, IDC_PW, m_pw);
DDX_Text(pDX, IDC_SID, m_sid);
DDX_Check(pDX, IDC_SPACER, m_spacer);
DDX_Text(pDX, IDC_USERID, m_userid);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CA2PShellDlg, CDialog)
//{{AFX_MSG_MAP(CA2PShellDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_SEL_SRC, OnSelSrc)
ON_BN_CLICKED(IDC_ADDEXT, OnAddExt)
ON_BN_CLICKED(IDC_DELEXT, OnDelExt)
ON_WM_CTLCOLOR()
ON_BN_CLICKED(IDC_VIEWLOG, OnViewlog)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CA2PShellDlg message handlers
BOOL CA2PShellDlg::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
sOptions = " ";
return TRUE;
}
void CA2PShellDlg::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 CA2PShellDlg::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 CA2PShellDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
//---------------------------------------------------
//
//---------------------------------------------------
void CA2PShellDlg::OnSelSrc()
{
CXSBrowseFolder cxb;
cxb.SetTitle("Select the root folder for the files you want to convert");
switch (cxb.Show(GetSafeHwnd(),szPath)){
// User clicked cancel
case CXSBrowseFolder::RET_CANCEL:
return;
break;
// The shell did not return a path for the selection
case CXSBrowseFolder::RET_NOPATH:
MessageBox("The shell did not return a path for the selected item!","ASP -> PHP Shell", MB_ICONSTOP | MB_TOPMOST);
return;
break;
}
mc_source.SetWindowText(szPath);
}
//---------------------------------------------------
//
//---------------------------------------------------
void CA2PShellDlg::OnOK()
{
int idx,count;
CString str;
SYSTEMTIME st;
// ok we got an OK so process the options (*sigh*)
if (m_pngs)
sOptions += " -pngs";
if (m_gif2png)
sOptions += " -gif2png";
if (m_nomagick)
sOptions += " -nomagick";
if (m_html)
sOptions += " -html";
if (m_globalasa)
sOptions += " -global_asa";
if (m_noty2k)
sOptions += " -y2k";
if (m_spacer)
sOptions += " -spacer";
if (m_includes)
sOptions += " -includes";
if (m_paths)
sOptions += " -fixwinpaths";
if (m_file_ext == 1)
sOptions += " -php3";
else if (m_file_ext == 2)
sOptions += " -php4";
if (m_case == 1)
sOptions += " -tolower";
else if (m_case == 2)
sOptions += " -toupper";
if (m_dbtype == 1)
sOptions += " -mysql";
else if (m_dbtype == 2)
sOptions += " -odbc";
else if (m_dbtype == 3)
sOptions += " -oracle";
else if (m_dbtype == 4)
sOptions += " -sybase";
else if (m_dbtype == 5)
sOptions += " -postgres";
m_dsn.TrimLeft();
m_dsn.TrimRight();
m_ip.TrimLeft();
m_ip.TrimRight();
m_pw.TrimLeft();
m_pw.TrimRight();
m_sid.TrimLeft();
m_sid.TrimRight();
m_userid.TrimLeft();
m_userid.TrimRight();
if (m_dsn.GetLength() > 0)
sOptions += " -dsn " + m_dsn;
if (m_ip.GetLength() > 0)
sOptions += " -address " + m_ip;
if (m_pw.GetLength() > 0)
sOptions += " -passwd " + m_pw;
if (m_sid.GetLength() > 0)
sOptions += " -database " + m_sid;
if (m_userid.GetLength() > 0)
sOptions += " -uid " + m_userid;
count = mc_exts.GetCount();
for (idx=0; idx<count; idx++){
mc_exts.GetText(idx,str);
sOptions += " -addextension " + str;
sExts.AddTail(str);
}
// ok go do it
BeginWaitCursor();
GetLocalTime(&st);
str.Format("ASP->PHP Conversion Started: %.2d-%.2d-%d %.2d:%.2d:%.2d\n\n",st.wDay,st.wMonth,st.wYear,st.wHour,st.wMinute,st.wSecond);
file.Open("asp2php_log.txt",CFile::modeCreate | CFile::modeWrite | CFile::typeText);
file.WriteString(str);
nNumFiles = 0;
ProcessFiles(szPath);
GetLocalTime(&st);
str.Format("\nASP->PHP Conversion Finished: %.2d-%.2d-%d %.2d:%.2d:%.2d\n\nConverted %d files\n",st.wDay,st.wMonth,st.wYear,st.wHour,st.wMinute,st.wSecond,nNumFiles);
file.WriteString(str);
file.Close();
EndWaitCursor();
}
//---------------------------------------------------
//
//---------------------------------------------------
void CA2PShellDlg::ProcessFiles(char *szPath)
{
bool bDone = false;
HANDLE hFind;
char *p;
WIN32_FIND_DATA fd;
CString sCmdLine;
CString sLog;
CString sFinalPath;
CString sNewPath;
sFinalPath.Format("%s\\*.*",szPath);
hFind = FindFirstFile(sFinalPath,&fd);
if (hFind == INVALID_HANDLE_VALUE)
return;
while (bDone == false){
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY){
if (fd.cFileName[0] != '.'){
sNewPath.Format("%s\\%s",szPath,fd.cFileName);
ProcessFiles((LPTSTR)(LPCTSTR)sNewPath);
}
if (FindNextFile(hFind,&fd) == 0)
bDone = true;
}
// its a file so chk the extension
else {
p = strrchr(fd.cFileName,'.');
if (p != NULL){
if ((stricmp(p,".asp") == 0) || sExts.Find(p)){
ZeroMemory(&si,sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi,sizeof(pi));
// Start the child process
sCmdLine.Format("asp2php %s \"%s\\%s\"",sOptions,szPath,fd.cFileName);
if (CreateProcess(NULL,(LPTSTR)(LPCTSTR)sCmdLine,NULL,NULL,FALSE,CREATE_NO_WINDOW,NULL,NULL,&si,&pi)){
// Wait until child process exits.
WaitForSingleObject(pi.hProcess,INFINITE);
// Close process and thread handles.
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
// write log entry
sLog.Format("Processed: %s\\%s",szPath,fd.cFileName);
file.WriteString(sLog + "\n");
nNumFiles++;
}
}
}
// next file object
if (FindNextFile(hFind,&fd) == 0)
return;
}
}
}
//---------------------------------------------------
//
//---------------------------------------------------
void CA2PShellDlg::OnViewlog()
{
char szFilePath[MAX_PATH];
char szPath[MAX_PATH];
GetCurrentDirectory(MAX_PATH,szPath);
sprintf(szFilePath,"%s\\asp2php_log.txt",szPath);
ShellExecute(this->GetSafeHwnd(),"open",szFilePath,NULL,szPath,SW_SHOWNORMAL);
}
//---------------------------------------------------
//
//---------------------------------------------------
void CA2PShellDlg::OnAddExt()
{
CString str;
mc_reqdext.GetWindowText(str);
str.TrimLeft();
str.TrimRight();
if (str.GetLength() < 2 || str.Find(".",0) == -1){
MessageBox("Extensions must be of the form <.xxx> !","ASP -> PHP Shell",MB_OK | MB_ICONSTOP);
return;
}
mc_exts.AddString(str);
mc_reqdext.SetWindowText("");
mc_reqdext.SetFocus();
}
//---------------------------------------------------
//
//---------------------------------------------------
void CA2PShellDlg::OnDelExt()
{
int idx;
if ((idx = mc_exts.GetCurSel()) == LB_ERR)
return;
mc_exts.DeleteString(idx);
}
//---------------------------------------------------
//
//---------------------------------------------------
HBRUSH CA2PShellDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (pWnd->GetDlgCtrlID() == IDC_SOURCE){
lBrush.lbStyle = BS_SOLID;
lBrush.lbColor = RGB(230,230,230);
hBrush = CreateBrushIndirect(&lBrush);
pDC->SetBkColor(RGB(230,230,230));
hbr = hBrush;
}
return hbr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -