📄 chtrecnerodlg.cpp
字号:
pniiNewItem->longFileName = strdup(name);
pniiNewItem->longSourceFilePath = strdup(path);
pniiNewItem->isDirectory =TRUE;
pniiNewItem->isReference = FALSE;
pniiNewItem->unicodeFileName = NULL;
pniiNewItem->nextItem = NULL;
//pniiNewItem->isReference = TRUE;
//++++++++++++++++++++++++++++++++++++++++
//CString pathname;
if(niiPrevItem)
niiPrevItem->nextItem = pniiNewItem;
niiPrevItem = pniiNewItem;
// niiPrevItem->nextItem = NULL;
//++++++++++++++++++++++++++++++++++++++++++
/* if(niiPrevItem)
niiPrevItem->nextItem = pniiNewItem1;
niiPrevItem = pniiNewItem1;*/
//}
m_pnwcWriteCD->nwcdpCDStamp = NULL;
m_pnwcWriteCD->nwcdArtist = NULL;
m_pnwcWriteCD->nwcdTitle = NULL;
m_pnwcWriteCD->nwcdCDExtra = FALSE;
m_pnwcWriteCD->nwcdNumTracks = 0;
if(m_strMediaType=="DVD-RW"||m_strMediaType=="DVD-R")
m_pnwcWriteCD->nwcdMediaType = MEDIA_DVD_ANY;
if(m_strMediaType=="CD-RW")
m_pnwcWriteCD->nwcdMediaType = MEDIA_CDRW;
m_pnwcWriteCD->nwcdMediaType = MEDIA_CD;
int i = m_cbxDevices.GetCurSel();
NERO_SCSI_DEVICE_INFO* nsdiDevice =(NERO_SCSI_DEVICE_INFO*)m_cbxDevices.GetItemDataPtr(i);
m_ndhDeviceHandle = NeroOpenDevice(nsdiDevice);
if (!m_ndhDeviceHandle)
{
AfxMessageBox("Device could not be opened: "+(CString)nsdiDevice->nsdiDeviceName);
}
else
{
if(GetCheckedRadioButton(IDC_CONTINUE,IDC_COVER)==IDC_CONTINUE)
{
NERO_IMPORT_DATA_TRACK_INFO nidtInfo;
NERO_IMPORT_DATA_TRACK_RESULT nidtResult;
CString csUserMsg = "";
memset(&nidtInfo, 0, sizeof(nidtInfo));
nidtInfo.nidtiSize = sizeof(nidtInfo);
void* pCDStamp = NULL;
NERO_ISO_ITEM* pniiItem = NULL;
NERO_CD_INFO* pnciInfo =NeroGetCDInfo(m_ndhDeviceHandle, 0);
if(pnciInfo != NULL)
{
pniiItem = NeroImportDataTrack(m_ndhDeviceHandle,pnciInfo->ncdiNumTracks - 1, &pCDStamp,&nidtInfo, 0, &nidtResult, NULL);
NeroFreeMem(pnciInfo);
}
if(nidtInfo.nidtipVolumeName != NULL)
{
NeroFreeMem (nidtInfo.nidtipVolumeName);
}
if((nidtResult != NIDTR_NO_ERROR) || (pniiItem == NULL))
{
static LPCSTR errors[] = {"an unknown error",
"a generic error","a drive error",
"a read error",
"a filesystem error",
"an invalid track number"};
if (nidtResult > NIDTR_INVALID_TRACKNUMBER)
nidtResult = NIDTR_NO_ERROR;
csUserMsg.Format("There was %s while importing the track!",errors[nidtResult]);
AfxMessageBox(csUserMsg);
}
else if(m_pniiFile != NULL)
{
if(MergeIsoTracks(&m_pniiFile, pniiItem))
m_pnwcWriteCD->nwcdpCDStamp = pCDStamp;
else
{
AfxMessageBox("There was an error while merging tracks!");
if(pCDStamp != NULL)
NeroFreeCDStamp(pCDStamp), pCDStamp = NULL;
}
}
}
m_Cancel.EnableWindow(false);
m_OK.EnableWindow(false);
m_cbxDevices.EnableWindow(false);
m_btnBrowse.EnableWindow(false);
m_btnBurn.EnableWindow(false);
m_btnRemove.EnableWindow(false);
m_pgsProgress.SetRange(0,100);
//if(!m_chkbxAudio.GetCheck() &&
//(m_pnwcWriteCD->nwcdIsoTrack != NULL))
m_pnwcWriteCD->nwcdIsoTrack = NeroCreateIsoTrackEx(m_pniiFile, "ChteauSmall", NCITEF_CREATE_ISO_FS|NCITEF_USE_JOLIET);
int iRes = NeroBurn(m_ndhDeviceHandle, NERO_ISO_AUDIO_CD,
m_pnwcWriteCD, NBF_WRITE | NBF_CLOSE_SESSION, 0, &m_npProgress);
if(m_pnwcWriteCD->nwcdIsoTrack != NULL)
NeroFreeIsoTrack(m_pnwcWriteCD->nwcdIsoTrack);
NeroCloseDevice(m_ndhDeviceHandle);
m_Cancel.EnableWindow(true);
m_OK.EnableWindow(true);
m_cbxDevices.EnableWindow(true);
m_btnBrowse.EnableWindow(true);
m_btnBurn.EnableWindow(true);
m_btnRemove.EnableWindow(m_lstFileList.GetSelCount() > 0);
m_pgsProgress.SetPos(0);
m_bAborted = false;
char* Log = NeroGetErrorLog();
//Display the error log contents
//AfxMessageBox(Log);
//Free the log
NeroFreeMem(Log);
//Free the NERO_ISO_ITEM struct list.
DeleteIsoItemTree(m_pniiFile);
m_pniiFile = NULL;
//Free the memory allocated for audio track file paths.
//Free the NERO_WRITE_CD struct, too.
if(m_pnwcWriteCD != NULL)
{
if(m_pnwcWriteCD->nwcdpCDStamp != NULL)
NeroFreeCDStamp(m_pnwcWriteCD->nwcdpCDStamp),m_pnwcWriteCD->nwcdpCDStamp = NULL;
free(m_pnwcWriteCD), m_pnwcWriteCD = NULL;
}
//Tell the userhow the burn process was finished.
switch(iRes)
{
case NEROAPI_BURN_OK:
AfxMessageBox ("BurnCD() : burn successful");
break;
case NEROAPI_BURN_UNKNOWN_CD_FORMAT:
AfxMessageBox ("BurnCD() : unknown CD format");
break;
case NEROAPI_BURN_INVALID_DRIVE:
AfxMessageBox ("BurnCD() : invalid drive");
break;
case NEROAPI_BURN_FAILED:
AfxMessageBox ("BurnCD() : burn failed");
break;
case NEROAPI_BURN_FUNCTION_NOT_ALLOWED:
AfxMessageBox ("BurnCD() : function not allowed");
break;
case NEROAPI_BURN_DRIVE_NOT_ALLOWED:
AfxMessageBox ("BurnCD() : drive not allowed");
break;
case NEROAPI_BURN_USER_ABORT:
AfxMessageBox ("BurnCD() : user aborted");
break;
case NEROAPI_BURN_BAD_MESSAGE_FILE:
AfxMessageBox ("BurnCD() : bad message file");
break;
default:
AfxMessageBox ("BurnCD() : unknown error");
break;
}
}
}
}
BOOL NERO_CALLBACK_ATTR CChtRecNeroDlg::IdleCallback(void *pUserData)
{
static MSG msg;
while (!(((CChtRecNeroDlg*)pUserData)->m_bAborted) &&
::PeekMessage(&msg,NULL,NULL,NULL,PM_NOREMOVE))
{
if (!AfxGetThread()->PumpMessage())
{
break;
}
}
return ((CChtRecNeroDlg*)pUserData)->m_bAborted;
}
void CChtRecNeroDlg::NeroAPIInit()
{
m_bAborted = false;
if (!NeroAPIGlueConnect (NULL)) {
return;
}
strcpy(m_pcNeroFilesPath, "ChteauFiles");
strcpy(m_pcVendor, "chteau");
strcpy(m_pcSoftware, "Chteau - Burning Rom");
strcpy(m_pcLanguageFile, "Nero.txt");
memset(&m_nsSettings, 0, sizeof(m_nsSettings));
m_nsSettings.nstNeroFilesPath = m_pcNeroFilesPath;
m_nsSettings.nstVendor = m_pcVendor;
m_nsSettings.nstIdle.ncCallbackFunction = IdleCallback;
m_nsSettings.nstIdle.ncUserData = this;
m_nsSettings.nstSoftware = m_pcSoftware;
m_nsSettings.nstUserDialog.ncCallbackFunction = UserDialog;
m_nsSettings.nstUserDialog.ncUserData = this;
m_nsSettings.nstLanguageFile =m_pcLanguageFile;
memset(&m_npProgress, 0, sizeof(m_npProgress));
m_npProgress.npAbortedCallback = AbortedCallback;
m_npProgress.npAddLogLineCallback = AddLogLine;
m_npProgress.npDisableAbortCallback = NULL;
m_npProgress.npProgressCallback = ProgressCallback;
m_npProgress.npSetPhaseCallback = SetPhaseCallback;
m_npProgress.npSetMajorPhaseCallback=NULL;
m_npProgress.npSubTaskProgressCallback=NULL;
m_npProgress.npUserData = this;
m_pndiDeviceInfos = NULL;
NEROAPI_INIT_ERROR initErr;
initErr = NeroInit (&m_nsSettings, NULL);
switch (initErr)
{
case NEROAPI_INIT_OK:
break;
case NEROAPI_INIT_INVALID_ARGS:
AfxMessageBox("The arguments are not valid.");
break;
case NEROAPI_INIT_INVALID_SERIAL_NUM:
AfxMessageBox("The Serial Number is not valid.");
break;
default:
AfxMessageBox("An error occured. The type of error cannot bedetermined.");
break;
}
m_pndiDeviceInfos = NeroGetAvailableDrivesEx (MEDIA_CD, NULL);
if (!m_pndiDeviceInfos) {
AfxMessageBox("NeroGetAvailableDrives() returned no availabledevices.");
}
else
{
if (m_pndiDeviceInfos->nsdisNumDevInfos > 0)
{
for (DWORD dDeviceCounter = 0; dDeviceCounter <m_pndiDeviceInfos->nsdisNumDevInfos; dDeviceCounter++)
{
int i = m_cbxDevices.AddString(m_pndiDeviceInfos->
nsdisDevInfos[dDeviceCounter].nsdiDeviceName);
m_cbxDevices.SetItemDataPtr(i, &m_pndiDeviceInfos->
nsdisDevInfos[dDeviceCounter]);
}
m_cbxDevices.SelectString(-1, m_pndiDeviceInfos->nsdisDevInfos[0].nsdiDeviceName);
}
else
{
AfxMessageBox("The number of available devices is 0.");
}
}
}
NeroUserDlgInOut NERO_CALLBACK_ATTR CChtRecNeroDlg::UserDialog(void
*pUserData, NeroUserDlgInOut type, void *data)
{
switch (type)
{
case DLG_AUTO_INSERT:
return DLG_RETURN_CONTINUE;
break;
case DLG_DISCONNECT_RESTART:
return DLG_RETURN_ON_RESTART;
break;
case DLG_DISCONNECT:
return DLG_RETURN_CONTINUE;
break;
case DLG_AUTO_INSERT_RESTART:
return DLG_RETURN_EXIT;
break;
case DLG_RESTART:
return DLG_RETURN_EXIT;
break;
case DLG_SETTINGS_RESTART:
return DLG_RETURN_CONTINUE;
break;
case DLG_OVERBURN:
return DLG_RETURN_TRUE;
break;
case DLG_AUDIO_PROBLEMS:
return DLG_RETURN_EXIT;
break;
case DLG_FILESEL_IMAGE:
{
static char BASED_CODE szFilter[] = "Image Files(*.nrg)|*.nrg|All Files (*.*)|*.*||";
CFileDialog dlgOpen(TRUE, NULL, "test.nrg", OFN_OVERWRITEPROMPT,szFilter, ((CChtRecNeroDlg*)pUserData));
if (dlgOpen.DoModal() == IDOK)
{
strcpy((char*)data,dlgOpen.GetPathName());
return DLG_RETURN_TRUE;
}
else
{
return DLG_BURNIMAGE_CANCEL;
}
}
break;
case DLG_WAITCD:
{
NERO_WAITCD_TYPE waitcdType = (NERO_WAITCD_TYPE) (int)data;
char *waitcdString = NeroGetLocalizedWaitCDTexts (waitcdType);
AfxMessageBox(waitcdString);
NeroFreeMem(waitcdString);
return DLG_RETURN_EXIT;
break;
}
default:
break;
}
return DLG_RETURN_EXIT;
}
BOOL NERO_CALLBACK_ATTR CChtRecNeroDlg::ProgressCallback(void *pUserData, DWORD dwProgressInPercent)
{
((CChtRecNeroDlg*)pUserData)->m_pgsProgress.SetPos(dwProgressInPercent);
return ((CChtRecNeroDlg*)pUserData)->m_bAborted;
}
BOOL NERO_CALLBACK_ATTR CChtRecNeroDlg::AbortedCallback(void *pUserData)
{
return ((CChtRecNeroDlg*)pUserData)->m_bAborted;
}
void NERO_CALLBACK_ATTR CChtRecNeroDlg::AddLogLine(void *pUserData, NERO_TEXT_TYPE type, const char *text)
{
return;
}
void NERO_CALLBACK_ATTR CChtRecNeroDlg::SetPhaseCallback(void *pUserData, const char *text)
{
return;
}
void CChtRecNeroDlg::NeroAPIFree()
{
if (m_pndiDeviceInfos)
NeroFreeMem(m_pndiDeviceInfos);
NeroClearErrors();
if(NeroDone())
AfxMessageBox("Detected memory leaks in Chteausmall");
NeroAPIGlueDone();
return;
}
inline LPCSTR GetFilename(const NERO_ISO_ITEM* pItem)
{
return (pItem->longFileName != NULL)? pItem->longFileName : pItem->fileName;
}
BOOL CChtRecNeroDlg::MergeIsoTracks(NERO_ISO_ITEM** ppniiTarget,NERO_ISO_ITEM* pniiToAdd)
{
BOOL bResult = ((ppniiTarget != NULL) && (*ppniiTarget != NULL) &&
(pniiToAdd != NULL));
//There are wwo loops. The outer loop corresponds to the first tree, the inner loop to the second tree.
for( ; bResult && (*ppniiTarget != NULL);ppniiTarget = &(*ppniiTarget)->nextItem)
{
for(NERO_ISO_ITEM** ppniiToAddLocal = &pniiToAdd;*ppniiToAddLocal != NULL; )
{
if(0 == stricmp(GetFilename(*ppniiTarget),GetFilename(*ppniiToAddLocal)))
{
time_t timeTarget = mktime(&(*ppniiTarget)->entryTime);
if(timeTarget == (time_t)-1)
{
HANDLE hFile = NULL;
FILETIME ftCreationTime;
FILETIME ftLastAccessTime;
FILETIME ftLastWriteTime;
hFile = CreateFile((*ppniiTarget)->longSourceFilePath,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if(hFile == INVALID_HANDLE_VALUE)
{
CString csMsg;
csMsg.Format("Could not open file: %s.",
(*ppniiTarget)->longSourceFilePath);
AfxMessageBox(csMsg);
}
else if(GetFileTime(hFile, &ftCreationTime,&ftLastAccessTime, &ftLastWriteTime))
timeTarget = CTime(ftLastWriteTime).GetTime();
if(hFile != INVALID_HANDLE_VALUE)
CloseHandle(hFile), hFile = NULL;
}
time_t timeToAdd = mktime(&(*ppniiToAddLocal)->entryTime);
if(timeTarget < timeToAdd)
{
NERO_ISO_ITEM* pniiTmpItem = *ppniiToAddLocal;
*ppniiToAddLocal = *ppniiTarget;
*ppniiTarget = pniiTmpItem;
pniiTmpItem = (*ppniiToAddLocal)->nextItem;
(*ppniiToAddLocal)->nextItem = (*ppniiTarget)->nextItem;
(*ppniiTarget)->nextItem = pniiTmpItem;
}
//Remove the item from the second tree.
NERO_ISO_ITEM* pniiTmpItem = *ppniiToAddLocal;
*ppniiToAddLocal = pniiTmpItem->nextItem;
pniiTmpItem->nextItem = NULL;
DeleteIsoItemTree(pniiTmpItem);
}
else
ppniiToAddLocal = &(*ppniiToAddLocal)->nextItem;
}
}
//Attach whatever is left of the new tree to the main tree.
*ppniiTarget = pniiToAdd;
//Returning true means, everything is fine, continue.
return bResult;
}
void CChtRecNeroDlg::DeleteIsoItemTree(NERO_ISO_ITEM *pniiItem)
{
//First free our own long filename strings, then free the whole tree.
FreeOurOwnResources(pniiItem);
NeroFreeIsoItemTree(pniiItem);
}
void CChtRecNeroDlg::FreeOurOwnResources(NERO_ISO_ITEM*pniiItem)
{
//Step through the tree until the ISO item tree pointer becomes NULL
while(pniiItem != NULL)
{
NERO_ISO_ITEM* pniiNextItem = pniiItem->nextItem;
//We have encountered another ISO item tree; recurse another level.
if(pniiItem->isDirectory)
FreeOurOwnResources (pniiItem->subDirFirstItem);
if(!pniiItem->isReference)
{
if(pniiItem->longFileName != NULL)
free((void*)pniiItem->longFileName),
pniiItem->longFileName = NULL;
if(pniiItem->longSourceFilePath != NULL)
free((void*)pniiItem->longSourceFilePath),
pniiItem->longSourceFilePath = NULL;
}
pniiItem = pniiNextItem;
}
}
void CChtRecNeroDlg::OnEraseCDRW()
{
EraseOption dlg;
//printf ("Erasing disc. This will take %d seconds.\n", time);
// check whether a valid handle was returned
int i = m_cbxDevices.GetCurSel();
// retrieve the NERO_SCSI_DEVICE_INFO pointer for the selected device
// and assign it to a local variable
NERO_SCSI_DEVICE_INFO* nsdiDevice = (NERO_SCSI_DEVICE_INFO*)m_cbxDevices.GetItemDataPtr(i);
// try to open the selected device
m_ndhDeviceHandle = NeroOpenDevice(nsdiDevice);
dlg.DoModal();
}
void CChtRecNeroDlg::OnOK()
{
NeroAPIFree();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -