// This is a part of the High Performance CD Engine Library.
// Copyright (C) 2001-2003 Swift Software Group Incorporated
// All rights reserved.
//
// This source code is only intended as a supplement to the
// High Performance CD Engine Reference and related
// electronic documentation provided with the library.
// See these sources for detailed information regarding the
// High Performance CD Engine product.
// AudioBurnerDlg.cpp : implementation file
//
#include "stdafx.h"
#include "CloneBurner.h"
#include "CloneBurnerDlg.h"
#include "DialogProgress.h"
#include "TocEntry.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define BLOCKS_AT_ONCE 10
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CCloneBurnerDlg dialog
CCloneBurnerDlg::CCloneBurnerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCloneBurnerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCloneBurnerDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_AUDIO_ICON);
m_pEnumerator=NULL;
memset(&m_ctx, 0, sizeof(m_ctx));
m_hOperationStartedEvent=CreateEvent(NULL, TRUE, FALSE, NULL);
m_hNotifyEvent=CreateEvent(NULL, TRUE, FALSE, NULL);
InitializeCriticalSection(&m_cs);
m_notify.nPercent=0;
m_notify.strText="";
m_pDevice = NULL;
m_nDevicesCount = 0;
}
CCloneBurnerDlg::~CCloneBurnerDlg()
{
CloseHandle(m_hOperationStartedEvent);
CloseHandle(m_hNotifyEvent);
DeleteCriticalSection(&m_cs);
}
void CCloneBurnerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_BUTTON_ERASE, m_btnErase);
DDX_Control(pDX, IDC_CHECK_QUICK, m_chkQuick);
DDX_Control(pDX, IDC_STATIC_FREE_SPACE, m_staticFreeSpace);
DDX_Control(pDX, IDC_COMBO_SPEED, m_comboSpeed);
DDX_Control(pDX, IDC_COMBO_DEVICES, m_comboDevices);
DDX_Control(pDX, IDC_COMBO_RAW_MODE, m_comboRawMode);
DDX_Control(pDX, IDC_CHECK_TEST, m_chkTest);
DDX_Control(pDX, IDC_CHECK_EJECT, m_chkEject);
DDX_Control(pDX, IDC_BUTTON_START, m_btnStart);
DDX_Control(pDX, IDC_EDIT_ROOT, m_editRootDir);
}
BEGIN_MESSAGE_MAP(CCloneBurnerDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_BUTTON_START, OnButtonStart)
ON_BN_CLICKED(IDC_BUTTON_EJECTIN, OnButtonEjectin)
ON_BN_CLICKED(IDC_BUTTON_EJECTOUT, OnButtonEjectout)
ON_BN_CLICKED(IDC_BUTTON_ERASE, OnButtonErase)
ON_MESSAGE( WM_DEVICECHANGE, OnDeviceChange)
ON_CBN_SELCHANGE(IDC_COMBO_DEVICES, OnCbnSelchangeComboDevices)
ON_BN_CLICKED(IDC_BUTTON_BROWSE, OnBnClickedButtonBrowse)
END_MESSAGE_MAP()
void CCloneBurnerDlg::SetDeviceControls(int nIndex)
{
m_nDevice=nIndex;
ICDDevice11* pDevice= (ICDDevice11*)m_pEnumerator->GetItem(m_arIndices[m_nDevice]);
if (pDevice==NULL)
{
TRACE("Function CCloneBurnerDlg::SetDeviceControls : Unable to get device object\nPossible reason : auto-insert notification enabled\nwhile writing (or any other) operation is in progress.\nThis is just a warning message - your CD is not damaged.");
return; // Protection from AI notification...
}
int nCapacity = pDevice->GetAvailableBlocks();
if (nCapacity == 0)
{
m_staticFreeSpace.SetWindowText("Insert a blank disc.");
m_btnStart.EnableWindow(FALSE);
m_nCapacity=0;
}
else
{
int nMin=(nCapacity)/(75*60);
BOOL bEmpty=pDevice->GetMediaIsBlank();
CString str;
if (bEmpty)
str.Format("%d min free (a blank disc)", nMin);
else
str.Format("%d min free (not a blank disc)", nMin);
m_staticFreeSpace.SetWindowText(str);
m_nCapacity=nCapacity;
m_btnStart.EnableWindow(m_nCapacity > 0);
}
int nCurSpeed, nCurSel;
nCurSel=m_comboSpeed.GetCurSel();
nCurSpeed=m_comboSpeed.GetItemData(nCurSel);
int nSpeed=pDevice->GetMaxWriteSpeed();
m_comboSpeed.ResetContent();
int nCnt = 0;
CString sSpeed;
for (int i = nSpeed; i > 0; i -= 2)
{
sSpeed.Format("x%d", i);
m_comboSpeed.InsertString(-1, sSpeed);
m_comboSpeed.SetItemData(nCnt++, i);
}
// Restore speed...
if (nCurSel != -1 && nCurSpeed <= nSpeed)
nSpeed = nCurSpeed;
sSpeed.Format("x%d", nSpeed);
m_comboSpeed.SelectString(-1, sSpeed);
BOOL bRW, bRWDisk;
bRW = pDevice->GetReWritePossible();
bRWDisk = pDevice->GetMediaIsReWritable();
if (bRW && bRWDisk)
{
m_chkQuick.EnableWindow();
m_btnErase.EnableWindow();
}
else
{
m_chkQuick.EnableWindow(FALSE);
m_btnErase.EnableWindow(FALSE);
}
pDevice->Release();
}
/////////////////////////////////////////////////////////////////////////////
// CCloneBurnerDlg message handlers
BOOL CCloneBurnerDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_chkTest.SetCheck(FALSE);
m_chkEject.SetCheck(FALSE);
m_pEngine=hpCDE::CreateEngine();
BOOL bResult=m_pEngine->Initialize();
if (!bResult)
{
bResult=m_pEngine->Initialize(TRUE);
if (!bResult)
{
AfxMessageBox("Unable to initialize CD writing engine.");
EndModalLoop(-1);
if (m_pEnumerator)
{
m_pEnumerator->Release();
m_pEnumerator=NULL;
}
return FALSE;
}
}
m_pEnumerator=m_pEngine->GetDeviceEnumerator();
int nDevices=m_pEnumerator->GetCount();
if (!nDevices)
{
AfxMessageBox("No CD devices available.");
EndModalLoop(-1);
if (m_pEnumerator)
{
m_pEnumerator->Release();
m_pEnumerator=NULL;
}
return FALSE;
}
m_nDevicesCount=0;
for (int i=0; i < nDevices; i++)
{
ICDDevice * pDevice=m_pEnumerator->GetItem(i);
if (!pDevice)
continue;
BOOL bWrite = pDevice->GetWritePossible();
if (bWrite)
{
TCHAR tcsDesc[256]; TCHAR tchLetter;
pDevice->GetDescription(tcsDesc, 256);
tchLetter = pDevice->GetDriveLetter();
TCHAR tcsName[1000];
_stprintf(tcsName, _T("(%C:) - %s"), tchLetter, tcsDesc);
m_arDeviceNames.Add(tcsName);
m_arIndices.Add(i);
m_comboDevices.AddString(m_arDeviceNames[m_nDevicesCount++]);
}
pDevice->Release();
}
m_chkQuick.SetCheck(TRUE);
if (m_nDevicesCount)
{
m_comboDevices.SelectString(-1, m_arDeviceNames[0]);
SetDeviceControls(0);
}
else
{
AfxMessageBox("Unable ot open any CD writer device.");
EndModalLoop(-1);
if (m_pEnumerator) {
m_pEnumerator->Release();
m_pEnumerator=NULL;
}
return FALSE;
}
// 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);
}
}
DragAcceptFiles();
// Set the icon for this dialog. The framework