1010#include " Packer.hpp"
1111#include " csc32.hpp"
1212#include " File.hpp"
13+ #include " FileException.hpp"
14+ #include " utils.hpp"
15+ #include " Log.hpp"
1316
1417std::string sw::Packer::path{};
1518
@@ -40,19 +43,19 @@ void sw::Packer::createChunkData(std::string path, sw::chunkHeader& header, sw::
4043{
4144 std::ifstream file (path, std::ios::binary | std::ios::ate);
4245 if (!file.is_open ())
43- throw std::exception ( );
46+ throw sw::FileException ( " Cannot open target file: " + path );
4447 std::streamsize size = file.tellg ();
4548 std::vector<char > buffer (size);
4649
4750 file.seekg (0 , std::ios::beg);
4851 file.read (buffer.data (), size);
4952
50- data.path = (char *)std::malloc (path.size () - sw::Packer::path.size () + 1 );
53+ data.path = (char *)sw::MemAlloc (path.size () - sw::Packer::path.size () + 1 );
5154 std::memset (data.path , ' \0 ' , path.size () - sw::Packer::path.size () + 1 );
5255 std::memcpy (data.path , path.data () + sw::Packer::path.size (), path.size () - sw::Packer::path.size ());
5356 data.pathCount = path.size () - sw::Packer::path.size ();
5457 fillProps (data);
55- data.data = std::malloc (size);
58+ data.data = sw::MemAlloc (size);
5659 std::memcpy (data.data , buffer.data (), size);
5760
5861 header.sizeBase = size;
@@ -64,11 +67,15 @@ void sw::Packer::readFile(std::string path)
6467 sw::resourceChunk chunk{};
6568 std::filesystem::path path1 (path);
6669
67- fillType (" RAWD" , chunk.header );
68- chunk.header .id = sw::computeCsc32 ((unsigned char *)path1.filename ().string ().data (), path1.filename ().string ().size ());
69- createChunkData (path, chunk.header , chunk.data );
70- chunk.header .crc32 = sw::computeCsc32 ((unsigned char *)&chunk.data , sizeof (chunk.data ));
71- sw::File::writeInFile (chunk);
70+ try {
71+ fillType (" RAWD" , chunk.header );
72+ chunk.header .id = sw::computeCsc32 ((unsigned char *) path1.filename ().string ().data (), path1.filename ().string ().size ());
73+ createChunkData (path, chunk.header , chunk.data );
74+ chunk.header .crc32 = sw::computeCsc32 ((unsigned char *) &chunk.data , sizeof (chunk.data ));
75+ sw::File::writeInFile (chunk);
76+ } catch (const std::exception& e) {
77+ sw::Log::AddLog (e.what (), sw::Log::WARNING);
78+ }
7279}
7380
7481void sw::Packer::fillType (std::string &&type, sw::chunkHeader& header)
0 commit comments