From e33e19d0587146859d48a134ec9fd94e7b7ba5cd Mon Sep 17 00:00:00 2001 From: "FWoltermann@gmail.com" Date: Thu, 8 Dec 2011 14:53:40 +0000 Subject: Initial upload --- Datafile/Archive.h | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 Datafile/Archive.h (limited to 'Datafile/Archive.h') diff --git a/Datafile/Archive.h b/Datafile/Archive.h new file mode 100644 index 0000000..f3ec099 --- /dev/null +++ b/Datafile/Archive.h @@ -0,0 +1,83 @@ +/* Project nGen + John DiCamillo Software Consulting + Copyright © 1997. All Rights Reserved. + + SUBSYSTEM: DataFile.exe + FILE: Archive.hpp + AUTHOR: John DiCamillo + +*/ + +#ifndef ARCHIVE_HPP +#define ARCHIVE_HPP + +// +------------------------------------------------------------------+ + +#define VERSION 0x0010 +#define BLOCK_SIZE 1024 +#define MAX_FILES 4096 +#define FILE_BLOCK 1024 +#define NAMELEN 64 + +// +------------------------------------------------------------------+ + +struct DataHeader +{ + DWORD version; + DWORD nfiles; + DWORD dir_blocks; + DWORD dir_size_comp; + DWORD dir_offset; +}; + +struct DataEntry +{ + char name[NAMELEN]; + DWORD size_orig; + DWORD size_comp; + DWORD offset; +}; + +class DataArchive +{ +public: + // ctor: + DataArchive(const char* name = 0); + ~DataArchive(); + + // operations: + void LoadDatafile(const char* name); + void Insert(const char* name); + void Extract(const char* name); + void Remove(const char* name); + void List(); + + void WriteEntry(int index, BYTE* buf); + int FindEntry(const char* req_name); + int ExpandEntry(int index, BYTE*& buf); + BYTE* CompressEntry(int index); + int InsertEntry(const char* name); + void RemoveEntry(int index); + DWORD Blocks(DWORD raw_size); + DWORD DirBlocks(); + DWORD FileBlocks(int index); + int FindDataBlocks(int blocks_needed); + void CreateBlockMap(); + + DWORD NumFiles() { return header.nfiles; } + DataEntry* GetFile(int i) { if (i>=0 && i<(int)header.nfiles) return &directory[i]; return 0; } + +private: + // persistent data members: + DataHeader header; + DataEntry directory[MAX_FILES]; + BYTE* dirbuf; + + // transient members: + char datafile[NAMELEN]; + + DWORD* block_map; + DWORD nblocks; +}; + +#endif -- cgit v1.1