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

@@ -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,7 +378,7 @@ 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);