Use an absolute directory in /usr/share/games/ for game data
[kball.git] / src / filehelp.cpp
bloba3852359be75bf0e721606ff1ef219525285d47a
1 // --------------------------------------------------------
2 // filehelp.cpp
3 // --------------------------------------------------------
4 // Copyright (c) 2003, 2004, Kronoman
5 // In loving memory of my father
6 // --------------------------------------------------------
7 // I use this for reach the datafile searching in common paths
8 // Is specially useful for datafiles in Windows, because most
9 // of the time Windows don't start the program in the executable path,
10 // and the program is unable to find the datafile.
11 // --------------------------------------------------------
13 #include <allegro.h>
14 #include "filehelp.h"
15 //#include <stdio.h>
17 // --------------------------------------------------------
18 // This checks for the filename in several places.
19 // Returns where the filename is located in buffer
20 // buffer should be a 2048 bytes char
21 // If the file is not found, return the filename...
22 // --------------------------------------------------------
23 char *where_is_the_filename(char *buffer, const char *filename)
25 char str[2048] = "/usr/share/games/kball/",
26 str2[2048]; // buffer for path making
28 // check in current executable path
29 //get_executable_name(str, 2048);
30 replace_filename(str2, str, filename, 2048);
32 if (! exists(filename) )
34 if (exists(str2))
36 usprintf(buffer,"%s", str2);
38 //printf("--> %s\n", buffer);
40 return buffer;
42 else
44 get_executable_name(str, 2048);
45 replace_filename(str, str, "", 2048);
46 if (! find_allegro_resource(str2, filename, get_extension(filename), NULL, NULL, NULL, str, 2048) )
48 usprintf(buffer,"%s", str2);
50 //printf("--> %s\n", buffer);
52 return buffer;
57 // default
58 usprintf(buffer,"%s", filename);
60 //printf("--> %s\n", buffer);
62 return buffer;