// FinishPage.cpp : implementation file
//
#include "stdafx.h"
#include "Scan2PDF.h"
#include "FinishPage.h"
#include "Scan2PDFDefs.h"
#include "Scan2PDFDlg.h"
#include "FileOperations.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFinishPage property page
IMPLEMENT_DYNCREATE(CFinishPage, CPropertyPageEx)
CFinishPage::CFinishPage() : CPropertyPageEx(CFinishPage::IDD)
{
//{{AFX_DATA_INIT(CFinishPage)
m_DeleteFolder = FALSE;
m_LaunchWizard = TRUE;
//}}AFX_DATA_INIT
m_psp.dwFlags |= PSP_HIDEHEADER;
}
CFinishPage::~CFinishPage()
{
}
void CFinishPage::DoDataExchange(CDataExchange* pDX)
{
CPropertyPageEx::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFinishPage)
DDX_Control(pDX, IDC_FINISH, m_Finish);
DDX_Check(pDX, IDC_DELETE_FOLDER_FILES, m_DeleteFolder);
DDX_Check(pDX, IDC_LAUNCH_WIZARD, m_LaunchWizard);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFinishPage, CPropertyPageEx)
//{{AFX_MSG_MAP(CFinishPage)
ON_BN_CLICKED(IDC_ABOUT, OnAbout)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFinishPage message handlers
BOOL CFinishPage::OnInitDialog()
{
CPropertyPageEx::OnInitDialog();
m_Finish.SetFontStatic(CString("Times New Roman"), 25, RGB(0, 0, 0), FS_BOLD);
m_Finish.SetBackground(RGB(255, 255, 255));
m_Finish.SetWindowText("Scan2PDF wizard finished!");
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
BOOL CFinishPage::OnSetActive()
{
CPropertySheetEx* pParent=(CPropertySheetEx*) GetParent();
pParent->SetWizardButtons(PSWIZB_BACK | PSWIZB_FINISH);
return CPropertyPageEx::OnSetActive();
}
BOOL CFinishPage::OnWizardFinish()
{
UpdateData(TRUE);
char lpFilename[_MAX_PATH];
ZeroMemory(lpFilename, _MAX_PATH);
GetModuleFileName(AfxGetInstanceHandle(), lpFilename, _MAX_PATH);
if (m_DeleteFolder)
{
CString szPath;
CString szApp;
szApp=AfxGetApp()->m_pszExeName;
szApp+=CString(".exe");
szPath=lpFilename;
szPath.Replace(szApp, "");
szPath+=theConf.m_ProjectName;
//szPath+=CString("\\*.*");
//delete the folder of all the contents
/*SHFILEOPSTRUCT op;
op.hwnd=m_hWnd;
op.lpszProgressTitle=NULL;
char TempPath[4096];
strcpy(TempPath, szPath.GetBuffer(0));
op.pFrom=TempPath;
op.pTo=NULL;
op.wFunc=FO_DELETE;
op.fFlags=FOF_SILENT;
op.hNameMappings=NULL;
SHFileOperation(&op);*/
CFileOperation fo;
if (!fo.Delete(szPath)) // do Copy
{
//fo.ShowError(); // if copy fails show error message
}
szPath=lpFilename;
szPath.Replace(szApp, "");
SetCurrentDirectory(szPath);
szPath+=theConf.m_ProjectName;
if (!RemoveDirectory(szPath))
{
LPVOID lpMsgBuf;
if (!FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL ))
{
// Handle the error.
}
// Process any inserts in lpMsgBuf.
// ...
// Display the string.
//AfxMessageBox((LPCTSTR) lpMsgBuf,MB_OK | MB_ICONERROR);
// Free the buffer.
LocalFree(lpMsgBuf);
}
//delete the project file name if exist
CString szProjFileName;
szProjFileName.Format("%s.prj", theConf.m_ProjectName.GetBuffer(0));
DeleteFile(szProjFileName);
} //Delete Folder
else
{
//save the project for future use
CString szProjFileName;
szProjFileName.Format("%s.prj", theConf.m_ProjectName.GetBuffer(0));
FILE* fp=fopen(szProjFileName.GetBuffer(0), "wt");
if (fp!=NULL)
{
fprintf(fp, "%d\n", theConf.m_ProjectSize); //Project Size
int index=theConf.m_PDFs.size();
for (int i=0; i<index; i++)
fprintf(fp, "%s\n", theConf.m_PDFs[i].GetBuffer(0));
fclose(fp);
}
}
if (m_LaunchWizard)
{
//launch new Scan2PDF.exe
ShellExecute(NULL, "open", lpFilename/*"Scan2PDF.exe"*/, NULL, NULL, SW_SHOW);
}
return CPropertyPageEx::OnWizardFinish();
}
void CFinishPage::OnAbout()
{
CScan2PDFDlg dlg;
dlg.DoModal();
}