Added file checking
Check to make sure if file exists before continuing
This commit is contained in:
33
main.cpp
33
main.cpp
@@ -13,7 +13,7 @@
|
||||
#include <G3DAll.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user