Add library functionality for level data

This commit is contained in:
xypwn
2020-05-05 13:40:52 +02:00
parent 9bbd5cf16a
commit 7586e8d5ab
2 changed files with 39 additions and 28 deletions

View File

@@ -20,24 +20,27 @@ const std::string commands = R"(Commands:
3: Encrypt and save to GD folder
0: Quit)";
enum class Command
{
enum class Command {
Decrypt,
Encrypt
};
bool ExecCommand(Command cmd, const std::string& in_filename, const std::string& out_filename)
{
bool ExecCommand(Command cmd, const std::string& in_filename, const std::string& out_filename) {
//Check if input file is valid
if(!IsFile(in_filename))
{
std::cerr << "ERROR: Could not open file " << in_filename << " for reading" << std::endl;
return false;
}
//Read file data into a string
std::string data = FileToStr(in_filename);
switch(cmd)
{
case Command::Decrypt:
std::cout << "Decrypting " << in_filename << "..." << std::endl;
if(!StrToFile(out_filename, Decrypt(in_filename)))
// Attempt to decrypt data and save it in the given output file
if(!StrToFile(out_filename, Decrypt(data, true)))
{
std::cerr << "ERROR: Could not open file " << out_filename << " for writing" << std::endl;
return false;
@@ -45,7 +48,8 @@ bool ExecCommand(Command cmd, const std::string& in_filename, const std::string&
break;
case Command::Encrypt:
std::cout << "Encrypting " << in_filename << "..." << std::endl;
if(!StrToFile(out_filename, Encrypt(in_filename)))
// Attempt to encrypt data and save it in the given output file
if(!StrToFile(out_filename, Encrypt(data, true)))
{
std::cerr << "ERROR: Could not open file " << out_filename << " for writing" << std::endl;
return false;