WIP encode and decode save files in action logs
This commit is contained in:
@@ -5,7 +5,10 @@
|
||||
#include "ticpp.h"
|
||||
#include <ctime>
|
||||
#include <iomanip>
|
||||
#include <fstream>
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <cppcodec/base64_rfc4648.hpp>
|
||||
using base64 = cppcodec::base64_rfc4648;
|
||||
|
||||
bool recording = false;
|
||||
bool replaying = false;
|
||||
@@ -81,4 +84,23 @@ Element* pop_next_action(std::string expected_action_type) {
|
||||
root->RemoveChild(next_action);
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
std::string encode_file(fs::path file) {
|
||||
std::ifstream ifs(file.string(), std::ios::binary|std::ios::ate);
|
||||
std::ifstream::pos_type pos = ifs.tellg();
|
||||
|
||||
std::vector<char> result(pos);
|
||||
|
||||
ifs.seekg(0, std::ios::beg);
|
||||
ifs.read(result.data(), pos);
|
||||
|
||||
return base64::encode(result.data(), result.size() * sizeof(char));
|
||||
}
|
||||
|
||||
void decode_file(std::string data, fs::path file) {
|
||||
std::ofstream ofs(file.string(), std::ios::binary|std::ios::ate);
|
||||
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));
|
||||
}
|
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
// Input recording system
|
||||
namespace ticpp { class Element; }
|
||||
@@ -15,5 +16,7 @@ extern bool init_action_log(std::string command, std::string file);
|
||||
extern void record_action(std::string action_type, std::string inner_text);
|
||||
extern bool has_next_action();
|
||||
extern Element* pop_next_action(std::string expected_action_type="");
|
||||
extern std::string encode_file(fs::path file);
|
||||
extern void decode_file(std::string data, fs::path file);
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user