// HNode.h: interface for the HNode class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_HNODE_H__2920EBA4_6B04_4358_8960_3205660CDA26__INCLUDED_)
#define AFX_HNODE_H__2920EBA4_6B04_4358_8960_3205660CDA26__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <afxtempl.h>

#define HN_PARSEERROR	1<<0
#define HN_NOTFOUND		1<<1
#define HN_LOOP			1<<2

#include"PathManager.h"

class HNode  
{
protected:

	static HNode *Create();
	static void Delete(HNode *node);
	
	CString FName,Path;
	CArray<HNode *,HNode *> Children;
	CArray<HNode *,HNode *> Clones;
	HNode *Parent,*Original;
	DWORD Flag;
	CPathManager *PathMan;
	HTREEITEM Item;

	HNode *AddChild(HNode *child);
	HNode *NewChild() {return AddChild(Create());}
	HNode *GetParent() {return Parent;}

	bool Parse(char *fbuf);
	bool IsAbove(HNode *node);
	bool ParseLocalFile(const CString &fname,const CString &path);
	bool ParseGlobalFile(const CString &fname);
	bool IsRoot() {return Parent==NULL;};
	bool IsCopy() {return Original!=NULL;};
	void Copy(HNode *node);
	bool CopyFromTree(HNode *dest);
	bool CopyFromTreeDown(HNode *dest);
	void Destroy();
	void VerifyNode();
	HTREEITEM AddItem(CTreeCtrl *tree,HTREEITEM parent);


public:
//	static CArray<HNode,HNode &> Guff;
//	static DWORD ObjCount;

	HTREEITEM GetItem() {return Item;}
	static void Initalize() {}
	DWORD NodeCount();
	DWORD TreeSize();
	HNode *Find(const CString fname,HNode *after=NULL,bool returnnext=false);
	void DrillDownTo(CTreeCtrl *tree);
	void FillTree(CTreeCtrl *tree,HNode *stopat,HTREEITEM parent=TVI_ROOT); 
	void FillTree(CTreeCtrl *tree,HTREEITEM parent=TVI_ROOT,int level=0,int levelmax=3); 
	void FillReverseTree(CTreeCtrl *tree,HTREEITEM parent=TVI_ROOT); 
	void SetPathManager(CPathManager *pman) {PathMan=pman;}
	CString GetFullPath() {return Path+FName;}
	bool IsSameName(HNode *node) { return !(node->FName.CompareNoCase(FName) || node->Path.CompareNoCase(Path));}
	void ParseDsp(const CString &fname,const CString &path);
	bool AddLocalFile(const CString &fname,const CString &path);
	HNode();		
	virtual ~HNode();

};

#endif // !defined(AFX_HNODE_H__2920EBA4_6B04_4358_8960_3205660CDA26__INCLUDED_)
