// MissingFilesView.cpp : implementation file
//

#include "stdafx.h"
#include "ContentTrack.h"
#include "MissingFilesView.h"
#include "NodeDataValueFileDoc.h"

#include "mainfrm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMissingFilesView

IMPLEMENT_DYNCREATE(CMissingFilesView, CListView)

CMissingFilesView::CMissingFilesView()
{
}

CMissingFilesView::~CMissingFilesView()
{
}


BEGIN_MESSAGE_MAP(CMissingFilesView, CListView)
	//{{AFX_MSG_MAP(CMissingFilesView)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMissingFilesView drawing

void CMissingFilesView::OnDraw(CDC* pDC)
{
//	CDocument* pDoc = GetDocument();
	// TODO: add draw code here
}

/////////////////////////////////////////////////////////////////////////////
// CMissingFilesView diagnostics

#ifdef _DEBUG
void CMissingFilesView::AssertValid() const
{
	CListView::AssertValid();
}

void CMissingFilesView::Dump(CDumpContext& dc) const
{
	CListView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMissingFilesView message handlers

void CMissingFilesView::OnInitialUpdate() 
{
	CListCtrl *pCtrl = &GetListCtrl();
	pCtrl->InsertColumn(0,"Missing Files",LVCFMT_LEFT,500);
	CListView::OnInitialUpdate();

	if (GetDocument()->IsKindOf(RUNTIME_CLASS(CNodeDataValueFileDoc)))
	{
		CNodeDataValueFileDoc *pDoc = (CNodeDataValueFileDoc *)GetDocument();
		CNodeDisk *pNode = pDoc->GetRootNode();
		InsertNode(pNode);
	}
}

BOOL CMissingFilesView::PreCreateWindow(CREATESTRUCT& cs) 
{
	// TODO: Add your specialized code here and/or call the base class
	cs.style |= LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS;	
	return CListView::PreCreateWindow(cs);
}

int CMissingFilesView::InsertNode(CNodeObject *pNode)
{
	int x=0;
	if (pNode->IsFile())
	{
		CNodeDataValueFile *pN = (CNodeDataValueFile *)pNode;
		if (!pN->GetNodeDisk())
		{
			CMainFrame *pFrame = (CMainFrame*)AfxGetMainWnd();
			CString str;
			pN->GetName(str);
			pFrame->SetMessageText(str);
			x++;
			CListCtrl *pCtrl = &GetListCtrl();
			CString name1;
			CNodeObject *pParent = pNode->GetParentNode();
			while (pParent && !pParent->IsFile())
				pParent = pParent->GetParentNode();
			if (pParent)
			{
				CNodeDisk *pDisk = ((CNodeDataValueFile *)pParent)->GetNodeDisk();
				name1 = pDisk->GetPath()+"->";
			}
			pCtrl->InsertItem(pCtrl->GetItemCount(),name1+str);
		}
	}
	POSITION pos = pNode->GetFirstChild();
	while (pos)
	{
		CNodeDisk *pChild = (CNodeDisk *)pNode->GetNextChild(pos);
		x+= InsertNode(pChild);
	}
	return x;
}