Inexor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Functions
stream.hpp File Reference
#include <stdio.h>
#include <string.h>
#include <zlib.h>
#include "inexor/shared/cube_endian.hpp"
#include "inexor/shared/cube_formatting.hpp"
#include "inexor/shared/cube_types.hpp"
#include "inexor/shared/cube_vector.hpp"

Go to the source code of this file.

Classes

struct  stream
 Legacy file system streams. More...
 
struct  streambuf< T >
 

Functions

char * makerelpath (const char *dir, const char *file, const char *prefix=nullptr, const char *cmd=nullptr)
 Append a string together but add the prefix in the field. More...
 
char * path (char *s)
 Modifies the input string to only contain slashes in the direction the platform allows. More...
 
char * path (const char *s, bool copy)
 Returns a static string with adapted slashes according to the platforms prefered pathseperator. More...
 
const char * parentdir (const char *directory)
 
bool fileexists (const char *path, const char *mode)
 Checks whether given file exists (and is available in the specific mode) Where Path is the filename and mode can optionally be set (but only effects posix systems) ATTENTION: DO NOT USE THIS METHOD DIRECTLY! It doesn't give a fuck about your homedir or any additional package dir, so use findfile instead! Available Modes are "w"/"a" for writeable files only and "d" for executeable files only ATTENTION2: if mode "w" or "a" are specified it checks for (parent) directory existence! More...
 
bool createdir (const char *path)
 Creates a directory of given name. More...
 
size_t fixpackagedir (char *dir)
 
const char * addpackagedir (const char *dir)
 Add an optional media directory. More...
 
const char * findfile (const char *filename, const char *mode)
 Checks whether given file exists (and is available in the specific mode) Where Path is the filename and mode can optionally be set Available Modes are "e" (see. More...
 
streamopenrawfile (const char *filename, const char *mode)
 
streamopenfile (const char *filename, const char *mode)
 
streamopentempfile (const char *filename, const char *mode)
 
streamopengzfile (const char *filename, const char *mode, stream *file=nullptr, int level=Z_BEST_COMPRESSION)
 
streamopenutf8file (const char *filename, const char *mode, stream *file=nullptr)
 
char * loadfile (const char *fn, size_t *size, bool utf8=true)
 
bool listdir (const char *dir, bool rel, const char *ext, vector< char * > &files)
 Internal use only Use listfiles instead. More...
 
int listfiles (const char *dir, const char *ext, vector< char * > &files)
 Lists all files in given directory and put it into vector files ext optionally filters for occurences with such extension only. More...
 

Function Documentation

const char* addpackagedir ( const char *  dir)

Add an optional media directory.

Inexor can have multiple directories for its content it will treat like the games root-folder.

References vector< T, MINSIZE >::add(), copystring(), packagedir::dir, packagedir::dirlen, fixpackagedir(), and newstring().

Referenced by main().

bool createdir ( const char *  path)

Creates a directory of given name.

Returns
Returns true on success

References copystring(), NULL, and PATHDIV.

Referenced by findfile(), and screenshot().

bool fileexists ( const char *  path,
const char *  mode 
)

Checks whether given file exists (and is available in the specific mode) Where Path is the filename and mode can optionally be set (but only effects posix systems) ATTENTION: DO NOT USE THIS METHOD DIRECTLY! It doesn't give a fuck about your homedir or any additional package dir, so use findfile instead! Available Modes are "w"/"a" for writeable files only and "d" for executeable files only ATTENTION2: if mode "w" or "a" are specified it checks for (parent) directory existence!

References parentdir().

Referenced by findfile(), findfile_(), and screenshot().

const char* findfile ( const char *  filename,
const char *  mode 
)

Checks whether given file exists (and is available in the specific mode) Where Path is the filename and mode can optionally be set Available Modes are "e" (see.

Returns
) "w"/"a" for writeable files only and "d" for executeable files only
Returns the filename of the found file (or the, if "e" is specified it returns NULL if nothing was found. Otherwise it returns the inital filename.

References copystring(), createdir(), packagedir::dir, dir, fileexists(), formatstring(), homedir, loopv, and PATHDIV.

Referenced by backup(), findfile_(), loadsurface(), main(), openrawfile(), opentempfile(), game::receivefile(), saveimage(), screenshot(), and game::sendmap().

size_t fixpackagedir ( char *  dir)

References path(), and PATHDIV.

Referenced by addpackagedir().

bool listdir ( const char *  dirname,
bool  rel,
const char *  ext,
vector< char * > &  files 
)

Internal use only Use listfiles instead.

Returns
false if dirname does not exists

References vector< T, MINSIZE >::add(), hmap::d, defformatstring, and newstring().

Referenced by listfiles().

int listfiles ( const char *  dir,
const char *  ext,
vector< char * > &  files 
)

Lists all files in given directory and put it into vector files ext optionally filters for occurences with such extension only.

References copystring(), packagedir::dir, formatstring(), homedir, listdir(), loopv, path(), and PATHDIV.

Referenced by filesval::update().

char* loadfile ( const char *  fn,
size_t *  size,
bool  utf8 = true 
)

References decodeutf8(), f(), openfile(), stream::read(), and stream::size().

Referenced by execfile().

char* makerelpath ( const char *  dir,
const char *  file,
const char *  prefix = nullptr,
const char *  cmd = nullptr 
)
stream* openfile ( const char *  filename,
const char *  mode 
)
stream* opengzfile ( const char *  filename,
const char *  mode,
stream file = nullptr,
int  level = Z_BEST_COMPRESSION 
)
stream* openrawfile ( const char *  filename,
const char *  mode 
)
stream* opentempfile ( const char *  filename,
const char *  mode 
)
stream* openutf8file ( const char *  filename,
const char *  mode,
stream file = nullptr 
)
const char* parentdir ( const char *  filename)
Returns
the parent directory of a file path
Warning
Removes last slash: texture/lastly.dg becomes texture

References copystring().

Referenced by execfile(), fileexists(), md2::load(), md3::loaddefaultparts(), and obj::loaddefaultparts().

char* path ( char *  s)
char* path ( const char *  s,
bool  copy 
)

Returns a static string with adapted slashes according to the platforms prefered pathseperator.

Warning
not threadsafe!

References copystring(), and path().