#pragma once
#include "BaseFile.h"

constexpr auto bufSize = 256;

class CBKASCFile :
	public CBaseFile
{
		bool m_bEof;
		int m_nInternalBlockNumber;
		int m_nInternalPos;
		std::wstring m_strInternalAscName;
		std::wstring m_strInternalCurrentName;
		void MakeintenalCurrentName();
		bool OpenInternalFile();

		char m_pWrBuf[bufSize];
		bool m_bFlushed;

	public:
		CBKASCFile(const std::wstring &strName);
		virtual ~CBKASCFile() override;

		virtual bool Open(bool bWrite) override; // открытие файла, имя которого задано в конструкторе
		virtual wchar_t ReadChar() override;
		virtual bool WriteChar(wchar_t tch) override;
		virtual bool WriteWord(uint16_t w);
		virtual long GetPos() override
		{
			if (m_f)
			{
				return ftell(m_f) - 4;
			}

			return 0;
		}
		virtual int SetPos(long pos, long mode) override
		{
			if (m_f)
			{
				return fseek(m_f, pos + 4, mode);
			}

			return 0;
		}
		virtual bool isEOF() override
		{
			return m_bEof;
		}
		bool FlushInternalWrBuff();

};

void TXT2ASC(CBaseFile *pInFile, CBaseFile *pOutFile);
