Skip to content

Commit

Permalink
优化导出逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonflylee committed Nov 25, 2017
1 parent 9156d68 commit b57c62f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 44 deletions.
18 changes: 13 additions & 5 deletions src/Assembly.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@
#define _ASSEMBLY_TREE_H_

class CAssemblyNode;
typedef ATL::CSimpleMap<CAtlString, CComPtr<CAssemblyNode> > CAssemblyMap;
template<> class CElementTraits<CComPtr<CAssemblyNode>> : public CElementTraitsBase<CComPtr<CAssemblyNode>>
{
public:
typedef CAssemblyNode * INARGTYPE;
typedef CAssemblyNode * OUTARGTYPE;
};

typedef ATL::CSimpleMap<CAtlString, CComPtr<CAssemblyNode>> CAssemblyMap;
typedef CAtlArray<CComPtr<CAssemblyNode>> CAssemblyList;
typedef ATL::CSimpleMap<CAssemblyNode *, HTREEITEM> CAssemblySet;

class CAssemblyNode : public IUnknown
Expand All @@ -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; }
Expand Down
50 changes: 21 additions & 29 deletions src/MainDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -210,9 +210,9 @@ LRESULT CMainDlg::OnClick(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)
::PathCombine(szWinSxS, nodeRoot.szName, TEXT("WinSxS\\Manifests"));
CAssemblyNode *pAssembly = reinterpret_cast<CAssemblyNode *>(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);
Expand All @@ -228,7 +228,6 @@ LRESULT CMainDlg::OnClick(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)
::FindClose(hFind);
}
}

return S_OK;
}

Expand All @@ -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;
Expand All @@ -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);
}

Expand Down
33 changes: 23 additions & 10 deletions src/SxsScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<IXMLDOMNodeList> pList;
HRESULT hr = pRoot->selectNodes(queryString, &pList);
Expand All @@ -72,7 +72,7 @@ HRESULT CreateList(IXMLDOMElement* pRoot, BSTR queryString, CAssemblyMap& nodeMa
CComPtr<CAssemblyNode> pAssembly = new CAssemblyNode();
if (SUCCEEDED(CreateNode(pNode, pAssembly)))
{
nodeMap.Add(pAssembly->szName, pAssembly);
nodeList.Add(pAssembly);
}
}
}
Expand All @@ -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<LPARAM>(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);
}
}

Expand Down Expand Up @@ -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);
}
}
}
Expand All @@ -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);
}

// 插入根节点
Expand Down

0 comments on commit b57c62f

Please sign in to comment.