#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; }