// NeroBurn.cpp: implementation of the CNeroBurn class. // ////////////////////////////////////////////////////////////////////// //这个类也是类之间相互引用的一个具体的成功的;例子 #include "stdafx.h" #include "LYFZIPManage.h" #include "NeroDlg.h" #include "NeroBurn.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; //NULL; nsSettings.nstIdle.ncUserData = NULL; // p;// nsSettings.nstSoftware = pcSoftware; nsSettings.nstUserDialog.ncCallbackFunction =pDlg->UserDialog; nsSettings.nstUserDialog.ncUserData =pDlg; // p; nsSettings.nstLanguageFile =NULL;//pcLanguageFile; memset(&npProgress, 0, sizeof(npProgress)); npProgress.npAbortedCallback =NULL;// p->AbortedCallback; npProgress.npAddLogLineCallback =NULL;//p->AddLogLine; npProgress.npDisableAbortCallback =NULL;//NULL; npProgress.npProgressCallback =pDlg->ProgressCallback; npProgress.npSetPhaseCallback =NULL;//p->SetPhaseCallback; npProgress.npUserData =pDlg; 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 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.Right(str.GetLength()-str.ReverseFind('\\')-1)); strcpy(pMniiFile->sourceFilePath,"c:\\"); pMniiFile->isDirectory=true; pMniiFile->isReference=false; if(i==m_DirArray.GetSize ()-1) { pMniiFile->nextItem=NULL; } else { pMniiFile->nextItem=m_photoMniiArray.ElementAt(i+1); } ////////////////////////// pMniiFile->subDirFirstItem=NULL; ////////////////////////// } for(i=0;insdiDevInfos[0]",1,1); // pndiDeviceInfos = NeroGetAvailableDrivesEx (MEDIA_CD, NULL); NERO_SCSI_DEVICE_INFO* nsdiDevice = (NERO_SCSI_DEVICE_INFO*)&pndiDeviceInfos->nsdisDevInfos[0]; //m_cbxDevices.GetItemDataPtr(i); ndhDeviceHandle = NeroOpenDevice(nsdiDevice); if (!ndhDeviceHandle) { AfxMessageBox("刻录设备不能打开, 请与系统管理员联系!", MB_ICONSTOP); NeroWorkError=true; //AppendString("Device could not be opened: "+(CString)nsdiDevice->nsdiDeviceName); } else { CString title=g_title+"("+m_name; title+=")客照"; 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, 0, &npProgress); else iRes= NeroBurn(ndhDeviceHandle, NERO_ISO_AUDIO_CD, &writeCD, NBF_WRITE|NBF_CLOSE_SESSION, 0, &npProgress); NeroFreeIsoTrack(writeCD.nwcdIsoTrack); NeroCloseDevice(ndhDeviceHandle); //m_btnAbort.EnableWindow(false); //m_mCancel.EnableWindow(true); //mOK.EnableWindow(true); //m_pgsProgress.SetPos(0); //m_cbxDevices.EnableWindow(true); //m_btnBrowse.EnableWindow(true); //m_btnBurn.EnableWindow(true); // mbAborted = false; char* Log = NeroGetErrorLog(); //AppendString(Log); switch(iRes) { case NEROAPI_BURN_OK: AfxMessageBox("刻录成功!", MB_ICONINFORMATION); //p->GetDlgItem(IDC_SURETEXT)->SetWindowText("光盘已经刻录好了,不要再按我了嘛!!"); 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->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; 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; if(j==photocount-1) pMniiFile->nextItem=NULL; else pMniiFile->nextItem=m_photoMniiArray.ElementAt(realpos+oldcount+1); realpos++; } NERO_ISO_ITEM *pMniiFile=m_photoMniiArray.ElementAt(GetPosFromName(dirname)); 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