Added data system to detect if run in good path

This commit is contained in:
Michaël Lemaire 2013-06-09 14:07:45 +02:00
parent eb837ef3bd
commit f3ddf1917f
3 changed files with 51 additions and 0 deletions

View file

@ -2,6 +2,7 @@
#include <stdlib.h>
#include "auto.h"
#include "tools/data.h"
#include "system.h"
#include "scenery.h"
#include "render.h"
@ -13,6 +14,12 @@
void paysagesInit()
{
systemInit();
if (!dataInit())
{
/* TODO Add error callback (for interface) */
fprintf(stderr, "ERROR : Can't locate data files.\n");
exit(1);
}
openclInit();
sceneryInit();

View file

@ -0,0 +1,34 @@
#include "data.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static const char* _datapath = NULL;
static int _tryDataPath(const char* path)
{
char* buffer;
buffer = malloc(sizeof (char) * (strlen(path) + 30));
strcpy(buffer, path);
strcat(buffer, "/.paysages_data");
FILE* f = fopen(buffer, "r");
free(buffer);
if (f)
{
_datapath = path;
fclose(f);
return 1;
}
else
{
return 0;
}
}
int dataInit()
{
return _tryDataPath("./data");
}

View file

@ -0,0 +1,10 @@
#ifndef _PAYSAGES_TOOLS_DATA_H_
#define _PAYSAGES_TOOLS_DATA_H_
/*
* Data directory management.
*/
int dataInit();
#endif