NeroBurn.cpp 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417
  1. // NeroBurn.cpp: implementation of the CNeroBurn class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. //这个类也是类之间相互引用的一个具体的成功的;例子
  5. #include "stdafx.h"
  6. #include "ylgl.h"
  7. #include "NeroDlg.h"
  8. #include "NeroBurn.h"
  9. #include "SelBrunDevice.h"
  10. #ifdef _DEBUG
  11. #undef THIS_FILE
  12. static char THIS_FILE[]=__FILE__;
  13. #define new DEBUG_NEW
  14. #endif
  15. //////////////////////////////////////////////////////////////////////
  16. // Construction/Destruction
  17. //////////////////////////////////////////////////////////////////////
  18. extern CNeroDlg* pDlg;
  19. CNeroBurn::CNeroBurn()
  20. {
  21. NeroBurnOK=false;
  22. NeroWorkError=false;
  23. #ifdef USE_KERNEL_DLL
  24. m_pRootItem = NULL;
  25. InitRootItem();
  26. #endif
  27. }
  28. CNeroBurn::~CNeroBurn()
  29. {
  30. NeroAPIFree();
  31. for(int i=0; i<m_photoMniiArray.GetSize (); i++)
  32. delete [](m_photoMniiArray.ElementAt (i));
  33. m_photoMniiArray.RemoveAll();
  34. }
  35. BOOL CNeroBurn::NeroAPIInit()
  36. {
  37. DWORD id=FindAppProcessID("imapi.exe");
  38. if(id!=-1)
  39. {
  40. HANDLE ProcessHandle=OpenProcess(PROCESS_ALL_ACCESS,FALSE,id);
  41. if(ProcessHandle)TerminateProcess(ProcessHandle,0);
  42. }
  43. if(!NeroAPIGlueConnect (NULL))
  44. {
  45. AfxMessageBox("刻录驱动未安装, 请与系统管理员联系!", MB_ICONSTOP);
  46. return 0;
  47. }
  48. WORD majhi, majlo, minhi, minlo;
  49. NeroGetAPIVersionEx(&majhi, &majlo, &minhi, &minlo, NULL);
  50. CString strVersion;
  51. strVersion.Format("NeroAPI version %d.%d.%d.%d",
  52. majhi, majlo, minhi, minlo);
  53. #ifdef VC60
  54. strcpy(pcNeroFilesPath, "NeroFiles");
  55. strcpy(pcVendor, "nero");
  56. strcpy(pcSoftware, "Nero - Burning Rom");
  57. strcpy(pcLanguageFile, "Nero.txt");
  58. #else
  59. _tcscpy_s(pcNeroFilesPath, 128, _T("NeroFiles"));
  60. _tcscpy_s(pcVendor, 128, _T("nero"));
  61. _tcscpy_s(pcSoftware, 128, _T("Nero - Burning Rom"));
  62. _tcscpy_s(pcLanguageFile, 128, _T("Nero.txt"));
  63. #endif
  64. nsSettings.nstNeroFilesPath = pcNeroFilesPath;
  65. nsSettings.nstVendor = pcVendor;
  66. nsSettings.nstIdle.ncCallbackFunction = pDlg->IdleCallback;
  67. nsSettings.nstIdle.ncUserData = pDlg;
  68. nsSettings.nstSoftware = pcSoftware;
  69. nsSettings.nstUserDialog.ncCallbackFunction = pDlg->UserDialog;
  70. nsSettings.nstUserDialog.ncUserData = pDlg;
  71. nsSettings.nstLanguageFile =pcLanguageFile;
  72. // npProgress will be used during the burn process
  73. npProgress.npAbortedCallback = pDlg->AbortedCallback;
  74. npProgress.npAddLogLineCallback = pDlg->AddLogLine;
  75. npProgress.npDisableAbortCallback = NULL;
  76. npProgress.npProgressCallback = pDlg->ProgressCallback;
  77. npProgress.npSetPhaseCallback = pDlg->SetPhaseCallback;
  78. npProgress.npUserData = pDlg;
  79. npProgress.npSetMajorPhaseCallback=NULL;
  80. npProgress.npSubTaskProgressCallback=NULL;
  81. pndiDeviceInfos = NULL;
  82. NEROAPI_INIT_ERROR initErr;
  83. initErr = NeroInit(&nsSettings, NULL);
  84. switch (initErr)
  85. {
  86. case NEROAPI_INIT_OK:
  87. //AppendString("Initialization of the NeroAPI successful.");
  88. break;
  89. case NEROAPI_INIT_INVALID_ARGS:
  90. {
  91. AfxMessageBox("无效的参数, 请与系统管理员联系!", MB_ICONSTOP);
  92. return 0;
  93. }
  94. break;
  95. case NEROAPI_INIT_INVALID_SERIAL_NUM:
  96. {
  97. AfxMessageBox("刻录驱动未正确安装, 请与系统管理员联系!", MB_ICONSTOP);
  98. return 0;
  99. }
  100. break;
  101. default:
  102. {
  103. AfxMessageBox("出现未知错误, 请与系统管理员联系!", MB_ICONSTOP);
  104. return 0;
  105. }
  106. //AppendString("An error occured. The type of error cannot bedetermined.");
  107. break;
  108. }
  109. pndiDeviceInfos = NeroGetAvailableDrivesEx (MEDIA_CD, NULL);
  110. int lgl=1;
  111. if (!pndiDeviceInfos) {
  112. //AppendString("NeroGetAvailableDrives() returned no available devices.");
  113. {
  114. AfxMessageBox("未找到可用的刻录设备, 请与系统管理员联系!", MB_ICONSTOP);
  115. return 0;
  116. }
  117. }
  118. else
  119. {
  120. if (pndiDeviceInfos->nsdisNumDevInfos > 0)
  121. {
  122. //AppendString("Found the following devices:");
  123. for (DWORD dDeviceCounter = 0; dDeviceCounter < pndiDeviceInfos->nsdisNumDevInfos; dDeviceCounter++)
  124. {
  125. //AppendString(pndiDeviceInfos->nsdisDevInfos[dDeviceCounter].nsdiDeviceName);
  126. //int i = m_cbxDevices.AddString(pndiDeviceInfos->nsdisDevInfos[dDeviceCounter].nsdiDeviceName);
  127. //m_cbxDevices.SetItemDataPtr(i, &pndiDeviceInfos->nsdisDevInfos[dDeviceCounter]);
  128. }
  129. //m_cbxDevices.SelectString(-1, pndiDeviceInfos->nsdisDevInfos[0].nsdiDeviceName);
  130. }
  131. else
  132. {
  133. //AppendString("The number of available devices is 0.");
  134. return 0;
  135. }
  136. }
  137. return 1;
  138. }
  139. void CNeroBurn::NeroAPIFree()
  140. {
  141. if (pndiDeviceInfos)
  142. {
  143. NeroFreeMem(pndiDeviceInfos);
  144. }
  145. NeroClearErrors();
  146. NeroDone();
  147. NeroAPIGlueDone();
  148. return;
  149. }
  150. // 如果pArray的元素有属于str的子目录或子文件, 将pArray的元素保存到array中;
  151. void GetChildArray(CString str, CStringArray *pArray, CStringArray &array)
  152. {
  153. CString temp;
  154. for(int i=0; i<pArray->GetSize(); i++)
  155. {
  156. temp=pArray->ElementAt(i);
  157. // 截取掉最后一层文件夹,保留前面的;
  158. temp=temp.Left(temp.ReverseFind('\\'));
  159. if(temp==str)
  160. {
  161. array.Add (pArray->ElementAt (i));
  162. }
  163. }
  164. }
  165. void GetChildPhotoArray(CString str, CStringArray *pArray, CStringArray &array)
  166. {
  167. CString temp;
  168. for(int i=0; i<pArray->GetSize (); i++)
  169. {
  170. temp=pArray->ElementAt (i);
  171. // 截取掉最后一层文件夹,保留前面的;
  172. temp=temp.Left (temp.ReverseFind ('\\'));
  173. if(temp==str)
  174. {
  175. array.Add (pArray->ElementAt (i));
  176. }
  177. }
  178. }
  179. void CNeroBurn::NeroAPIBurn()
  180. {
  181. #ifdef USE_KERNEL_DLL
  182. DiscBurn();
  183. RemoveRootItem();
  184. return;
  185. #endif
  186. INT i = 0;
  187. // 清空所有NERO_ISO_ITEM元素对象;
  188. for( i=0; i<m_photoMniiArray.GetSize(); i++)
  189. {
  190. delete [](m_photoMniiArray.ElementAt(i));
  191. }
  192. m_photoMniiArray.RemoveAll();
  193. CString str;
  194. // 创建根目录NERO_ISO_ITEM元素;
  195. for(i=0;i<m_DirArray.GetSize ();i++)
  196. {
  197. NERO_ISO_ITEM *pMniiFile=new NERO_ISO_ITEM;
  198. m_photoMniiArray.Add(pMniiFile);
  199. m_nameArray.Add(m_DirArray.ElementAt(i));
  200. }
  201. // 创建完所有根目录NERO_ISO_IMTE元素对象后,设置每个元素isDirectory=TRUE;
  202. for(i=0;i<m_DirArray.GetSize ();i++)
  203. {
  204. NERO_ISO_ITEM *pMniiFile=m_photoMniiArray.ElementAt (i);
  205. str=m_DirRealNameArray.ElementAt (i);
  206. #ifdef VC60
  207. strcpy(pMniiFile->fileName,str.Right(str.GetLength()-str.ReverseFind('\\')-1));
  208. strcpy(pMniiFile->sourceFilePath,"c:\\");
  209. #else
  210. _tcscpy_s(pMniiFile->fileName, 252, str.Right(str.GetLength()-str.ReverseFind('\\')-1));
  211. _tcscpy_s(pMniiFile->sourceFilePath, 252, "c:\\");
  212. #endif
  213. pMniiFile->isDirectory=true;
  214. pMniiFile->isReference=false;
  215. pMniiFile->unicodeFileName=NULL;
  216. if(i==m_DirArray.GetSize ()-1)
  217. {
  218. pMniiFile->nextItem=NULL;
  219. }
  220. else
  221. {// nextItem指向同类型的元素指针;
  222. pMniiFile->nextItem=m_photoMniiArray.ElementAt(i+1);
  223. }
  224. //////////////////////////
  225. pMniiFile->subDirFirstItem=NULL;
  226. //////////////////////////
  227. }
  228. // 继续创建根目录以下的文件层和文件;
  229. for(i=0;i<m_DirArray.GetSize ();i++)
  230. {
  231. JoinDir(m_DirArray.ElementAt(i));
  232. }
  233. NERO_WRITE_CD writeCD;
  234. memset(&writeCD,0,sizeof(writeCD));
  235. writeCD.nwcdpCDStamp=NULL;
  236. writeCD.nwcdArtist=NULL;
  237. writeCD.nwcdTitle=NULL;
  238. writeCD.nwcdCDExtra=FALSE;
  239. writeCD.nwcdNumTracks=0;
  240. if(m_bDvd)
  241. {
  242. writeCD.nwcdMediaType = MEDIA_DVD_ANY;
  243. }
  244. NERO_SCSI_DEVICE_INFO* nsdiDevice;
  245. nsdiDevice =(NERO_SCSI_DEVICE_INFO*)&pndiDeviceInfos->nsdisDevInfos[0];
  246. ndhDeviceHandle = NeroOpenDevice(nsdiDevice);
  247. if (!ndhDeviceHandle)
  248. {
  249. AfxMessageBox("刻录设备不能打开, 请与系统管理员联系!", MB_ICONSTOP);
  250. NeroWorkError=true;
  251. }
  252. else
  253. {
  254. CString title=g_title+"("+m_strCustomerInfo;
  255. title+=")客照";
  256. if(m_bDvd)
  257. writeCD.nwcdIsoTrack = NeroCreateIsoTrackEx(\
  258. m_photoMniiArray.ElementAt(0),title,NCITEF_USE_JOLIET|NCITEF_CREATE_ISO_FS);
  259. else
  260. writeCD.nwcdIsoTrack = NeroCreateIsoTrackEx(\
  261. m_photoMniiArray.ElementAt(0),title,NCITEF_USE_JOLIET);
  262. int iRes;
  263. if(m_bDvd)
  264. iRes= NeroBurn(ndhDeviceHandle, NERO_ISO_AUDIO_MEDIA, &writeCD,
  265. NBF_WRITE|NBF_CLOSE_SESSION, 10, &npProgress);
  266. else
  267. iRes= NeroBurn(ndhDeviceHandle, NERO_ISO_AUDIO_CD, &writeCD,
  268. NBF_WRITE|NBF_CLOSE_SESSION, 0, &npProgress);
  269. //NBF_WRITE|NBF_CLOSE_SESSION
  270. NeroFreeIsoTrack(writeCD.nwcdIsoTrack);
  271. NeroCloseDevice(ndhDeviceHandle);
  272. char* Log = NeroGetErrorLog();
  273. switch(iRes)
  274. {
  275. case NEROAPI_BURN_OK:
  276. AfxMessageBox("刻录成功!", MB_ICONINFORMATION);
  277. NeroBurnOK=true;
  278. break;
  279. case NEROAPI_BURN_UNKNOWN_CD_FORMAT:
  280. AfxMessageBox("刻录失败:无效刻录盘格式!", MB_ICONSTOP);
  281. NeroWorkError=true;
  282. //AppendString ("BurnCD() : unknown CD format");
  283. break;
  284. case NEROAPI_BURN_INVALID_DRIVE:
  285. //AppendString ("BurnCD() : invalid drive");
  286. AfxMessageBox("刻录失败:驱动器无效!", MB_ICONSTOP);
  287. NeroWorkError=true;
  288. break;
  289. case NEROAPI_BURN_FAILED:
  290. AfxMessageBox("刻录失败!", MB_ICONSTOP);
  291. NeroWorkError=true;
  292. //AppendString ("BurnCD() : burn failed");
  293. break;
  294. case NEROAPI_BURN_FUNCTION_NOT_ALLOWED:
  295. //AppendString ("BurnCD() : function not allowed");
  296. case NEROAPI_BURN_DRIVE_NOT_ALLOWED:
  297. //AppendString ("BurnCD() : drive not allowed");
  298. AfxMessageBox("刻录失败:刻录驱动未安装正确!", MB_ICONSTOP);
  299. NeroWorkError=true;
  300. break;
  301. default:
  302. AfxMessageBox("刻录失败:未知错误!", MB_ICONSTOP);
  303. NeroWorkError=true;
  304. //AppendString ("BurnCD() : unknown error");
  305. break;
  306. }
  307. }
  308. }
  309. void CNeroBurn::JoinDir(CString dirname)
  310. {
  311. CString str;
  312. if(GetPosFromName(dirname)==-1)
  313. {// 如果目录不在m_DirArray中,要先把根目录加进m_nameArray中;
  314. NERO_ISO_ITEM *pMniiFile=new NERO_ISO_ITEM;
  315. m_photoMniiArray.Add(pMniiFile);
  316. m_nameArray.Add(dirname);
  317. str=dirname;
  318. #ifdef VC60
  319. strcpy(pMniiFile->fileName,str.Right(str.GetLength()-str.ReverseFind('\\')-1));
  320. strcpy(pMniiFile->sourceFilePath,"c:\\");
  321. #else
  322. _tcscpy_s(pMniiFile->fileName, 252, str.Right(str.GetLength()-str.ReverseFind('\\')-1));
  323. _tcscpy_s(pMniiFile->sourceFilePath, 252, "c:\\");
  324. #endif
  325. pMniiFile->isDirectory=true;
  326. pMniiFile->isReference=false;
  327. pMniiFile->unicodeFileName=NULL;
  328. pMniiFile->nextItem=NULL;
  329. }
  330. // dirname这个根目录下的子目录;
  331. CStringArray childdirarray;
  332. // 子目录下的相片路径;
  333. CStringArray childphotoarray;
  334. // 将m_pDir中所有dirname的子目录放到childdirarray中;
  335. GetChildArray(dirname, m_pDir, childdirarray);
  336. // 将dirname目录的所有相片路径保存到childphotoarray中;
  337. GetChildPhotoArray(dirname, &(m_pPhotoArray[GetDirPos(dirname)]), childphotoarray);
  338. // 获取dirname这个根目录所有子目录个数;
  339. int dircount=childdirarray.GetSize ();
  340. // 获取dirname这个根目录所有相片张数;
  341. int photocount=childphotoarray.GetSize ();
  342. // oldcount为尾元素索引;
  343. int oldcount=m_photoMniiArray.GetSize();
  344. if( dircount==0 && photocount==0 )
  345. {
  346. NERO_ISO_ITEM *pMniiFile=m_photoMniiArray.ElementAt(GetPosFromName(dirname));
  347. pMniiFile->subDirFirstItem=NULL;
  348. return;
  349. }
  350. // 再添加dircount + photocount 个NERO_ISO_ITEM元素;
  351. int nn = 0;
  352. for( nn=0; nn<dircount+photocount; nn++)
  353. {
  354. NERO_ISO_ITEM *pMniiFile=new NERO_ISO_ITEM;
  355. m_photoMniiArray.Add(pMniiFile);
  356. m_nameArray.Add("");
  357. }
  358. // 设置之前添加的NERO_ISO_ITEM元素中的前dircount个为目录文件;
  359. int realpos=0;
  360. for( nn=0; nn<childdirarray.GetSize (); nn++)
  361. {
  362. str=childdirarray.ElementAt (nn);
  363. NERO_ISO_ITEM *pMniiFile=m_photoMniiArray.ElementAt(realpos+oldcount);
  364. m_nameArray.SetAt(realpos+oldcount, str);
  365. #ifdef VC60
  366. strcpy(pMniiFile->fileName,str.Right(str.GetLength()-str.ReverseFind('\\')-1));
  367. strcpy(pMniiFile->sourceFilePath,"c:\\");
  368. #else
  369. _tcscpy_s(pMniiFile->fileName, 252, str.Right(str.GetLength()-str.ReverseFind('\\')-1));
  370. _tcscpy_s(pMniiFile->sourceFilePath, 252, "c:\\");
  371. #endif
  372. pMniiFile->isDirectory=true;
  373. pMniiFile->isReference=false;
  374. pMniiFile->unicodeFileName=NULL;
  375. if(nn==dircount+photocount-1)
  376. {
  377. pMniiFile->nextItem=NULL;
  378. }
  379. else
  380. {
  381. pMniiFile->nextItem=m_photoMniiArray.ElementAt(realpos+oldcount+1);
  382. }
  383. realpos++;
  384. }
  385. // 再设置剩余的photocount个元素为文件元素;
  386. for(int j=0; j<childphotoarray.GetSize(); j++)
  387. {
  388. CString path=childphotoarray.ElementAt(j);
  389. NERO_ISO_ITEM *pMniiFile=m_photoMniiArray.ElementAt(realpos+oldcount);
  390. m_nameArray.SetAt(realpos+oldcount, path);
  391. #ifdef VC60
  392. strcpy(pMniiFile->fileName,path.Right(path.GetLength()-path.ReverseFind('\\')-1));
  393. strcpy(pMniiFile->sourceFilePath,path);
  394. #else
  395. _tcscpy_s(pMniiFile->fileName, 252, path.Right(path.GetLength()-path.ReverseFind('\\')-1));
  396. _tcscpy_s(pMniiFile->sourceFilePath, 252, path);
  397. #endif
  398. pMniiFile->isDirectory=false;
  399. pMniiFile->isReference=false;
  400. pMniiFile->unicodeFileName=NULL;
  401. if(j==photocount-1)
  402. pMniiFile->nextItem=NULL;
  403. else
  404. pMniiFile->nextItem=m_photoMniiArray.ElementAt(realpos+oldcount+1);
  405. realpos++;
  406. }
  407. int pos=GetPosFromName(dirname);
  408. NERO_ISO_ITEM *pMniiFile=m_photoMniiArray.ElementAt(pos);
  409. // 设置dirname根元素的NERO_ISO_ITEM的第一个子目录元素指针;
  410. pMniiFile->subDirFirstItem=m_photoMniiArray.ElementAt(oldcount);
  411. for( nn=0; nn<childdirarray.GetSize (); nn++)
  412. {
  413. JoinDir(childdirarray.ElementAt (nn));
  414. }
  415. }
  416. int CNeroBurn::GetDirPos(CString dir)
  417. {
  418. for(int i=0; i<m_pDir->GetSize(); i++)
  419. {
  420. if(dir==m_pDir->ElementAt(i))
  421. return i;
  422. }
  423. return -1;
  424. }
  425. //imapi.exe
  426. int CNeroBurn::GetPosFromName(CString dirname)
  427. {
  428. for(int i=0; i<m_nameArray.GetSize(); i++)
  429. {
  430. if(dirname==m_nameArray.ElementAt(i))
  431. return i;
  432. }
  433. return -1;
  434. }
  435. #ifdef USE_KERNEL_DLL
  436. /************************************************************************/
  437. /*
  438. 函数:InitRootItem
  439. 描述:初始化光盘。
  440. 参数:
  441. 返回:返回光盘根虚拟元素。
  442. 注意:
  443. 示例:
  444. */
  445. /************************************************************************/
  446. NERO_ISO_ITEM* CNeroBurn::InitRootItem()
  447. {
  448. if ( m_pRootItem == NULL )
  449. {
  450. m_pRootItem = new NERO_ISO_ITEM;
  451. ZeroMemory(m_pRootItem, sizeof(NERO_ISO_ITEM));
  452. m_pRootItem->isDirectory = TRUE;
  453. m_pRootItem->longFileName = _strdup(_T("光盘根级虚元素"));
  454. m_pRootItem->isReference = FALSE;
  455. m_pRootItem->unicodeFileName = NULL;
  456. m_pRootItem->nextItem = NULL;
  457. m_pRootItem->subDirFirstItem = NULL;
  458. }
  459. return m_pRootItem;
  460. }
  461. /************************************************************************/
  462. /*
  463. 函数:GetDiscItem
  464. 描述:返回光盘要刻录的第一个元素。
  465. 参数:
  466. 返回:返回光盘要刻录的第一个元素。
  467. 注意:
  468. 示例:
  469. */
  470. /************************************************************************/
  471. NERO_ISO_ITEM* CNeroBurn::GetDiscItem()
  472. {
  473. if ( m_pRootItem == NULL)
  474. {
  475. if ( InitRootItem() == NULL )
  476. {
  477. WriteTextLog(_T("获取光盘根目录失败!"));
  478. return NULL;
  479. }
  480. }
  481. if ( m_pRootItem )
  482. return m_pRootItem->subDirFirstItem;
  483. else
  484. return NULL;
  485. }
  486. /************************************************************************/
  487. /*
  488. 函数:AddSiblingRootItem
  489. 描述:将元素添加到根目录的兄弟链中。
  490. 参数:
  491. pRootItem[IN]:新的根目录兄弟项;
  492. 返回:成功添加返回新项,否则返回NULL;
  493. 注意:。
  494. 示例:
  495. */
  496. /************************************************************************/
  497. NERO_ISO_ITEM* CNeroBurn::AddSiblingRootItem( IN NERO_ISO_ITEM* pRootItem )
  498. {
  499. if ( m_pRootItem == NULL)
  500. {
  501. if ( InitRootItem() == NULL )
  502. {
  503. WriteTextLog(_T("获取光盘根目录失败!"));
  504. return NULL;
  505. }
  506. }
  507. if ( pRootItem == NULL )
  508. return NULL;
  509. if ( m_pRootItem->subDirFirstItem == NULL )
  510. {// 当根元素空时,赋值为第一个值;
  511. m_pRootItem->subDirFirstItem = pRootItem;
  512. }
  513. else
  514. {
  515. NERO_ISO_ITEM* pNextItem = m_pRootItem->subDirFirstItem;
  516. while( pNextItem->nextItem )
  517. pNextItem = pNextItem->nextItem;
  518. pNextItem->nextItem = pRootItem;
  519. }
  520. m_vtItems.push_back(pRootItem);
  521. return pRootItem;
  522. }
  523. /************************************************************************/
  524. /*
  525. 函数:AddSiblingRootItem
  526. 描述:将元素添加到根目录的兄弟链中。
  527. 参数:
  528. strRootName[IN]:新的根目录兄弟项名称;
  529. bIsDirectory[IN]:新的根目录兄弟项类型;
  530. 返回:成功添加返回新项,否则返回NULL
  531. 注意:
  532. 示例:
  533. */
  534. /************************************************************************/
  535. NERO_ISO_ITEM* CNeroBurn::AddSiblingRootItem( IN CString strRootName, IN BOOL bIsDirectory )
  536. {
  537. if ( strRootName.IsEmpty() )
  538. {
  539. WriteTextLog(_T("获取光盘根目录失败!"));
  540. return NULL;
  541. }
  542. if ( m_pRootItem == NULL)
  543. {
  544. if ( InitRootItem() == NULL )
  545. {
  546. WriteTextLog(_T("获取光盘根目录失败!"));
  547. return NULL;
  548. }
  549. }
  550. NERO_ISO_ITEM* pRootItem = new NERO_ISO_ITEM;
  551. ZeroMemory(pRootItem, sizeof(NERO_ISO_ITEM));
  552. if ( !bIsDirectory ){// 根元素是文件;
  553. char path[MAX_PATH];
  554. char* name;
  555. GetFullPathName(strRootName, MAX_PATH, path, &name);
  556. pRootItem->isDirectory = FALSE;
  557. pRootItem->longFileName = _strdup(name);
  558. pRootItem->longSourceFilePath = _strdup(path);
  559. pRootItem->isReference = FALSE;
  560. pRootItem->unicodeFileName = NULL;
  561. pRootItem->nextItem = NULL;
  562. pRootItem->subDirFirstItem = NULL;
  563. }else{ // 根元素是目录;
  564. pRootItem->isDirectory = TRUE;
  565. pRootItem->longFileName = _strdup(strRootName);
  566. pRootItem->isReference = FALSE;
  567. pRootItem->unicodeFileName = NULL;
  568. pRootItem->nextItem = NULL;
  569. pRootItem->subDirFirstItem = NULL;
  570. }
  571. if ( m_pRootItem->subDirFirstItem == NULL )
  572. {
  573. m_pRootItem->subDirFirstItem = pRootItem;
  574. }
  575. else
  576. {
  577. NERO_ISO_ITEM* pNextItem = m_pRootItem->subDirFirstItem;
  578. while( pNextItem->nextItem )
  579. pNextItem = pNextItem->nextItem;
  580. pNextItem->nextItem = pRootItem;
  581. }
  582. m_vtItems.push_back(pRootItem);
  583. return pRootItem;
  584. }
  585. /************************************************************************/
  586. /*
  587. 函数:AddItem2SiblingItem
  588. 描述:添加新元素到指定的兄弟项中;
  589. 参数:
  590. pSiblingItem[IN]: 作为兄弟链的参考兄弟项;
  591. pNewItem[IN]:需要添加兄弟链中的新项;
  592. 返回:
  593. 成功添加返回TRUE,否则返回FALSE;
  594. 注意:
  595. pSiblingItem不指定具体的类型,如果文件类型(isDirectory==FALSE)或目录类型(isDirectory==TRUE).
  596. 示例:
  597. */
  598. /************************************************************************/
  599. NERO_ISO_ITEM* CNeroBurn::AddItem2SiblingItem( IN NERO_ISO_ITEM* pSiblingItem, IN NERO_ISO_ITEM* pNewItem)
  600. {
  601. if ( m_pRootItem == NULL || m_pRootItem->subDirFirstItem == NULL )
  602. {
  603. WriteTextLog(_T("获取光盘根目录失败!"));
  604. OutputDebugString(_T("\nAddItem2SiblingItem:光盘的根项元素空!\n"));
  605. return NULL;
  606. }
  607. if ( pSiblingItem == NULL )
  608. {
  609. WriteTextLog(_T("获取光盘根目录失败!"));
  610. OutputDebugString(_T("\nAddItem2SiblingItem:光盘的兄弟项元素空!\n"));
  611. return NULL;
  612. }
  613. NERO_ISO_ITEM* pNextItem = pSiblingItem;
  614. while(pNextItem->nextItem)
  615. {
  616. pNextItem = pNextItem->nextItem;
  617. }
  618. pNextItem->nextItem = pNewItem;
  619. pNewItem->nextItem = NULL;
  620. m_vtItems.push_back(pNewItem);
  621. return pNewItem;
  622. }
  623. /************************************************************************/
  624. /*
  625. 函数:AddItem2Path
  626. 描述:添加新元素到指定的目录下;
  627. 参数:
  628. strDiscPath[IN]:光盘目录,作为新元素要父目录;
  629. pNewItem[IN]:新元素,将插入到strDiscPath目录下;
  630. 返回:成功添加返回TRUE,否则返回FALS;
  631. 注意:
  632. 示例:
  633. */
  634. /************************************************************************/
  635. NERO_ISO_ITEM* CNeroBurn::AddItem2Path( IN CString strDiscPath, IN NERO_ISO_ITEM* pNewItem)
  636. {
  637. if ( m_pRootItem == NULL || m_pRootItem->subDirFirstItem == NULL)
  638. {
  639. WriteTextLog(_T("获取光盘根目录失败!"));
  640. OutputDebugString(_T("\nAddItem2Path:光盘的根项元素空!\n"));
  641. return NULL;
  642. }
  643. if ( strDiscPath.IsEmpty() )
  644. {
  645. WriteTextLog(_T("获取光盘根目录失败!"));
  646. OutputDebugString(_T("\nAddItem2Path:光盘的兄弟项元素名称空\n"));
  647. return NULL;
  648. }
  649. // 首先查找;
  650. NERO_ISO_ITEM *pTailPathItem = FindPathItem(strDiscPath);
  651. if ( pTailPathItem == NULL )
  652. {
  653. WriteTextLog(_T("获取光盘根目录失败!"));
  654. OutputDebugString(_T("\nAddItem2Path:未找到光盘指定路径元素:"));
  655. OutputDebugString(strDiscPath);
  656. return NULL;
  657. }
  658. pNewItem->nextItem = NULL;
  659. if ( pTailPathItem->subDirFirstItem )
  660. {
  661. NERO_ISO_ITEM* pNextItem = pTailPathItem->subDirFirstItem;
  662. while ( pNextItem->nextItem )
  663. {
  664. pNextItem = pNextItem->nextItem;
  665. }
  666. pNextItem->nextItem = pNewItem;
  667. }
  668. else
  669. {
  670. pTailPathItem->subDirFirstItem = pNewItem;
  671. }
  672. m_vtItems.push_back(pNewItem);
  673. return pNewItem;
  674. }
  675. /************************************************************************/
  676. /*
  677. 函数:AddSiblingPath
  678. 描述:添加新目录到指定的光盘目录的兄弟链尾中;
  679. 参数:
  680. strDiscPath[IN]:光盘目录,作为新元素兄弟链头路径;
  681. strNewPath[IN]:新目录,strDiscPath的兄弟项;
  682. 返回:
  683. 成功返回TRUE,否则返回FALSE;
  684. 注意:
  685. 示例:
  686. */
  687. /************************************************************************/
  688. NERO_ISO_ITEM* CNeroBurn::AddSiblingPath(IN CString strDiscPath, IN CString strNewPath)
  689. {
  690. // 首先查找;
  691. NERO_ISO_ITEM *pTailPathItem = FindPathItem(strDiscPath);
  692. if ( pTailPathItem == NULL )
  693. {
  694. WriteTextLog(_T("获取光盘根目录失败!"));
  695. OutputDebugString(_T("\nAddPath2Path:未找到光盘指定路径元素:"));
  696. OutputDebugString(strDiscPath);
  697. return NULL;
  698. }
  699. NERO_ISO_ITEM* pNewItem = new NERO_ISO_ITEM;
  700. ZeroMemory(pNewItem,sizeof(NERO_ISO_ITEM));
  701. pNewItem->isDirectory = TRUE;
  702. pNewItem->isReference = FALSE;
  703. pNewItem->unicodeFileName = NULL;
  704. pNewItem->longFileName = _strdup(strNewPath);
  705. //sprintf_s(pNewItem->fileName, "%s", strNewPath);
  706. pNewItem->subDirFirstItem = NULL;
  707. pNewItem->nextItem = NULL;
  708. while( pTailPathItem->nextItem )
  709. {
  710. pTailPathItem = pTailPathItem->nextItem;
  711. }
  712. pTailPathItem->nextItem = pNewItem;
  713. m_vtItems.push_back(pNewItem);
  714. return pNewItem;
  715. }
  716. /************************************************************************/
  717. /*
  718. 函数:AddPath
  719. 描述:添加新的目录到光盘目录中,若目录不存在,则重新创建目录元素;
  720. 参数:
  721. strNewPath[IN]:新目录,根目录的新兄弟项;
  722. 返回:
  723. 成功返回TRUE,否则返回FALSE;
  724. 注意:
  725. 示例:
  726. */
  727. /************************************************************************/
  728. NERO_ISO_ITEM* CNeroBurn::AddPath(IN CString strNewPath)
  729. {
  730. INT nIndex = 0;
  731. CString strPath = strNewPath;
  732. strPath.TrimRight(_T('\\'));
  733. strPath += _T("\\");
  734. NERO_ISO_ITEM* pTailPath = NULL;
  735. do
  736. {
  737. nIndex = strPath.ReverseFind(_T('\\'));
  738. if ( nIndex != -1 )
  739. {
  740. strPath = strPath.Left(nIndex);
  741. pTailPath = FindPathItem(strPath);
  742. }
  743. else
  744. {// 最后一个;
  745. pTailPath = FindPathItem(strPath);
  746. }
  747. } while ( !pTailPath && nIndex != -1);
  748. if ( pTailPath == NULL ){// 全新目录;
  749. pTailPath = m_pRootItem;
  750. strNewPath.TrimRight(_T("\\"));
  751. strNewPath += _T("\\");
  752. do
  753. {
  754. nIndex = strNewPath.Find(_T("\\"));
  755. if ( nIndex != -1 )
  756. {
  757. if ( pTailPath == NULL )
  758. {
  759. WriteTextLog(_T("获取光盘根目录失败!"));
  760. OutputDebugString(_T("\n添加目录时出错\n"));
  761. break;
  762. }
  763. pTailPath = AddPath2PathItem(pTailPath, strNewPath.Left(nIndex));
  764. strNewPath = strNewPath.Mid(nIndex + 1);
  765. }
  766. } while ( strNewPath.Find(_T("\\")) != -1 );
  767. }
  768. else
  769. {
  770. if ( strNewPath == strPath )
  771. return pTailPath;
  772. strNewPath.Delete(0, strPath.GetLength()+1);
  773. strNewPath.TrimRight(_T("\\"));
  774. strNewPath += _T("\\");
  775. do {
  776. nIndex = strNewPath.Find(_T("\\"));
  777. if ( nIndex != -1 )
  778. {
  779. if ( pTailPath == NULL )
  780. {
  781. WriteTextLog(_T("获取光盘根目录失败!"));
  782. OutputDebugString(_T("\n添加目录时出错\n"));
  783. break;
  784. }
  785. pTailPath = AddPath2PathItem(pTailPath, strNewPath.Left(nIndex));
  786. strNewPath = strNewPath.Mid(nIndex + 1);
  787. }
  788. } while ( strNewPath.Find(_T("\\")) != -1 );
  789. }
  790. return pTailPath;
  791. }
  792. /************************************************************************/
  793. /*
  794. 函数:AddPath2Path
  795. 描述:添加新目录到指定的光盘目录下;
  796. 参数:
  797. strDiscPath[IN]:光盘目录,作为新元素要父目录;
  798. strNewPath[IN]:新目录,将插入到strDiscPath目录下;
  799. 返回:
  800. 成功返回TRUE,否则返回FALSE;
  801. 注意:
  802. 示例:
  803. */
  804. /************************************************************************/
  805. NERO_ISO_ITEM* CNeroBurn::AddPath2Path(IN CString strDiscPath, IN CString strNewPath)
  806. {
  807. // 首先查找;
  808. NERO_ISO_ITEM *pTailPathItem = FindPathItem(strDiscPath);
  809. if ( pTailPathItem == NULL )
  810. {
  811. WriteTextLog(_T("AddPath2Path:无光盘目录"));
  812. OutputDebugString(_T("\nAddPath2Path:未找到光盘指定路径元素:"));
  813. OutputDebugString(strDiscPath);
  814. return NULL;
  815. }
  816. NERO_ISO_ITEM* pNewItem = new NERO_ISO_ITEM;
  817. ZeroMemory(pNewItem,sizeof(NERO_ISO_ITEM));
  818. pNewItem->isDirectory = TRUE;
  819. pNewItem->isReference = FALSE;
  820. pNewItem->unicodeFileName = NULL;
  821. pNewItem->longFileName = _strdup(strNewPath);
  822. //sprintf_s(pNewItem->fileName, "%s", strNewPath);
  823. pNewItem->subDirFirstItem = NULL;
  824. pNewItem->nextItem = NULL;
  825. if ( pTailPathItem->subDirFirstItem )
  826. {
  827. NERO_ISO_ITEM* pNextItem = pTailPathItem->subDirFirstItem;
  828. while ( pNextItem->nextItem )
  829. {
  830. pNextItem = pNextItem->nextItem;
  831. }
  832. pNextItem->nextItem = pNewItem;
  833. }
  834. else
  835. {
  836. pTailPathItem->subDirFirstItem = pNewItem;
  837. }
  838. m_vtItems.push_back(pNewItem);
  839. return pNewItem;
  840. }
  841. /************************************************************************/
  842. /*
  843. 函数:AddPath2PathItem
  844. 描述:添加新目录到指定的光盘目录下;
  845. 参数:
  846. pPathItem[IN]:光盘目录,作为新元素要父目录;
  847. strNewPath[IN]:新目录,将插入到strDiscPath目录下;
  848. 返回:
  849. 成功返回TRUE,否则返回FALSE;
  850. 注意:
  851. 示例:
  852. */
  853. /************************************************************************/
  854. NERO_ISO_ITEM* CNeroBurn::AddPath2PathItem(IN NERO_ISO_ITEM* pPathItem, IN CString strNewPath )
  855. {
  856. if ( pPathItem == NULL || pPathItem->isDirectory == FALSE )
  857. {
  858. WriteTextLog(_T("AddPath2PathItem:目录元素空或非目录元素!"));
  859. return NULL;
  860. }
  861. NERO_ISO_ITEM* pNewItem = new NERO_ISO_ITEM;
  862. ZeroMemory(pNewItem,sizeof(NERO_ISO_ITEM));
  863. pNewItem->isDirectory = TRUE;
  864. pNewItem->isReference = FALSE;
  865. pNewItem->unicodeFileName = NULL;
  866. pNewItem->longFileName = _strdup(strNewPath);
  867. //sprintf_s(pNewItem->fileName, "%s", strNewPath);
  868. pNewItem->subDirFirstItem = NULL;
  869. pNewItem->nextItem = NULL;
  870. m_vtItems.push_back(pNewItem);
  871. if ( pPathItem->subDirFirstItem == NULL )
  872. return pPathItem->subDirFirstItem = pNewItem;
  873. NERO_ISO_ITEM* pNextItem = pPathItem->subDirFirstItem;
  874. while( pNextItem->nextItem)
  875. {
  876. pNextItem = pNextItem->nextItem;
  877. }
  878. return pNextItem->nextItem = pNewItem;
  879. }
  880. /************************************************************************/
  881. /*
  882. 函数:AddFile2Path
  883. 描述:添加新文件到指定的光盘目录下;
  884. 参数:
  885. strDiscPath[IN]:光盘目录,作为新元素的父目录;
  886. strFileName[IN]:新文件,将插入到strDiscPath目录下;
  887. 返回:
  888. 成功返回TRUE,否则返回FALSE;
  889. 注意:
  890. 示例:
  891. */
  892. /************************************************************************/
  893. NERO_ISO_ITEM* CNeroBurn::AddFile2Path(IN CString strDiscPath, IN CString strFileName)
  894. {
  895. // 首先查找;
  896. NERO_ISO_ITEM *pTailPathItem = FindPathItem(strDiscPath);
  897. if ( pTailPathItem == NULL )
  898. {
  899. pTailPathItem = AddPath(strDiscPath);
  900. if ( pTailPathItem == NULL )
  901. {
  902. WriteTextLog(_T("AddFile2Path:获取目录项尾元素失败!"));
  903. OutputDebugString(_T("\nAddFile2Path:未找到光盘指定路径元素:"));
  904. OutputDebugString(strDiscPath);
  905. return NULL;
  906. }
  907. }
  908. NERO_ISO_ITEM* pNewItem = new NERO_ISO_ITEM;
  909. ZeroMemory(pNewItem, sizeof(NERO_ISO_ITEM));
  910. pNewItem->isDirectory = FALSE;
  911. pNewItem->isReference = FALSE;
  912. pNewItem->unicodeFileName = NULL;
  913. char path[MAX_PATH];
  914. char* name;
  915. GetFullPathName(strFileName, MAX_PATH, path, &name);
  916. pNewItem->longFileName = _strdup(name);
  917. pNewItem->longSourceFilePath = _strdup(path);
  918. //sprintf_s(pNewItem->fileName,"%s", strFileName);
  919. pNewItem->nextItem = NULL;
  920. pNewItem->subDirFirstItem = NULL;
  921. if ( pTailPathItem->subDirFirstItem )
  922. {
  923. NERO_ISO_ITEM* pNextItem = pTailPathItem->subDirFirstItem;
  924. while ( pNextItem->nextItem )
  925. {
  926. pNextItem = pNextItem->nextItem;
  927. }
  928. pNextItem->nextItem = pNewItem;
  929. }
  930. else
  931. {
  932. pTailPathItem->subDirFirstItem = pNewItem;
  933. }
  934. m_vtItems.push_back(pNewItem);
  935. return pNewItem;
  936. }
  937. /************************************************************************/
  938. /*
  939. 函数:AddFile2SiblingItem
  940. 描述:将文件添加到指定的兄弟项中;
  941. 参数:
  942. pSiblingItem[IN]:
  943. strFileName[IN]:
  944. 返回:
  945. 注意:
  946. 示例:
  947. */
  948. /************************************************************************/
  949. NERO_ISO_ITEM* CNeroBurn::AddFile2SiblingItem(IN NERO_ISO_ITEM* pSiblingItem, IN CString strFileName)
  950. {
  951. if (pSiblingItem == NULL)
  952. {
  953. WriteTextLog(_T("AddFile2SiblingItem:树兄弟项空!"));
  954. OutputDebugString(_T("\nAddFile2SiblingItem:树兄弟项出错!\n"));
  955. return NULL;
  956. }
  957. NERO_ISO_ITEM* pNewItem = new NERO_ISO_ITEM;
  958. ZeroMemory(pNewItem, sizeof(NERO_ISO_ITEM));
  959. pNewItem->isDirectory = FALSE;
  960. pNewItem->isReference = FALSE;
  961. char path[MAX_PATH];
  962. char* name;
  963. GetFullPathName(strFileName, MAX_PATH, path, &name);
  964. pNewItem->longFileName = _strdup(name);
  965. pNewItem->longSourceFilePath = _strdup(path);
  966. //sprintf_s(pNewItem->fileName,"%s",strFileName);
  967. pNewItem->nextItem = NULL;
  968. pNewItem->subDirFirstItem = NULL;
  969. NERO_ISO_ITEM* pNextItem = pSiblingItem;
  970. while(pNextItem->nextItem)
  971. {
  972. pNextItem = pNextItem->nextItem;
  973. }
  974. pNextItem->nextItem = pNewItem;
  975. m_vtItems.push_back(pNewItem);
  976. return pNewItem;
  977. }
  978. /************************************************************************/
  979. /*
  980. 函数:FindPathItem
  981. 描述:查找指定的光盘目录,返回目录元素指针对象;
  982. 参数:
  983. strDiscPath[IN]:要查找的光盘目录,格式如下:"光盘根目录\子目录1\子目录2\子目录3";
  984. 返回:
  985. 若存在该光盘目录,则返回该目录元素对象的指针(返回最后一层目录名对应的元素指针),否则返回NULL;
  986. 注意:
  987. 示例:
  988. */
  989. /************************************************************************/
  990. NERO_ISO_ITEM* CNeroBurn::FindPathItem( IN CString strDiscPath )
  991. {
  992. if (strDiscPath.IsEmpty())
  993. {
  994. WriteTextLog(_T("FindPathItem:光盘目录参数空!"));
  995. return NULL;
  996. }
  997. if ( m_pRootItem == NULL || m_pRootItem->subDirFirstItem == NULL)
  998. {
  999. WriteTextLog(_T("FindPathItem:光盘根目录元素空!"));
  1000. return NULL;
  1001. }
  1002. INT nIndex = 0;
  1003. CStringArray AryLayerName;
  1004. strDiscPath.TrimRight(_T('\\'));
  1005. strDiscPath += _T("\\");
  1006. do
  1007. {
  1008. nIndex = strDiscPath.Find(_T("\\"));
  1009. if ( nIndex != -1 )
  1010. {
  1011. AryLayerName.Add(strDiscPath.Left(nIndex));
  1012. strDiscPath = strDiscPath.Mid(nIndex+1);
  1013. }
  1014. } while ( strDiscPath.Find(_T("\\")) != -1 );
  1015. NERO_ISO_ITEM *pTailItem = NULL;
  1016. NERO_ISO_ITEM *pNextItem = m_pRootItem->subDirFirstItem;
  1017. for ( nIndex = 0; nIndex < AryLayerName.GetSize(); nIndex++ )
  1018. {
  1019. pTailItem = FindPathInSibling(pNextItem, AryLayerName.ElementAt(nIndex));
  1020. if ( pTailItem == NULL )
  1021. {
  1022. break;
  1023. }
  1024. else
  1025. {
  1026. pNextItem = pTailItem->subDirFirstItem;
  1027. }
  1028. }
  1029. if ( (AryLayerName.GetSize() == nIndex) && pTailItem )
  1030. {
  1031. return pTailItem;
  1032. }
  1033. return NULL;
  1034. }
  1035. /************************************************************************/
  1036. /*
  1037. 函数:FindSiblingPath
  1038. 描述:在指定的兄弟链中(以及兄弟链中的子链),从兄弟链头元素开始查找指定目录名的元素指针;
  1039. 参数:
  1040. pSiblingHeadItem[IN]:兄弟链的头元素,作为查找时的开始位置;
  1041. strDiscPath[IN]:要在兄弟链中(以及兄弟链中的子链)查找的目录名(只是单层目录名)。
  1042. 返回:
  1043. 成功在兄弟链中(以及兄弟链中的子链)查找到该目录名元素,返回该元素对象指针;若未查找到,返回NULL;
  1044. 注意:
  1045. 示例:
  1046. */
  1047. /************************************************************************/
  1048. NERO_ISO_ITEM* CNeroBurn::FindPathInSibling( IN NERO_ISO_ITEM* pSiblingHeadItem, IN CString& strDiscPath )
  1049. {
  1050. if ( pSiblingHeadItem == NULL )
  1051. {
  1052. WriteTextLog(_T("FindPathInSibling兄弟结点空!"));
  1053. return NULL;
  1054. }
  1055. BOOL bFind = FALSE;
  1056. NERO_ISO_ITEM* pNextItem = pSiblingHeadItem;
  1057. do {
  1058. if (pNextItem->isDirectory)
  1059. {
  1060. if ( strDiscPath.CompareNoCase(pNextItem->longFileName) == 0 )
  1061. {
  1062. bFind = TRUE;
  1063. break;
  1064. }
  1065. }
  1066. pNextItem = pNextItem->nextItem;
  1067. } while ( pNextItem );
  1068. return bFind ? pNextItem : NULL;
  1069. }
  1070. /************************************************************************/
  1071. /*
  1072. 函数:FindSiblingNextToLast
  1073. 描述:返回兄弟链中的倒数第二个元素或者最后一个;
  1074. 参数:
  1075. pSiblingHeadItem[IN] 兄弟链的头元素;
  1076. 返回:
  1077. 返回兄弟链中的倒数第二个元素或者最后一个;
  1078. 注意:当兄弟链的只有一个元素时,返回的是本身,也是最后一个;
  1079. 示例:
  1080. */
  1081. /************************************************************************/
  1082. NERO_ISO_ITEM* CNeroBurn::FindSiblingNextToLast( IN NERO_ISO_ITEM* pSiblingHeadItem )
  1083. {
  1084. if ( pSiblingHeadItem == NULL || pSiblingHeadItem->nextItem == NULL )
  1085. {
  1086. return pSiblingHeadItem;
  1087. }
  1088. NERO_ISO_ITEM* pSiblingTail = pSiblingHeadItem;
  1089. while ( pSiblingTail->nextItem->nextItem )
  1090. {
  1091. pSiblingTail = pSiblingTail->nextItem;
  1092. }
  1093. return pSiblingTail;
  1094. }
  1095. /************************************************************************/
  1096. /*
  1097. 函数:RemoveRootItem
  1098. 描述:删除整个光盘项;
  1099. 参数:
  1100. 返回:
  1101. 注意:
  1102. 示例:
  1103. */
  1104. /************************************************************************/
  1105. void CNeroBurn::RemoveRootItem()
  1106. {
  1107. RemoveAllItem(m_pRootItem);
  1108. if (m_pRootItem)
  1109. {
  1110. if(m_pRootItem->longFileName != NULL)
  1111. free((void*)m_pRootItem->longFileName), m_pRootItem->longFileName = NULL;
  1112. if(m_pRootItem->longSourceFilePath != NULL)
  1113. free((void*)m_pRootItem->longSourceFilePath), m_pRootItem->longSourceFilePath = NULL;
  1114. delete m_pRootItem;
  1115. m_pRootItem = NULL;
  1116. }
  1117. }
  1118. /************************************************************************/
  1119. /*
  1120. 函数:RemoveAllItem
  1121. 描述:删除指定根结点的全部元素;
  1122. 参数:
  1123. 返回:
  1124. 注意:
  1125. 示例:
  1126. */
  1127. /************************************************************************/
  1128. void CNeroBurn::RemoveAllItem(IN NERO_ISO_ITEM* pRootItem)
  1129. {
  1130. #if 1
  1131. for( vector<NERO_ISO_ITEM*>::iterator it = m_vtItems.begin(); it != m_vtItems.end();)
  1132. {
  1133. NERO_ISO_ITEM *pItem = *it;
  1134. it = m_vtItems.erase(it);
  1135. if(pItem->longFileName != NULL)
  1136. free((void*)pItem->longFileName), pItem->longFileName = NULL;
  1137. if(pItem->longSourceFilePath != NULL)
  1138. free((void*)pItem->longSourceFilePath), pItem->longSourceFilePath = NULL;
  1139. delete pItem;
  1140. pItem = NULL;
  1141. }
  1142. return;
  1143. #else
  1144. if( pRootItem == NULL ){
  1145. WriteTextLog(_T("RemoveChildItem:删除出错!"));
  1146. OutputDebugString(_T("\nRemoveChildItem:删除出错,!\n"));
  1147. return;
  1148. }
  1149. if ( pRootItem->subDirFirstItem == NULL && pRootItem->nextItem == NULL ){// 最后一个元素;
  1150. //OutputDebugString(_T("\nRemoveAllItem:目录元素\n"));
  1151. return;
  1152. }
  1153. NERO_ISO_ITEM* pNext2Last = NULL;
  1154. do {
  1155. // 查找到兄弟链中的倒第二个(或者最后一个);
  1156. pNext2Last = FindSiblingNextToLast(pRootItem->subDirFirstItem);
  1157. NERO_ISO_ITEM* pTailItem = pNext2Last->nextItem;
  1158. if ( pTailItem )
  1159. {// 倒数第二个;
  1160. if (pTailItem->isDirectory)
  1161. {
  1162. RemoveAllItem(pTailItem);
  1163. }
  1164. pNext2Last->nextItem = NULL;
  1165. if(!pTailItem->isReference)
  1166. {
  1167. if(pTailItem->longFileName != NULL)
  1168. free((void*)pTailItem->longFileName), pTailItem->longFileName = NULL;
  1169. if(pTailItem->longSourceFilePath != NULL)
  1170. free((void*)pTailItem->longSourceFilePath), pTailItem->longSourceFilePath = NULL;
  1171. }
  1172. delete pTailItem;
  1173. pTailItem = NULL;
  1174. }
  1175. else
  1176. {// 第一个(也是最后一个);
  1177. if ( pNext2Last->isDirectory )
  1178. {
  1179. RemoveAllItem(pNext2Last);
  1180. }
  1181. if(!pNext2Last->isReference)
  1182. {
  1183. if(pNext2Last->longFileName != NULL)
  1184. free((void*)pNext2Last->longFileName), pNext2Last->longFileName = NULL;
  1185. if(pNext2Last->longSourceFilePath != NULL)
  1186. free((void*)pNext2Last->longSourceFilePath), pNext2Last->longSourceFilePath = NULL;
  1187. }
  1188. delete pNext2Last;
  1189. pNext2Last = NULL;
  1190. pRootItem->subDirFirstItem = NULL;
  1191. }
  1192. }while( pRootItem->subDirFirstItem );
  1193. #endif
  1194. }
  1195. void CNeroBurn::DiscBurn()
  1196. {
  1197. NERO_WRITE_CD writeCD;
  1198. memset(&writeCD,0,sizeof(writeCD));
  1199. writeCD.nwcdpCDStamp=NULL;
  1200. writeCD.nwcdArtist=NULL;
  1201. writeCD.nwcdTitle=NULL;
  1202. writeCD.nwcdCDExtra=FALSE;
  1203. writeCD.nwcdNumTracks=0;
  1204. if(m_bDvd)
  1205. {
  1206. writeCD.nwcdMediaType = MEDIA_DVD_ANY;
  1207. }
  1208. NERO_SCSI_DEVICE_INFO* nsdiDevice;
  1209. nsdiDevice =(NERO_SCSI_DEVICE_INFO*)&pndiDeviceInfos->nsdisDevInfos[0];
  1210. ndhDeviceHandle = NeroOpenDevice(nsdiDevice);
  1211. if (!ndhDeviceHandle)
  1212. {
  1213. AfxMessageBox(_T("刻录设备不能打开, 请与系统管理员联系!"), MB_ICONSTOP);
  1214. NeroWorkError=true;
  1215. }
  1216. else
  1217. {
  1218. CString title = g_title+ _T("(") + m_strCustomerInfo;
  1219. title += _T(")客照");
  1220. if(m_bDvd)
  1221. writeCD.nwcdIsoTrack = NeroCreateIsoTrackEx(m_pRootItem->subDirFirstItem,title,NCITEF_USE_JOLIET|NCITEF_CREATE_ISO_FS);
  1222. else
  1223. writeCD.nwcdIsoTrack = NeroCreateIsoTrackEx(m_pRootItem->subDirFirstItem,title,NCITEF_USE_JOLIET);
  1224. int iRes;
  1225. if(m_bDvd)
  1226. iRes= NeroBurn(ndhDeviceHandle, NERO_ISO_AUDIO_MEDIA, &writeCD,
  1227. NBF_WRITE|NBF_CLOSE_SESSION, 10, &npProgress);
  1228. else
  1229. iRes= NeroBurn(ndhDeviceHandle, NERO_ISO_AUDIO_CD, &writeCD,
  1230. NBF_WRITE|NBF_CLOSE_SESSION, 0, &npProgress);
  1231. NeroFreeIsoTrack(writeCD.nwcdIsoTrack);
  1232. NeroCloseDevice(ndhDeviceHandle);
  1233. char* Log = NeroGetErrorLog();
  1234. switch(iRes)
  1235. {
  1236. case NEROAPI_BURN_OK:
  1237. AfxMessageBox(_T("刻录成功!"), MB_ICONINFORMATION);
  1238. NeroBurnOK=true;
  1239. break;
  1240. case NEROAPI_BURN_UNKNOWN_CD_FORMAT:
  1241. AfxMessageBox(_T("刻录失败:无效刻录盘格式!"), MB_ICONSTOP);
  1242. NeroWorkError=true;
  1243. //AppendString ("BurnCD() : unknown CD format");
  1244. break;
  1245. case NEROAPI_BURN_INVALID_DRIVE:
  1246. //AppendString ("BurnCD() : invalid drive");
  1247. AfxMessageBox(_T("刻录失败:驱动器无效!"), MB_ICONSTOP);
  1248. NeroWorkError=true;
  1249. break;
  1250. case NEROAPI_BURN_FAILED:
  1251. AfxMessageBox(_T("刻录失败!"), MB_ICONSTOP);
  1252. NeroWorkError=true;
  1253. //AppendString ("BurnCD() : burn failed");
  1254. break;
  1255. case NEROAPI_BURN_FUNCTION_NOT_ALLOWED:
  1256. //AppendString ("BurnCD() : function not allowed");
  1257. case NEROAPI_BURN_DRIVE_NOT_ALLOWED:
  1258. //AppendString ("BurnCD() : drive not allowed");
  1259. AfxMessageBox(_T("刻录失败:刻录驱动未安装正确!"), MB_ICONSTOP);
  1260. NeroWorkError=true;
  1261. break;
  1262. default:
  1263. AfxMessageBox(_T("刻录失败:未知错误!"), MB_ICONSTOP);
  1264. NeroWorkError=true;
  1265. //AppendString ("BurnCD() : unknown error");
  1266. break;
  1267. }
  1268. }
  1269. }
  1270. #endif