From b4c60ec6246eef937d556d3ab3afd8d64c54d08f Mon Sep 17 00:00:00 2001 From: andreja6 Date: Tue, 10 Apr 2018 14:10:41 -0700 Subject: [PATCH] Added file checking Check to make sure if file exists before continuing --- main.cpp | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/main.cpp b/main.cpp index d669364..dc3de21 100644 --- a/main.cpp +++ b/main.cpp @@ -13,7 +13,7 @@ #include #if G3D_VER < 61000 - #error Requires G3D 6.10 + #error Requires G3D 6.10 #endif static const float VNUM = 0.01F; static const std::string VERSION = "PRE-ALPHA "; @@ -101,9 +101,10 @@ void Demo::onInit() { GApplet::onInit(); } -void OnError(int err) +void OnError(int err, std::string msg = "") { - MessageBox(NULL, "An unexpected error has occured and Dynamica has to quit. We're sorry!","Dynamica Crash", MB_OK); + std::string emsg = "An unexpected error has occured and Dynamica has to quit. We're sorry!" + msg; + MessageBox(NULL, emsg.c_str(),"Dynamica Crash", MB_OK); exit(err); } @@ -189,6 +190,21 @@ std::string ExePath() { return std::string( buffer ).substr( 0, pos); } +std::string GetFileInPath(std::string file) +{ + std::string name = ExePath() + file; + struct stat buf; + if (stat(name.c_str(), &buf) != -1) + { + return name; + } + else + OnError(202, "\r\nFile not found: " + name); + return NULL; + + +} + void makeFlag(Vector3 &vec, RenderDevice* &rd) { Vector3 up = Vector3(vec.x, vec.y+3, vec.z); @@ -338,11 +354,10 @@ void App::main() { setDebugMode(false); debugController.setActive(false); // Load objects here - go = Texture::fromFile(ExePath() + "/content/images/Run.png"); - fntdominant = GFont::fromFile(ExePath() + "\\content\\font\\dominant.fnt"); - fntlighttrek = GFont::fromFile(ExePath() + "\\content\\font\\lighttrek.fnt"); + go = Texture::fromFile(GetFileInPath("/content/images/Run.png")); + fntdominant = GFont::fromFile(GetFileInPath("/content/font/dominant.fnt")); + fntlighttrek = GFont::fromFile(GetFileInPath("/content/font/lighttrek.fnt")); sky = Sky::create(NULL, ExePath() + "/content/sky/"); - applet->run(); } @@ -363,11 +378,11 @@ int main(int argc, char** argv) { //settings.useNetwork = false; //settings.window.width = 1024; //settings.window.height = 768; - settings.window.defaultIconFilename = ExePath() + "/content/images/rico.png"; + settings.window.defaultIconFilename = GetFileInPath("/content/images/rico.png"); settings.window.resizable = true; App app = App(settings); //app.window()->setIcon(ExePath() + "/content/images/rico.png"); app.run(); return 0; -} +} \ No newline at end of file