dEngine
Simple 2D C++ game engine
Packer.h
Go to the documentation of this file.
1 #ifndef PACKER_UTIL_PACKER_H
2 #define PACKER_UTIL_PACKER_H
3 
4 #include <iostream>
5 #include <string>
6 #include <algorithm>
7 #include <fstream>
8 #include <map>
9 #include <filesystem>
10 #include <zlib.h>
11 #include <map>
12 
16 namespace packer {
20  class Packer {
21  public:
26  Packer(std::string filePath);
31  void ReadFileToBuffer(const std::filesystem::path filePath);
35  void WriteTable();
36 
37 
38  private:
42  std::map<std::string,std::string> fileLocMap;
48  std::vector<char> MapToVector();
54  bool fileExists(const std::string& filename);
59  void deleteFileIfExists(const std::string& filename);
64  std::vector<char> compressBuffer(const std::vector<char> &buffer);
65 
66  std::string outFilePath;
67  std::vector<char> buffer;
68 
73  std::string getFileType(const std::string &extension);
74  };
75 }
76 
77 #endif //PACKER_UTIL_PACKER_H
std::vector< char > buffer
Definition: Packer.h:67
Namespace consisting of the packer utility.
Definition: CLIArg.h:11
Packer(std::string filePath)
Create a new packer.
Definition: Packer.cpp:4
bool fileExists(const std::string &filename)
Checks if file exists.
Definition: Packer.cpp:143
void deleteFileIfExists(const std::string &filename)
Deletes a file if it exists.
Definition: Packer.cpp:148
void WriteTable()
Writes a table of contents to the top of the file.
Definition: Packer.cpp:64
Takes care of packing files into a .dat file.
Definition: Packer.h:20
std::string getFileType(const std::string &extension)
Get a file&#39;s type based on file extension.
Definition: Packer.cpp:115
void ReadFileToBuffer(const std::filesystem::path filePath)
Read a new file into the buffer and write to the packed file.
Definition: Packer.cpp:9
std::vector< char > compressBuffer(const std::vector< char > &buffer)
Perform lossless compression on a buffer using zlib.
Definition: Packer.cpp:130
std::string outFilePath
Definition: Packer.h:66
std::map< std::string, std::string > fileLocMap
A map containing every file in the package and it&#39;s starting location.
Definition: Packer.h:42
std::vector< char > MapToVector()
Definition: Packer.cpp:105