Skip to content

Commit c8354f3

Browse files
authored
Merge pull request #2 from Creative-Rift/feature/unpack
Feature/unpack
2 parents 8fbd36e + 45d24b7 commit c8354f3

16 files changed

Lines changed: 300 additions & 44 deletions

File tree

cmake/Packer.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@ set( SRC_FOLDERS
99
${CMAKE_CURRENT_SOURCE_DIR}/sources/
1010
${CMAKE_CURRENT_SOURCE_DIR}/sources/file/
1111
${CMAKE_CURRENT_SOURCE_DIR}/sources/pack/
12+
${CMAKE_CURRENT_SOURCE_DIR}/sources/log/
13+
${CMAKE_CURRENT_SOURCE_DIR}/sources/exception/
14+
${CMAKE_CURRENT_SOURCE_DIR}/sources/utils/
1215
)
1316
## INCLUDE FOLDERS
1417
set( INC_FOLDERS
1518
${CMAKE_CURRENT_SOURCE_DIR}/includes/
1619
${CMAKE_CURRENT_SOURCE_DIR}/includes/file/
1720
${CMAKE_CURRENT_SOURCE_DIR}/includes/pack/
21+
${CMAKE_CURRENT_SOURCE_DIR}/includes/log/
22+
${CMAKE_CURRENT_SOURCE_DIR}/includes/exception/
1823
)
1924

2025
## GET SOURCES

cmake/UnPacker.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@ set( SRC_FOLDERS
99
${CMAKE_CURRENT_SOURCE_DIR}/sources/
1010
${CMAKE_CURRENT_SOURCE_DIR}/sources/file/
1111
${CMAKE_CURRENT_SOURCE_DIR}/sources/unpack/
12+
${CMAKE_CURRENT_SOURCE_DIR}/sources/exception/
13+
${CMAKE_CURRENT_SOURCE_DIR}/sources/utils/
14+
${CMAKE_CURRENT_SOURCE_DIR}/sources/log/
1215
)
1316
## INCLUDE FOLDERS
1417
set( INC_FOLDERS
1518
${CMAKE_CURRENT_SOURCE_DIR}/includes/
1619
${CMAKE_CURRENT_SOURCE_DIR}/includes/file/
1720
${CMAKE_CURRENT_SOURCE_DIR}/includes/unpack/
21+
${CMAKE_CURRENT_SOURCE_DIR}/includes/exception/
22+
${CMAKE_CURRENT_SOURCE_DIR}/includes/log/
1823
)
1924

2025
## GET SOURCES
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
** ShipWreck Engine , 2023
3+
** FileException.hpp
4+
*/
5+
6+
#ifndef SW_PACKER_FILEEXCEPTION_HPP
7+
#define SW_PACKER_FILEEXCEPTION_HPP
8+
9+
#include <exception>
10+
#include <string>
11+
12+
namespace sw
13+
{
14+
class FileException : public std::exception
15+
{
16+
private:
17+
std::string m_reason;
18+
public:
19+
explicit FileException(std::string&& reason);
20+
[[nodiscard]] const char *what() const override;
21+
};
22+
}
23+
24+
#endif //SW_PACKER_FILEEXCEPTION_HPP
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
** ShipWreck Engine , 2023
3+
** MemoryException.hpp
4+
*/
5+
6+
#ifndef SW_PACKER_MEMORYEXCEPTION_HPP
7+
#define SW_PACKER_MEMORYEXCEPTION_HPP
8+
9+
#include <exception>
10+
#include <string>
11+
12+
namespace sw {
13+
14+
class MemoryException : public std::exception
15+
{
16+
private:
17+
std::string m_message;
18+
public:
19+
explicit MemoryException(std::string message);
20+
[[nodiscard]]const char * what() const override;
21+
};
22+
23+
} // sw
24+
25+
#endif //SW_PACKER_MEMORYEXCEPTION_HPP

includes/file/File.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
#include "Chunk.hpp"
1414

15+
#define FILE_TYPE "SWFP"
16+
#define FILE_VERSION 100
17+
1518
namespace sw {
1619

1720
/// \brief Define the type of the file

includes/log/Log.hpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
** ShipWreck Engine , 2023
3+
** Log.hpp
4+
*/
5+
6+
#ifndef SW_PACKER_LOG_HPP
7+
#define SW_PACKER_LOG_HPP
8+
9+
#include <vector>
10+
#include <string>
11+
#include <map>
12+
13+
namespace sw {
14+
15+
class Log {
16+
public:
17+
enum Level {
18+
NONE,
19+
DEBUG,
20+
WARNING,
21+
ERROR,
22+
};
23+
static void AddLog(std::string&& message, Level logLevel = DEBUG);
24+
static void CloseLog();
25+
26+
private:
27+
static std::vector<std::string> m_logs;
28+
static std::map<Level, std::string> m_levels;
29+
};
30+
31+
} // sw
32+
33+
#endif //SW_PACKER_LOG_HPP

includes/unpack/UnPackFile.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@
88

99
#include <string>
1010

11+
#include "Chunk.hpp"
12+
1113
namespace sw {
1214

1315
class UnPackFile {
1416
public:
15-
explicit UnPackFile(std::string path);
17+
explicit UnPackFile(std::string path, std::string outputPath = "./");
1618
private:
19+
std::fstream m_file;
1720

21+
void readChunk(std::string& outputPath);
22+
void createFile(sw::chunkHeader &chunkHeader, std::string path, std::string& outputPath);
1823
};
1924

2025
} // sw

includes/utils.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
** ShipWreck Engine , 2023
3+
** utils.hpp
4+
*/
5+
6+
#ifndef SW_PACKER_UTILS_HPP
7+
#define SW_PACKER_UTILS_HPP
8+
9+
namespace sw {
10+
11+
void *MemAlloc(size_t size);
12+
13+
}
14+
15+
#endif //SW_PACKER_UTILS_HPP
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
** ShipWreck Engine , 2023
3+
** FileException.cpp
4+
*/
5+
6+
#include "FileException.hpp"
7+
8+
sw::FileException::FileException(std::string&& reason) :
9+
m_reason(reason)
10+
{}
11+
12+
const char *sw::FileException::what() const
13+
{
14+
return m_reason.c_str();
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
** ShipWreck Engine , 2023
3+
** MemoryException.cpp
4+
*/
5+
6+
#include "MemoryException.hpp"
7+
8+
sw::MemoryException::MemoryException(std::string message) :
9+
m_message(message)
10+
{}
11+
12+
const char *sw::MemoryException::what() const
13+
{
14+
return m_message.c_str();
15+
}

0 commit comments

Comments
 (0)