Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
common.cpp File Reference
#include <string>
#include <stdio.h>
#include <unistd.h>
#include "common.h"

Go to the source code of this file.

Functions

string getdatadir ()
 

Variables

const char * datadirs []
 

Function Documentation

string getdatadir ( )

Definition at line 55 of file common.cpp.

References VSFileSystem::datadir, datadirs, fclose, fopen, and i.

56 {
57  string datadir;
58  char tmppwd[65536];
59  if (NULL == getcwd( tmppwd, 32768 ))
60  tmppwd[0] = '\0';
61  unsigned int i = 0;
62  for (; i < ( sizeof (datadirs)/sizeof (datadirs[0]) ); i++) {
63  if( chdir( datadirs[i] ) )
64  continue;
65  FILE *tfp = fopen( "vegastrike.config", "r" );
66  if (tfp) {
67  fclose( tfp );
68  //We have found the data directory
69  break;
70  }
71  }
72  if ( i >= sizeof (datadirs)/sizeof (datadirs[0]) ) {
73  printf( "Unable to find data directory\n" );
74  for (i = 0; i < ( sizeof (datadirs)/sizeof (datadirs[0]) ); i++)
75  printf( "Tried %s\n", datadirs[i] );
76  datadir = tmppwd;
77  if( chdir( tmppwd ) )
78  printf( "Unable to set current directory to data directory\n" );
79  }
80  //Set data dir
81  else if (datadirs[i][0] != '/') {
82  //Was a relative path
83  datadir = tmppwd;
84  datadir += '/';
85  datadir += datadirs[i];
86  } else {
87  datadir = datadirs[i];
88  }
89  return datadir;
90 }

Variable Documentation

const char* datadirs[]
Initial value:
= {
".",
"../data",
"../../data",
"../Resources/data",
"/usr/share/local/vegastrike/data",
"/usr/local/share/vegastrike/data",
"/usr/local/vegastrike/data",
"/usr/share/vegastrike/data",
"/usr/local/games/vegastrike/data",
"/usr/games/vegastrike/data",
"/opt/share/vegastrike/data",
"/usr/share/local/vegastrike/data4.x",
"/usr/local/share/vegastrike/data4.x",
"/usr/local/vegastrike/data4.x",
"/usr/share/vegastrike/data4.x",
"/usr/local/games/vegastrike/data4.x",
"/usr/games/vegastrike/data4.x",
"/opt/share/vegastrike/data4.x",
}

Definition at line 30 of file common.cpp.

Referenced by getdatadir().