NeroItem.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  1. #include "StdAfx.h"
  2. #include "NeroItem.h"
  3. NERO_ISO_ITEM *CreateNeroIsoItemOfSize(size_t size)
  4. {
  5. return (NERO_ISO_ITEM*)malloc(size);
  6. }
  7. //#define CreateNeroIsoItem() NeroCreateIsoItemOfSize(sizeof(NERO_ISO_ITEM))//无法分配内存,禁用;
  8. //#define CreateNeroIsoItem() CreateNeroIsoItemOfSize(sizeof(NERO_ISO_ITEM))
  9. #define CreateNeroIsoItem() new NERO_ISO_ITEM
  10. CDiscItem::CDiscItem(void)
  11. {
  12. m_pVirtualItem = NULL;
  13. InitVituralItem();
  14. }
  15. CDiscItem::~CDiscItem(void)
  16. {
  17. RemoveAllItem( );
  18. }
  19. NERO_ISO_ITEM* CDiscItem::InitVituralItem()
  20. {
  21. if ( m_pVirtualItem == NULL )
  22. {
  23. m_pVirtualItem = CreateNeroIsoItem();
  24. ZeroMemory(m_pVirtualItem, sizeof(NERO_ISO_ITEM));
  25. m_pVirtualItem->isDirectory = TRUE;
  26. m_pVirtualItem->longFileName = _strdup("光盘根级虚元素");
  27. m_pVirtualItem->isReference = FALSE;
  28. m_pVirtualItem->unicodeFileName = NULL;
  29. m_pVirtualItem->nextItem = NULL;
  30. m_pVirtualItem->subDirFirstItem = NULL;
  31. }
  32. return m_pVirtualItem;
  33. }
  34. NERO_ISO_ITEM* CDiscItem::GetHeadItem()
  35. {
  36. if ( m_pVirtualItem == NULL )
  37. {
  38. m_pVirtualItem = CreateNeroIsoItem();
  39. ZeroMemory(m_pVirtualItem, sizeof(NERO_ISO_ITEM));
  40. m_pVirtualItem->isDirectory = TRUE;
  41. m_pVirtualItem->longFileName = _strdup("光盘根级虚元素");
  42. m_pVirtualItem->isReference = FALSE;
  43. m_pVirtualItem->unicodeFileName = NULL;
  44. m_pVirtualItem->nextItem = NULL;
  45. m_pVirtualItem->subDirFirstItem = NULL;
  46. }
  47. return m_pVirtualItem->subDirFirstItem;
  48. }
  49. /************************************************************************/
  50. /* 函数:[3/21/2018 Jeff];
  51. /* 描述:返回光盘要刻录的第一个元素;
  52. /* 参数:;
  53. /* [IN] :;
  54. /* [OUT] :;
  55. /* [IN/OUT] :;
  56. /* 返回:void;
  57. /* 注意:;
  58. /* 示例:;
  59. /*
  60. /* 修改:;
  61. /* 日期:;
  62. /* 内容:;
  63. /************************************************************************/
  64. NERO_ISO_ITEM* CDiscItem::GetVirtualItem()
  65. {
  66. return InitVituralItem();
  67. }
  68. /************************************************************************/
  69. /* 函数:[3/23/2018 Jeff];
  70. /* 描述:将元素添加到根目录的兄弟链中;
  71. /* 参数:;
  72. /* [IN] pRootItem:新的根目录兄弟项;
  73. /* [OUT] :;
  74. /* [IN/OUT] :;
  75. /* 返回:成功添加返回新项,否则返回NULL;
  76. /* 注意:;
  77. /* 示例:;
  78. /*
  79. /* 修改:;
  80. /* 日期:;
  81. /* 内容:;
  82. /************************************************************************/
  83. NERO_ISO_ITEM* CDiscItem::AddSibling2RootItem( IN NERO_ISO_ITEM* pRootItem )
  84. {
  85. if ( m_pVirtualItem == NULL)
  86. {
  87. if ( InitVituralItem() == NULL )
  88. return NULL;
  89. }
  90. if ( pRootItem == NULL )
  91. return NULL;
  92. if ( m_pVirtualItem->subDirFirstItem == NULL )
  93. {// 当根元素空时,赋值为第一个值;
  94. m_pVirtualItem->subDirFirstItem = pRootItem;
  95. }
  96. else
  97. {
  98. NERO_ISO_ITEM* pNextItem = m_pVirtualItem->subDirFirstItem;
  99. while( pNextItem->nextItem )
  100. pNextItem = pNextItem->nextItem;
  101. pNextItem->nextItem = pRootItem;
  102. }
  103. return pRootItem;
  104. }
  105. /************************************************************************/
  106. /* 函数:[3/23/2018 Jeff];
  107. /* 描述:将元素添加到根目录的兄弟链中;
  108. /* 参数:;
  109. /* [IN] strRootName:新的根目录兄弟项名称;
  110. /* [IN] bIsDirectory:新的根目录兄弟项类型;
  111. /* [OUT] :;
  112. /* [IN/OUT] :;
  113. /* 返回:成功添加返回新项,否则返回NULL;
  114. /* 注意:;
  115. /* 示例:;
  116. /*
  117. /* 修改:;
  118. /* 日期:;
  119. /* 内容:;
  120. /************************************************************************/
  121. NERO_ISO_ITEM* CDiscItem::AddSibling2RootItem( IN TString strRootName, IN BOOL bIsDirectory )
  122. {
  123. if ( strRootName.size() )
  124. return NULL;
  125. if ( m_pVirtualItem == NULL)
  126. {
  127. if ( InitVituralItem() == NULL )
  128. return NULL;
  129. }
  130. NERO_ISO_ITEM* pRootItem = CreateNeroIsoItem();
  131. ZeroMemory(pRootItem, sizeof(NERO_ISO_ITEM));
  132. if ( !bIsDirectory ){// 根元素是文件;
  133. TCHAR* name;
  134. TCHAR path[MAX_PATH];
  135. GetFullPathName(strRootName.c_str(), MAX_PATH, path, &name);
  136. #ifdef UNICODE
  137. pRootItem->longFileName = _strdup(convert("UCS-2LE", "GBK", (const char*)name, _tcslen(name) * sizeof(TCHAR)).c_str());
  138. pRootItem->longSourceFilePath = _strdup(convert("UCS-2LE", "GBK", (const char*)path, _tcslen(path) * sizeof(TCHAR)).c_str());
  139. #else
  140. pRootItem->longFileName = _strdup(name);
  141. pRootItem->longSourceFilePath = _strdup(path);
  142. #endif
  143. pRootItem->isDirectory = FALSE;
  144. pRootItem->isReference = FALSE;
  145. pRootItem->unicodeFileName = NULL;
  146. pRootItem->nextItem = NULL;
  147. pRootItem->subDirFirstItem = NULL;
  148. }else{ // 根元素是目录;
  149. pRootItem->isDirectory = TRUE;
  150. #ifdef UNICODE
  151. pRootItem->longFileName = _strdup(convert("UCS-2LE", "GBK", (const char*)strRootName.c_str(), strRootName.size() * sizeof(TCHAR)).c_str());
  152. #else
  153. pRootItem->longFileName = _strdup(strRootName.c_str());
  154. #endif
  155. pRootItem->isReference = FALSE;
  156. pRootItem->unicodeFileName = NULL;
  157. pRootItem->nextItem = NULL;
  158. pRootItem->subDirFirstItem = NULL;
  159. }
  160. if ( m_pVirtualItem->subDirFirstItem == NULL )
  161. {
  162. m_pVirtualItem->subDirFirstItem = pRootItem;
  163. }
  164. else
  165. {
  166. NERO_ISO_ITEM* pNextItem = m_pVirtualItem->subDirFirstItem;
  167. while( pNextItem->nextItem )
  168. pNextItem = pNextItem->nextItem;
  169. pNextItem->nextItem = pRootItem;
  170. }
  171. return pRootItem;
  172. }
  173. /************************************************************************/
  174. /* 函数:[3/23/2018 Jeff];
  175. /* 描述:添加新元素到指定的兄弟项中;
  176. /* 参数:;
  177. /* [IN] pSiblingItem:作为兄弟链的参考兄弟项;
  178. /* [IN] pNewItem:需要添加兄弟链中的新项;
  179. /* [IN/OUT] :;
  180. /* 返回:成功添加返回TRUE,否则返回FALSE;
  181. /* 注意:pSiblingItem不指定具体的类型,如果文件类型(isDirectory==FALSE)或目录类型(isDirectory==TRUE).;
  182. /* 示例:;
  183. /*
  184. /* 修改:;
  185. /* 日期:;
  186. /* 内容:;
  187. /************************************************************************/
  188. NERO_ISO_ITEM* CDiscItem::AddItem2SiblingItem( IN NERO_ISO_ITEM* pSiblingItem, IN NERO_ISO_ITEM* pNewItem)
  189. {
  190. if ( m_pVirtualItem == NULL || m_pVirtualItem->subDirFirstItem == NULL )
  191. {
  192. OutputDebugString(_T("\nAddItem2SiblingItem:光盘的根项元素空!\n"));
  193. return NULL;
  194. }
  195. if ( pSiblingItem == NULL )
  196. {
  197. OutputDebugString(_T("\nAddItem2SiblingItem:光盘的兄弟项元素空!\n"));
  198. return NULL;
  199. }
  200. NERO_ISO_ITEM* pNextItem = pSiblingItem;
  201. while(pNextItem->nextItem)
  202. {
  203. pNextItem = pNextItem->nextItem;
  204. }
  205. pNextItem->nextItem = pNewItem;
  206. pNewItem->nextItem = NULL;
  207. return pNewItem;
  208. }
  209. /************************************************************************/
  210. /* 函数:[3/23/2018 Jeff];
  211. /* 描述:添加新元素到指定的目录下;
  212. /* 参数:;
  213. /* [IN] strDiscPath:光盘目录,作为新元素要父目录;
  214. /* [IN] pNewItem:新元素,将插入到strDiscPath目录下;
  215. /* [IN/OUT] :;
  216. /* 返回:成功添加返回TRUE,否则返回FALS;
  217. /* 注意:;
  218. /* 示例:;
  219. /*
  220. /* 修改:;
  221. /* 日期:;
  222. /* 内容:;
  223. /************************************************************************/
  224. NERO_ISO_ITEM* CDiscItem::AddItem2Path( IN TString strDiscPath, IN NERO_ISO_ITEM* pNewItem)
  225. {
  226. if ( m_pVirtualItem == NULL || m_pVirtualItem->subDirFirstItem == NULL)
  227. {
  228. OutputDebugString(_T("\nAddItem2Path:光盘的根项元素空!\n"));
  229. return NULL;
  230. }
  231. if ( strDiscPath.size() )
  232. {
  233. OutputDebugString(_T("\nAddItem2Path:光盘的兄弟项元素名称空\n"));
  234. return NULL;
  235. }
  236. // 首先查找;
  237. NERO_ISO_ITEM *pTailPathItem = FindPathItem(strDiscPath);
  238. if ( pTailPathItem == NULL )
  239. {
  240. OutputDebugString(_T("\nAddItem2Path:未找到光盘指定路径元素:"));
  241. OutputDebugString(strDiscPath.c_str());
  242. return NULL;
  243. }
  244. pNewItem->nextItem = NULL;
  245. if ( pTailPathItem->subDirFirstItem )
  246. {
  247. NERO_ISO_ITEM* pNextItem = pTailPathItem->subDirFirstItem;
  248. while ( pNextItem->nextItem )
  249. {
  250. pNextItem = pNextItem->nextItem;
  251. }
  252. pNextItem->nextItem = pNewItem;
  253. }
  254. else
  255. {
  256. pTailPathItem->subDirFirstItem = pNewItem;
  257. }
  258. return pNewItem;
  259. }
  260. /************************************************************************/
  261. /* 函数:[3/23/2018 Jeff];
  262. /* 描述:添加新目录到指定的光盘目录的兄弟链尾中;
  263. /* 参数:;
  264. /* [IN] strDiscPath:光盘目录,作为新元素兄弟链头路径;
  265. /* [IN] strNewPath:新目录,strDiscPath的兄弟项;
  266. /* [IN/OUT] :;
  267. /* 返回:成功返回TRUE,否则返回FALSE;
  268. /* 注意:;
  269. /* 示例:;
  270. /*
  271. /* 修改:;
  272. /* 日期:;
  273. /* 内容:;
  274. /************************************************************************/
  275. NERO_ISO_ITEM* CDiscItem::AddSiblingPath(IN TString strDiscPath, IN TString strNewPath)
  276. {
  277. // 首先查找;
  278. NERO_ISO_ITEM *pTailPathItem = FindPathItem(strDiscPath);
  279. if ( pTailPathItem == NULL )
  280. {
  281. OutputDebugString(_T("\nAddPath2Path:未找到光盘指定路径元素:"));
  282. OutputDebugString(strDiscPath.c_str());
  283. return NULL;
  284. }
  285. NERO_ISO_ITEM* pNewItem = CreateNeroIsoItem();
  286. ZeroMemory(pNewItem,sizeof(NERO_ISO_ITEM));
  287. pNewItem->isDirectory = TRUE;
  288. pNewItem->isReference = FALSE;
  289. pNewItem->unicodeFileName = NULL;
  290. #ifdef UNICODE
  291. pNewItem->longFileName = _strdup(convert("UCS-2LE", "GBK", (const char*)strNewPath.c_str(), strNewPath.size() * sizeof(TCHAR)).c_str());
  292. #else
  293. pNewItem->longFileName = _strdup(strNewPath.c_str());
  294. #endif
  295. //sprintf_s(pNewItem->fileName, "%s", strNewPath);
  296. pNewItem->subDirFirstItem = NULL;
  297. pNewItem->nextItem = NULL;
  298. while( pTailPathItem->nextItem )
  299. {
  300. pTailPathItem = pTailPathItem->nextItem;
  301. }
  302. pTailPathItem->nextItem = pNewItem;
  303. return pNewItem;
  304. }
  305. /************************************************************************/
  306. /* 函数:[3/23/2018 Jeff];
  307. /* 描述:添加新的目录到光盘目录中,若目录不存在,则重新创建目录元素;
  308. /* 参数:;
  309. /* [IN] strNewPath:新目录,根目录的新兄弟项;
  310. /* [OUT] :;
  311. /* [IN/OUT] :;
  312. /* 返回:成功返回TRUE,否则返回FALSE;
  313. /* 注意:该函数有问题, strNewPath,未进行验证;
  314. /* 示例:;
  315. /*
  316. /* 修改:;
  317. /* 日期:;
  318. /* 内容:;
  319. /************************************************************************/
  320. NERO_ISO_ITEM* CDiscItem::AddPath(IN TString strNewPath)
  321. {
  322. INT nIndex = 0;
  323. nIndex = strNewPath.find_first_of(_T(":\\"));
  324. if ( nIndex != TString::npos )
  325. strNewPath = strNewPath.substr(nIndex + 2);
  326. if ( strNewPath[strNewPath.size() - 1] != _T('\\') )
  327. strNewPath.append(_T("\\"));
  328. NERO_ISO_ITEM* pHeadPath = m_pVirtualItem, *pTailPath = pHeadPath->subDirFirstItem;
  329. do
  330. {
  331. nIndex = strNewPath.find_first_of(_T('\\'));
  332. if ( nIndex != TString::npos )
  333. {
  334. pTailPath = FindPathInSibling(pTailPath, strNewPath.substr(0,nIndex));
  335. if (!pTailPath)
  336. {
  337. break;
  338. }
  339. pHeadPath = pTailPath;
  340. pTailPath = pTailPath->subDirFirstItem;
  341. strNewPath = strNewPath.substr(nIndex + 1);
  342. }
  343. } while (nIndex != -1);
  344. // 根元素空;
  345. if ( m_pVirtualItem->subDirFirstItem == NULL )
  346. pHeadPath = m_pVirtualItem;
  347. while(strNewPath.find_first_of(_T("\\")) != TString::npos)
  348. {
  349. nIndex = strNewPath.find_first_of(_T('\\'));
  350. if ( nIndex != TString::npos )
  351. {
  352. pHeadPath = AddPath2Path(pHeadPath, strNewPath.substr(0,nIndex));
  353. strNewPath = strNewPath.substr(nIndex + 1);
  354. }
  355. }
  356. return pHeadPath;
  357. }
  358. /************************************************************************/
  359. /* 函数:[3/23/2018 Jeff];
  360. /* 描述:添加新目录到指定的光盘目录下;
  361. /* 参数:;
  362. /* [IN] strDiscPath:光盘目录,作为新元素要父目录;
  363. /* [IN] strNewPath:;
  364. /* [IN/OUT] :新目录,将插入到strDiscPath目录下;
  365. /* 返回:成功返回TRUE,否则返回FALSE;
  366. /* 注意:;
  367. /* 示例:;
  368. /*
  369. /* 修改:;
  370. /* 日期:;
  371. /* 内容:;
  372. /************************************************************************/
  373. NERO_ISO_ITEM* CDiscItem::AddPath2Path(IN TString strDiscPath, IN TString strNewPath)
  374. {
  375. // 首先查找;
  376. NERO_ISO_ITEM *pTailPathItem = FindPathItem(strDiscPath);
  377. if ( pTailPathItem == NULL )
  378. {
  379. OutputDebugString(_T("\nAddPath2Path:未找到光盘指定路径元素:"));
  380. OutputDebugString(strDiscPath.c_str());
  381. return NULL;
  382. }
  383. NERO_ISO_ITEM* pNewItem = CreateNeroIsoItem();
  384. ZeroMemory(pNewItem,sizeof(NERO_ISO_ITEM));
  385. pNewItem->isDirectory = TRUE;
  386. pNewItem->isReference = FALSE;
  387. pNewItem->unicodeFileName = NULL;
  388. #ifdef UNICODE
  389. pNewItem->longFileName = _strdup(convert("UCS-2LE", "GBK", (const char*)strNewPath.c_str(), strNewPath.size() * sizeof(TCHAR)).c_str());
  390. #else
  391. pNewItem->longFileName = _strdup(strNewPath.c_str());
  392. #endif
  393. //sprintf_s(pNewItem->fileName, "%s", strNewPath);
  394. pNewItem->subDirFirstItem = NULL;
  395. pNewItem->nextItem = NULL;
  396. if ( pTailPathItem->subDirFirstItem )
  397. {
  398. NERO_ISO_ITEM* pNextItem = pTailPathItem->subDirFirstItem;
  399. while ( pNextItem->nextItem )
  400. {
  401. pNextItem = pNextItem->nextItem;
  402. }
  403. pNextItem->nextItem = pNewItem;
  404. }
  405. else
  406. {
  407. pTailPathItem->subDirFirstItem = pNewItem;
  408. }
  409. return pNewItem;
  410. }
  411. /************************************************************************/
  412. /* 函数:[3/23/2018 Jeff];
  413. /* 描述:添加新目录到指定的光盘目录下;
  414. /* 参数:;
  415. /* [IN] pPathItem:光盘目录,作为新元素要父目录;
  416. /* [IN] strNewPath:新目录,将插入到strDiscPath目录下;
  417. /* [IN/OUT] :;
  418. /* 返回:成功返回TRUE,否则返回FALSE;
  419. /* 注意:;
  420. /* 示例:;
  421. /*
  422. /* 修改:;
  423. /* 日期:;
  424. /* 内容:;
  425. /************************************************************************/
  426. NERO_ISO_ITEM* CDiscItem::AddPath2Path(IN NERO_ISO_ITEM* pPathItem, IN TString strNewPath )
  427. {
  428. if ( pPathItem == NULL || pPathItem->isDirectory == FALSE )
  429. {
  430. return NULL;
  431. }
  432. NERO_ISO_ITEM* pNewItem = CreateNeroIsoItem();
  433. ZeroMemory(pNewItem,sizeof(NERO_ISO_ITEM));
  434. pNewItem->isDirectory = TRUE;
  435. pNewItem->isReference = FALSE;
  436. pNewItem->unicodeFileName = NULL;
  437. #ifdef UNICODE
  438. pNewItem->longFileName = _strdup(convert("UCS-2LE", "GBK", (const char*)strNewPath.c_str(), strNewPath.size() * sizeof(TCHAR)).c_str());
  439. #else
  440. pNewItem->longFileName = _strdup(strNewPath.c_str());
  441. #endif
  442. //sprintf_s(pNewItem->fileName, "%s", strNewPath);
  443. pNewItem->subDirFirstItem = NULL;
  444. pNewItem->nextItem = NULL;
  445. if ( pPathItem->subDirFirstItem == NULL )
  446. return pPathItem->subDirFirstItem = pNewItem;
  447. NERO_ISO_ITEM* pNextItem = pPathItem->subDirFirstItem;
  448. while( pNextItem->nextItem)
  449. {
  450. pNextItem = pNextItem->nextItem;
  451. }
  452. return pNextItem->nextItem = pNewItem;
  453. }
  454. /************************************************************************/
  455. /* 函数:[3/23/2018 Jeff];
  456. /* 描述:添加新文件到指定的光盘目录下;
  457. /* 参数:;
  458. /* [IN] strDiscPath:光盘目录,作为新元素的父目录;
  459. /* [IN] strFileName:新文件,将插入到strDiscPath目录下;
  460. /* [IN/OUT] :;
  461. /* 返回:成功返回TRUE,否则返回FALSE;
  462. /* 注意:;
  463. /* 示例:;
  464. /*
  465. /* 修改:;
  466. /* 日期:;
  467. /* 内容:;
  468. /************************************************************************/
  469. NERO_ISO_ITEM* CDiscItem::AddFile2Path(IN TString strDiscPath, IN TString strFileName)
  470. {
  471. // 首先查找;
  472. NERO_ISO_ITEM *pTailPathItem = FindPathItem(strDiscPath);
  473. if ( pTailPathItem == NULL )
  474. {
  475. pTailPathItem = AddPath(strDiscPath);
  476. if ( pTailPathItem == NULL )
  477. {
  478. OutputDebugString(_T("\nAddFile2Path:未找到光盘指定路径元素:"));
  479. OutputDebugString(strDiscPath.c_str());
  480. return NULL;
  481. }
  482. }
  483. NERO_ISO_ITEM* pNewItem = CreateNeroIsoItem();
  484. ZeroMemory(pNewItem, sizeof(NERO_ISO_ITEM));
  485. pNewItem->isDirectory = FALSE;
  486. pNewItem->isReference = FALSE;
  487. pNewItem->unicodeFileName = NULL;
  488. TCHAR* name;
  489. TCHAR path[MAX_PATH];
  490. GetFullPathName(strFileName.c_str(), MAX_PATH, path, &name);
  491. #ifdef UNICODE
  492. pNewItem->longFileName = _strdup(convert("UCS-2LE", "GBK", (const char*)name, _tcslen(name) * sizeof(TCHAR)).c_str());
  493. pNewItem->longSourceFilePath = _strdup(convert("UCS-2LE", "GBK", (const char*)path, _tcslen(path) * sizeof(TCHAR)).c_str());
  494. #else
  495. pNewItem->longFileName = _strdup(name);
  496. pNewItem->longSourceFilePath = _strdup(path);
  497. #endif
  498. //sprintf_s(pNewItem->fileName,"%s", strFileName);
  499. pNewItem->nextItem = NULL;
  500. pNewItem->subDirFirstItem = NULL;
  501. if ( pTailPathItem->subDirFirstItem )
  502. {
  503. NERO_ISO_ITEM* pNextItem = pTailPathItem->subDirFirstItem;
  504. while ( pNextItem->nextItem )
  505. {
  506. pNextItem = pNextItem->nextItem;
  507. }
  508. pNextItem->nextItem = pNewItem;
  509. }
  510. else
  511. {
  512. pTailPathItem->subDirFirstItem = pNewItem;
  513. }
  514. return pNewItem;
  515. }
  516. NERO_ISO_ITEM* CDiscItem::AddFile2Path(IN NERO_ISO_ITEM* pPathItem, IN TString strFileName)
  517. {
  518. if ( pPathItem == NULL && !pPathItem->isDirectory)
  519. {
  520. return NULL;
  521. }
  522. NERO_ISO_ITEM* pNewItem = CreateNeroIsoItem();
  523. ZeroMemory(pNewItem, sizeof(NERO_ISO_ITEM));
  524. pNewItem->isDirectory = FALSE;
  525. pNewItem->isReference = FALSE;
  526. pNewItem->unicodeFileName = NULL;
  527. TCHAR* name;
  528. TCHAR path[MAX_PATH];
  529. GetFullPathName(strFileName.c_str(), MAX_PATH, path, &name);
  530. #ifdef UNICODE
  531. pNewItem->longFileName = _strdup(convert("UCS-2LE", "GBK", (const char*)name, _tcslen(name) * sizeof(TCHAR)).c_str());
  532. pNewItem->longSourceFilePath = _strdup(convert("UCS-2LE", "GBK", (const char*)path, _tcslen(path) * sizeof(TCHAR)).c_str());
  533. #else
  534. pNewItem->longFileName = _strdup(name);
  535. pNewItem->longSourceFilePath = _strdup(path);
  536. #endif
  537. //sprintf_s(pNewItem->fileName,"%s", strFileName);
  538. pNewItem->nextItem = NULL;
  539. pNewItem->subDirFirstItem = NULL;
  540. if ( pPathItem->subDirFirstItem )
  541. {
  542. NERO_ISO_ITEM* pNextItem = pPathItem->subDirFirstItem;
  543. while ( pNextItem->nextItem )
  544. {
  545. pNextItem = pNextItem->nextItem;
  546. }
  547. pNextItem->nextItem = pNewItem;
  548. }
  549. else
  550. {
  551. pPathItem->subDirFirstItem = pNewItem;
  552. }
  553. return pNewItem;
  554. }
  555. /************************************************************************/
  556. /* 函数:[3/23/2018 Jeff];
  557. /* 描述:将文件添加到指定的兄弟项中;
  558. /* 参数:;
  559. /* [IN] :;
  560. /* [OUT] :;
  561. /* [IN/OUT] :;
  562. /* 返回:void;
  563. /* 注意:;
  564. /* 示例:;
  565. /*
  566. /* 修改:;
  567. /* 日期:;
  568. /* 内容:;
  569. /************************************************************************/
  570. NERO_ISO_ITEM* CDiscItem::AddFile2SiblingItem(IN NERO_ISO_ITEM* pSiblingItem, IN TString strFileName)
  571. {
  572. if (pSiblingItem == NULL)
  573. {
  574. OutputDebugString(_T("\nAddFile2SiblingItem:树兄弟项出错!\n"));
  575. return NULL;
  576. }
  577. NERO_ISO_ITEM* pNewItem = CreateNeroIsoItem();
  578. ZeroMemory(pNewItem, sizeof(NERO_ISO_ITEM));
  579. pNewItem->isDirectory = FALSE;
  580. pNewItem->isReference = FALSE;
  581. TCHAR* name;
  582. TCHAR path[MAX_PATH];
  583. GetFullPathName(strFileName.c_str(), MAX_PATH, path, &name);
  584. #ifdef UNICODE
  585. pNewItem->longFileName = _strdup(convert("UCS-2LE", "GBK", (const char*)name, _tcslen(name) * sizeof(TCHAR)).c_str());
  586. pNewItem->longSourceFilePath = _strdup(convert("UCS-2LE", "GBK", (const char*)path, _tcslen(path) * sizeof(TCHAR)).c_str());
  587. #else
  588. pNewItem->longFileName = _strdup(name);
  589. pNewItem->longSourceFilePath = _strdup(path);
  590. #endif
  591. pNewItem->nextItem = NULL;
  592. pNewItem->subDirFirstItem = NULL;
  593. NERO_ISO_ITEM* pNextItem = pSiblingItem;
  594. while(pNextItem->nextItem)
  595. {
  596. pNextItem = pNextItem->nextItem;
  597. }
  598. pNextItem->nextItem = pNewItem;
  599. return pNewItem;
  600. }
  601. /************************************************************************/
  602. /* 函数:[3/23/2018 Jeff];
  603. /* 描述:查找指定的光盘目录,返回目录元素指针对象;
  604. /* 参数:;
  605. /* [IN] strDiscPath:要查找的光盘目录,格式如下:"光盘根目录\子目录1\子目录2\子目录3";
  606. /* [OUT] :;
  607. /* [IN/OUT] :;
  608. /* 返回:若存在该光盘目录,则返回该目录元素对象的指针(返回最后一层目录名对应的元素指针),否则返回NULL;;
  609. /* 注意:;
  610. /* 示例:;
  611. /*
  612. /* 修改:;
  613. /* 日期:;
  614. /* 内容:;
  615. /************************************************************************/
  616. NERO_ISO_ITEM* CDiscItem::FindPathItem( IN TString strDiscPath )
  617. {
  618. if (!strDiscPath.size())
  619. return NULL;
  620. if ( m_pVirtualItem == NULL || m_pVirtualItem->subDirFirstItem == NULL)
  621. return NULL;
  622. INT nIndex = strDiscPath.find_first_of(_T(":\\"));
  623. if ( nIndex != TString::npos )
  624. strDiscPath = strDiscPath.substr(nIndex + 2);
  625. if ( strDiscPath[strDiscPath.size()-1] != _T('\\') )
  626. strDiscPath.append(_T("\\"));
  627. NERO_ISO_ITEM* pHeadPath = m_pVirtualItem, *pTailPath = pHeadPath->subDirFirstItem;
  628. do
  629. {
  630. nIndex = strDiscPath.find_first_of(_T("\\"));
  631. if ( nIndex != TString::npos )
  632. {
  633. pTailPath = FindPathInSibling(pTailPath, strDiscPath.substr(0,nIndex));
  634. if (!pTailPath) {
  635. break;
  636. }
  637. pHeadPath = pTailPath;
  638. pTailPath = pTailPath->subDirFirstItem;
  639. strDiscPath = strDiscPath.substr(nIndex+1);
  640. }
  641. } while ( strDiscPath.find_first_of(_T("\\")) != -1 );
  642. return pHeadPath == m_pVirtualItem ? NULL : pHeadPath;
  643. }
  644. /************************************************************************/
  645. /* 函数:[3/23/2018 Jeff];
  646. /* 描述:在指定的兄弟链中(以及兄弟链中的子链),从兄弟链头元素开始查找指定目录名的元素指针;
  647. /* 参数:;
  648. /* [IN] pSiblingHeadItem:兄弟链的头元素,作为查找时的开始位置;
  649. /* [IN] strDiscPath:要在兄弟链中(以及兄弟链中的子链)查找的目录名(只是单层目录名)。;
  650. /* [IN/OUT] :;
  651. /* 返回:成功在兄弟链中(以及兄弟链中的子链)查找到该目录名元素,返回该元素对象指针;若未查找到,返回NULL;
  652. /* 注意:若兄弟链中,存在项,但是另一兄弟项的子链中也存在着同名的项,但却比另一兄弟项先找到,此时就会产生问题;
  653. /* 示例:;
  654. /*
  655. /* 修改:;
  656. /* 日期:;
  657. /* 内容:;
  658. /************************************************************************/
  659. NERO_ISO_ITEM* CDiscItem::FindPathInSibling( IN NERO_ISO_ITEM* pSiblingHeadItem, IN TString& strDiscPath )
  660. {
  661. if ( pSiblingHeadItem == NULL )
  662. return NULL;
  663. BOOL bFind = FALSE;
  664. NERO_ISO_ITEM* pNextItem = pSiblingHeadItem;
  665. do {
  666. if (pNextItem->isDirectory)
  667. {
  668. #ifdef UNICODE
  669. if ( convert("UCS-2LE", "GBK", (const char*)strDiscPath.c_str(), strDiscPath.size() * sizeof(TCHAR)).compare(pNextItem->longFileName) == 0 )
  670. #else
  671. if ( strDiscPath.compare(pNextItem->longFileName) == 0 )
  672. #endif
  673. {
  674. bFind = TRUE;
  675. break;
  676. }
  677. }
  678. pNextItem = pNextItem->nextItem;
  679. } while ( pNextItem );
  680. return bFind ? pNextItem : NULL;
  681. }
  682. /************************************************************************/
  683. /* 函数:[3/23/2018 Jeff];
  684. /* 描述:在指定的兄弟链中(以及兄弟链中的子链),从兄弟链头元素开始查找指定目录名的元素指针;
  685. /* 参数:;
  686. /* [IN] pSiblingHeadItem:兄弟链的头元素,作为查找时的开始位置;
  687. /* [IN] strDiscPath:要在兄弟链中(以及兄弟链中的子链)查找的目录名(只是单层目录名)。;
  688. /* [IN/OUT] :;
  689. /* 返回:成功在兄弟链中(以及兄弟链中的子链)查找到该目录名元素,返回该元素对象指针;若未查找到,返回NULL;
  690. /* 注意:先在兄弟链中查找,找不到后再到子链中查找;
  691. /* 示例:;
  692. /*
  693. /* 修改:;
  694. /* 日期:;
  695. /* 内容:;
  696. /************************************************************************/
  697. NERO_ISO_ITEM* CDiscItem::FindPathInSiblingEx( IN NERO_ISO_ITEM* pSiblingHeadItem, IN TString& strDiscPath )
  698. {
  699. if ( pSiblingHeadItem == NULL )
  700. return NULL;
  701. BOOL bFind = FALSE;
  702. NERO_ISO_ITEM* pNextItem = pSiblingHeadItem;
  703. do {
  704. if (pNextItem->isDirectory)
  705. {
  706. #ifdef UNICODE
  707. if ( convert("UCS-2LE", "GBK", (const char*)strDiscPath.c_str(), strDiscPath.size() * sizeof(TCHAR)).compare(pNextItem->longFileName) == 0 )
  708. #else
  709. if ( strDiscPath.compare(pNextItem->longFileName) == 0 )
  710. #endif
  711. {
  712. bFind = TRUE;
  713. break;
  714. }
  715. else
  716. {
  717. if ( pNextItem->subDirFirstItem )
  718. {
  719. NERO_ISO_ITEM *pResultItem = NULL;
  720. if ( (pResultItem = FindPathInSibling(pNextItem->subDirFirstItem, strDiscPath)) != NULL )
  721. {
  722. bFind = TRUE;
  723. pNextItem = pResultItem;
  724. break;
  725. }
  726. }
  727. }
  728. }
  729. pNextItem = pNextItem->nextItem;
  730. } while ( pNextItem );
  731. return bFind ? pNextItem : NULL;
  732. }
  733. /************************************************************************/
  734. /* 函数:[3/23/2018 Jeff];
  735. /* 描述:返回兄弟链中的倒数第二个元素或者最后一个;
  736. /* 参数:;
  737. /* [IN] pSiblingHeadItem:兄弟链的头元素;
  738. /* [OUT] :;
  739. /* [IN/OUT] :;
  740. /* 返回:返回兄弟链中的倒数第二个元素或者最后一个;
  741. /* 注意:当兄弟链的只有一个元素时,返回的是本身,也是最后一个;
  742. /* 示例:;
  743. /*
  744. /* 修改:;
  745. /* 日期:;
  746. /* 内容:;
  747. /************************************************************************/
  748. NERO_ISO_ITEM* CDiscItem::FindLastItemInSibling( IN NERO_ISO_ITEM* pSiblingHeadItem )
  749. {
  750. if ( pSiblingHeadItem == NULL || pSiblingHeadItem->nextItem == NULL )
  751. {
  752. return pSiblingHeadItem;
  753. }
  754. NERO_ISO_ITEM* pSiblingTail = pSiblingHeadItem;
  755. do
  756. {
  757. pSiblingTail = pSiblingTail->nextItem;
  758. }while ( pSiblingTail->nextItem );
  759. return pSiblingTail;
  760. }
  761. /************************************************************************/
  762. /* 函数:[3/23/2018 Jeff];
  763. /* 描述:;
  764. /* 参数:;
  765. /* [IN] :;
  766. /* [OUT] :;
  767. /* [IN/OUT] :;
  768. /* 返回:void;
  769. /* 注意:;
  770. /* 示例:;
  771. /*
  772. /* 修改:;
  773. /* 日期:;
  774. /* 内容:;
  775. /************************************************************************/
  776. void CDiscItem::DeleteIsoItemTree(NERO_ISO_ITEM *pItem)
  777. {
  778. while(pItem != NULL)
  779. {
  780. NERO_ISO_ITEM *pNexItem = pItem->nextItem;
  781. if ( pItem->isDirectory)
  782. DeleteIsoItemTree(pItem->subDirFirstItem);
  783. if (!pItem->isReference)
  784. {// 非引用项;
  785. if(pItem->longFileName != NULL)
  786. free((void*)pItem->longFileName), pItem->longFileName = NULL;
  787. if(pItem->longSourceFilePath != NULL)
  788. free((void*)pItem->longSourceFilePath), pItem->longSourceFilePath = NULL;
  789. // 释放;
  790. delete pItem;
  791. pItem = NULL;
  792. }
  793. else
  794. {
  795. // 引用的必须使用NeroFreeIsoItem释放;
  796. NeroFreeIsoItem(pItem);
  797. }
  798. pItem = pNexItem;
  799. }
  800. }
  801. /************************************************************************/
  802. /* 函数:[3/23/2018 Jeff];
  803. /* 描述:删除指定根结点的全部元素;
  804. /* 参数:;
  805. /* [IN] :;
  806. /* [OUT] :;
  807. /* [IN/OUT] :;
  808. /* 返回:void;
  809. /* 注意:NeroFreeIsoItemTree函数是用于释放使用CreateNeroIsoItem()创建的对象;
  810. /* 示例:;
  811. /*
  812. /* 修改:;
  813. /* 日期:;
  814. /* 内容:;
  815. /************************************************************************/
  816. void CDiscItem::RemoveAllItem( )
  817. {
  818. DeleteIsoItemTree(m_pVirtualItem);
  819. //NeroFreeIsoItemTree(m_pVirtualItem);//如果使用函数CreateNeroIsoItem();来创建,在这里释放;
  820. m_pVirtualItem = NULL;
  821. }