diff --git a/src/Assembly.h b/src/Assembly.h index 49c0fd0..fd0d905 100644 --- a/src/Assembly.h +++ b/src/Assembly.h @@ -2,7 +2,15 @@ #define _ASSEMBLY_TREE_H_ class CAssemblyNode; -typedef ATL::CSimpleMap > CAssemblyMap; +template<> class CElementTraits> : public CElementTraitsBase> +{ +public: + typedef CAssemblyNode * INARGTYPE; + typedef CAssemblyNode * OUTARGTYPE; +}; + +typedef ATL::CSimpleMap> CAssemblyMap; +typedef CAtlArray> CAssemblyList; typedef ATL::CSimpleMap CAssemblySet; class CAssemblyNode : public IUnknown @@ -17,10 +25,10 @@ class CAssemblyNode : public IUnknown // 选中状态 BOOL bCheck; CAssemblySet Parent; - CAssemblyMap Depend; - CAssemblyMap Package; - CAssemblyMap Component; - CAssemblyMap Driver; + CAssemblyList Depend; + CAssemblyList Package; + CAssemblyList Component; + CAssemblyList Driver; public: STDMETHOD(QueryInterface)(REFIID /*riid*/, void ** /*ppv*/) { return E_NOTIMPL; } diff --git a/src/MainDlg.cpp b/src/MainDlg.cpp index 5999b8e..a96b741 100644 --- a/src/MainDlg.cpp +++ b/src/MainDlg.cpp @@ -182,9 +182,9 @@ LRESULT CMainDlg::OnChanged(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/) if (bChecked == pNode->bCheck) return S_OK; // 树节点级联选中 pNode->bCheck = bChecked; - for (int i = 0; i < pNode->Package.GetSize(); i++) + for (size_t i = 0; i < pNode->Package.GetCount(); i++) { - CAssemblyNode *pChild = pNode->Package.GetValueAt(i); + CAssemblyNode *pChild = pNode->Package.GetAt(i); for (int j = 0; j < pChild->Parent.GetSize(); j++) { TreeView_SetCheckState(pnmh->hwndFrom, pChild->Parent.GetValueAt(j), bChecked); @@ -210,9 +210,9 @@ LRESULT CMainDlg::OnClick(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/) ::PathCombine(szWinSxS, nodeRoot.szName, TEXT("WinSxS\\Manifests")); CAssemblyNode *pAssembly = reinterpret_cast(tvi.lParam); - for (int i = 0; i < pAssembly->Component.GetSize(); i++) + for (size_t i = 0; i < pAssembly->Component.GetCount(); i++) { - CAssemblyNode *pNode = pAssembly->Component.GetValueAt(i); + CAssemblyNode *pNode = pAssembly->Component.GetAt(i); CAtlString szPackage = pNode->szName.GetLength() < 40 ? pNode->szName : pNode->szName.Left(19) + TEXT("..") + pNode->szName.Right(19); _stprintf_s(szSearch, _countof(szSearch), TEXT("%s\\%s_%s_%s_%s_*.manifest"), szWinSxS, (PCTSTR)pNode->szArch, (PCTSTR)szPackage.MakeLower(), (PCTSTR)pNode->szToken, (PCTSTR)pNode->szVersion); @@ -228,7 +228,6 @@ LRESULT CMainDlg::OnClick(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/) ::FindClose(hFind); } } - return S_OK; } @@ -240,29 +239,6 @@ LRESULT CMainDlg::OnContext(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/ return ::TrackPopupMenu(::GetSubMenu(m_hMenu, 0), TPM_LEFTALIGN | TPM_LEFTBUTTON, pt.x, pt.y, 0, m_hWnd, NULL); } -/** -* 递归导出包名列表 -*/ -void RecurveExport(CAssemblyNode *pParent, HANDLE hFile) -{ - CHAR szName[MAX_PATH + 2]; - for (int i = 0; i < pParent->Package.GetSize(); i++) - { - CAssemblyNode *pNode = pParent->Package.GetValueAt(i); - if (NULL == pNode) continue; - - if (pNode->bCheck) - { - DWORD cbLen = (DWORD)sprintf_s(szName, _countof(szName), "%ws\r\n", (LPCTSTR)pNode->szName); - ::WriteFile(hFile, szName, cbLen, &cbLen, NULL); - } - else if (pNode->Package.GetSize() > 0) - { - RecurveExport(pNode, hFile); - } - } -} - LRESULT CMainDlg::OnExport(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { CAtlString szFilter; @@ -286,7 +262,23 @@ LRESULT CMainDlg::OnExport(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, return MessageBox(szFilter, CMainDlg::GetWndCaption(), MB_ICONERROR); } - RecurveExport(&nodeRoot, hFile); + CHAR szName[MAX_PATH + 2]; + for (int i = 0; i < mapPackage.GetSize(); i++) + { + CAssemblyNode *pNode = mapPackage.GetValueAt(i); + if (pNode->bCheck) + { + BOOL bCheck = TRUE; + for (int j = 0; j < pNode->Parent.GetSize(); j++) if (pNode->Parent.GetKeyAt(j)->bCheck) bCheck = FALSE; + for (size_t j = 0; j < pNode->Depend.GetCount(); j++) if (pNode->Depend.GetAt(j)->bCheck) bCheck = FALSE; + if (bCheck) + { + DWORD cbLen = (DWORD)sprintf_s(szName, _countof(szName), "%ws\r\n", (LPCTSTR)pNode->szName); + ::WriteFile(hFile, szName, cbLen, &cbLen, NULL); + } + } + } + return ::CloseHandle(hFile); } diff --git a/src/SxsScan.cpp b/src/SxsScan.cpp index 49ccb67..c0fbbf5 100644 --- a/src/SxsScan.cpp +++ b/src/SxsScan.cpp @@ -53,7 +53,7 @@ HRESULT CreateNode(IXMLDOMNode *pNode, CAssemblyNode *pAssembly) /** * 查找多个元素 */ -HRESULT CreateList(IXMLDOMElement* pRoot, BSTR queryString, CAssemblyMap& nodeMap) +HRESULT CreateList(IXMLDOMElement* pRoot, BSTR queryString, CAssemblyList& nodeList) { CComPtr pList; HRESULT hr = pRoot->selectNodes(queryString, &pList); @@ -72,7 +72,7 @@ HRESULT CreateList(IXMLDOMElement* pRoot, BSTR queryString, CAssemblyMap& nodeMa CComPtr pAssembly = new CAssemblyNode(); if (SUCCEEDED(CreateNode(pNode, pAssembly))) { - nodeMap.Add(pAssembly->szName, pAssembly); + nodeList.Add(pAssembly); } } } @@ -89,15 +89,15 @@ void CMainDlg::RecurveInsert(HTREEITEM hParent, CAssemblyNode *pParent) tvi.hInsertAfter = TVI_SORT; tvi.item.mask = TVIF_TEXT | TVIF_PARAM; - for (int i = 0; i < pParent->Package.GetSize(); i++) + for (size_t i = 0; i < pParent->Package.GetCount(); i++) { - CAssemblyNode *pChild = pParent->Package.GetValueAt(i); + CAssemblyNode *pChild = pParent->Package.GetAt(i); tvi.item.pszText = pChild->szName.GetBuffer(); tvi.item.lParam = reinterpret_cast(pChild); HTREEITEM hItem = TreeView_InsertItem(m_tree, &tvi); pChild->Parent.SetAt(pParent, hItem); // 添加到搜索容器 - if (pChild->Package.GetSize() > 0) RecurveInsert(hItem, pChild); + if (pChild->Package.GetCount() > 0) RecurveInsert(hItem, pChild); } } @@ -156,17 +156,30 @@ DWORD CALLBACK CMainDlg::ThreadScan(LPVOID lpParam) for (int i = 0; i < pDlg->mapPackage.GetSize(); i++) { CAssemblyNode *pChild, *pParent = pDlg->mapPackage.GetValueAt(i); - for (int j = 0; j < pParent->Package.GetSize(); j++) + for (size_t j = 0; j < pParent->Package.GetCount(); j++) { - while (NULL == (pChild = pDlg->mapPackage.Lookup(pParent->Package.GetKeyAt(j)))) + while (NULL == (pChild = pDlg->mapPackage.Lookup(pParent->Package.GetAt(j)->szName))) { pParent->Package.RemoveAt(j); - if (j >= pParent->Package.GetSize()) break; + if (j >= pParent->Package.GetCount()) break; } if (NULL != pChild) { pChild->Parent.Add(pParent, NULL); - pParent->Package.SetAtIndex(j, pChild->szName, pChild); + pParent->Package.SetAt(j, pChild); + } + } + + for (size_t j = 0; j < pParent->Depend.GetCount(); j++) + { + while (NULL == (pChild = pDlg->mapPackage.Lookup(pParent->Depend.GetAt(j)->szName))) + { + pParent->Depend.RemoveAt(j); + if (j >= pParent->Depend.GetCount()) break; + } + if (NULL != pChild) + { + pParent->Depend.SetAt(j, pChild); } } } @@ -175,7 +188,7 @@ DWORD CALLBACK CMainDlg::ThreadScan(LPVOID lpParam) for (int i = 0; i < pDlg->mapPackage.GetSize(); i++) { CAssemblyNode *pNode = pDlg->mapPackage.GetValueAt(i); - if (pNode->Parent.GetSize() == 0) pDlg->nodeRoot.Package.Add(pNode->szName, pNode); + if (pNode->Parent.GetSize() == 0) pDlg->nodeRoot.Package.Add(pNode); } // 插入根节点