// NeroBurn.cpp: implementation of the CNeroBurn class. // ////////////////////////////////////////////////////////////////////// //这个类也是类之间相互引用的一个具体的成功的;例子 #include "stdafx.h" #include "ylgl.h" #include "NeroDlg.h" #include "NeroBurn.h" #include "SelBrunDevice.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// extern CNeroDlg* pDlg; CNeroBurn::CNeroBurn() { NeroBurnOK=false; NeroWorkError=false; } CNeroBurn::~CNeroBurn() { NeroAPIFree(); for(int i=0; iIdleCallback; nsSettings.nstIdle.ncUserData = pDlg; nsSettings.nstSoftware = pcSoftware; nsSettings.nstUserDialog.ncCallbackFunction = pDlg->UserDialog; nsSettings.nstUserDialog.ncUserData = pDlg; nsSettings.nstLanguageFile =pcLanguageFile; // npProgress will be used during the burn process npProgress.npAbortedCallback = pDlg->AbortedCallback; npProgress.npAddLogLineCallback = pDlg->AddLogLine; npProgress.npDisableAbortCallback = NULL; npProgress.npProgressCallback = pDlg->ProgressCallback; npProgress.npSetPhaseCallback = pDlg->SetPhaseCallback; npProgress.npUserData = pDlg; npProgress.npSetMajorPhaseCallback=NULL; npProgress.npSubTaskProgressCallback=NULL; pndiDeviceInfos = NULL; NEROAPI_INIT_ERROR initErr; initErr = NeroInit(&nsSettings, NULL); switch (initErr) { case NEROAPI_INIT_OK: //AppendString("Initialization of the NeroAPI successful."); break; case NEROAPI_INIT_INVALID_ARGS: { AfxMessageBox("无效的参数, 请与系统管理员联系!", MB_ICONSTOP); return 0; } break; case NEROAPI_INIT_INVALID_SERIAL_NUM: { AfxMessageBox("刻录驱动未正确安装, 请与系统管理员联系!", MB_ICONSTOP); return 0; } break; default: { AfxMessageBox("出现未知错误, 请与系统管理员联系!", MB_ICONSTOP); return 0; } //AppendString("An error occured. The type of error cannot bedetermined."); break; } pndiDeviceInfos = NeroGetAvailableDrivesEx (MEDIA_CD, NULL); int lgl=1; if (!pndiDeviceInfos) { //AppendString("NeroGetAvailableDrives() returned no available devices."); { AfxMessageBox("未找到可用的刻录设备, 请与系统管理员联系!", MB_ICONSTOP); return 0; } } else { if (pndiDeviceInfos->nsdisNumDevInfos > 0) { //AppendString("Found the following devices:"); for (DWORD dDeviceCounter = 0; dDeviceCounter < pndiDeviceInfos->nsdisNumDevInfos; dDeviceCounter++) { //AppendString(pndiDeviceInfos->nsdisDevInfos[dDeviceCounter].nsdiDeviceName); //int i = m_cbxDevices.AddString(pndiDeviceInfos->nsdisDevInfos[dDeviceCounter].nsdiDeviceName); //m_cbxDevices.SetItemDataPtr(i, &pndiDeviceInfos->nsdisDevInfos[dDeviceCounter]); } //m_cbxDevices.SelectString(-1, pndiDeviceInfos->nsdisDevInfos[0].nsdiDeviceName); } else { //AppendString("The number of available devices is 0."); return 0; } } return 1; } void CNeroBurn::NeroAPIFree() { if (pndiDeviceInfos) { NeroFreeMem(pndiDeviceInfos); } NeroClearErrors(); NeroDone(); NeroAPIGlueDone(); return; } void GetChildArray(CString str, CStringArray *pArray, CStringArray &array) { CString dirname=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1); CString temp; for(int i=0; iGetSize (); i++) { temp=pArray->ElementAt (i); temp=temp.Left (temp.ReverseFind ('\\')); if(temp==str) array.Add (pArray->ElementAt (i)); } } void GetChildPhotoArray(CString str, CStringArray *pArray, CStringArray &array) { // AfxMessageBox(str); CString temp; for(int i=0; iGetSize (); i++) { temp=pArray->ElementAt (i); temp=temp.Left (temp.ReverseFind ('\\')); if(temp==str) { array.Add (pArray->ElementAt (i)); /// AfxMessageBox(pArray->ElementAt (i)); } } } void CNeroBurn::NeroAPIBurn() { for(int i=0; ifileName, str); strcpy(pMniiFile->sourceFilePath,"c:\\");*/ str=m_DirRealNameArray.ElementAt (i); strcpy(pMniiFile->fileName,str.Right(str.GetLength()-str.ReverseFind('\\')-1)); strcpy(pMniiFile->sourceFilePath,"c:\\"); pMniiFile->isDirectory=true; pMniiFile->isReference=false; pMniiFile->unicodeFileName=NULL; if(i==m_DirArray.GetSize ()-1) { pMniiFile->nextItem=NULL; } else { pMniiFile->nextItem=m_photoMniiArray.ElementAt(i+1); } ////////////////////////// pMniiFile->subDirFirstItem=NULL; ////////////////////////// } for(i=0;insdisNumDevInfos > 0) { CStringArray array; for (DWORD dDeviceCounter = 0; dDeviceCounter < pndiDeviceInfos->nsdisNumDevInfos; dDeviceCounter++) array.Add (pndiDeviceInfos->nsdisDevInfos[dDeviceCounter].nsdiDeviceName); SelBrunDevice dlg; dlg.pArray=&array; dlg.DoModal (); nsdiDevice =(NERO_SCSI_DEVICE_INFO*)&pndiDeviceInfos->nsdisDevInfos[dlg.m_cbxDevices.GetCurSel ()]; } else*/ nsdiDevice =(NERO_SCSI_DEVICE_INFO*)&pndiDeviceInfos->nsdisDevInfos[0]; ndhDeviceHandle = NeroOpenDevice(nsdiDevice); if (!ndhDeviceHandle) { AfxMessageBox("刻录设备不能打开, 请与系统管理员联系!", MB_ICONSTOP); NeroWorkError=true; } else { CString title=g_title+"("+m_name; title+=")客照"; /* NERO_ISO_ITEM mniiFile; strcpy(mniiFile.fileName, "1.png"); strcpy(mniiFile.sourceFilePath, "e:\\1.png"); mniiFile.isDirectory=FALSE; mniiFile.isReference=FALSE; mniiFile.unicodeFileName=NULL; // we only have one item mniiFile.nextItem=NULL;*/ if(m_bDvd) writeCD.nwcdIsoTrack = NeroCreateIsoTrackEx(\ m_photoMniiArray.ElementAt(0),title,NCITEF_USE_JOLIET|NCITEF_CREATE_ISO_FS); else writeCD.nwcdIsoTrack = NeroCreateIsoTrackEx(\ m_photoMniiArray.ElementAt(0),title,NCITEF_USE_JOLIET); int iRes; if(m_bDvd) iRes= NeroBurn(ndhDeviceHandle, NERO_ISO_AUDIO_MEDIA, &writeCD, NBF_WRITE|NBF_CLOSE_SESSION, 10, &npProgress); else iRes= NeroBurn(ndhDeviceHandle, NERO_ISO_AUDIO_CD, &writeCD, NBF_WRITE|NBF_CLOSE_SESSION, 0, &npProgress); //NBF_WRITE|NBF_CLOSE_SESSION NeroFreeIsoTrack(writeCD.nwcdIsoTrack); NeroCloseDevice(ndhDeviceHandle); char* Log = NeroGetErrorLog(); // AfxMessageBox(Log); switch(iRes) { case NEROAPI_BURN_OK: AfxMessageBox("刻录成功!", MB_ICONINFORMATION); NeroBurnOK=true; break; case NEROAPI_BURN_UNKNOWN_CD_FORMAT: AfxMessageBox("刻录失败:无效刻录盘格式!", MB_ICONSTOP); NeroWorkError=true; //AppendString ("BurnCD() : unknown CD format"); break; case NEROAPI_BURN_INVALID_DRIVE: //AppendString ("BurnCD() : invalid drive"); AfxMessageBox("刻录失败:驱动器无效!", MB_ICONSTOP); NeroWorkError=true; break; case NEROAPI_BURN_FAILED: AfxMessageBox("刻录失败!", MB_ICONSTOP); NeroWorkError=true; //AppendString ("BurnCD() : burn failed"); break; case NEROAPI_BURN_FUNCTION_NOT_ALLOWED: //AppendString ("BurnCD() : function not allowed"); case NEROAPI_BURN_DRIVE_NOT_ALLOWED: //AppendString ("BurnCD() : drive not allowed"); AfxMessageBox("刻录失败:刻录驱动未安装正确!", MB_ICONSTOP); NeroWorkError=true; break; default: AfxMessageBox("刻录失败:未知错误!", MB_ICONSTOP); NeroWorkError=true; //AppendString ("BurnCD() : unknown error"); break; } } } void CNeroBurn::JoinDir(CString dirname) { CString str; if(GetPosFromName(dirname)==-1) {//把根目录加进去 NERO_ISO_ITEM *pMniiFile=new NERO_ISO_ITEM; m_photoMniiArray.Add(pMniiFile); m_nameArray.Add(dirname); str=dirname; strcpy(pMniiFile->fileName,str.Right(str.GetLength()-str.ReverseFind('\\')-1)); strcpy(pMniiFile->sourceFilePath,"c:\\"); pMniiFile->isDirectory=true; pMniiFile->isReference=false; pMniiFile->unicodeFileName=NULL; pMniiFile->nextItem=NULL; } CStringArray childdirarray; CStringArray childphotoarray; GetChildArray(dirname, m_pDir, childdirarray); GetChildPhotoArray(dirname, &(m_pPhotoArray[GetDirPos(dirname)]), childphotoarray); int dircount=childdirarray.GetSize (); int photocount=childphotoarray.GetSize (); int oldcount=m_photoMniiArray.GetSize(); if( dircount==0 && photocount==0 ) { NERO_ISO_ITEM *pMniiFile=m_photoMniiArray.ElementAt(GetPosFromName(dirname)); pMniiFile->subDirFirstItem=NULL;return; } for(int nn=0; nnfileName,str.Right(str.GetLength()-str.ReverseFind('\\')-1)); strcpy(pMniiFile->sourceFilePath,"c:\\"); pMniiFile->isDirectory=true; pMniiFile->isReference=false; pMniiFile->unicodeFileName=NULL; if(nn==dircount+photocount-1) { pMniiFile->nextItem=NULL; } else { pMniiFile->nextItem=m_photoMniiArray.ElementAt(realpos+oldcount+1); } realpos++; } for(int j=0; jfileName,path.Right(path.GetLength()-path.ReverseFind('\\')-1)); strcpy(pMniiFile->sourceFilePath,path); pMniiFile->isDirectory=false; pMniiFile->isReference=false; pMniiFile->unicodeFileName=NULL; if(j==photocount-1) pMniiFile->nextItem=NULL; else pMniiFile->nextItem=m_photoMniiArray.ElementAt(realpos+oldcount+1); realpos++; } int pos=GetPosFromName(dirname); NERO_ISO_ITEM *pMniiFile=m_photoMniiArray.ElementAt(pos); pMniiFile->subDirFirstItem=m_photoMniiArray.ElementAt(oldcount); for( nn=0; nnGetSize(); i++) { if(dir==m_pDir->ElementAt(i)) return i; } return -1; } //imapi.exe int CNeroBurn::GetPosFromName(CString dirname) { for(int i=0; i