neptools

Modding tools to Neptunia games
git clone https://git.neptards.moe/neptards/neptools.git
Log | Files | Refs | Submodules | README | LICENSE

utils.cpp (1181B)


      1 #include "utils.hpp"
      2 
      3 #include "source.hpp"
      4 
      5 #include <libshit/string_utils.hpp>
      6 
      7 #include <fstream>
      8 #include <iomanip>
      9 
     10 // workaround incompatibilities between clang+msvc libs, mingw ofstream (no wide
     11 // char open) and linux...
     12 #ifndef BOOST_FILESYSTEM_C_STR
     13 #  define BOOST_FILESYSTEM_C_STR c_str()
     14 #endif
     15 
     16 namespace Neptools
     17 {
     18 
     19   std::ofstream OpenOut(const boost::filesystem::path& pth)
     20   {
     21     std::ofstream os;
     22     os.exceptions(std::ios_base::failbit | std::ios_base::badbit);
     23     os.open(pth.BOOST_FILESYSTEM_C_STR, std::ios_base::out | std::ios_base::binary);
     24     return os;
     25   }
     26 
     27   std::ifstream OpenIn(const boost::filesystem::path& pth)
     28   {
     29     std::ifstream is;
     30     is.exceptions(std::ios_base::failbit | std::ios_base::badbit);
     31     is.open(pth.BOOST_FILESYSTEM_C_STR, std::ios_base::in | std::ios_base::binary);
     32     return is;
     33   }
     34 
     35   void DumpBytes(std::ostream& os, Source data)
     36   {
     37     os << '"';
     38 
     39     bool hex = false;
     40     for (FilePosition offs = 0, size = data.GetSize(); offs < size; )
     41     {
     42       auto chunk = data.GetChunk(offs);
     43       for (char c : chunk)
     44         hex = Libshit::DumpByte(os, c, hex);
     45       offs += chunk.length();
     46     }
     47     os << '"';
     48   }
     49 
     50 }