//
//  Copyright © 2001 - 2002, RESON Inc. All Rights Reserved.
//
//  No part of this file may be reproduced or transmitted in any form or by
//  any means, electronic or mechanical, including photocopy, recording, or
//  information storage or retrieval system, without permission in writing
//  from RESON Inc.
//
//  Filename:   7kFile.h
//
//  Project:    6046.
//
//  Author(s):  W. Arcus
//
//  Purpose:    
//
//  Notes:
//

#if !defined(AFX_7KFILE_H__814C7B7C_9BE1_4405_879B_7046C7CD91C0__INCLUDED_)
#define AFX_7KFILE_H__814C7B7C_9BE1_4405_879B_7046C7CD91C0__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class EXPORT_DLL C7kFile
{
public:

    typedef enum tag7kFILEMODE
    {
        accessModeRead                = 0,
        accessModeWrite
    }
    EACCESSMODE;

    typedef enum tag7KFILEERROR
    {
        errorNone                   = 0,
        errorInvalidParameter,
        errorInvalidFileName,
        errorInvalidHandle,
        errorFileSeek,
        errorUnspecifiedException,
        errorOpen,
        errorWrite,
        errorRead
    }
    E7KFILEERROR;

    // Services.

                        C7kFile             (   void );
    virtual            ~C7kFile             (   void );

    // File operations.
                    
    bool                Open                (   LPCTSTR             lpszFileName    = NULL,
                                                const EACCESSMODE  &reAccessMode    = accessModeRead );

    bool                Close               (   void );

    // Record operations.

    bool                Write               (   BYTE                *pbyRecord,
                                                const unsigned long &rulBytesToWrite );

    bool                Read                (   BYTE                *pbyRecord,
                                                unsigned long       &rulBytesRead,
                                                const unsigned long &rulMaxBufferSize,
                                                const bool          &rbUseChecksum  = false );

    bool                Flush               (   void );

    double              FileSize            (   void );

    bool                IsFileOpen          (   void )  const;

    // State retrieval.

    LPCTSTR             FileName            (   void )  const;
    E7KFILEERROR        GetLastError        (   void )  const;
    LPCTSTR             GetVersion          (   void )  const;

    // General static helpers.

    static CString      BuildDefaultFileName(   void );

    static bool         IsFileNameValid     (   LPCTSTR             lpszFileName );

private:

    // Attributes.

    E7KFILEERROR        m_eLastError;

    HANDLE              m_hFile;
    CString             m_FileName;

    const char         *m_pszVersion;

    // Services.

                        C7kFile             (   const   C7kFile     &rRhs );        // Not implemented for now.
    C7kFile &           operator    =       (   const   C7kFile     &rRhs );        // Not implemented for now.

    bool                IsValidFileHandle   (   void ) const;
    bool                IsInvalidFileHandle (   void ) const;

    void                SetEndOfFile        (   void );
    void                SetBeginningOfFile  (   void );

};

#endif // !defined(AFX_7KFILE_H__814C7B7C_9BE1_4405_879B_7046C7CD91C0__INCLUDED_)
