Added file checking

Check to make sure if file exists before continuing
This commit is contained in:
andreja6
2018-04-10 14:10:41 -07:00
parent e0bad6e42b
commit b4c60ec624

View File

@@ -13,7 +13,7 @@
#include <G3DAll.h> #include <G3DAll.h>
#if G3D_VER < 61000 #if G3D_VER < 61000
#error Requires G3D 6.10 #error Requires G3D 6.10
#endif #endif
static const float VNUM = 0.01F; static const float VNUM = 0.01F;
static const std::string VERSION = "PRE-ALPHA "; static const std::string VERSION = "PRE-ALPHA ";
@@ -101,9 +101,10 @@ void Demo::onInit() {
GApplet::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); exit(err);
} }
@@ -189,6 +190,21 @@ std::string ExePath() {
return std::string( buffer ).substr( 0, pos); 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) void makeFlag(Vector3 &vec, RenderDevice* &rd)
{ {
Vector3 up = Vector3(vec.x, vec.y+3, vec.z); Vector3 up = Vector3(vec.x, vec.y+3, vec.z);
@@ -338,11 +354,10 @@ void App::main() {
setDebugMode(false); setDebugMode(false);
debugController.setActive(false); debugController.setActive(false);
// Load objects here // Load objects here
go = Texture::fromFile(ExePath() + "/content/images/Run.png"); go = Texture::fromFile(GetFileInPath("/content/images/Run.png"));
fntdominant = GFont::fromFile(ExePath() + "\\content\\font\\dominant.fnt"); fntdominant = GFont::fromFile(GetFileInPath("/content/font/dominant.fnt"));
fntlighttrek = GFont::fromFile(ExePath() + "\\content\\font\\lighttrek.fnt"); fntlighttrek = GFont::fromFile(GetFileInPath("/content/font/lighttrek.fnt"));
sky = Sky::create(NULL, ExePath() + "/content/sky/"); sky = Sky::create(NULL, ExePath() + "/content/sky/");
applet->run(); applet->run();
} }
@@ -363,11 +378,11 @@ int main(int argc, char** argv) {
//settings.useNetwork = false; //settings.useNetwork = false;
//settings.window.width = 1024; //settings.window.width = 1024;
//settings.window.height = 768; //settings.window.height = 768;
settings.window.defaultIconFilename = ExePath() + "/content/images/rico.png"; settings.window.defaultIconFilename = GetFileInPath("/content/images/rico.png");
settings.window.resizable = true; settings.window.resizable = true;
App app = App(settings); App app = App(settings);
//app.window()->setIcon(ExePath() + "/content/images/rico.png"); //app.window()->setIcon(ExePath() + "/content/images/rico.png");
app.run(); app.run();
return 0; return 0;
} }