Inexor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Functions | Variables
stream.cpp File Reference
#include <stdarg.h>
#include <algorithm>
#include <memory>
#include "inexor/io/Logging.hpp"
#include "inexor/io/legacy/stream.hpp"
#include "inexor/network/SharedVar.hpp"
#include "inexor/shared/command.hpp"
#include "inexor/shared/cube_loops.hpp"
#include "inexor/shared/cube_tools.hpp"
#include "inexor/shared/cube_unicode.hpp"
#include "inexor/shared/tools.hpp"
#include "zconf.h"
#include "zlib.h"
#include <dirent.h>
#include <sys/stat.h>
#include <unistd.h>

Classes

struct  packagedir
 
struct  filestream
 
struct  gzstream
 
struct  utf8stream
 

Functions

char * makerelpath (const char *dir, const char *file, const char *prefix, const char *cmd)
 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 *filename)
 
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...
 
bool listdir (const char *dirname, 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...
 
 VAR (dbggz, 0, 0, 1)
 
streamopenrawfile (const char *filename, const char *mode)
 
streamopenfile (const char *filename, const char *mode)
 
streamopentempfile (const char *name, const char *mode)
 
streamopengzfile (const char *filename, const char *mode, stream *file, int level)
 
streamopenutf8file (const char *filename, const char *mode, stream *file)
 
char * loadfile (const char *fn, size_t *size, bool utf8)
 

Variables

string homedir = ""
 
vector< packagedirpackagedirs
 

Class Documentation

struct packagedir
Class Members
const char * dir
size_t dirlen

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 
)

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

Referenced by execfile().

char* makerelpath ( const char *  dir,
const char *  file,
const char *  prefix,
const char *  cmd 
)
stream* openfile ( const char *  filename,
const char *  mode 
)
stream* opengzfile ( const char *  filename,
const char *  mode,
stream file,
int  level 
)
stream* openrawfile ( const char *  filename,
const char *  mode 
)
stream* opentempfile ( const char *  name,
const char *  mode 
)
stream* openutf8file ( const char *  filename,
const char *  mode,
stream file 
)
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().

VAR ( dbggz  ,
,
,
 
)

Variable Documentation

string homedir = ""

Referenced by findfile(), and listfiles().

vector<packagedir> packagedirs