1 /*
2  * Copyright (C) 2015-2017, by Laszlo Szeremi under the Boost license.
3  *
4  * Pixel Perfect Engine, data compression module
5  */
6 module PixelPerfectEngine.system.dat;
7 
8 import std.stdio;
9 import std.file;
10 import std.zlib;
11 
12 /**
13  * Stores compressed data on the hard drive to save storage space. Currently have a low-priority, not yet implemented.
14  */ 
15 
16 public class DatFile{
17 	private string fileName;
18 	private void[] dataBuffer;
19 	private DatFileHeader header;
20 
21 	public this(string file){
22 		fileName = file;
23 	}
24 
25 	/*public void load(){
26 		dataBuffer = uncompress(std.file.read(fileName));
27 
28 		header.headerLenght = cast(uint)dataBuffer[0..3];
29 		int j = -1;
30 		string s;
31 		for(int i = 4; i < header.headerLenght; i++){
32 			if(cast(ubyte)dataBuffer[i] == 255 && j == -1){
33 				header.fileName ~= s;
34 				j++;
35 			}
36 			if(j++ != -1){
37 				if(j == 0){
38 					header.filePos[s] = cast(uint)dataBuffer[i..i+4];
39 				}
40 				else if(j == 4){
41 					header.fileLenght[s] = cast(uint)dataBuffer[i..i+4];
42 				}
43 				j++;
44 				if(j == 8){
45 					j = -1;
46 					s = "";
47 				}
48 			}
49 			else{
50 				s ~= cast(char)dataBuffer[i];
51 			}
52 		}
53 	}*/
54 
55 	public void[] getFile(string name){
56 		return dataBuffer[header.filePos[name] .. header.fileLenght[name]];
57 	}
58 }
59 
60 protected struct DatFileHeader{
61 	public uint headerLenght;
62 	public uint[string] fileLenght, filePos;
63 	public string[] fileName;
64 
65 	//public this();
66 }