| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914 |
- #include "StdAfx.h"
- #include "NeroItem.h"
- NERO_ISO_ITEM *CreateNeroIsoItemOfSize(size_t size)
- {
- return (NERO_ISO_ITEM*)malloc(size);
- }
- //#define CreateNeroIsoItem() NeroCreateIsoItemOfSize(sizeof(NERO_ISO_ITEM))//无法分配内存,禁用;
- //#define CreateNeroIsoItem() CreateNeroIsoItemOfSize(sizeof(NERO_ISO_ITEM))
- #define CreateNeroIsoItem() new NERO_ISO_ITEM
- CDiscItem::CDiscItem(void)
- {
- m_pVirtualItem = NULL;
- InitVituralItem();
- }
- CDiscItem::~CDiscItem(void)
- {
- RemoveAllItem( );
- }
- NERO_ISO_ITEM* CDiscItem::InitVituralItem()
- {
- if ( m_pVirtualItem == NULL )
- {
- m_pVirtualItem = CreateNeroIsoItem();
- ZeroMemory(m_pVirtualItem, sizeof(NERO_ISO_ITEM));
- m_pVirtualItem->isDirectory = TRUE;
- m_pVirtualItem->longFileName = _strdup("光盘根级虚元素");
- m_pVirtualItem->isReference = FALSE;
- m_pVirtualItem->unicodeFileName = NULL;
- m_pVirtualItem->nextItem = NULL;
- m_pVirtualItem->subDirFirstItem = NULL;
- }
- return m_pVirtualItem;
- }
- NERO_ISO_ITEM* CDiscItem::GetHeadItem()
- {
- if ( m_pVirtualItem == NULL )
- {
- m_pVirtualItem = CreateNeroIsoItem();
- ZeroMemory(m_pVirtualItem, sizeof(NERO_ISO_ITEM));
- m_pVirtualItem->isDirectory = TRUE;
- m_pVirtualItem->longFileName = _strdup("光盘根级虚元素");
- m_pVirtualItem->isReference = FALSE;
- m_pVirtualItem->unicodeFileName = NULL;
- m_pVirtualItem->nextItem = NULL;
- m_pVirtualItem->subDirFirstItem = NULL;
- }
- return m_pVirtualItem->subDirFirstItem;
- }
- /************************************************************************/
- /* 函数:[3/21/2018 Jeff];
- /* 描述:返回光盘要刻录的第一个元素;
- /* 参数:;
- /* [IN] :;
- /* [OUT] :;
- /* [IN/OUT] :;
- /* 返回:void;
- /* 注意:;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- NERO_ISO_ITEM* CDiscItem::GetVirtualItem()
- {
- return InitVituralItem();
- }
- /************************************************************************/
- /* 函数:[3/23/2018 Jeff];
- /* 描述:将元素添加到根目录的兄弟链中;
- /* 参数:;
- /* [IN] pRootItem:新的根目录兄弟项;
- /* [OUT] :;
- /* [IN/OUT] :;
- /* 返回:成功添加返回新项,否则返回NULL;
- /* 注意:;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- NERO_ISO_ITEM* CDiscItem::AddSibling2RootItem( IN NERO_ISO_ITEM* pRootItem )
- {
- if ( m_pVirtualItem == NULL)
- {
- if ( InitVituralItem() == NULL )
- return NULL;
- }
- if ( pRootItem == NULL )
- return NULL;
- if ( m_pVirtualItem->subDirFirstItem == NULL )
- {// 当根元素空时,赋值为第一个值;
- m_pVirtualItem->subDirFirstItem = pRootItem;
- }
- else
- {
- NERO_ISO_ITEM* pNextItem = m_pVirtualItem->subDirFirstItem;
- while( pNextItem->nextItem )
- pNextItem = pNextItem->nextItem;
- pNextItem->nextItem = pRootItem;
- }
- return pRootItem;
- }
- /************************************************************************/
- /* 函数:[3/23/2018 Jeff];
- /* 描述:将元素添加到根目录的兄弟链中;
- /* 参数:;
- /* [IN] strRootName:新的根目录兄弟项名称;
- /* [IN] bIsDirectory:新的根目录兄弟项类型;
- /* [OUT] :;
- /* [IN/OUT] :;
- /* 返回:成功添加返回新项,否则返回NULL;
- /* 注意:;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- NERO_ISO_ITEM* CDiscItem::AddSibling2RootItem( IN TString strRootName, IN BOOL bIsDirectory )
- {
- if ( strRootName.size() )
- return NULL;
- if ( m_pVirtualItem == NULL)
- {
- if ( InitVituralItem() == NULL )
- return NULL;
- }
- NERO_ISO_ITEM* pRootItem = CreateNeroIsoItem();
- ZeroMemory(pRootItem, sizeof(NERO_ISO_ITEM));
- if ( !bIsDirectory ){// 根元素是文件;
- TCHAR* name;
- TCHAR path[MAX_PATH];
- GetFullPathName(strRootName.c_str(), MAX_PATH, path, &name);
- #ifdef UNICODE
- pRootItem->longFileName = _strdup(convert("UCS-2LE", "GBK", (const char*)name, _tcslen(name) * sizeof(TCHAR)).c_str());
- pRootItem->longSourceFilePath = _strdup(convert("UCS-2LE", "GBK", (const char*)path, _tcslen(path) * sizeof(TCHAR)).c_str());
- #else
- pRootItem->longFileName = _strdup(name);
- pRootItem->longSourceFilePath = _strdup(path);
- #endif
- pRootItem->isDirectory = FALSE;
- pRootItem->isReference = FALSE;
- pRootItem->unicodeFileName = NULL;
- pRootItem->nextItem = NULL;
- pRootItem->subDirFirstItem = NULL;
- }else{ // 根元素是目录;
- pRootItem->isDirectory = TRUE;
- #ifdef UNICODE
- pRootItem->longFileName = _strdup(convert("UCS-2LE", "GBK", (const char*)strRootName.c_str(), strRootName.size() * sizeof(TCHAR)).c_str());
- #else
- pRootItem->longFileName = _strdup(strRootName.c_str());
- #endif
- pRootItem->isReference = FALSE;
- pRootItem->unicodeFileName = NULL;
- pRootItem->nextItem = NULL;
- pRootItem->subDirFirstItem = NULL;
- }
- if ( m_pVirtualItem->subDirFirstItem == NULL )
- {
- m_pVirtualItem->subDirFirstItem = pRootItem;
- }
- else
- {
- NERO_ISO_ITEM* pNextItem = m_pVirtualItem->subDirFirstItem;
- while( pNextItem->nextItem )
- pNextItem = pNextItem->nextItem;
- pNextItem->nextItem = pRootItem;
- }
- return pRootItem;
- }
- /************************************************************************/
- /* 函数:[3/23/2018 Jeff];
- /* 描述:添加新元素到指定的兄弟项中;
- /* 参数:;
- /* [IN] pSiblingItem:作为兄弟链的参考兄弟项;
- /* [IN] pNewItem:需要添加兄弟链中的新项;
- /* [IN/OUT] :;
- /* 返回:成功添加返回TRUE,否则返回FALSE;
- /* 注意:pSiblingItem不指定具体的类型,如果文件类型(isDirectory==FALSE)或目录类型(isDirectory==TRUE).;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- NERO_ISO_ITEM* CDiscItem::AddItem2SiblingItem( IN NERO_ISO_ITEM* pSiblingItem, IN NERO_ISO_ITEM* pNewItem)
- {
- if ( m_pVirtualItem == NULL || m_pVirtualItem->subDirFirstItem == NULL )
- {
- OutputDebugString(_T("\nAddItem2SiblingItem:光盘的根项元素空!\n"));
- return NULL;
- }
- if ( pSiblingItem == NULL )
- {
- OutputDebugString(_T("\nAddItem2SiblingItem:光盘的兄弟项元素空!\n"));
- return NULL;
- }
- NERO_ISO_ITEM* pNextItem = pSiblingItem;
- while(pNextItem->nextItem)
- {
- pNextItem = pNextItem->nextItem;
- }
- pNextItem->nextItem = pNewItem;
- pNewItem->nextItem = NULL;
- return pNewItem;
- }
- /************************************************************************/
- /* 函数:[3/23/2018 Jeff];
- /* 描述:添加新元素到指定的目录下;
- /* 参数:;
- /* [IN] strDiscPath:光盘目录,作为新元素要父目录;
- /* [IN] pNewItem:新元素,将插入到strDiscPath目录下;
- /* [IN/OUT] :;
- /* 返回:成功添加返回TRUE,否则返回FALS;
- /* 注意:;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- NERO_ISO_ITEM* CDiscItem::AddItem2Path( IN TString strDiscPath, IN NERO_ISO_ITEM* pNewItem)
- {
- if ( m_pVirtualItem == NULL || m_pVirtualItem->subDirFirstItem == NULL)
- {
- OutputDebugString(_T("\nAddItem2Path:光盘的根项元素空!\n"));
- return NULL;
- }
- if ( strDiscPath.size() )
- {
- OutputDebugString(_T("\nAddItem2Path:光盘的兄弟项元素名称空\n"));
- return NULL;
- }
- // 首先查找;
- NERO_ISO_ITEM *pTailPathItem = FindPathItem(strDiscPath);
- if ( pTailPathItem == NULL )
- {
- OutputDebugString(_T("\nAddItem2Path:未找到光盘指定路径元素:"));
- OutputDebugString(strDiscPath.c_str());
- 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;
- }
- return pNewItem;
- }
- /************************************************************************/
- /* 函数:[3/23/2018 Jeff];
- /* 描述:添加新目录到指定的光盘目录的兄弟链尾中;
- /* 参数:;
- /* [IN] strDiscPath:光盘目录,作为新元素兄弟链头路径;
- /* [IN] strNewPath:新目录,strDiscPath的兄弟项;
- /* [IN/OUT] :;
- /* 返回:成功返回TRUE,否则返回FALSE;
- /* 注意:;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- NERO_ISO_ITEM* CDiscItem::AddSiblingPath(IN TString strDiscPath, IN TString strNewPath)
- {
- // 首先查找;
- NERO_ISO_ITEM *pTailPathItem = FindPathItem(strDiscPath);
- if ( pTailPathItem == NULL )
- {
- OutputDebugString(_T("\nAddPath2Path:未找到光盘指定路径元素:"));
- OutputDebugString(strDiscPath.c_str());
- return NULL;
- }
- NERO_ISO_ITEM* pNewItem = CreateNeroIsoItem();
- ZeroMemory(pNewItem,sizeof(NERO_ISO_ITEM));
- pNewItem->isDirectory = TRUE;
- pNewItem->isReference = FALSE;
- pNewItem->unicodeFileName = NULL;
- #ifdef UNICODE
- pNewItem->longFileName = _strdup(convert("UCS-2LE", "GBK", (const char*)strNewPath.c_str(), strNewPath.size() * sizeof(TCHAR)).c_str());
- #else
- pNewItem->longFileName = _strdup(strNewPath.c_str());
- #endif
- //sprintf_s(pNewItem->fileName, "%s", strNewPath);
- pNewItem->subDirFirstItem = NULL;
- pNewItem->nextItem = NULL;
- while( pTailPathItem->nextItem )
- {
- pTailPathItem = pTailPathItem->nextItem;
- }
- pTailPathItem->nextItem = pNewItem;
- return pNewItem;
- }
- /************************************************************************/
- /* 函数:[3/23/2018 Jeff];
- /* 描述:添加新的目录到光盘目录中,若目录不存在,则重新创建目录元素;
- /* 参数:;
- /* [IN] strNewPath:新目录,根目录的新兄弟项;
- /* [OUT] :;
- /* [IN/OUT] :;
- /* 返回:成功返回TRUE,否则返回FALSE;
- /* 注意:该函数有问题, strNewPath,未进行验证;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- NERO_ISO_ITEM* CDiscItem::AddPath(IN TString strNewPath)
- {
- INT nIndex = 0;
- nIndex = strNewPath.find_first_of(_T(":\\"));
- if ( nIndex != TString::npos )
- strNewPath = strNewPath.substr(nIndex + 2);
- if ( strNewPath[strNewPath.size() - 1] != _T('\\') )
- strNewPath.append(_T("\\"));
- NERO_ISO_ITEM* pHeadPath = m_pVirtualItem, *pTailPath = pHeadPath->subDirFirstItem;
- do
- {
- nIndex = strNewPath.find_first_of(_T('\\'));
- if ( nIndex != TString::npos )
- {
- pTailPath = FindPathInSibling(pTailPath, strNewPath.substr(0,nIndex));
- if (!pTailPath)
- {
- break;
- }
- pHeadPath = pTailPath;
- pTailPath = pTailPath->subDirFirstItem;
- strNewPath = strNewPath.substr(nIndex + 1);
- }
- } while (nIndex != -1);
- // 根元素空;
- if ( m_pVirtualItem->subDirFirstItem == NULL )
- pHeadPath = m_pVirtualItem;
- while(strNewPath.find_first_of(_T("\\")) != TString::npos)
- {
- nIndex = strNewPath.find_first_of(_T('\\'));
- if ( nIndex != TString::npos )
- {
- pHeadPath = AddPath2Path(pHeadPath, strNewPath.substr(0,nIndex));
- strNewPath = strNewPath.substr(nIndex + 1);
- }
- }
- return pHeadPath;
- }
- /************************************************************************/
- /* 函数:[3/23/2018 Jeff];
- /* 描述:添加新目录到指定的光盘目录下;
- /* 参数:;
- /* [IN] strDiscPath:光盘目录,作为新元素要父目录;
- /* [IN] strNewPath:;
- /* [IN/OUT] :新目录,将插入到strDiscPath目录下;
- /* 返回:成功返回TRUE,否则返回FALSE;
- /* 注意:;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- NERO_ISO_ITEM* CDiscItem::AddPath2Path(IN TString strDiscPath, IN TString strNewPath)
- {
- // 首先查找;
- NERO_ISO_ITEM *pTailPathItem = FindPathItem(strDiscPath);
- if ( pTailPathItem == NULL )
- {
- OutputDebugString(_T("\nAddPath2Path:未找到光盘指定路径元素:"));
- OutputDebugString(strDiscPath.c_str());
- return NULL;
- }
- NERO_ISO_ITEM* pNewItem = CreateNeroIsoItem();
- ZeroMemory(pNewItem,sizeof(NERO_ISO_ITEM));
- pNewItem->isDirectory = TRUE;
- pNewItem->isReference = FALSE;
- pNewItem->unicodeFileName = NULL;
- #ifdef UNICODE
- pNewItem->longFileName = _strdup(convert("UCS-2LE", "GBK", (const char*)strNewPath.c_str(), strNewPath.size() * sizeof(TCHAR)).c_str());
- #else
- pNewItem->longFileName = _strdup(strNewPath.c_str());
- #endif
- //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;
- }
- return pNewItem;
- }
- /************************************************************************/
- /* 函数:[3/23/2018 Jeff];
- /* 描述:添加新目录到指定的光盘目录下;
- /* 参数:;
- /* [IN] pPathItem:光盘目录,作为新元素要父目录;
- /* [IN] strNewPath:新目录,将插入到strDiscPath目录下;
- /* [IN/OUT] :;
- /* 返回:成功返回TRUE,否则返回FALSE;
- /* 注意:;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- NERO_ISO_ITEM* CDiscItem::AddPath2Path(IN NERO_ISO_ITEM* pPathItem, IN TString strNewPath )
- {
- if ( pPathItem == NULL || pPathItem->isDirectory == FALSE )
- {
- return NULL;
- }
- NERO_ISO_ITEM* pNewItem = CreateNeroIsoItem();
- ZeroMemory(pNewItem,sizeof(NERO_ISO_ITEM));
- pNewItem->isDirectory = TRUE;
- pNewItem->isReference = FALSE;
- pNewItem->unicodeFileName = NULL;
- #ifdef UNICODE
- pNewItem->longFileName = _strdup(convert("UCS-2LE", "GBK", (const char*)strNewPath.c_str(), strNewPath.size() * sizeof(TCHAR)).c_str());
- #else
- pNewItem->longFileName = _strdup(strNewPath.c_str());
- #endif
- //sprintf_s(pNewItem->fileName, "%s", strNewPath);
- pNewItem->subDirFirstItem = NULL;
- pNewItem->nextItem = NULL;
- if ( pPathItem->subDirFirstItem == NULL )
- return pPathItem->subDirFirstItem = pNewItem;
- NERO_ISO_ITEM* pNextItem = pPathItem->subDirFirstItem;
- while( pNextItem->nextItem)
- {
- pNextItem = pNextItem->nextItem;
- }
- return pNextItem->nextItem = pNewItem;
- }
- /************************************************************************/
- /* 函数:[3/23/2018 Jeff];
- /* 描述:添加新文件到指定的光盘目录下;
- /* 参数:;
- /* [IN] strDiscPath:光盘目录,作为新元素的父目录;
- /* [IN] strFileName:新文件,将插入到strDiscPath目录下;
- /* [IN/OUT] :;
- /* 返回:成功返回TRUE,否则返回FALSE;
- /* 注意:;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- NERO_ISO_ITEM* CDiscItem::AddFile2Path(IN TString strDiscPath, IN TString strFileName)
- {
- // 首先查找;
- NERO_ISO_ITEM *pTailPathItem = FindPathItem(strDiscPath);
- if ( pTailPathItem == NULL )
- {
- pTailPathItem = AddPath(strDiscPath);
- if ( pTailPathItem == NULL )
- {
- OutputDebugString(_T("\nAddFile2Path:未找到光盘指定路径元素:"));
- OutputDebugString(strDiscPath.c_str());
- return NULL;
- }
- }
- NERO_ISO_ITEM* pNewItem = CreateNeroIsoItem();
- ZeroMemory(pNewItem, sizeof(NERO_ISO_ITEM));
- pNewItem->isDirectory = FALSE;
- pNewItem->isReference = FALSE;
- pNewItem->unicodeFileName = NULL;
- TCHAR* name;
- TCHAR path[MAX_PATH];
- GetFullPathName(strFileName.c_str(), MAX_PATH, path, &name);
- #ifdef UNICODE
- pNewItem->longFileName = _strdup(convert("UCS-2LE", "GBK", (const char*)name, _tcslen(name) * sizeof(TCHAR)).c_str());
- pNewItem->longSourceFilePath = _strdup(convert("UCS-2LE", "GBK", (const char*)path, _tcslen(path) * sizeof(TCHAR)).c_str());
- #else
- pNewItem->longFileName = _strdup(name);
- pNewItem->longSourceFilePath = _strdup(path);
- #endif
- //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;
- }
- return pNewItem;
- }
- NERO_ISO_ITEM* CDiscItem::AddFile2Path(IN NERO_ISO_ITEM* pPathItem, IN TString strFileName)
- {
- if ( pPathItem == NULL && !pPathItem->isDirectory)
- {
- return NULL;
- }
- NERO_ISO_ITEM* pNewItem = CreateNeroIsoItem();
- ZeroMemory(pNewItem, sizeof(NERO_ISO_ITEM));
- pNewItem->isDirectory = FALSE;
- pNewItem->isReference = FALSE;
- pNewItem->unicodeFileName = NULL;
- TCHAR* name;
- TCHAR path[MAX_PATH];
- GetFullPathName(strFileName.c_str(), MAX_PATH, path, &name);
- #ifdef UNICODE
- pNewItem->longFileName = _strdup(convert("UCS-2LE", "GBK", (const char*)name, _tcslen(name) * sizeof(TCHAR)).c_str());
- pNewItem->longSourceFilePath = _strdup(convert("UCS-2LE", "GBK", (const char*)path, _tcslen(path) * sizeof(TCHAR)).c_str());
- #else
- pNewItem->longFileName = _strdup(name);
- pNewItem->longSourceFilePath = _strdup(path);
- #endif
- //sprintf_s(pNewItem->fileName,"%s", strFileName);
- pNewItem->nextItem = NULL;
- pNewItem->subDirFirstItem = NULL;
- if ( pPathItem->subDirFirstItem )
- {
- NERO_ISO_ITEM* pNextItem = pPathItem->subDirFirstItem;
- while ( pNextItem->nextItem )
- {
- pNextItem = pNextItem->nextItem;
- }
- pNextItem->nextItem = pNewItem;
- }
- else
- {
- pPathItem->subDirFirstItem = pNewItem;
- }
- return pNewItem;
- }
- /************************************************************************/
- /* 函数:[3/23/2018 Jeff];
- /* 描述:将文件添加到指定的兄弟项中;
- /* 参数:;
- /* [IN] :;
- /* [OUT] :;
- /* [IN/OUT] :;
- /* 返回:void;
- /* 注意:;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- NERO_ISO_ITEM* CDiscItem::AddFile2SiblingItem(IN NERO_ISO_ITEM* pSiblingItem, IN TString strFileName)
- {
- if (pSiblingItem == NULL)
- {
- OutputDebugString(_T("\nAddFile2SiblingItem:树兄弟项出错!\n"));
- return NULL;
- }
- NERO_ISO_ITEM* pNewItem = CreateNeroIsoItem();
- ZeroMemory(pNewItem, sizeof(NERO_ISO_ITEM));
- pNewItem->isDirectory = FALSE;
- pNewItem->isReference = FALSE;
- TCHAR* name;
- TCHAR path[MAX_PATH];
- GetFullPathName(strFileName.c_str(), MAX_PATH, path, &name);
- #ifdef UNICODE
- pNewItem->longFileName = _strdup(convert("UCS-2LE", "GBK", (const char*)name, _tcslen(name) * sizeof(TCHAR)).c_str());
- pNewItem->longSourceFilePath = _strdup(convert("UCS-2LE", "GBK", (const char*)path, _tcslen(path) * sizeof(TCHAR)).c_str());
- #else
- pNewItem->longFileName = _strdup(name);
- pNewItem->longSourceFilePath = _strdup(path);
- #endif
- pNewItem->nextItem = NULL;
- pNewItem->subDirFirstItem = NULL;
- NERO_ISO_ITEM* pNextItem = pSiblingItem;
- while(pNextItem->nextItem)
- {
- pNextItem = pNextItem->nextItem;
- }
- pNextItem->nextItem = pNewItem;
- return pNewItem;
- }
- /************************************************************************/
- /* 函数:[3/23/2018 Jeff];
- /* 描述:查找指定的光盘目录,返回目录元素指针对象;
- /* 参数:;
- /* [IN] strDiscPath:要查找的光盘目录,格式如下:"光盘根目录\子目录1\子目录2\子目录3";
- /* [OUT] :;
- /* [IN/OUT] :;
- /* 返回:若存在该光盘目录,则返回该目录元素对象的指针(返回最后一层目录名对应的元素指针),否则返回NULL;;
- /* 注意:;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- NERO_ISO_ITEM* CDiscItem::FindPathItem( IN TString strDiscPath )
- {
- if (!strDiscPath.size())
- return NULL;
- if ( m_pVirtualItem == NULL || m_pVirtualItem->subDirFirstItem == NULL)
- return NULL;
- INT nIndex = strDiscPath.find_first_of(_T(":\\"));
- if ( nIndex != TString::npos )
- strDiscPath = strDiscPath.substr(nIndex + 2);
- if ( strDiscPath[strDiscPath.size()-1] != _T('\\') )
- strDiscPath.append(_T("\\"));
- NERO_ISO_ITEM* pHeadPath = m_pVirtualItem, *pTailPath = pHeadPath->subDirFirstItem;
- do
- {
- nIndex = strDiscPath.find_first_of(_T("\\"));
- if ( nIndex != TString::npos )
- {
- pTailPath = FindPathInSibling(pTailPath, strDiscPath.substr(0,nIndex));
- if (!pTailPath) {
- break;
- }
- pHeadPath = pTailPath;
- pTailPath = pTailPath->subDirFirstItem;
- strDiscPath = strDiscPath.substr(nIndex+1);
- }
- } while ( strDiscPath.find_first_of(_T("\\")) != -1 );
- return pHeadPath == m_pVirtualItem ? NULL : pHeadPath;
- }
- /************************************************************************/
- /* 函数:[3/23/2018 Jeff];
- /* 描述:在指定的兄弟链中(以及兄弟链中的子链),从兄弟链头元素开始查找指定目录名的元素指针;
- /* 参数:;
- /* [IN] pSiblingHeadItem:兄弟链的头元素,作为查找时的开始位置;
- /* [IN] strDiscPath:要在兄弟链中(以及兄弟链中的子链)查找的目录名(只是单层目录名)。;
- /* [IN/OUT] :;
- /* 返回:成功在兄弟链中(以及兄弟链中的子链)查找到该目录名元素,返回该元素对象指针;若未查找到,返回NULL;
- /* 注意:若兄弟链中,存在项,但是另一兄弟项的子链中也存在着同名的项,但却比另一兄弟项先找到,此时就会产生问题;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- NERO_ISO_ITEM* CDiscItem::FindPathInSibling( IN NERO_ISO_ITEM* pSiblingHeadItem, IN TString& strDiscPath )
- {
- if ( pSiblingHeadItem == NULL )
- return NULL;
- BOOL bFind = FALSE;
- NERO_ISO_ITEM* pNextItem = pSiblingHeadItem;
- do {
- if (pNextItem->isDirectory)
- {
- #ifdef UNICODE
- if ( convert("UCS-2LE", "GBK", (const char*)strDiscPath.c_str(), strDiscPath.size() * sizeof(TCHAR)).compare(pNextItem->longFileName) == 0 )
- #else
- if ( strDiscPath.compare(pNextItem->longFileName) == 0 )
- #endif
- {
- bFind = TRUE;
- break;
- }
- }
- pNextItem = pNextItem->nextItem;
- } while ( pNextItem );
- return bFind ? pNextItem : NULL;
- }
- /************************************************************************/
- /* 函数:[3/23/2018 Jeff];
- /* 描述:在指定的兄弟链中(以及兄弟链中的子链),从兄弟链头元素开始查找指定目录名的元素指针;
- /* 参数:;
- /* [IN] pSiblingHeadItem:兄弟链的头元素,作为查找时的开始位置;
- /* [IN] strDiscPath:要在兄弟链中(以及兄弟链中的子链)查找的目录名(只是单层目录名)。;
- /* [IN/OUT] :;
- /* 返回:成功在兄弟链中(以及兄弟链中的子链)查找到该目录名元素,返回该元素对象指针;若未查找到,返回NULL;
- /* 注意:先在兄弟链中查找,找不到后再到子链中查找;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- NERO_ISO_ITEM* CDiscItem::FindPathInSiblingEx( IN NERO_ISO_ITEM* pSiblingHeadItem, IN TString& strDiscPath )
- {
- if ( pSiblingHeadItem == NULL )
- return NULL;
- BOOL bFind = FALSE;
- NERO_ISO_ITEM* pNextItem = pSiblingHeadItem;
- do {
- if (pNextItem->isDirectory)
- {
- #ifdef UNICODE
- if ( convert("UCS-2LE", "GBK", (const char*)strDiscPath.c_str(), strDiscPath.size() * sizeof(TCHAR)).compare(pNextItem->longFileName) == 0 )
- #else
- if ( strDiscPath.compare(pNextItem->longFileName) == 0 )
- #endif
- {
- bFind = TRUE;
- break;
- }
- else
- {
- if ( pNextItem->subDirFirstItem )
- {
- NERO_ISO_ITEM *pResultItem = NULL;
- if ( (pResultItem = FindPathInSibling(pNextItem->subDirFirstItem, strDiscPath)) != NULL )
- {
- bFind = TRUE;
- pNextItem = pResultItem;
- break;
- }
- }
- }
- }
- pNextItem = pNextItem->nextItem;
- } while ( pNextItem );
- return bFind ? pNextItem : NULL;
- }
- /************************************************************************/
- /* 函数:[3/23/2018 Jeff];
- /* 描述:返回兄弟链中的倒数第二个元素或者最后一个;
- /* 参数:;
- /* [IN] pSiblingHeadItem:兄弟链的头元素;
- /* [OUT] :;
- /* [IN/OUT] :;
- /* 返回:返回兄弟链中的倒数第二个元素或者最后一个;
- /* 注意:当兄弟链的只有一个元素时,返回的是本身,也是最后一个;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- NERO_ISO_ITEM* CDiscItem::FindLastItemInSibling( IN NERO_ISO_ITEM* pSiblingHeadItem )
- {
- if ( pSiblingHeadItem == NULL || pSiblingHeadItem->nextItem == NULL )
- {
- return pSiblingHeadItem;
- }
- NERO_ISO_ITEM* pSiblingTail = pSiblingHeadItem;
- do
- {
- pSiblingTail = pSiblingTail->nextItem;
- }while ( pSiblingTail->nextItem );
- return pSiblingTail;
- }
- /************************************************************************/
- /* 函数:[3/23/2018 Jeff];
- /* 描述:;
- /* 参数:;
- /* [IN] :;
- /* [OUT] :;
- /* [IN/OUT] :;
- /* 返回:void;
- /* 注意:;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- void CDiscItem::DeleteIsoItemTree(NERO_ISO_ITEM *pItem)
- {
- while(pItem != NULL)
- {
- NERO_ISO_ITEM *pNexItem = pItem->nextItem;
- if ( pItem->isDirectory)
- DeleteIsoItemTree(pItem->subDirFirstItem);
- if (!pItem->isReference)
- {// 非引用项;
- 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;
- }
- else
- {
- // 引用的必须使用NeroFreeIsoItem释放;
- NeroFreeIsoItem(pItem);
- }
- pItem = pNexItem;
- }
- }
- /************************************************************************/
- /* 函数:[3/23/2018 Jeff];
- /* 描述:删除指定根结点的全部元素;
- /* 参数:;
- /* [IN] :;
- /* [OUT] :;
- /* [IN/OUT] :;
- /* 返回:void;
- /* 注意:NeroFreeIsoItemTree函数是用于释放使用CreateNeroIsoItem()创建的对象;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- void CDiscItem::RemoveAllItem( )
- {
- DeleteIsoItemTree(m_pVirtualItem);
- //NeroFreeIsoItemTree(m_pVirtualItem);//如果使用函数CreateNeroIsoItem();来创建,在这里释放;
- m_pVirtualItem = NULL;
- }
|