123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415 |
- // 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; i<m_photoMniiArray.GetSize (); i++)
- delete [](m_photoMniiArray.ElementAt (i));
- m_photoMniiArray.RemoveAll();
- }
- extern DWORD FindAppProcessID(CString path);
- BOOL CNeroBurn::NeroAPIInit()
- {
- DWORD id=FindAppProcessID("imapi.exe");
- if(id!=-1)
- {
- HANDLE ProcessHandle=OpenProcess(PROCESS_ALL_ACCESS,FALSE,id);
- if(ProcessHandle)TerminateProcess(ProcessHandle,0);
- }
- if(!NeroAPIGlueConnect (NULL))
- {
- AfxMessageBox("刻录驱动未安装, 请与系统管理员联系!", MB_ICONSTOP);
- return 0;
- }
- dwVersion = NeroGetAPIVersion();
- CString strVersion;
- strVersion.Format("NeroAPI version %d.%d.%d.%d",
- dwVersion / 1000,
- (dwVersion / 100) % 10,
- (dwVersion / 10) % 10,
- dwVersion % 10);
- //AppendString(strVersion);
- //AppendString("Filling NERO_SETTINGS structure");
- strcpy(pcNeroFilesPath, "11111");
- strcpy(pcVendor, "ahead");
- strcpy(pcSoftware, "Nero - Burning Rom");
- strcpy(pcLanguageFile, "Nero.txt");
- memset(&nsSettings, 0, sizeof(nsSettings));
- nsSettings.nstNeroFilesPath = pcNeroFilesPath;
- nsSettings.nstVendor = pcVendor;
- nsSettings.nstIdle.ncCallbackFunction =NULL; // p->IdleCallback;
- //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; i<pArray->GetSize (); 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; i<pArray->GetSize (); 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; i<m_photoMniiArray.GetSize (); i++)
- delete [](m_photoMniiArray.ElementAt (i));
- m_photoMniiArray.RemoveAll();
- CString str;
- for(i=0;i<m_DirArray.GetSize ();i++)
- {
- NERO_ISO_ITEM *pMniiFile=new NERO_ISO_ITEM;
- m_photoMniiArray.Add(pMniiFile);
- m_nameArray.Add(m_DirArray.ElementAt(i));
- }
- for(i=0;i<m_DirArray.GetSize ();i++)
- {
- NERO_ISO_ITEM *pMniiFile=m_photoMniiArray.ElementAt (i);
- 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;
- if(i==m_DirArray.GetSize ()-1)
- {
- pMniiFile->nextItem=NULL;
- }
- else
- {
- pMniiFile->nextItem=m_photoMniiArray.ElementAt(i+1);
- }
- //////////////////////////
- pMniiFile->subDirFirstItem=NULL;
- //////////////////////////
- }
- for(i=0;i<m_DirArray.GetSize ();i++)
- {
- JoinDir(m_DirArray.ElementAt(i));
- }
-
- NERO_WRITE_CD writeCD;
- memset(&writeCD,0,sizeof(writeCD));
- writeCD.nwcdpCDStamp=NULL;
- writeCD.nwcdArtist=NULL;
- writeCD.nwcdTitle=NULL;
- writeCD.nwcdCDExtra=FALSE;
- writeCD.nwcdNumTracks=0;
- //int i = m_cbxDevices.GetCurSel();
- //AfxMessageBox("直接使用pndiDeviceInfos->nsdiDevInfos[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; nn<dircount+photocount; nn++)
- {
- NERO_ISO_ITEM *pMniiFile=new NERO_ISO_ITEM;
- m_photoMniiArray.Add(pMniiFile);
- m_nameArray.Add("");
- }
- int realpos=0;
- for( nn=0; nn<childdirarray.GetSize (); nn++)
- {
- str=childdirarray.ElementAt (nn);
- NERO_ISO_ITEM *pMniiFile=m_photoMniiArray.ElementAt(realpos+oldcount);
- m_nameArray.SetAt(realpos+oldcount, str);
-
- strcpy(pMniiFile->fileName,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; j<childphotoarray.GetSize(); j++)
- {
- CString path=childphotoarray.ElementAt(j);
- NERO_ISO_ITEM *pMniiFile=m_photoMniiArray.ElementAt(realpos+oldcount);
- m_nameArray.SetAt(realpos+oldcount, path);
- strcpy(pMniiFile->fileName,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; nn<childdirarray.GetSize (); nn++)
- {
- JoinDir(childdirarray.ElementAt (nn));
- }
- }
- int CNeroBurn::GetDirPos(CString dir)
- {
- for(int i=0; i<m_pDir->GetSize(); i++)
- {
- if(dir==m_pDir->ElementAt(i))
- return i;
- }
- return -1;
- }
- //imapi.exe
- int CNeroBurn::GetPosFromName(CString dirname)
- {
- for(int i=0; i<m_nameArray.GetSize(); i++)
- {
- if(dirname==m_nameArray.ElementAt(i))
- return i;
- }
- return -1;
- }
|