naev 0.12.5
nfile.c File Reference

Handles read/write abstractions to the users directory. More...

#include "nfile.h"
#include "array.h"
#include "conf.h"
#include "log.h"
#include "nfd.h"
Include dependency graph for nfile.c:

Go to the source code of this file.

Functions

const char * nfile_configPath (void)
 Gets Naev's config path (for user preferences such as conf.lua)
const char * nfile_cachePath (void)
 Gets Naev's cache path (for cached data such as generated textures)
 if (strncpy(path==NULL)
 for (;p >=opath;p--)
 for (;p[0] !='\0';p++)
 if (!nfile_dirExists(opath))
int nfile_dirMakeExist (const char *path)
 Creates a directory if it doesn't exist.
int nfile_dirExists (const char *path)
 Checks to see if a directory exists.
int nfile_fileExists (const char *path)
 Checks to see if a file exists.
int nfile_backupIfExists (const char *path)
 Backup a file, if it exists.
int nfile_copyIfExists (const char *file1, const char *file2)
 Copy a file, if it exists.
char * nfile_readFile (size_t *filesize, const char *path)
 Tries to read a file.
int nfile_touch (const char *path)
 Tries to create the file if it doesn't exist.
int nfile_writeFile (const char *data, size_t len, const char *path)
 Tries to write a file.
int nfile_isSeparator (uint32_t c)
 Checks to see if a character is used to separate files in a path.
int _nfile_concatPaths (char buf[static 1], int maxLength, const char path[static 1],...)
int nfile_simplifyPath (char path[static 1])
 Simplifies the path removing things like ".." or consecutive "/".
void SDL_ShowOpenFileDialog (SDL_DialogFileCallback callback, void *userdata, SDL_Window *window, const SDL_DialogFileFilter *filters, const char *default_location, SDL_bool allow_many)
void SDL_ShowOpenFolderDialog (SDL_DialogFileCallback callback, void *userdata, SDL_Window *window, const char *default_location, SDL_bool allow_many)
void SDL_ShowSaveFileDialog (SDL_DialogFileCallback callback, void *userdata, SDL_Window *window, const SDL_DialogFileFilter *filters, const char *default_location)

Variables

static char naev_configPath [PATH_MAX] = "\0"
static char naev_cachePath [PATH_MAX] = "\0"
char * p
size_t len
int ret
 return

Detailed Description

Handles read/write abstractions to the users directory.

Todo
Add support for Windows and macOS.

Definition in file nfile.c.

Function Documentation

◆ _nfile_concatPaths()

int _nfile_concatPaths ( char buf[static 1],
int maxLength,
const char path[static 1],
... )

Definition at line 616 of file nfile.c.

◆ for() [1/2]

for ( ;p >=opath;p-- )

Definition at line 235 of file nfile.c.

◆ for() [2/2]

for ( ;p ! [0] = '\0'; p++)

Definition at line 250 of file nfile.c.

◆ if() [1/2]

if ( ! nfile_dirExistsopath)

Definition at line 261 of file nfile.c.

◆ if() [2/2]

if ( strncpy( path = = NULL)

Definition at line 221 of file nfile.c.

◆ nfile_backupIfExists()

int nfile_backupIfExists ( const char * path)

Backup a file, if it exists.

Parameters
pathprintf formatted string pointing to the file to backup.
Returns
0 on success, or if file does not exist, -1 on error.

Definition at line 356 of file nfile.c.

◆ nfile_cachePath()

const char * nfile_cachePath ( void )

Gets Naev's cache path (for cached data such as generated textures)

Returns
The xdg cache path.

Definition at line 162 of file nfile.c.

◆ nfile_configPath()

const char * nfile_configPath ( void )

Gets Naev's config path (for user preferences such as conf.lua)

Returns
The xdg config path.

Definition at line 113 of file nfile.c.

◆ nfile_copyIfExists()

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

Copy a file, if it exists.

Parameters
file1Filename to copy from.
file2Filename to copy to.
Returns
0 on success, or if file1 does not exist, -1 on error.

Definition at line 378 of file nfile.c.

◆ nfile_dirExists()

int nfile_dirExists ( const char * path)

Checks to see if a directory exists.

Parameters
pathPath to directory
Returns
1 on exists, 0 otherwise

Definition at line 309 of file nfile.c.

◆ nfile_dirMakeExist()

int nfile_dirMakeExist ( const char * path)

Creates a directory if it doesn't exist.

Parameters
pathPath to create directory if it doesn't exist.
Returns
0 on success.

Definition at line 277 of file nfile.c.

◆ nfile_fileExists()

int nfile_fileExists ( const char * path)

Checks to see if a file exists.

Parameters
pathstring pointing to the file to check for existence.
Returns
1 if file exists, 0 if it doesn't or -1 on error.

Definition at line 329 of file nfile.c.

◆ nfile_isSeparator()

int nfile_isSeparator ( uint32_t c)

Checks to see if a character is used to separate files in a path.

Parameters
cCharacter to check.
Returns
1 if is a separator, 0 otherwise.

Definition at line 605 of file nfile.c.

◆ nfile_readFile()

char * nfile_readFile ( size_t * filesize,
const char * path )

Tries to read a file.

Parameters
filesizeStores the size of the file.
pathPath of the file.
Returns
The file data.

Definition at line 442 of file nfile.c.

◆ nfile_simplifyPath()

int nfile_simplifyPath ( char path[static 1])

Simplifies the path removing things like ".." or consecutive "/".

Parameters
pathPath to simplify. Gets overwritten.
Returns
0 on success.

Definition at line 676 of file nfile.c.

◆ nfile_touch()

int nfile_touch ( const char * path)

Tries to create the file if it doesn't exist.

Parameters
pathPath of the file to create.

Definition at line 533 of file nfile.c.

◆ nfile_writeFile()

int nfile_writeFile ( const char * data,
size_t len,
const char * path )

Tries to write a file.

Parameters
dataPointer to the data to write.
lenThe size of data.
pathPath of the file.
Returns
0 on success, -1 on error.

Definition at line 559 of file nfile.c.

◆ SDL_ShowOpenFileDialog()

void SDL_ShowOpenFileDialog ( SDL_DialogFileCallback callback,
void * userdata,
SDL_Window * window,
const SDL_DialogFileFilter * filters,
const char * default_location,
SDL_bool allow_many )

Definition at line 731 of file nfile.c.

◆ SDL_ShowOpenFolderDialog()

void SDL_ShowOpenFolderDialog ( SDL_DialogFileCallback callback,
void * userdata,
SDL_Window * window,
const char * default_location,
SDL_bool allow_many )

Definition at line 781 of file nfile.c.

◆ SDL_ShowSaveFileDialog()

void SDL_ShowSaveFileDialog ( SDL_DialogFileCallback callback,
void * userdata,
SDL_Window * window,
const SDL_DialogFileFilter * filters,
const char * default_location )

Definition at line 818 of file nfile.c.

Variable Documentation

◆ len

size_t len

Definition at line 218 of file nfile.c.

◆ naev_cachePath

char naev_cachePath[PATH_MAX] = "\0"
static

Store Naev's cache path.

Definition at line 156 of file nfile.c.

◆ naev_configPath

char naev_configPath[PATH_MAX] = "\0"
static

Store Naev's config path.

Definition at line 107 of file nfile.c.

◆ p

p
Initial value:
{
char opath[PATH_MAX]
#define PATH_MAX
Definition naev.h:57

Definition at line 217 of file nfile.c.

◆ ret

int ret

Definition at line 219 of file nfile.c.

◆ return

return

Definition at line 267 of file nfile.c.