//this file is part of eMule
//Copyright (C)2002 Merkur ( devs@emule-project.net / http://www.emule-project.net )
//
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either
//version 2 of the License, or (at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#pragma once
#include <list>
#include "opcodes.h"

class CFileDetailDialogInterface; // NEO: MLD - [ModelesDialogs] <-- Xanatos --
class CFilePreferencesDialogInterface; // NEO: MLD - [ModelesDialogs] <-- Xanatos -- // NEO: FCFG - [FileConfiguration]  <-- Xanatos --

/*
					   CPartFile
					 /
		  CKnownFile
		/
CAbstractFile - CCollectionFile
		\
		  CSearchFile
*/

namespace Kademlia
{
	class CUInt128;
	class CEntry;
	typedef std::list<CStringW> WordList;
};

// NEO: XC - [ExtendedComments] -- Xanatos -->
struct Comment_Struct{
	uchar		m_achUserHash[16];

	CString		m_strUserName;
	CString		m_strFileName;

	uint8		m_uRating; 
	CString		m_strComment;
};
// NEO: XC END <-- Xanatos --

class CTag;

typedef CTypedPtrList<CPtrList, Kademlia::CEntry*> CKadEntryPtrList;

class CAbstractFile: public CObject
{
	DECLARE_DYNAMIC(CAbstractFile)

public:
	CAbstractFile();
	CAbstractFile(const CAbstractFile* pAbstractFile);
	virtual ~CAbstractFile();

	//const CString& GetFileName() const { return m_strFileName; }
	virtual CString GetFileName(bool forceReal = false) const { UNREFERENCED_PARAMETER(forceReal); return m_strFileName; } // NEO: PP - [PasswordProtection] <-- Xanatos --
	virtual void SetFileName(LPCTSTR pszFileName, bool bReplaceInvalidFileSystemChars = false, bool bAutoSetFileType = true); // 'bReplaceInvalidFileSystemChars' is set to 'false' for backward compatibility!

	// returns the ED2K file type (an ASCII string)
	const CString& GetFileType() const { return m_strFileType; }
	virtual void SetFileType(LPCTSTR pszFileType);

	// returns the file type which is used to be shown in the GUI
	CString GetFileTypeDisplayStr() const;

	const uchar* GetFileHash() const { return m_abyFileHash; }
	void SetFileHash(const uchar* pucFileHash);
	bool HasNullHash() const;

	EMFileSize		GetFileSize() const					{ return m_nFileSize; }
	virtual void	SetFileSize(EMFileSize nFileSize)	{ m_nFileSize = nFileSize; }
	bool			IsLargeFile() const					{ return m_nFileSize > (uint64)OLD_MAX_EMULE_FILE_SIZE; }

	uint32 GetIntTagValue(uint8 tagname) const;
	uint32 GetIntTagValue(LPCSTR tagname) const;
	bool GetIntTagValue(uint8 tagname, uint32& ruValue) const;
	uint64 GetInt64TagValue(uint8 tagname) const;
	uint64 GetInt64TagValue(LPCSTR tagname) const;
	bool GetInt64TagValue(uint8 tagname, uint64& ruValue) const;
	void SetIntTagValue(uint8 tagname, uint32 uValue);
	void SetInt64TagValue(uint8 tagname, uint64 uValue);
	const CString& GetStrTagValue(uint8 tagname) const;
	const CString& GetStrTagValue(LPCSTR tagname) const;
	void SetStrTagValue(uint8 tagname, LPCTSTR);
	CTag* GetTag(uint8 tagname, uint8 tagtype) const;
	CTag* GetTag(LPCSTR tagname, uint8 tagtype) const;
	CTag* GetTag(uint8 tagname) const;
	CTag* GetTag(LPCSTR tagname) const;
	const CArray<CTag*, CTag*>& GetTags() const { return taglist; }
	void AddTagUnique(CTag* pTag);
	void ClearTags();
	void CopyTags(const CArray<CTag*, CTag*>& tags);
	virtual bool IsPartFile() const { return false; }

	// NEO: XC - [ExtendedComments] -- Xanatos -->
	void	AddComment(Comment_Struct comment);
	void	ClearCommentList();
	const CList<Comment_Struct*>& GetCommentList() const { return m_CommentList; }
	// NEO: XC END <-- Xanatos --
	bool	HasComment() const { return m_bHasComment; }
	void	SetHasComment(bool in) { m_bHasComment = in; }
	UINT	UserRating() const { return m_uUserRating; }
	bool	HasRating()	const { return m_uUserRating > 0; }
	bool	HasBadRating()  const { return (m_uUserRating == 1); } // NEO: MOD - [CodeImprovement] <-- Xanatos --
	void	SetUserRating(UINT in) { m_uUserRating = in; }
	const CString& GetFileComment() /*const*/;
	UINT	GetFileRating() /*const*/;
	void	LoadComment();
	virtual void	UpdateFileRatingCommentAvail() { }

	// NEO: KII - [KadInterfaceImprovement] -- Xanatos -->
	uint32	GetKadFileSearchID() const { return kadFileSearchID; }
	void	SetKadFileSearchID(uint32 id) { kadFileSearchID = id; }
	// NEO: KII END <-- Xanatos --

	bool IsCompressible() const {return compressible;} // NEO: MOD - [IsCompressible] <-- Xanatos --
	bool IsCollection() const {return iscollection;} // NEO: MOD - [IsCollection] <-- Xanatos --

	bool AddNote(Kademlia::CEntry* pEntry);
	const CKadEntryPtrList& getNotes() const { return m_kadNotes; }

	virtual void GetTooltipFileInfo(CString &info); // NEO: NTT - [NewToolTips] <-- Xanatos --

	CFileDetailDialogInterface*			GetDetailDialogInterface() const { return m_DetailDialogInterface; } // NEO: MLD - [ModelesDialogs] <-- Xanatos --
	CFilePreferencesDialogInterface*	GetPreferencesDialogInterface() const { return m_PreferencesDialogInterface; } // NEO: MLD - [ModelesDialogs] <-- Xanatos -- // NEO: FCFG - [FileConfiguration]  <-- Xanatos --

#ifdef _DEBUG
	// Diagnostic Support
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:
	CString m_strFileName;
	uchar	m_abyFileHash[16];
	EMFileSize	m_nFileSize;
	CString m_strComment;
	UINT	m_uRating;
	bool	m_bCommentLoaded;
	UINT	m_uUserRating;
	bool	m_bHasComment;
	uint32	kadFileSearchID; // NEO: KII - [KadInterfaceImprovement] <-- Xanatos --
	bool	compressible; // NEO: MOD - [IsCompressible] <-- Xanatos --
	bool	iscollection; // NEO: MOD - [IsCollection] <-- Xanatos --


	// received comments list
	CList<Comment_Struct*> m_CommentList; // NEO: XC - [ExtendedComments] <-- Xanatos --
	CString m_strFileType;
	CArray<CTag*, CTag*> taglist;
	CKadEntryPtrList m_kadNotes;

	CFileDetailDialogInterface*			m_DetailDialogInterface; // NEO: MLD - [ModelesDialogs] <-- Xanatos --
	CFilePreferencesDialogInterface*	m_PreferencesDialogInterface; // NEO: MLD - [ModelesDialogs] <-- Xanatos -- // NEO: FCFG - [FileConfiguration]  <-- Xanatos --
};
