31#include "glue_macos.h"
53 return PHYSFS_exists(
"VERSION" ) && PHYSFS_exists( START_DATA_PATH );
66 ERR( _(
"Unable to find game data. You may need to install, specify a datapath, or run using naev.sh (if developing).") );
75 WARN( _(
"ndata version inconsistency with this version of Naev!") );
76 WARN( _(
"Expected ndata version %s got %s."),
naev_version( 0 ), cbuf );
78 ERR( _(
"Please get a compatible ndata version!") );
80 WARN( _(
"Naev will probably crash now as the versions are probably not compatible.") );
97 PHYSFS_setWriteDir( PHYSFS_getPrefDir(
".",
"org.naev.Naev" ) );
99 PHYSFS_setWriteDir( PHYSFS_getPrefDir(
".",
"naev" ) );
101 if (PHYSFS_getWriteDir() == NULL) {
102 WARN(_(
"Cannot determine data path, using current directory."));
103 PHYSFS_setWriteDir(
"./naev/" );
114 if ( conf.
ndata != NULL && PHYSFS_mount( conf.
ndata, NULL, 1 ) )
115 LOG(_(
"Added datapath from conf.lua file: %s"), conf.
ndata);
118 if ( !
ndata_found() && macos_isBundle() && macos_resourcesPath( buf,
PATH_MAX-4 ) >= 0 && strncat( buf,
"/dat", 4 ) ) {
119 LOG(_(
"Trying default datapath: %s"), buf);
120 PHYSFS_mount( buf, NULL, 1 );
124 if ( !
ndata_found() && env.isAppImage && nfile_concatPaths( buf,
PATH_MAX, env.appdir, PKGDATADIR,
"dat" ) >= 0 ) {
125 LOG(_(
"Trying default datapath: %s"), buf);
126 PHYSFS_mount( buf, NULL, 1 );
130 LOG(_(
"Trying default datapath: %s"), buf);
131 PHYSFS_mount( buf, NULL, 1 );
134 if (!
ndata_found() && nfile_concatPaths( buf,
PATH_MAX, PHYSFS_getBaseDir(),
"dat" ) >= 0) {
135 LOG(_(
"Trying default datapath: %s"), buf);
136 PHYSFS_mount( buf, NULL, 1 );
139 PHYSFS_mount( PHYSFS_getWriteDir(), NULL, 0 );
158 PHYSFS_sint64 len, n;
159 PHYSFS_Stat path_stat;
161 if (!PHYSFS_stat( path, &path_stat )) {
162 WARN( _(
"Error occurred while opening '%s': %s" ), path,
163 _(PHYSFS_getErrorByCode( PHYSFS_getLastErrorCode() ) ) );
167 if (path_stat.filetype != PHYSFS_FILETYPE_REGULAR) {
168 WARN( _(
"Error occurred while opening '%s': It is not a regular file" ), path );
174 file = PHYSFS_openRead( path );
175 if ( file == NULL ) {
176 WARN( _(
"Error occurred while opening '%s': %s" ), path,
177 _(PHYSFS_getErrorByCode( PHYSFS_getLastErrorCode() ) ) );
183 len = PHYSFS_fileLength( file );
185 WARN( _(
"Error occurred while seeking '%s': %s" ), path,
186 _(PHYSFS_getErrorByCode( PHYSFS_getLastErrorCode() ) ) );
187 PHYSFS_close( file );
193 buf = malloc( len+1 );
195 WARN(_(
"Out of Memory"));
196 PHYSFS_close( file );
205 size_t pos = PHYSFS_readBytes( file, &buf[ n ], len - n );
207 WARN( _(
"Error occurred while reading '%s': %s" ), path,
208 _(PHYSFS_getErrorByCode( PHYSFS_getLastErrorCode() ) ) );
209 PHYSFS_close( file );
238 if (strcmp(files[i], files[i+1]) == 0) {
256 dir_len = strlen( origdir );
257 fmt = dir_len && origdir[dir_len-1]==
'/' ?
"%s%s" :
"%s/%s";
258 SDL_asprintf( &path, fmt, origdir, fname );
259 if (!PHYSFS_stat( path, &stat )) {
260 WARN( _(
"PhysicsFS: Cannot stat %s: %s"), path,
261 _(PHYSFS_getErrorByCode( PHYSFS_getLastErrorCode() ) ) );
264 else if (stat.filetype == PHYSFS_FILETYPE_REGULAR)
266 else if (stat.filetype == PHYSFS_FILETYPE_DIRECTORY ) {
272 return PHYSFS_ENUM_OK;
288 if (!PHYSFS_exists( path ))
291 snprintf(backup,
sizeof(backup),
"%s.backup", path);
305 PHYSFS_File *f_in, *f_out;
307 PHYSFS_sint64 lr, lw;
313 if (!PHYSFS_exists(file1))
317 f_in = PHYSFS_openRead( file1 );
318 f_out = PHYSFS_openWrite( file2 );
319 if ((f_in==NULL) || (f_out==NULL)) {
320 WARN( _(
"Failure to copy '%s' to '%s': %s"), file1, file2,
321 _(PHYSFS_getErrorByCode( PHYSFS_getLastErrorCode() ) ) );
329 lr = PHYSFS_readBytes( f_in, buf,
sizeof(buf) );
333 if (PHYSFS_eof( f_in ))
338 lw = PHYSFS_writeBytes( f_out, buf, lr );
344 PHYSFS_close( f_in );
345 PHYSFS_close( f_out );
350 WARN( _(
"Failure to copy '%s' to '%s': %s"), file1, file2,
351 _(PHYSFS_getErrorByCode( PHYSFS_getLastErrorCode() ) ) );
352 PHYSFS_close( f_in );
353 PHYSFS_close( f_out );
369 for (i=strlen(path)-1; i>0; i--)
374 return strcmp( &path[i+1], ext )==0;
388 PHYSFS_Stat path_stat;
389 snprintf( path, len,
"%s%s", default_path, filename );
390 if (PHYSFS_stat( path, &path_stat ) && (path_stat.filetype == PHYSFS_FILETYPE_REGULAR))
392 snprintf( path, len,
"%s", filename );
393 if (PHYSFS_stat( path, &path_stat ) && (path_stat.filetype == PHYSFS_FILETYPE_REGULAR))
Provides macros to work with dynamic arrays.
#define array_erase(ptr_array, first, last)
Erases elements in interval [first, last).
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
#define array_push_back(ptr_array, element)
Adds a new element at the end of the array.
#define array_create(basic_type)
Creates a new dynamic array of ‘basic_type’.
int naev_versionCompare(const char *version)
Compares the version against the current naev version.
Header file with generic functions and naev-specifics.
const char * naev_version(int long_version)
Returns the version in a human readable string.
int ndata_backupIfExists(const char *path)
Backup a file, if it exists.
void ndata_setupReadDirs(void)
Sets up the PhysicsFS search path.
static void ndata_testVersion(void)
Test version to see if it matches.
int ndata_copyIfExists(const char *file1, const char *file2)
Copy a file, if it exists.
void ndata_setupWriteDir(void)
Gets Naev's data path (for user data such as saves and screenshots)
static int ndata_found(void)
Checks to see if the physfs search path is enough to find game data.
void * ndata_read(const char *path, size_t *filesize)
Reads a file from the ndata (will be NUL terminated).
int ndata_matchExt(const char *path, const char *ext)
Sees if a file matches an extension.
static int ndata_enumerateCallback(void *data, const char *origdir, const char *fname)
The PHYSFS_EnumerateCallback for ndata_listRecursive.
char ** ndata_listRecursive(const char *path)
Lists all the visible files in a directory, at any depth.
int ndata_getPathDefault(char *path, int len, const char *default_path, const char *filename)
Tries to see if a file is in a default path before seeing if it is an absolute path.
int strsort(const void *p1, const void *p2)
Sort function for sorting strings with qsort().
int plugin_init(void)
Initialize and loads all the available plugins.