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);
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;
160 PHYSFS_Stat path_stat;
162 if (!PHYSFS_stat( path, &path_stat )) {
163 WARN( _(
"Error occurred while opening '%s': %s" ), path,
164 _(PHYSFS_getErrorByCode( PHYSFS_getLastErrorCode() ) ) );
168 if (path_stat.filetype != PHYSFS_FILETYPE_REGULAR) {
169 WARN( _(
"Error occurred while opening '%s': It is not a regular file" ), path );
175 file = PHYSFS_openRead( path );
176 if ( file == NULL ) {
177 WARN( _(
"Error occurred while opening '%s': %s" ), path,
178 _(PHYSFS_getErrorByCode( PHYSFS_getLastErrorCode() ) ) );
184 len = PHYSFS_fileLength( file );
186 WARN( _(
"Error occurred while seeking '%s': %s" ), path,
187 _(PHYSFS_getErrorByCode( PHYSFS_getLastErrorCode() ) ) );
188 PHYSFS_close( file );
194 buf = malloc( len+1 );
196 WARN(_(
"Out of Memory"));
197 PHYSFS_close( file );
206 pos = PHYSFS_readBytes( file, &buf[ n ], len - n );
208 WARN( _(
"Error occurred while reading '%s': %s" ), path,
209 _(PHYSFS_getErrorByCode( PHYSFS_getLastErrorCode() ) ) );
210 PHYSFS_close( file );
239 if (strcmp(files[i], files[i+1]) == 0) {
257 dir_len = strlen( origdir );
258 fmt = dir_len && origdir[dir_len-1]==
'/' ?
"%s%s" :
"%s/%s";
259 asprintf( &path, fmt, origdir, fname );
260 if (!PHYSFS_stat( path, &stat )) {
261 WARN( _(
"PhysicsFS: Cannot stat %s: %s"), path,
262 _(PHYSFS_getErrorByCode( PHYSFS_getLastErrorCode() ) ) );
265 else if (stat.filetype == PHYSFS_FILETYPE_REGULAR)
267 else if (stat.filetype == PHYSFS_FILETYPE_DIRECTORY ) {
273 return PHYSFS_ENUM_OK;
289 if (!PHYSFS_exists( path ))
292 snprintf(backup,
sizeof(backup),
"%s.backup", path);
306 PHYSFS_File *f_in, *f_out;
308 PHYSFS_sint64 lr, lw;
314 if (!PHYSFS_exists(file1))
318 f_in = PHYSFS_openRead( file1 );
319 f_out = PHYSFS_openWrite( file2 );
320 if ((f_in==NULL) || (f_out==NULL)) {
321 WARN( _(
"Failure to copy '%s' to '%s': %s"), file1, file2,
322 _(PHYSFS_getErrorByCode( PHYSFS_getLastErrorCode() ) ) );
330 lr = PHYSFS_readBytes( f_in, buf,
sizeof(buf) );
334 if (PHYSFS_eof( f_in ))
339 lw = PHYSFS_writeBytes( f_out, buf, lr );
345 PHYSFS_close( f_in );
346 PHYSFS_close( f_out );
351 WARN( _(
"Failure to copy '%s' to '%s': %s"), file1, file2,
352 _(PHYSFS_getErrorByCode( PHYSFS_getLastErrorCode() ) ) );
353 PHYSFS_close( f_in );
354 PHYSFS_close( f_out );
370 for (i=strlen(path)-1; i>0; i--)
375 return strcmp( &path[i+1], ext )==0;
389 PHYSFS_Stat path_stat;
390 snprintf( path, len,
"%s%s", default_path, filename );
391 if (PHYSFS_stat( path, &path_stat ) && (path_stat.filetype == PHYSFS_FILETYPE_REGULAR))
393 snprintf( path, len,
"%s", filename );
394 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 macos_resourcesPath(char *res, size_t n)
Get the path to the bundle resources directory.
int macos_isBundle()
Determine if we're running from inside an app bundle.
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.
static char buf[NEWS_MAX_LENGTH]
int asprintf(char **strp, const char *fmt,...)
Like sprintf(), but it allocates a large-enough string and returns the pointer in the first argument....
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.