naev 0.10.4
Functions
ndata.c File Reference

Wrappers to set up and access game assets (mounted via PhysicsFS). We choose our underlying directories in ndata_setupWriteDir() and ndata_setupReadDirs(). However, conf.c code may have seeded the search path based on command-line arguments. More...

#include "ndata.h"
#include "array.h"
#include "conf.h"
#include "env.h"
#include "log.h"
#include "nfile.h"
#include "nstring.h"
#include "plugin.h"

Go to the source code of this file.

Functions

static void ndata_testVersion (void)
 Test version to see if it matches. More...
 
static int ndata_found (void)
 Checks to see if the physfs search path is enough to find game data. More...
 
static int ndata_enumerateCallback (void *data, const char *origdir, const char *fname)
 The PHYSFS_EnumerateCallback for ndata_listRecursive. More...
 
void ndata_setupWriteDir (void)
 Gets Naev's data path (for user data such as saves and screenshots) More...
 
void ndata_setupReadDirs (void)
 Sets up the PhysicsFS search path. More...
 
void * ndata_read (const char *path, size_t *filesize)
 Reads a file from the ndata (will be NUL terminated). More...
 
char ** ndata_listRecursive (const char *path)
 Lists all the visible files in a directory, at any depth. More...
 
int ndata_backupIfExists (const char *path)
 Backup a file, if it exists. More...
 
int ndata_copyIfExists (const char *file1, const char *file2)
 Copy a file, if it exists. More...
 
int ndata_matchExt (const char *path, const char *ext)
 Sees if a file matches an extension. More...
 
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. More...
 

Detailed Description

Wrappers to set up and access game assets (mounted via PhysicsFS). We choose our underlying directories in ndata_setupWriteDir() and ndata_setupReadDirs(). However, conf.c code may have seeded the search path based on command-line arguments.

Definition in file ndata.c.

Function Documentation

◆ ndata_backupIfExists()

int ndata_backupIfExists ( const char *  path)

Backup a file, if it exists.

Parameters
pathPhysicsFS relative pathname to back up.
Returns
0 on success, or if file does not exist, -1 on error.

Definition at line 282 of file ndata.c.

◆ ndata_copyIfExists()

int ndata_copyIfExists ( const char *  file1,
const char *  file2 
)

Copy a file, if it exists.

Parameters
file1PhysicsFS relative pathname to copy from.
file2PhysicsFS relative pathname to copy to.
Returns
0 on success, or if file1 does not exist, -1 on error.

Definition at line 304 of file ndata.c.

◆ ndata_enumerateCallback()

static int ndata_enumerateCallback ( void *  data,
const char *  origdir,
const char *  fname 
)
static

The PHYSFS_EnumerateCallback for ndata_listRecursive.

Definition at line 250 of file ndata.c.

◆ ndata_found()

static int ndata_found ( void  )
static

Checks to see if the physfs search path is enough to find game data.

Definition at line 48 of file ndata.c.

◆ ndata_getPathDefault()

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.

Parameters
[out]pathPath found.
lenLength of path.
default_pathDefault path to look in.
filenameName of the file to look for.
Returns
1 if found.

Definition at line 387 of file ndata.c.

◆ ndata_listRecursive()

char ** ndata_listRecursive ( const char *  path)

Lists all the visible files in a directory, at any depth.

Will sort by path, and (unlike underlying PhysicsFS) make sure to list each file path only once.

Returns
Array of (allocated) file paths relative to base_dir.

Definition at line 232 of file ndata.c.

◆ ndata_matchExt()

int ndata_matchExt ( const char *  path,
const char *  ext 
)

Sees if a file matches an extension.

Parameters
pathPath to check extension of.
extExtension to check.
Returns
1 on match, 0 otherwise.

Definition at line 366 of file ndata.c.

◆ ndata_read()

void * ndata_read ( const char *  path,
size_t *  filesize 
)

Reads a file from the ndata (will be NUL terminated).

Parameters
pathPath of the file to read.
[out]filesizeStores the size of the file.
Returns
The file data or NULL on error.

Definition at line 154 of file ndata.c.

◆ ndata_setupReadDirs()

void ndata_setupReadDirs ( void  )

Sets up the PhysicsFS search path.

Definition at line 110 of file ndata.c.

◆ ndata_setupWriteDir()

void ndata_setupWriteDir ( void  )

Gets Naev's data path (for user data such as saves and screenshots)

Definition at line 88 of file ndata.c.

◆ ndata_testVersion()

static void ndata_testVersion ( void  )
static

Test version to see if it matches.

Definition at line 59 of file ndata.c.