Added basic file encryption to writeFile and readFile; Minor changes

This commit is contained in:
grayson committed 2021-08-26 13:17:29 -05:00
1 parent d74f808a17
commit bc5c17ebfb
15 files changed
+26 -29545

No files matched your search

+2 -5
View File
@@ -1,8 +1,6 @@
#include "Application.h"
#include <thread>
#include "GL\glew.h"
#include "GL\wglew.h"
#include "Utility.h"
@@ -197,7 +195,7 @@ namespace nf {
while (m_running) {
start_time = std::chrono::steady_clock::now();
m_currentState->update(m_deltaTime);
m_currentState->render();
m_currentState->render(*m_renderer);
m_renderer->doFrame();
m_frames++;
if (m_stateChange)
@@ -205,11 +203,10 @@ namespace nf {
m_fpsClock2 = std::chrono::steady_clock::now();
m_fpsDuration = m_fpsClock2 - m_fpsClock1;
if (m_fpsDuration.count() >= 1.0) {
m_FPS = m_frames;
m_FPS = m_frames - 1;
m_frames = 0;
Log("FPS: " + std::to_string(m_FPS));
m_fpsClock1 = std::chrono::steady_clock::now();
//TODO: Rework calculating FPS
}
std::this_thread::sleep_until(next_time);
m_deltaTime = (double)(std::chrono::steady_clock::now() - start_time).count();
+1 -1
View File
@@ -16,7 +16,7 @@ namespace nf {
}
void Gamestate::render() {
void Gamestate::render(Renderer& renderer) {
}
+1 -1
View File
@@ -23,7 +23,7 @@ namespace nf {
m_counter++;
}
void IntroGamestate::render() {
void IntroGamestate::render(Renderer& renderer) {
}
void IntroGamestate::onExit() {
+15 -5
View File
@@ -81,8 +81,8 @@ namespace nf {
MultiByteToWideChar(CP_ACP, NULL, cstr, -1, out, length);
return out;
}
//TODO: File encryption
bool writeFile(const char* filename, const std::string& in) {
bool writeFile(const char* filename, const std::string& in, bool encrypted) {
std::string file(filename);
if (file.find('/') != std::string::npos || file.find('\\') != std::string::npos) {
int pos = file.find_last_of("/\\");
@@ -100,19 +100,29 @@ namespace nf {
out.open(filename);
if (!out)
Error("File \"" + (std::string)filename + (std::string)"\" could not be written!");
out << in;
std::string write(in);
if (encrypted) {
for (unsigned int i = 0; i < write.size(); i++)
write[i] = write[i] + 100;
}
out << write;
out.close();
return true;
}
std::string readFile(const char* filename) {
std::string readFile(const char* filename, bool encrypted) {
std::ifstream in;
in.open(filename);
if (!in)
Error("File \"" + (std::string)filename + (std::string)"\" could not be read!");
std::stringstream ss;
ss << in.rdbuf();
return ss.str();
std::string read(ss.str());
if (encrypted) {
for (unsigned int i = 0; i < read.size(); i++)
read[i] = read[i] - 100;
}
return read;
}
}
+1 -1
View File
@@ -13,7 +13,7 @@ namespace nf {
virtual void onEnter();
virtual void update(double deltaTime);
virtual void render();
virtual void render(Renderer& renderer);
virtual void onExit();
protected:
+1 -1
View File
@@ -9,7 +9,7 @@ namespace nf {
void onEnter() override;
void update(double deltaTime) override;
void render() override;
void render(Renderer& renderer) override;
void onExit() override;
private:
+2 -2
View File
@@ -46,7 +46,7 @@ std::exit(-1);}
const wchar_t* toWide(const char* in);
const wchar_t* toWide(const std::string& in);
bool writeFile(const char* filename, const std::string& in);
std::string readFile(const char* filename);
bool writeFile(const char* filename, const std::string& in, bool encrypted = false);
std::string readFile(const char* filename, bool encrypted = false);
}