#ifndef FILES_FILES_H
#define FILES_FILES_H TRUE

/*
**   $VER: files.h V0.9B
**
**   File definitions.
**
**   (C) Copyright 1996-1997 DreamWorld Productions.
**       All Rights Reserved.
*/

#ifndef DPKERNEL_H
#include <games/dpkernel.h>
#endif

/****************************************************************************
** Module information.
*/

#define FileModVersion  0
#define FileModRevision 9

/****************************************************************************
** Mini structures for source and destination operations.
*/

struct Source {      /* Source structure, for internal use only */
  WORD ID;
  APTR Src;
};

struct FileName {    /* Filename structure */
  WORD ID;           /* ID_FILENAME */
  BYTE *Name;        /* Pointer to filename */
};

struct MemPtr {      /* Memory location structure */
  WORD ID;           /* ID_MEMPTR */
  APTR Address;      /* Pointer to memory area */
  LONG Size;         /* Must supply a size unless you are a MemBlock */
};

/****************************************************************************
** File Object.
*/

#define FILEVERSION 1
#define TAGS_FILE   ((ID_SPCTAGS<<16)|ID_FILE)

struct File {
  struct Head Head;       /* 00: Standard structure header */
  LONG   BytePos;         /* 12: Current position in file */
  LONG   Size;            /* 16: Total size of the file */
  LONG   Flags;           /* 20: File opening flags */
  struct Head *Source;    /* 24: Direct pointer to the original Source structure */
  struct File *Prev;      /* 28: Previous file in chain */
  struct File *Next;      /* 32: Next file in chain */
  BYTE   *Comment;        /* 36: Pointer to comment string */
  struct Time *Date;      /* 40: Set at time of creation */
  LONG   Permissions;     /* 44: User permission flags */

  /*** Private fields start now ***/

  LONG   prvHandle;
  LONG   prvKey;
  LONG   prvLastPos;
  WORD   prvAFlags;
};

/* File tags */

#define FLA_BytePos (TLONG|12)
#define FLA_Size    (TLONG|16)
#define FLA_Flags   (TLONG|20)
#define FLA_Source  (TAPTR|24)
#define FLA_Prev    (TAPTR|28)
#define FLA_Next    (TAPTR|32)
#define FLA_Comment (TAPTR|36)
#define FLA_Date    (TAPTR|40)

/****************************************************************************
** Opening flags for Files and Directories.
*/

#define FL_OLDFILE 0
#define FL_WRITE    (1L<<0)
#define FL_LOCK     (1L<<1)
/*#define FL_NEW    (1L<<2)*/
#define FL_FIND     (1L<<3)
#define FL_NOUNPACK (1L<<4)
#define FL_NOPACK   (1L<<4)
#define FL_NOBUFFER (1L<<5)
#define FL_NEWFILE  (1L<<6)
#define FL_READ     ((0)|FL_OLDFILE)

/****************************************************************************
** Permission flags for Files and Directories.
*/

#define FPT_READ     0x00000001
#define FPT_WRITE    0x00000002
#define FPT_EXECUTE  0x00000004
#define FPT_DELETE   0x00000008
#define FPT_SCRIPT   0x00000010
#define FPT_HIDDEN   0x00000020
#define FPT_ARCHIVE  0x00000040
#define FPT_PASSWORD 0x00000080

/****************************************************************************
** Directory Object.  The format/version of the DirEntry and FileEntry
** structures is dependent on the directory version.
*/

#define DIRVERSION     1
#define TAGS_DIRECTORY (ID_SPCTAGS<<16)|ID_DIRECTORY

struct Directory {
  struct Head Head;             /* 00: Standard header */
  struct Directory *ChildDir;   /* 12: First directory in list */
  struct File      *ChildFile;  /* 16: First file in list */
  struct FileName  *Source;     /* 20: Location and Name of this directory */
  LONG   Flags;                 /* 24: Opening Flags (see file flags) */
  BYTE   *Comment;              /* 28: Pointer to comment string */
  LONG   Permissions;           /* 32: User Flags */
  struct Time *Date;            /* 36: Set to time of creation */
  struct Directory *Next;       /* 40: Next directory in this list */
  struct Directory *Prev;       /* 44: Previous directory in this list */

  /*** Private fields ***/

  WORD   prvAFlags;
};

#define DIRA_Source      (TAPTR|20)
#define DIRA_Flags       (TLONG|24)
#define DIRA_Comment     (TAPTR|28)
#define DIRA_Permissions (TLONG|32)
#define DIRA_Date        (TAPTR|36)

#endif /* FILES_FILES_H */

