123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611 |
- // 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;
- #ifdef USE_KERNEL_DLL
- m_pRootItem = NULL;
- InitRootItem();
- #endif
- }
- CNeroBurn::~CNeroBurn()
- {
- NeroAPIFree();
- for(int i=0; i<m_photoMniiArray.GetSize (); i++)
- delete [](m_photoMniiArray.ElementAt (i));
- m_photoMniiArray.RemoveAll();
- }
- 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;
- }
- WORD majhi, majlo, minhi, minlo;
- NeroGetAPIVersionEx(&majhi, &majlo, &minhi, &minlo, NULL);
- CString strVersion;
- strVersion.Format("NeroAPI version %d.%d.%d.%d",
- majhi, majlo, minhi, minlo);
- #if defined(VC80) || defined(VC70) || defined(VC60)
- strcpy(pcNeroFilesPath, "NeroFiles");
- strcpy(pcVendor, "nero");
- strcpy(pcSoftware, "Nero - Burning Rom");
- strcpy(pcLanguageFile, "Nero.txt");
- #else
- _tcscpy_s(pcNeroFilesPath, 128, _T("NeroFiles"));
- _tcscpy_s(pcVendor, 128, _T("nero"));
- _tcscpy_s(pcSoftware, 128, _T("Nero - Burning Rom"));
- _tcscpy_s(pcLanguageFile, 128, _T("Nero.txt"));
- #endif
- nsSettings.nstNeroFilesPath = pcNeroFilesPath;
- nsSettings.nstVendor = pcVendor;
- nsSettings.nstIdle.ncCallbackFunction = (void*)pDlg->IdleCallback;
- nsSettings.nstIdle.ncUserData = pDlg;
- nsSettings.nstSoftware = pcSoftware;
- nsSettings.nstUserDialog.ncCallbackFunction = (void*)pDlg->UserDialog;
- nsSettings.nstUserDialog.ncUserData = pDlg;
- nsSettings.nstLanguageFile =pcLanguageFile;
- // npProgress will be used during the burn process
- npProgress.npAbortedCallback = (NERO_ABORTED_CALLBACK)pDlg->AbortedCallback;
- npProgress.npAddLogLineCallback = (NERO_ADD_LOG_LINE_CALLBACK)pDlg->AddLogLine;
- npProgress.npDisableAbortCallback = NULL;
- npProgress.npProgressCallback = (NERO_PROGRESS_CALLBACK)pDlg->ProgressCallback;
- npProgress.npSetPhaseCallback = (NERO_SET_PHASE_CALLBACK)pDlg->SetPhaseCallback;
- npProgress.npUserData = pDlg;
- npProgress.npSetMajorPhaseCallback=NULL;
- npProgress.npSubTaskProgressCallback=NULL;
- m_pndiDeviceInfos = NULL;
- NEROAPI_INIT_ERROR initErr;
- initErr = NeroInit(&nsSettings, NULL);
- switch (initErr)
- {
- case NEROAPI_INIT_OK:
- 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;
- }
- break;
- }
- // 获取可用的设备;
- m_pndiDeviceInfos = NeroGetAvailableDrivesEx(m_bDvd ? MEDIA_DVD_ANY : MEDIA_CD, NULL);
- if (!m_pndiDeviceInfos || m_pndiDeviceInfos->nsdisNumDevInfos == 0)
- {
- AfxMessageBox("未找到可用的刻录设备, 请与系统管理员联系!", MB_ICONSTOP);
- return 0;
- }
- return 1;
- }
- void CNeroBurn::NeroAPIFree()
- {
- if (m_pndiDeviceInfos)
- {
- NeroFreeMem(m_pndiDeviceInfos);
- }
- NeroClearErrors();
- NeroDone();
- NeroAPIGlueDone();
- return;
- }
- // 如果pArray的元素有属于str的子目录或子文件, 将pArray的元素保存到array中;
- void GetChildArray(CString str, CStringArray *pArray, CStringArray &array)
- {
- 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)
- {
- 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 CNeroBurn::NeroAPIBurn()
- {
- #ifdef USE_KERNEL_DLL
- DiscBurn();
- RemoveRootItem();
- return;
- #endif
- INT i = 0;
- // 清空所有NERO_ISO_ITEM元素对象;
- for( i=0; i<m_photoMniiArray.GetSize(); i++)
- {
- delete [](m_photoMniiArray.ElementAt(i));
- }
- m_photoMniiArray.RemoveAll();
- CString str;
- // 创建根目录NERO_ISO_ITEM元素;
- 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));
- }
- // 创建完所有根目录NERO_ISO_IMTE元素对象后,设置每个元素isDirectory=TRUE;
- for(i=0;i<m_DirArray.GetSize ();i++)
- {
- NERO_ISO_ITEM *pMniiFile=m_photoMniiArray.ElementAt (i);
- str=m_DirRealNameArray.ElementAt (i);
- #if defined(VC80) || defined(VC70) || defined(VC60)
- strcpy(pMniiFile->fileName,str.Right(str.GetLength()-str.ReverseFind('\\')-1));
- strcpy(pMniiFile->sourceFilePath,"c:\\");
- #else
- _tcscpy_s(pMniiFile->fileName, 252, str.Right(str.GetLength()-str.ReverseFind('\\')-1));
- _tcscpy_s(pMniiFile->sourceFilePath, 252, "c:\\");
- #endif
- pMniiFile->isDirectory=true;
- pMniiFile->isReference=false;
- pMniiFile->unicodeFileName=NULL;
- if(i==m_DirArray.GetSize ()-1)
- {
- pMniiFile->nextItem=NULL;
- }
- else
- {// nextItem指向同类型的元素指针;
- 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;
- if(m_bDvd)
- {
- writeCD.nwcdMediaType = MEDIA_DVD_ANY;
- }
- NERO_SCSI_DEVICE_INFO* nsdiDevice;
- nsdiDevice =(NERO_SCSI_DEVICE_INFO*)&m_pndiDeviceInfos->nsdisDevInfos[0];
- m_ndhDeviceHandle = NeroOpenDevice(nsdiDevice);
- if (!m_ndhDeviceHandle)
- {
- AfxMessageBox("刻录设备不能打开, 请与系统管理员联系!", MB_ICONSTOP);
- NeroWorkError=true;
- }
- else
- {
- CString title=g_title+"("+m_strCustomerInfo;
- title+=")客照";
- 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(m_ndhDeviceHandle, NERO_ISO_AUDIO_MEDIA, &writeCD,
- NBF_WRITE|NBF_CLOSE_SESSION, 10, &npProgress);
- else
- iRes= NeroBurn(m_ndhDeviceHandle, NERO_ISO_AUDIO_CD, &writeCD,
- NBF_WRITE|NBF_CLOSE_SESSION, 0, &npProgress);
- //NBF_WRITE|NBF_CLOSE_SESSION
- NeroFreeIsoTrack(writeCD.nwcdIsoTrack);
- NeroCloseDevice(m_ndhDeviceHandle);
- char* Log = NeroGetErrorLog();
- 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)
- {// 如果目录不在m_DirArray中,要先把根目录加进m_nameArray中;
- NERO_ISO_ITEM *pMniiFile=new NERO_ISO_ITEM;
- m_photoMniiArray.Add(pMniiFile);
- m_nameArray.Add(dirname);
- str=dirname;
- #if defined(VC80) || defined(VC70) || defined(VC60)
- strcpy(pMniiFile->fileName,str.Right(str.GetLength()-str.ReverseFind('\\')-1));
- strcpy(pMniiFile->sourceFilePath,"c:\\");
- #else
- _tcscpy_s(pMniiFile->fileName, 252, str.Right(str.GetLength()-str.ReverseFind('\\')-1));
- _tcscpy_s(pMniiFile->sourceFilePath, 252, "c:\\");
- #endif
- pMniiFile->isDirectory=true;
- pMniiFile->isReference=false;
- pMniiFile->unicodeFileName=NULL;
- pMniiFile->nextItem=NULL;
- }
- // dirname这个根目录下的子目录;
- CStringArray childdirarray;
- // 子目录下的相片路径;
- CStringArray childphotoarray;
- // 将m_pDir中所有dirname的子目录放到childdirarray中;
- GetChildArray(dirname, m_pDir, childdirarray);
- // 将dirname目录的所有相片路径保存到childphotoarray中;
- GetChildPhotoArray(dirname, &(m_pPhotoArray[GetDirPos(dirname)]), childphotoarray);
- // 获取dirname这个根目录所有子目录个数;
- int dircount=childdirarray.GetSize ();
- // 获取dirname这个根目录所有相片张数;
- int photocount=childphotoarray.GetSize ();
- // oldcount为尾元素索引;
- int oldcount=m_photoMniiArray.GetSize();
- if( dircount==0 && photocount==0 )
- {
- NERO_ISO_ITEM *pMniiFile=m_photoMniiArray.ElementAt(GetPosFromName(dirname));
- pMniiFile->subDirFirstItem=NULL;
- return;
- }
- // 再添加dircount + photocount 个NERO_ISO_ITEM元素;
- int nn = 0;
- for( nn=0; nn<dircount+photocount; nn++)
- {
- NERO_ISO_ITEM *pMniiFile=new NERO_ISO_ITEM;
- m_photoMniiArray.Add(pMniiFile);
- m_nameArray.Add("");
- }
- // 设置之前添加的NERO_ISO_ITEM元素中的前dircount个为目录文件;
- 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);
- #if defined(VC80) || defined(VC70) || defined(VC60)
- strcpy(pMniiFile->fileName,str.Right(str.GetLength()-str.ReverseFind('\\')-1));
- strcpy(pMniiFile->sourceFilePath,"c:\\");
- #else
- _tcscpy_s(pMniiFile->fileName, 252, str.Right(str.GetLength()-str.ReverseFind('\\')-1));
- _tcscpy_s(pMniiFile->sourceFilePath, 252, "c:\\");
- #endif
- 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++;
- }
- // 再设置剩余的photocount个元素为文件元素;
- 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);
- #if defined(VC80) || defined(VC70) || defined(VC60)
- strcpy(pMniiFile->fileName,path.Right(path.GetLength()-path.ReverseFind('\\')-1));
- strcpy(pMniiFile->sourceFilePath,path);
- #else
- _tcscpy_s(pMniiFile->fileName, 252, path.Right(path.GetLength()-path.ReverseFind('\\')-1));
- _tcscpy_s(pMniiFile->sourceFilePath, 252, path);
- #endif
- 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);
- // 设置dirname根元素的NERO_ISO_ITEM的第一个子目录元素指针;
- 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;
- }
- #ifdef USE_KERNEL_DLL
- /************************************************************************/
- /*
- 函数:InitRootItem
- 描述:初始化光盘。
- 参数:
- 返回:返回光盘根虚拟元素。
- 注意:
- 示例:
- */
- /************************************************************************/
- NERO_ISO_ITEM* CNeroBurn::InitRootItem()
- {
- if ( m_pRootItem == NULL )
- {
- m_pRootItem = new NERO_ISO_ITEM;
- ZeroMemory(m_pRootItem, sizeof(NERO_ISO_ITEM));
- m_pRootItem->isDirectory = TRUE;
- m_pRootItem->longFileName = _strdup(_T("光盘根级虚元素"));
- m_pRootItem->isReference = FALSE;
- m_pRootItem->unicodeFileName = NULL;
- m_pRootItem->nextItem = NULL;
- m_pRootItem->subDirFirstItem = NULL;
- }
- return m_pRootItem;
- }
- /************************************************************************/
- /*
- 函数:GetDiscItem
- 描述:返回光盘要刻录的第一个元素。
- 参数:
- 返回:返回光盘要刻录的第一个元素。
- 注意:
- 示例:
- */
- /************************************************************************/
- NERO_ISO_ITEM* CNeroBurn::GetDiscItem()
- {
- if ( m_pRootItem == NULL)
- {
- if ( InitRootItem() == NULL )
- {
- WriteTextLog(_T("获取光盘根目录失败!"));
- return NULL;
- }
- }
- if ( m_pRootItem )
- return m_pRootItem->subDirFirstItem;
- else
- return NULL;
- }
- /************************************************************************/
- /*
- 函数:AddSiblingRootItem
- 描述:将元素添加到根目录的兄弟链中。
- 参数:
- pRootItem[IN]:新的根目录兄弟项;
- 返回:成功添加返回新项,否则返回NULL;
- 注意:。
- 示例:
- */
- /************************************************************************/
- NERO_ISO_ITEM* CNeroBurn::AddSiblingRootItem( IN NERO_ISO_ITEM* pRootItem )
- {
- if ( m_pRootItem == NULL)
- {
- if ( InitRootItem() == NULL )
- {
- WriteTextLog(_T("获取光盘根目录失败!"));
- return NULL;
- }
- }
- if ( pRootItem == NULL )
- return NULL;
- if ( m_pRootItem->subDirFirstItem == NULL )
- {// 当根元素空时,赋值为第一个值;
- m_pRootItem->subDirFirstItem = pRootItem;
- }
- else
- {
- NERO_ISO_ITEM* pNextItem = m_pRootItem->subDirFirstItem;
- while( pNextItem->nextItem )
- pNextItem = pNextItem->nextItem;
- pNextItem->nextItem = pRootItem;
- }
- m_vtItems.push_back(pRootItem);
- return pRootItem;
- }
- /************************************************************************/
- /*
- 函数:AddSiblingRootItem
- 描述:将元素添加到根目录的兄弟链中。
- 参数:
- strRootName[IN]:新的根目录兄弟项名称;
- bIsDirectory[IN]:新的根目录兄弟项类型;
- 返回:成功添加返回新项,否则返回NULL
- 注意:
- 示例:
- */
- /************************************************************************/
- NERO_ISO_ITEM* CNeroBurn::AddSiblingRootItem( IN CString strRootName, IN BOOL bIsDirectory )
- {
- if ( strRootName.IsEmpty() )
- {
- WriteTextLog(_T("获取光盘根目录失败!"));
- return NULL;
- }
- if ( m_pRootItem == NULL)
- {
- if ( InitRootItem() == NULL )
- {
- WriteTextLog(_T("获取光盘根目录失败!"));
- return NULL;
- }
- }
- NERO_ISO_ITEM* pRootItem = new NERO_ISO_ITEM;
- ZeroMemory(pRootItem, sizeof(NERO_ISO_ITEM));
- if ( !bIsDirectory ){// 根元素是文件;
- char path[MAX_PATH];
- char* name;
- GetFullPathName(strRootName, MAX_PATH, path, &name);
- pRootItem->isDirectory = FALSE;
- pRootItem->longFileName = _strdup(name);
- pRootItem->longSourceFilePath = _strdup(path);
- pRootItem->isReference = FALSE;
- pRootItem->unicodeFileName = NULL;
- pRootItem->nextItem = NULL;
- pRootItem->subDirFirstItem = NULL;
- }else{ // 根元素是目录;
- pRootItem->isDirectory = TRUE;
- pRootItem->longFileName = _strdup(strRootName);
- pRootItem->isReference = FALSE;
- pRootItem->unicodeFileName = NULL;
- pRootItem->nextItem = NULL;
- pRootItem->subDirFirstItem = NULL;
- }
- if ( m_pRootItem->subDirFirstItem == NULL )
- {
- m_pRootItem->subDirFirstItem = pRootItem;
- }
- else
- {
- NERO_ISO_ITEM* pNextItem = m_pRootItem->subDirFirstItem;
- while( pNextItem->nextItem )
- pNextItem = pNextItem->nextItem;
- pNextItem->nextItem = pRootItem;
- }
- m_vtItems.push_back(pRootItem);
- return pRootItem;
- }
- /************************************************************************/
- /*
- 函数:AddItem2SiblingItem
- 描述:添加新元素到指定的兄弟项中;
- 参数:
- pSiblingItem[IN]: 作为兄弟链的参考兄弟项;
- pNewItem[IN]:需要添加兄弟链中的新项;
- 返回:
- 成功添加返回TRUE,否则返回FALSE;
- 注意:
- pSiblingItem不指定具体的类型,如果文件类型(isDirectory==FALSE)或目录类型(isDirectory==TRUE).
- 示例:
- */
- /************************************************************************/
- NERO_ISO_ITEM* CNeroBurn::AddItem2SiblingItem( IN NERO_ISO_ITEM* pSiblingItem, IN NERO_ISO_ITEM* pNewItem)
- {
- if ( m_pRootItem == NULL || m_pRootItem->subDirFirstItem == NULL )
- {
- WriteTextLog(_T("获取光盘根目录失败!"));
- OutputDebugString(_T("\nAddItem2SiblingItem:光盘的根项元素空!\n"));
- return NULL;
- }
- if ( pSiblingItem == NULL )
- {
- WriteTextLog(_T("获取光盘根目录失败!"));
- OutputDebugString(_T("\nAddItem2SiblingItem:光盘的兄弟项元素空!\n"));
- return NULL;
- }
- NERO_ISO_ITEM* pNextItem = pSiblingItem;
- while(pNextItem->nextItem)
- {
- pNextItem = pNextItem->nextItem;
- }
- pNextItem->nextItem = pNewItem;
- pNewItem->nextItem = NULL;
- m_vtItems.push_back(pNewItem);
- return pNewItem;
- }
- /************************************************************************/
- /*
- 函数:AddItem2Path
- 描述:添加新元素到指定的目录下;
- 参数:
- strDiscPath[IN]:光盘目录,作为新元素要父目录;
- pNewItem[IN]:新元素,将插入到strDiscPath目录下;
- 返回:成功添加返回TRUE,否则返回FALS;
- 注意:
- 示例:
- */
- /************************************************************************/
- NERO_ISO_ITEM* CNeroBurn::AddItem2Path( IN CString strDiscPath, IN NERO_ISO_ITEM* pNewItem)
- {
- if ( m_pRootItem == NULL || m_pRootItem->subDirFirstItem == NULL)
- {
- WriteTextLog(_T("获取光盘根目录失败!"));
- OutputDebugString(_T("\nAddItem2Path:光盘的根项元素空!\n"));
- return NULL;
- }
- if ( strDiscPath.IsEmpty() )
- {
- WriteTextLog(_T("获取光盘根目录失败!"));
- OutputDebugString(_T("\nAddItem2Path:光盘的兄弟项元素名称空\n"));
- return NULL;
- }
-
- // 首先查找;
- NERO_ISO_ITEM *pTailPathItem = FindPathItem(strDiscPath);
- if ( pTailPathItem == NULL )
- {
- WriteTextLog(_T("获取光盘根目录失败!"));
- OutputDebugString(_T("\nAddItem2Path:未找到光盘指定路径元素:"));
- OutputDebugString(strDiscPath);
- return NULL;
- }
- pNewItem->nextItem = NULL;
- if ( pTailPathItem->subDirFirstItem )
- {
- NERO_ISO_ITEM* pNextItem = pTailPathItem->subDirFirstItem;
- while ( pNextItem->nextItem )
- {
- pNextItem = pNextItem->nextItem;
- }
- pNextItem->nextItem = pNewItem;
- }
- else
- {
- pTailPathItem->subDirFirstItem = pNewItem;
- }
- m_vtItems.push_back(pNewItem);
- return pNewItem;
- }
- /************************************************************************/
- /*
- 函数:AddSiblingPath
- 描述:添加新目录到指定的光盘目录的兄弟链尾中;
- 参数:
- strDiscPath[IN]:光盘目录,作为新元素兄弟链头路径;
- strNewPath[IN]:新目录,strDiscPath的兄弟项;
- 返回:
- 成功返回TRUE,否则返回FALSE;
- 注意:
- 示例:
- */
- /************************************************************************/
- NERO_ISO_ITEM* CNeroBurn::AddSiblingPath(IN CString strDiscPath, IN CString strNewPath)
- {
- // 首先查找;
- NERO_ISO_ITEM *pTailPathItem = FindPathItem(strDiscPath);
- if ( pTailPathItem == NULL )
- {
- WriteTextLog(_T("获取光盘根目录失败!"));
- OutputDebugString(_T("\nAddPath2Path:未找到光盘指定路径元素:"));
- OutputDebugString(strDiscPath);
- return NULL;
- }
- NERO_ISO_ITEM* pNewItem = new NERO_ISO_ITEM;
- ZeroMemory(pNewItem,sizeof(NERO_ISO_ITEM));
- pNewItem->isDirectory = TRUE;
- pNewItem->isReference = FALSE;
- pNewItem->unicodeFileName = NULL;
- pNewItem->longFileName = _strdup(strNewPath);
- //sprintf_s(pNewItem->fileName, "%s", strNewPath);
- pNewItem->subDirFirstItem = NULL;
- pNewItem->nextItem = NULL;
- while( pTailPathItem->nextItem )
- {
- pTailPathItem = pTailPathItem->nextItem;
- }
- pTailPathItem->nextItem = pNewItem;
- m_vtItems.push_back(pNewItem);
- return pNewItem;
- }
- /************************************************************************/
- /*
- 函数:AddPath
- 描述:添加新的目录到光盘目录中,若目录不存在,则重新创建目录元素;
- 参数:
- strNewPath[IN]:新目录,根目录的新兄弟项;
- 返回:
- 成功返回TRUE,否则返回FALSE;
- 注意:
- 示例:
- */
- /************************************************************************/
- NERO_ISO_ITEM* CNeroBurn::AddPath(IN CString strNewPath)
- {
- INT nIndex = 0;
- CString strPath = strNewPath;
- strPath.TrimRight(_T('\\'));
- strPath += _T("\\");
- NERO_ISO_ITEM* pTailPath = NULL;
- do
- {
- nIndex = strPath.ReverseFind(_T('\\'));
- if ( nIndex != -1 )
- {
- strPath = strPath.Left(nIndex);
- pTailPath = FindPathItem(strPath);
- }
- else
- {// 最后一个;
- pTailPath = FindPathItem(strPath);
- }
- } while ( !pTailPath && nIndex != -1);
- if ( pTailPath == NULL ){// 全新目录;
- pTailPath = m_pRootItem;
- strNewPath.TrimRight(_T("\\"));
- strNewPath += _T("\\");
- do
- {
- nIndex = strNewPath.Find(_T("\\"));
- if ( nIndex != -1 )
- {
- if ( pTailPath == NULL )
- {
- WriteTextLog(_T("获取光盘根目录失败!"));
- OutputDebugString(_T("\n添加目录时出错\n"));
- break;
- }
- pTailPath = AddPath2PathItem(pTailPath, strNewPath.Left(nIndex));
- strNewPath = strNewPath.Mid(nIndex + 1);
- }
- } while ( strNewPath.Find(_T("\\")) != -1 );
- }
- else
- {
- if ( strNewPath == strPath )
- return pTailPath;
- strNewPath.Delete(0, strPath.GetLength()+1);
- strNewPath.TrimRight(_T("\\"));
- strNewPath += _T("\\");
- do {
- nIndex = strNewPath.Find(_T("\\"));
- if ( nIndex != -1 )
- {
- if ( pTailPath == NULL )
- {
- WriteTextLog(_T("获取光盘根目录失败!"));
- OutputDebugString(_T("\n添加目录时出错\n"));
- break;
- }
- pTailPath = AddPath2PathItem(pTailPath, strNewPath.Left(nIndex));
- strNewPath = strNewPath.Mid(nIndex + 1);
- }
- } while ( strNewPath.Find(_T("\\")) != -1 );
- }
- return pTailPath;
- }
- /************************************************************************/
- /*
- 函数:AddPath2Path
- 描述:添加新目录到指定的光盘目录下;
- 参数:
- strDiscPath[IN]:光盘目录,作为新元素要父目录;
- strNewPath[IN]:新目录,将插入到strDiscPath目录下;
- 返回:
- 成功返回TRUE,否则返回FALSE;
- 注意:
- 示例:
- */
- /************************************************************************/
- NERO_ISO_ITEM* CNeroBurn::AddPath2Path(IN CString strDiscPath, IN CString strNewPath)
- {
- // 首先查找;
- NERO_ISO_ITEM *pTailPathItem = FindPathItem(strDiscPath);
- if ( pTailPathItem == NULL )
- {
- WriteTextLog(_T("AddPath2Path:无光盘目录"));
- OutputDebugString(_T("\nAddPath2Path:未找到光盘指定路径元素:"));
- OutputDebugString(strDiscPath);
- return NULL;
- }
- NERO_ISO_ITEM* pNewItem = new NERO_ISO_ITEM;
- ZeroMemory(pNewItem,sizeof(NERO_ISO_ITEM));
- pNewItem->isDirectory = TRUE;
- pNewItem->isReference = FALSE;
- pNewItem->unicodeFileName = NULL;
- pNewItem->longFileName = _strdup(strNewPath);
- //sprintf_s(pNewItem->fileName, "%s", strNewPath);
- pNewItem->subDirFirstItem = NULL;
- pNewItem->nextItem = NULL;
- if ( pTailPathItem->subDirFirstItem )
- {
- NERO_ISO_ITEM* pNextItem = pTailPathItem->subDirFirstItem;
- while ( pNextItem->nextItem )
- {
- pNextItem = pNextItem->nextItem;
- }
- pNextItem->nextItem = pNewItem;
- }
- else
- {
- pTailPathItem->subDirFirstItem = pNewItem;
- }
- m_vtItems.push_back(pNewItem);
- return pNewItem;
- }
- /************************************************************************/
- /*
- 函数:AddPath2PathItem
- 描述:添加新目录到指定的光盘目录下;
- 参数:
- pPathItem[IN]:光盘目录,作为新元素要父目录;
- strNewPath[IN]:新目录,将插入到strDiscPath目录下;
- 返回:
- 成功返回TRUE,否则返回FALSE;
- 注意:
- 示例:
- */
- /************************************************************************/
- NERO_ISO_ITEM* CNeroBurn::AddPath2PathItem(IN NERO_ISO_ITEM* pPathItem, IN CString strNewPath )
- {
- if ( pPathItem == NULL || pPathItem->isDirectory == FALSE )
- {
- WriteTextLog(_T("AddPath2PathItem:目录元素空或非目录元素!"));
- return NULL;
- }
- NERO_ISO_ITEM* pNewItem = new NERO_ISO_ITEM;
- ZeroMemory(pNewItem,sizeof(NERO_ISO_ITEM));
- pNewItem->isDirectory = TRUE;
- pNewItem->isReference = FALSE;
- pNewItem->unicodeFileName = NULL;
- pNewItem->longFileName = _strdup(strNewPath);
- //sprintf_s(pNewItem->fileName, "%s", strNewPath);
- pNewItem->subDirFirstItem = NULL;
- pNewItem->nextItem = NULL;
- m_vtItems.push_back(pNewItem);
- if ( pPathItem->subDirFirstItem == NULL )
- return pPathItem->subDirFirstItem = pNewItem;
- NERO_ISO_ITEM* pNextItem = pPathItem->subDirFirstItem;
- while( pNextItem->nextItem)
- {
- pNextItem = pNextItem->nextItem;
- }
- return pNextItem->nextItem = pNewItem;
- }
- /************************************************************************/
- /*
- 函数:AddFile2Path
- 描述:添加新文件到指定的光盘目录下;
- 参数:
- strDiscPath[IN]:光盘目录,作为新元素的父目录;
- strFileName[IN]:新文件,将插入到strDiscPath目录下;
- 返回:
- 成功返回TRUE,否则返回FALSE;
- 注意:
- 示例:
- */
- /************************************************************************/
- NERO_ISO_ITEM* CNeroBurn::AddFile2Path(IN CString strDiscPath, IN CString strFileName)
- {
- // 首先查找;
- NERO_ISO_ITEM *pTailPathItem = FindPathItem(strDiscPath);
- if ( pTailPathItem == NULL )
- {
- pTailPathItem = AddPath(strDiscPath);
- if ( pTailPathItem == NULL )
- {
- WriteTextLog(_T("AddFile2Path:获取目录项尾元素失败!"));
- OutputDebugString(_T("\nAddFile2Path:未找到光盘指定路径元素:"));
- OutputDebugString(strDiscPath);
- return NULL;
- }
- }
- NERO_ISO_ITEM* pNewItem = new NERO_ISO_ITEM;
- ZeroMemory(pNewItem, sizeof(NERO_ISO_ITEM));
- pNewItem->isDirectory = FALSE;
- pNewItem->isReference = FALSE;
- pNewItem->unicodeFileName = NULL;
- char path[MAX_PATH];
- char* name;
- GetFullPathName(strFileName, MAX_PATH, path, &name);
- pNewItem->longFileName = _strdup(name);
- pNewItem->longSourceFilePath = _strdup(path);
- //sprintf_s(pNewItem->fileName,"%s", strFileName);
- pNewItem->nextItem = NULL;
- pNewItem->subDirFirstItem = NULL;
- if ( pTailPathItem->subDirFirstItem )
- {
- NERO_ISO_ITEM* pNextItem = pTailPathItem->subDirFirstItem;
- while ( pNextItem->nextItem )
- {
- pNextItem = pNextItem->nextItem;
- }
- pNextItem->nextItem = pNewItem;
- }
- else
- {
- pTailPathItem->subDirFirstItem = pNewItem;
- }
- m_vtItems.push_back(pNewItem);
- return pNewItem;
- }
- /************************************************************************/
- /*
- 函数:AddFile2SiblingItem
- 描述:将文件添加到指定的兄弟项中;
- 参数:
- pSiblingItem[IN]:
- strFileName[IN]:
- 返回:
- 注意:
- 示例:
- */
- /************************************************************************/
- NERO_ISO_ITEM* CNeroBurn::AddFile2SiblingItem(IN NERO_ISO_ITEM* pSiblingItem, IN CString strFileName)
- {
- if (pSiblingItem == NULL)
- {
- WriteTextLog(_T("AddFile2SiblingItem:树兄弟项空!"));
- OutputDebugString(_T("\nAddFile2SiblingItem:树兄弟项出错!\n"));
- return NULL;
- }
- NERO_ISO_ITEM* pNewItem = new NERO_ISO_ITEM;
- ZeroMemory(pNewItem, sizeof(NERO_ISO_ITEM));
- pNewItem->isDirectory = FALSE;
- pNewItem->isReference = FALSE;
- char path[MAX_PATH];
- char* name;
- GetFullPathName(strFileName, MAX_PATH, path, &name);
- pNewItem->longFileName = _strdup(name);
- pNewItem->longSourceFilePath = _strdup(path);
- //sprintf_s(pNewItem->fileName,"%s",strFileName);
- pNewItem->nextItem = NULL;
- pNewItem->subDirFirstItem = NULL;
- NERO_ISO_ITEM* pNextItem = pSiblingItem;
- while(pNextItem->nextItem)
- {
- pNextItem = pNextItem->nextItem;
- }
- pNextItem->nextItem = pNewItem;
- m_vtItems.push_back(pNewItem);
- return pNewItem;
- }
- /************************************************************************/
- /*
- 函数:FindPathItem
- 描述:查找指定的光盘目录,返回目录元素指针对象;
- 参数:
- strDiscPath[IN]:要查找的光盘目录,格式如下:"光盘根目录\子目录1\子目录2\子目录3";
- 返回:
- 若存在该光盘目录,则返回该目录元素对象的指针(返回最后一层目录名对应的元素指针),否则返回NULL;
- 注意:
- 示例:
- */
- /************************************************************************/
- NERO_ISO_ITEM* CNeroBurn::FindPathItem( IN CString strDiscPath )
- {
- if (strDiscPath.IsEmpty())
- {
- WriteTextLog(_T("FindPathItem:光盘目录参数空!"));
- return NULL;
- }
- if ( m_pRootItem == NULL || m_pRootItem->subDirFirstItem == NULL)
- {
- WriteTextLog(_T("FindPathItem:光盘根目录元素空!"));
- return NULL;
- }
- INT nIndex = 0;
- CStringArray AryLayerName;
- strDiscPath.TrimRight(_T('\\'));
- strDiscPath += _T("\\");
- do
- {
- nIndex = strDiscPath.Find(_T("\\"));
- if ( nIndex != -1 )
- {
- AryLayerName.Add(strDiscPath.Left(nIndex));
- strDiscPath = strDiscPath.Mid(nIndex+1);
- }
- } while ( strDiscPath.Find(_T("\\")) != -1 );
- NERO_ISO_ITEM *pTailItem = NULL;
- NERO_ISO_ITEM *pNextItem = m_pRootItem->subDirFirstItem;
- for ( nIndex = 0; nIndex < AryLayerName.GetSize(); nIndex++ )
- {
- pTailItem = FindPathInSibling(pNextItem, AryLayerName.ElementAt(nIndex));
- if ( pTailItem == NULL )
- {
- break;
- }
- else
- {
- pNextItem = pTailItem->subDirFirstItem;
- }
- }
- if ( (AryLayerName.GetSize() == nIndex) && pTailItem )
- {
- return pTailItem;
- }
- return NULL;
- }
- /************************************************************************/
- /*
- 函数:FindSiblingPath
- 描述:在指定的兄弟链中(以及兄弟链中的子链),从兄弟链头元素开始查找指定目录名的元素指针;
- 参数:
- pSiblingHeadItem[IN]:兄弟链的头元素,作为查找时的开始位置;
- strDiscPath[IN]:要在兄弟链中(以及兄弟链中的子链)查找的目录名(只是单层目录名)。
- 返回:
- 成功在兄弟链中(以及兄弟链中的子链)查找到该目录名元素,返回该元素对象指针;若未查找到,返回NULL;
- 注意:
- 示例:
- */
- /************************************************************************/
- NERO_ISO_ITEM* CNeroBurn::FindPathInSibling( IN NERO_ISO_ITEM* pSiblingHeadItem, IN CString& strDiscPath )
- {
- if ( pSiblingHeadItem == NULL )
- {
- WriteTextLog(_T("FindPathInSibling兄弟结点空!"));
- return NULL;
- }
- BOOL bFind = FALSE;
- NERO_ISO_ITEM* pNextItem = pSiblingHeadItem;
- do {
- if (pNextItem->isDirectory)
- {
- if ( strDiscPath.CompareNoCase(pNextItem->longFileName) == 0 )
- {
- bFind = TRUE;
- break;
- }
- }
- pNextItem = pNextItem->nextItem;
- } while ( pNextItem );
- return bFind ? pNextItem : NULL;
- }
- /************************************************************************/
- /*
- 函数:FindSiblingNextToLast
- 描述:返回兄弟链中的倒数第二个元素或者最后一个;
- 参数:
- pSiblingHeadItem[IN] 兄弟链的头元素;
- 返回:
- 返回兄弟链中的倒数第二个元素或者最后一个;
- 注意:当兄弟链的只有一个元素时,返回的是本身,也是最后一个;
- 示例:
- */
- /************************************************************************/
- NERO_ISO_ITEM* CNeroBurn::FindSiblingNextToLast( IN NERO_ISO_ITEM* pSiblingHeadItem )
- {
- if ( pSiblingHeadItem == NULL || pSiblingHeadItem->nextItem == NULL )
- {
- return pSiblingHeadItem;
- }
- NERO_ISO_ITEM* pSiblingTail = pSiblingHeadItem;
- while ( pSiblingTail->nextItem->nextItem )
- {
- pSiblingTail = pSiblingTail->nextItem;
- }
- return pSiblingTail;
- }
- /************************************************************************/
- /*
- 函数:RemoveRootItem
- 描述:删除整个光盘项;
- 参数:
-
- 返回:
-
- 注意:
- 示例:
- */
- /************************************************************************/
- void CNeroBurn::RemoveRootItem()
- {
- RemoveAllItem(m_pRootItem);
- if (m_pRootItem)
- {
- if(m_pRootItem->longFileName != NULL)
- free((void*)m_pRootItem->longFileName), m_pRootItem->longFileName = NULL;
- if(m_pRootItem->longSourceFilePath != NULL)
- free((void*)m_pRootItem->longSourceFilePath), m_pRootItem->longSourceFilePath = NULL;
- delete m_pRootItem;
- m_pRootItem = NULL;
- }
- }
- /************************************************************************/
- /*
- 函数:RemoveAllItem
- 描述:删除指定根结点的全部元素;
- 参数:
-
- 返回:
-
- 注意:
- 示例:
- */
- /************************************************************************/
- void CNeroBurn::RemoveAllItem(IN NERO_ISO_ITEM* pRootItem)
- {
- #if 1
- for( vector<NERO_ISO_ITEM*>::iterator it = m_vtItems.begin(); it != m_vtItems.end();)
- {
- NERO_ISO_ITEM *pItem = *it;
- it = m_vtItems.erase(it);
- if(pItem->longFileName != NULL)
- free((void*)pItem->longFileName), pItem->longFileName = NULL;
- if(pItem->longSourceFilePath != NULL)
- free((void*)pItem->longSourceFilePath), pItem->longSourceFilePath = NULL;
- delete pItem;
- pItem = NULL;
- }
- return;
- #else
- if( pRootItem == NULL ){
- WriteTextLog(_T("RemoveChildItem:删除出错!"));
- OutputDebugString(_T("\nRemoveChildItem:删除出错,!\n"));
- return;
- }
- if ( pRootItem->subDirFirstItem == NULL && pRootItem->nextItem == NULL ){// 最后一个元素;
- //OutputDebugString(_T("\nRemoveAllItem:目录元素\n"));
- return;
- }
- NERO_ISO_ITEM* pNext2Last = NULL;
- do {
- // 查找到兄弟链中的倒第二个(或者最后一个);
- pNext2Last = FindSiblingNextToLast(pRootItem->subDirFirstItem);
- NERO_ISO_ITEM* pTailItem = pNext2Last->nextItem;
- if ( pTailItem )
- {// 倒数第二个;
- if (pTailItem->isDirectory)
- {
- RemoveAllItem(pTailItem);
- }
- pNext2Last->nextItem = NULL;
- if(!pTailItem->isReference)
- {
- if(pTailItem->longFileName != NULL)
- free((void*)pTailItem->longFileName), pTailItem->longFileName = NULL;
- if(pTailItem->longSourceFilePath != NULL)
- free((void*)pTailItem->longSourceFilePath), pTailItem->longSourceFilePath = NULL;
- }
- delete pTailItem;
- pTailItem = NULL;
- }
- else
- {// 第一个(也是最后一个);
- if ( pNext2Last->isDirectory )
- {
- RemoveAllItem(pNext2Last);
- }
- if(!pNext2Last->isReference)
- {
- if(pNext2Last->longFileName != NULL)
- free((void*)pNext2Last->longFileName), pNext2Last->longFileName = NULL;
- if(pNext2Last->longSourceFilePath != NULL)
- free((void*)pNext2Last->longSourceFilePath), pNext2Last->longSourceFilePath = NULL;
- }
- delete pNext2Last;
- pNext2Last = NULL;
- pRootItem->subDirFirstItem = NULL;
- }
- }while( pRootItem->subDirFirstItem );
- #endif
- }
- void CNeroBurn::DiscBurn()
- {
- // 使用第一个设备来刻录;;
- NERO_SCSI_DEVICE_INFO* nsdiDevice = &m_pndiDeviceInfos->nsdisDevInfos[0];
- // 打开设备;
- m_ndhDeviceHandle = NeroOpenDevice(nsdiDevice);
- if (!m_ndhDeviceHandle)
- {
- AfxMessageBox(_T("刻录设备不能打开, 请与系统管理员联系!"), MB_ICONSTOP);
- NeroWorkError = true;
- return;
- }
- // 读取CD或DVD媒体信息;
- NERO_CD_INFO* pNeroCDInfo = NeroGetCDInfo(m_ndhDeviceHandle, NGCDI_READ_CD_TEXT | NGCDI_READ_ISRC);
- if ( pNeroCDInfo == NULL )
- {
- AfxMessageBox(_T("获取光盘失败, 请与系统管理员联系!"), MB_ICONSTOP);
- NeroWorkError = true;
- return;
- }
- // 光盘不可写;
- if ( !pNeroCDInfo->ncdiIsWriteable )
- {
- AfxMessageBox(_T("光盘不可写, 请更换新的光盘!"), MB_ICONSTOP);
- NeroWorkError = true;
- return;
- }
- #if 0
- // 光盘文件系统格式(但是,好像没有用, 估计是SDK版本太老);
- // pNeroCDInfo->ncdiTrackInfos[0].ntiFSType; // NTFST_UDF DVD格式刻录; NTFST_CDRFS CD格式刻录;
- if ( m_bDvd && pNeroCDInfo->ncdiTrackInfos[0].ntiFSType == NTFST_CDRFS )
- {
- AfxMessageBox(_T("所选DVD格式刻录,但光盘文件系统是CD格式,请更换DVD文件系统(UDF或新)的光盘!"), MB_ICONSTOP);
- NeroWorkError = true;
- return;
- }
- if ( !m_bDvd && pNeroCDInfo->ncdiTrackInfos[0].ntiFSType == NTFST_UDF )
- {
- AfxMessageBox(_T("所选DVD格式刻录,但光盘文件系统是CD格式,请更换DVD文件系统(UDF或新)的光盘!"), MB_ICONSTOP);
- NeroWorkError = true;
- return;
- }
- #endif
- // 设置写CD参数 ;
- NERO_WRITE_CD writeCD;
- memset(&writeCD,0,sizeof(writeCD));
- writeCD.nwcdpCDStamp = NULL;
- writeCD.nwcdArtist = NULL;
- writeCD.nwcdTitle = NULL;
- writeCD.nwcdCDExtra = FALSE;
- writeCD.nwcdNumTracks = 0;
- // writeCD.nwcdMediaType = m_bDvd ? MEDIA_DVD_ANY : MEDIA_CD; // 这里不是按光盘的媒体类型来赋值;
- writeCD.nwcdMediaType = pNeroCDInfo->ncdiMediaType;
- CString title = g_title+ _T("(") + m_strCustomerInfo;
- title += _T(")客照");
- if ( true )
- {// 追加方式刻录;
- NERO_IMPORT_DATA_TRACK_INFO nidtInfo;
- NERO_IMPORT_DATA_TRACK_RESULT nidtResult;
- // Prepare the struct.
- CString csUserMsg = "";
- memset(&nidtInfo, 0, sizeof(nidtInfo));
- nidtInfo.nidtiSize = sizeof(nidtInfo);
- void* pCDStamp = NULL;
- NERO_ISO_ITEM* pniiItem = NULL;
- pniiItem = NeroImportDataTrack(m_ndhDeviceHandle, pNeroCDInfo->ncdiNumTracks - 1, &pCDStamp, &nidtInfo, 0, &nidtResult, NULL);
- // If there is a volume name after import, print it out.
- if(nidtInfo.nidtipVolumeName != NULL)
- {
- csUserMsg.Format("Imported volume name: %s", nidtInfo.nidtipVolumeName);
- //AppendString(csUserMsg);
- NeroFreeMem (nidtInfo.nidtipVolumeName);
- }
- // If there was an error during import, let the user know about it.
- 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]);
- //AppendString(csUserMsg);
- }
- else if(m_pRootItem->subDirFirstItem != NULL)
- {
- if(MergeIsoTracks(&m_pRootItem->subDirFirstItem, pniiItem)) // Merge the new track with the existing one.
- writeCD.nwcdpCDStamp = pCDStamp;
- else
- {
- //AppendString("There was an error while merging tracks!");
- if(pCDStamp != NULL)
- NeroFreeCDStamp(pCDStamp), pCDStamp = NULL;
- }
- }
- }
- writeCD.nwcdIsoTrack = NeroCreateIsoTrackEx(m_pRootItem->subDirFirstItem,title,NCITEF_USE_JOLIET|NCITEF_CREATE_ISO_FS);
- // 以追回的方式刻录 : 使用MEDIA_DVD_ANY 或 MEDIA_CD时, NERO_CD_FORMAT固定为NERO_ISO_AUDIO_MEDIA;
- int iRes = NeroBurn(m_ndhDeviceHandle, NERO_ISO_AUDIO_MEDIA, &writeCD, NBF_WRITE|NBF_CLOSE_SESSION, 0/*Maximum*/, &npProgress);
- // 释放媒体资源;
- NeroFreeMem(pNeroCDInfo);
- // free memory that was allocated for the track
- if(writeCD.nwcdIsoTrack != NULL)
- NeroFreeIsoTrack(writeCD.nwcdIsoTrack);
- // Free the NERO_WRITE_CD struct too
- if(writeCD.nwcdpCDStamp != NULL)
- NeroFreeCDStamp(writeCD.nwcdpCDStamp), writeCD.nwcdpCDStamp = NULL;
- NeroCloseDevice(m_ndhDeviceHandle);
- char* Log = NeroGetErrorLog();
- switch(iRes)
- {
- case NEROAPI_BURN_OK:
- AfxMessageBox(_T("刻录成功!"), MB_ICONINFORMATION);
- NeroBurnOK=true;
- break;
- case NEROAPI_BURN_UNKNOWN_CD_FORMAT:
- AfxMessageBox(_T("刻录失败:无效刻录盘格式!"), MB_ICONSTOP);
- NeroWorkError=true;
- break;
- case NEROAPI_BURN_INVALID_DRIVE:
- AfxMessageBox(_T("刻录失败:驱动器无效!"), MB_ICONSTOP);
- NeroWorkError=true;
- break;
- case NEROAPI_BURN_FAILED:
- AfxMessageBox(_T("刻录失败!"), MB_ICONSTOP);
- NeroWorkError=true;
- break;
- case NEROAPI_BURN_FUNCTION_NOT_ALLOWED:
- case NEROAPI_BURN_DRIVE_NOT_ALLOWED:
- AfxMessageBox(_T("刻录失败:刻录驱动未安装正确!"), MB_ICONSTOP);
- NeroWorkError=true;
- break;
- default:
- AfxMessageBox(_T("刻录失败:未知错误!"), MB_ICONSTOP);
- NeroWorkError=true;
- break;
- }
- }
- inline LPCSTR GetFilename(const NERO_ISO_ITEM* pItem)
- {
- return (pItem->longFileName != NULL)? pItem->longFileName : pItem->fileName;
- }
- // The following function performs a merge operation between two iso item trees.
- // The second tree is added onto the first one and the extra items are deleted.
- // As we do not allow to add directories in our file list we do not make recursive
- // calls of this method.
- BOOL CNeroBurn::MergeIsoTracks(NERO_ISO_ITEM** ppniiTarget, NERO_ISO_ITEM* pniiToAdd)
- {
- BOOL bResult = ((ppniiTarget != NULL) && (*ppniiTarget != NULL) && (pniiToAdd != NULL));
- // Two loops. Outer loops the first tree, the inner loops the second tree.
- for( ; bResult && (*ppniiTarget != NULL); ppniiTarget = &(*ppniiTarget)->nextItem)
- {
- for(NERO_ISO_ITEM** ppniiToAddLocal = &pniiToAdd; *ppniiToAddLocal != NULL; )
- {
- // Compare entry names...
- if(0 == stricmp(GetFilename(*ppniiTarget), GetFilename(*ppniiToAddLocal)))
- {
- // If there is a file name conflict between iso items that belong to imported sessions
- // always replace the old files in terms of modification times.
- time_t timeTarget = mktime(&(*ppniiTarget)->entryTime);
- if(timeTarget == (time_t)-1)
- {
- HANDLE hFile = NULL; // handle to file
- FILETIME ftCreationTime; // creation time
- FILETIME ftLastAccessTime; // last access time
- FILETIME ftLastWriteTime; // last write time
- hFile = CreateFileA((*ppniiTarget)->longSourceFilePath, // open the file to get handle
- GENERIC_READ, // open for reading
- FILE_SHARE_READ, // share for reading
- NULL, // no security
- OPEN_EXISTING, // existing file only
- FILE_ATTRIBUTE_NORMAL, // normal file
- NULL); // no attr. template
- if(hFile == INVALID_HANDLE_VALUE)
- {
- CString csMsg;
- csMsg.Format("Could not open file: %s.", (*ppniiTarget)->longSourceFilePath);
- //AppendString(csMsg); // show error
- }
- 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 we have to replace one item, we will now switch places of items in the first and second tree.
- // Since one of the items has to be deleted eventually, this operation will
- // essentially keep the item from the second tree and delete the item from the first tree.
- 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 // No match, advance to the next item.
- 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;
- }
- // This function deletes the iso tree recursively.
- void CNeroBurn::DeleteIsoItemTree(NERO_ISO_ITEM* pniiItem)
- {
- // First free our own long filename strings, then free the whole tree.
- FreeOurOwnResources(pniiItem);
- NeroFreeIsoItemTree(pniiItem);
- }
- void CNeroBurn::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;
- }
- }
- /************************************************************************/
- /* 函数:获取读写速度[3/22/2018 Jeff];
- /* 描述:;
- /* 参数:;
- /* [IN] :;
- /* [OUT] :;
- /* [IN/OUT] :;
- /* 返回:void;
- /* 注意:必须在外部释放NeroFreeMem(pnsiWrite);
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- NERO_SPEED_INFOS *CNeroBurn::GetAvailableSpeeds(bool IsWriteSpeed /*= true*/)
- {
- // 获取媒体信息;
- NERO_CD_INFO* pNeroCDInfo = NeroGetCDInfo(m_ndhDeviceHandle, NGCDI_READ_CD_TEXT | NGCDI_READ_ISRC);
- if ( pNeroCDInfo == NULL )
- return NULL;
- NERO_SPEED_INFOS *pnsiWrite = NeroGetAvailableSpeeds(m_ndhDeviceHandle,IsWriteSpeed ? ACCESSTYPE_WRITE :ACCESSTYPE_READ, pNeroCDInfo->ncdiMediaType,NULL);
- // 释放媒体资源;
- NeroFreeMem(pNeroCDInfo);
- return pnsiWrite;
- }
- #endif
|