Clean up; add 2nd GD savefile

This commit is contained in:
xypwn
2020-05-05 12:18:28 +02:00
parent 3732939ef1
commit 9bbd5cf16a
2 changed files with 66 additions and 15 deletions

View File

@@ -7,6 +7,15 @@
constexpr int CHUNK = 16384;
constexpr int WINDOW_BITS = 15;
//Returns true if it was able to open the given file for reading
bool IsFile(const std::string& filename)
{
std::ifstream file(filename);
const bool ret = file.good();
file.close();
return ret;
}
//Reads the contents of a given file into a string
std::string FileToStr(const std::string& filename) {
std::ifstream file(filename, std::ios::binary);
@@ -18,11 +27,14 @@ std::string FileToStr(const std::string& filename) {
}
//Writes the contents of a string to the given file
void StrToFile(const std::string& filename, const std::string& data) {
std::ofstream ofile;
ofile.open(filename);
// returns false if it was unable to open the file
bool StrToFile(const std::string& filename, const std::string& data) {
std::ofstream ofile(filename, std::ios::binary);
if(!ofile.good())
return false;
ofile << data;
ofile.close();
return true;
}
//XORs each byte of a string reference