Skip to content

Commit

Permalink
wrap load_party base64 data
Browse files Browse the repository at this point in the history
  • Loading branch information
NQNStudios committed Nov 16, 2024
1 parent 2bf4c91 commit 4cd2d0a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/fileio/fileio_party.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ bool load_party(fs::path file_to_load, cUniverse& univ){
}

if(recording && result){
record_action("load_party", encode_file(file_to_load));
record_action("load_party", encode_file(file_to_load), true);
}

return result;
Expand Down
10 changes: 9 additions & 1 deletion src/tools/replay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <fstream>
#include <sstream>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/erase.hpp>
#include <boost/optional.hpp>
#include <cppcodec/base64_rfc4648.hpp>
#include <locale>
Expand Down Expand Up @@ -221,11 +222,18 @@ std::string encode_file(fs::path file) {
ifs.seekg(0, std::ios::beg);
ifs.read(result.data(), pos);

return base64::encode(result.data(), result.size() * sizeof(char));
std::string raw_base64 = base64::encode(result.data(), result.size() * sizeof(char));
std::ostringstream wrapped_base64;
const size_t cols = 76;
for(size_t start = 0; start < raw_base64.size(); start += cols){
wrapped_base64 << raw_base64.substr(start, cols) << std::endl;
}
return wrapped_base64.str();
}

void decode_file(std::string data, fs::path file) {
std::ofstream ofs(file.string(), std::ios::binary|std::ios::ate);
data = boost::algorithm::erase_all_copy(data, "\n");
std::vector<uint8_t> bytes = base64::decode(data.c_str(), strlen(data.c_str()) * sizeof(char));
char* bytes_as_c_str = reinterpret_cast<char*>(bytes.data());
ofs.write(bytes_as_c_str, bytes.size() / sizeof(char));
Expand Down

0 comments on commit 4cd2d0a

Please sign in to comment.