Added data system to detect if run in good path
This commit is contained in:
parent
eb837ef3bd
commit
f3ddf1917f
3 changed files with 51 additions and 0 deletions
|
@ -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();
|
||||
|
|
34
src/rendering/tools/data.c
Normal file
34
src/rendering/tools/data.c
Normal 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");
|
||||
}
|
10
src/rendering/tools/data.h
Normal file
10
src/rendering/tools/data.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifndef _PAYSAGES_TOOLS_DATA_H_
|
||||
#define _PAYSAGES_TOOLS_DATA_H_
|
||||
|
||||
/*
|
||||
* Data directory management.
|
||||
*/
|
||||
|
||||
int dataInit();
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue