Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VSFileSystem Namespace Reference

Classes

class  VSFile
 

Typedefs

typedef vsUMap< string, VSErrorFileLookupCache
 

Enumerations

enum  VSError {
  Shared, Ok, SocketError, FileNotFound,
  LocalPermissionDenied, RemotePermissionDenied, DownloadInterrupted, IncompleteWrite,
  IncompleteRead, EndOfFile, IsDirectory, BadFormat,
  Unspecified
}
 
enum  VSFileMode { ReadOnly, ReadWrite, CreateWrite }
 
enum  VSFileType {
  UniverseFile, SystemFile, CockpitFile, UnitFile,
  UnitSaveFile, TextureFile, SoundFile, PythonFile,
  MeshFile, CommFile, AiFile, SaveFile,
  AnimFile, VideoFile, VSSpriteFile, MissionFile,
  MusicFile, AccountFile, ZoneBuffer, JPEGBuffer,
  UnknownFile
}
 
enum  VSVolumeType { VSFSNone, VSFSSplit, VSFSBig }
 
enum  VSVolumeFormat { vfmtUNK, vfmtVSR, vfmtPK3 }
 

Functions

void ChangeToProgramDirectory (char *argv0)
 
VSError CachedFileLookup (FileLookupCache &cache, const string &file, VSFileType type)
 
void DisplayType (VSFileSystem::VSFileType type)
 
void DisplayType (VSFileSystem::VSFileType type, std::ostream &ostr)
 
int GetReadBytes (char *fmt, va_list ap)
 
string HOMESUBDIR (".vegastrike")
 
std::string GetHashName (const std::string &name)
 
std::string GetHashName (const std::string &name, const Vector &scale, int faction)
 
std::string GetSharedMeshHashName (const std::string &name, const Vector &scale, int faction)
 
std::string GetSharedTextureHashName (const std::string &name)
 
std::string GetSharedSoundHashName (const std::string &name)
 
std::string MakeSharedPathReturnHome (const std::string &newpath)
 
std::string MakeSharedPath (const std::string &s)
 
std::string MakeSharedStarSysPath (const std::string &s)
 
std::string GetCorrectStarSysPath (const std::string &name, bool &autogenerated)
 
FILE * vs_open (const char *filename, const char *mode)
 
size_t vs_read (void *ptr, size_t size, size_t nmemb, FILE *fp)
 
size_t vs_write (const void *ptr, size_t size, size_t nmemb, FILE *fp)
 
void vs_close (FILE *fp)
 
int vs_fprintf (FILE *fp, const char *format,...)
 
void vs_dprintf (char level, const char *format,...)
 
int vs_fseek (FILE *fp, long offset, int whence)
 
long vs_ftell (FILE *fp)
 
void vs_rewind (FILE *fp)
 
bool vs_feof (FILE *fp)
 
long vs_getsize (FILE *fp)
 
void InitHomeDirectory ()
 
void InitDataDirectory ()
 
void LoadConfig (string subdir)
 
void InitMods ()
 
void InitPaths (string conf, string subdir)
 
void CreateDirectoryAbs (const char *filename)
 
void CreateDirectoryAbs (const string &filename)
 
void CreateDirectoryHome (const char *filename)
 
void CreateDirectoryHome (const string &filename)
 
void CreateDirectoryData (const char *filename)
 
void CreateDirectoryData (const string &filename)
 
bool DirectoryExists (const char *filename)
 
bool DirectoryExists (const string &filename)
 
int FileExists (const string &root, const char *filename, VSFileType type, bool lookinvolume)
 
int FileExists (const string &root, const string &filename, VSFileType type, bool lookinvolume)
 
int FileExistsData (const char *filename, VSFileType type)
 
int FileExistsData (const string &filename, VSFileType type)
 
int FileExistsHome (const char *filename, VSFileType type)
 
int FileExistsHome (const string &filename, VSFileType type)
 
VSError GetError (const char *str)
 
VSError LookForFile (const string &file, VSFileType type, VSFileMode mode)
 
VSError LookForFile (VSFile &f, VSFileType type, VSFileMode mode)
 
static void pathAppend (string &dest, string &suffix)
 
template<class A >
int vs_fscanf (FILE *fp, const char *format, A *a)
 
template<class A , class B >
int vs_fscanf (FILE *fp, const char *format, A *a, B *b)
 
template<class A , class B , class C >
int vs_fscanf (FILE *fp, const char *format, A *a, B *b, C *c)
 
template<class A , class B , class C , class D >
int vs_fscanf (FILE *fp, const char *format, A *a, B *b, C *c, D *d)
 
template<class A , class B , class C , class D , class E >
int vs_fscanf (FILE *fp, const char *format, A *a, B *b, C *c, D *d, E *e)
 
template<class A , class B , class C , class D , class E , class F >
int vs_fscanf (FILE *fp, const char *format, A *a, B *b, C *c, D *d, E *e, F *f)
 
string GetHashName (const std::string &name, const class Vector &scale, int faction)
 
string GetSharedMeshHashName (const std::string &, const class Vector &scale, int faction)
 

Variables

std::string vegastrike_cwd
 
bool use_volumes
 
string volume_format
 
enum VSVolumeFormat q_volume_format
 
vector< vector< string > > SubDirectories
 
vector< string > Directories
 
vector< string > Rootdir
 
string sharedtextures
 
string sharedunits
 
string sharedsounds
 
string sharedmeshes
 
string sharedsectors
 
string sharedcockpits
 
string shareduniverse
 
string aidir
 
string sharedanims
 
string sharedvideos
 
string sharedsprites
 
string savedunitpath
 
string modname
 
string moddir
 
string datadir
 
string homedir
 
string config_file
 
string weapon_list
 
string universe_name
 
vector< string > current_path
 
vector< string > current_directory
 
vector< string > current_subdirectory
 
vector< VSFileTypecurrent_type
 
vector< std::string > savedpwd
 
vector< std::string > curdir
 
vector< std::vector
< std::string > > 
savedcurdir
 
vector< intUseVolumes
 
string failed
 
vsUMap< string, CPK3 * > pk3_opened_files
 
string HOMESUBDIR
 

Typedef Documentation

Definition at line 82 of file vsfilesystem.h.

Enumeration Type Documentation

Enumerator
Shared 
Ok 
SocketError 
FileNotFound 
LocalPermissionDenied 
RemotePermissionDenied 
DownloadInterrupted 
IncompleteWrite 
IncompleteRead 
EndOfFile 
IsDirectory 
BadFormat 
Unspecified 

Definition at line 36 of file vsfilesystem.h.

Enumerator
ReadOnly 
ReadWrite 
CreateWrite 

Definition at line 43 of file vsfilesystem.h.

Enumerator
UniverseFile 
SystemFile 
CockpitFile 
UnitFile 
UnitSaveFile 
TextureFile 
SoundFile 
PythonFile 
MeshFile 
CommFile 
AiFile 
SaveFile 
AnimFile 
VideoFile 
VSSpriteFile 
MissionFile 
MusicFile 
AccountFile 
ZoneBuffer 
JPEGBuffer 
UnknownFile 

Definition at line 46 of file vsfilesystem.h.

47 {
48  //File types
49  UniverseFile, //Loaded from universe subdir
50  SystemFile, //Loaded from sectors subdir written in homedir/sectors/universename
51  CockpitFile, //Loaded from cockpits subdir
52  UnitFile, //Loaded from units subdir
53  UnitSaveFile, //Saved unit file
54  TextureFile, //Loaded from current path or from textures subdir
55  SoundFile, //Loaded from current path or from sounds subdir
56  PythonFile, //Loaded from bases subdir // not really used
57  MeshFile, //Loaded from current path or from meshes subdir
58  CommFile, //Loaded from communications subdir
59  AiFile, //Loaded from ai subdir
60  SaveFile, //Loaded from homedir/save and saved in homedir/save
61  AnimFile, //Loaded from animations subdir
62  VideoFile, //Loaded from movies subdir
63  VSSpriteFile, //Loaded from current path or from sprites subdir
64  MissionFile, //Loaded from mission subdir
65  MusicFile, //Loaded from homedir
66  AccountFile, //Loaded from datadir/accounts and written in datadir/accounts
67  //Buffer types
68  ZoneBuffer, //Indicates a ZoneInfo buffer coming from server
69  JPEGBuffer, //Indicates a JPEG buffer coming from network
70  //Unknown
71  UnknownFile //Loaded from homedir or datadir and written in homedir
72 };
Enumerator
vfmtUNK 
vfmtVSR 
vfmtPK3 

Definition at line 75 of file vsfilesystem.h.

Enumerator
VSFSNone 
VSFSSplit 
VSFSBig 

Definition at line 74 of file vsfilesystem.h.

Function Documentation

VSError VSFileSystem::CachedFileLookup ( FileLookupCache &  cache,
const string &  file,
VSFileType  type 
)

Definition at line 194 of file vsfilesystem.cpp.

References GetHashName(), and LookForFile().

Referenced by getTemplate().

195 {
196  string hashName = GetHashName( file );
197  FileLookupCache::iterator it = cache.find( hashName );
198  if ( it != cache.end() )
199  return it->second;
200 
201  else
202  return cache[hashName] = LookForFile( file, type );
203 }
void VSFileSystem::ChangeToProgramDirectory ( char *  argv0)

Definition at line 136 of file vsfilesystem.cpp.

References c, pwd, vegastrike_cwd, and vs_fprintf().

Referenced by main().

137 {
138  {
139  char pwd[8192];
140  pwd[0] = '\0';
141  if (NULL != getcwd( pwd, 8191 )) {
142  pwd[8191] = '\0';
144  } else {
145  VSFileSystem::vs_fprintf( stderr, "Cannot change to program directory: path too long");
146  }
147  }
148  int ret = -1; /* Should it use argv[0] directly? */
149  char *program = argv0;
150 #ifndef _WIN32
151  char buf[65536];
152  {
153  char linkname[128]; /* /proc/<pid>/exe */
154  linkname[0] = '\0';
155  pid_t pid;
156 
157  /* Get our PID and build the name of the link in /proc */
158  pid = getpid();
159 
160  sprintf( linkname, "/proc/%d/exe", pid );
161  ret = readlink( linkname, buf, 65535 );
162  if (ret <= 0) {
163  sprintf( linkname, "/proc/%d/file", pid );
164  ret = readlink( linkname, buf, 65535 );
165  }
166  if (ret <= 0)
167  ret = readlink( program, buf, 65535 );
168  if (ret > 0) {
169  buf[ret] = '\0';
170  /* Ensure proper NUL termination */
171  program = buf;
172  }
173  }
174 #endif
175 
176  char *parentdir;
177  int pathlen = strlen( program );
178  parentdir = new char[pathlen+1];
179  char *c;
180  strncpy( parentdir, program, pathlen+1 );
181  c = (char*) parentdir;
182  while (*c != '\0') /* go to end */
183  c++;
184  while ( (*c != '/') && (*c != '\\') && c > parentdir ) /* back up to parent */
185  c--;
186  *c = '\0'; /* cut off last part (binary name) */
187  if (strlen( parentdir ) > 0) {
188  if (chdir( parentdir )) /* chdir to the binary app's parent */
189  VSFileSystem::vs_fprintf( stderr, "Cannot change to program directory.");
190  }
191  delete[] parentdir;
192 }
void VSFileSystem::CreateDirectoryAbs ( const char *  filename)

Definition at line 962 of file vsfilesystem.cpp.

References DirectoryExists(), GetError(), and VSExit().

Referenced by CreateDirectoryAbs(), CreateDirectoryData(), CreateDirectoryHome(), and InitHomeDirectory().

963 {
964  int err;
965  if ( !DirectoryExists( filename ) ) {
966  err = mkdir( filename
967 #if !defined (_WIN32) || defined (__CYGWIN__)
968  , 0xFFFFFFFF
969 #endif
970  );
971  if (err < 0 && errno != EEXIST) {
972  cerr<<"Errno="<<errno<<" - FAILED TO CREATE : "<<filename<<endl;
973  GetError( "CreateDirectory" );
974  VSExit( 1 );
975  }
976  }
977 }
void VSFileSystem::CreateDirectoryAbs ( const string &  filename)

Definition at line 979 of file vsfilesystem.cpp.

References CreateDirectoryAbs().

980 {
981  CreateDirectoryAbs( filename.c_str() );
982 }
void VSFileSystem::CreateDirectoryData ( const char *  filename)

Definition at line 991 of file vsfilesystem.cpp.

References CreateDirectoryAbs(), and datadir.

Referenced by CreateDirectoryData().

992 {
993  CreateDirectoryAbs( datadir+"/"+string( filename ) );
994 }
void VSFileSystem::CreateDirectoryData ( const string &  filename)

Definition at line 995 of file vsfilesystem.cpp.

References CreateDirectoryData().

996 {
997  CreateDirectoryData( filename.c_str() );
998 }
void VSFileSystem::CreateDirectoryHome ( const char *  filename)
void VSFileSystem::CreateDirectoryHome ( const string &  filename)

Definition at line 987 of file vsfilesystem.cpp.

References CreateDirectoryHome().

988 {
989  CreateDirectoryHome( filename.c_str() );
990 }
bool VSFileSystem::DirectoryExists ( const char *  filename)

Definition at line 1001 of file vsfilesystem.cpp.

Referenced by CreateDirectoryAbs(), DirectoryExists(), InitHomeDirectory(), LoadConfig(), and ParseCommandLine().

1002 {
1003  struct stat s;
1004  if (stat( filename, &s ) < 0)
1005  return false;
1006  if (s.st_mode&S_IFDIR)
1007  return true;
1008  return false;
1009 }
bool VSFileSystem::DirectoryExists ( const string &  filename)

Definition at line 1010 of file vsfilesystem.cpp.

References DirectoryExists().

1011 {
1012  return DirectoryExists( filename.c_str() );
1013 }
void VSFileSystem::DisplayType ( VSFileSystem::VSFileType  type)

Definition at line 205 of file vsfilesystem.cpp.

Referenced by VSFileSystem::VSFile::Close(), VSFileSystem::VSFile::OpenReadOnly(), and operator<<().

206 {
207  DisplayType( type, std::cerr );
208 }
void VSFileSystem::DisplayType ( VSFileSystem::VSFileType  type,
std::ostream &  ostr 
)

Definition at line 213 of file vsfilesystem.cpp.

References AccountFile, AiFile, AnimFile, CASE, CockpitFile, CommFile, MeshFile, MissionFile, MusicFile, PythonFile, SaveFile, SoundFile, SystemFile, TextureFile, UnitFile, UniverseFile, UnknownFile, VideoFile, VSSpriteFile, and ZoneBuffer.

214 {
215  switch (type)
216  {
218  CASE( VSFileSystem::SystemFile )
219  CASE( VSFileSystem::CockpitFile )
220  CASE( VSFileSystem::UnitFile )
221  CASE( VSFileSystem::PythonFile )
222  CASE( VSFileSystem::TextureFile )
223  CASE( VSFileSystem::SoundFile )
224  CASE( VSFileSystem::MeshFile )
225  CASE( VSFileSystem::CommFile )
226  CASE( VSFileSystem::AiFile )
227  CASE( VSFileSystem::SaveFile )
228  CASE( VSFileSystem::AnimFile )
229  CASE( VSFileSystem::VideoFile )
230  CASE( VSFileSystem::VSSpriteFile )
231  CASE( VSFileSystem::MissionFile )
232  CASE( VSFileSystem::MusicFile )
233  CASE( VSFileSystem::AccountFile )
234  CASE( VSFileSystem::ZoneBuffer )
235  CASE( VSFileSystem::UnknownFile )
236  default:
237  ostr<<"VSFileSystem::<undefined VSFileType>";
238  break;
239  }
240 }
int VSFileSystem::FileExists ( const string &  root,
const char *  filename,
VSFileType  type,
bool  lookinvolume 
)

Definition at line 1017 of file vsfilesystem.cpp.

References Directories, failed, accountXML::file, CPK3::FileExists(), isin_bigvolumes, nameof(), CPK3::Open(), pk3_opened_files, q_volume_format, UnknownFile, UseVolumes, vfmtPK3, vfmtVSR, volume_format, VSFS_DEBUG(), VSFSBig, VSFSNone, and VSFSSplit.

Referenced by FileExists(), FileExistsData(), FileExistsHome(), InitDataDirectory(), InitPaths(), LoadConfig(), LookForFile(), and VSFileSystem::VSFile::OpenReadOnly().

1018 {
1019  int found = -1;
1020  bool volok = false;
1021  string fullpath;
1022  const char *file;
1023  if (filename[0] == '/')
1024  file = filename+1;
1025  else
1026  file = filename;
1027  const char *rootsep = (root == "" || root == "/") ? "" : "/";
1028  if (!UseVolumes[type] || !lookinvolume) {
1029  if (type == UnknownFile)
1030  fullpath = root+rootsep+file;
1031  else
1032  fullpath = root+rootsep+Directories[type]+"/"+file;
1033  struct stat s;
1034  if (stat( fullpath.c_str(), &s ) >= 0) {
1035  if (s.st_mode&S_IFDIR) {
1036  cerr<<" File is a directory ! ";
1037  found = -1;
1038  } else {
1040  found = 1;
1041  }
1042  }
1043  //}
1044  } else {
1045  if (q_volume_format == vfmtVSR) {} else if (q_volume_format == vfmtPK3) {
1046  CPK3 *vol;
1047  string filestr;
1048 
1049  //TRY TO OPEN A DATA.VOLFORMAT FILE IN THE ROOT DIRECTORY PASSED AS AN ARG
1050  filestr = Directories[type]+"/"+file;
1051  fullpath = root+rootsep+"data."+volume_format;
1052  vsUMap< string, CPK3* >::iterator it;
1053  it = pk3_opened_files.find( fullpath );
1054  failed += "Looking for file in VOLUME : "+fullpath+"... ";
1055  if ( it == pk3_opened_files.end() ) {
1056  //File is not opened so we open it and add it in the pk3 file map
1057  vol = new CPK3;
1058  if ( ( volok = vol->Open( fullpath.c_str() ) ) ) {
1059  failed += " VOLUME OPENED\n";
1060  //We add the resource file to the map only if we could have opened it
1061  std::pair< std::string, CPK3* >pk3_pair( fullpath, vol );
1062  pk3_opened_files.insert( pk3_pair );
1063  } else {
1064  failed += " COULD NOT OPEN VOLUME\n";
1065  }
1066  } else {
1067  failed += " VOLUME FOUND\n";
1068  vol = it->second;
1069  volok = true;
1070  }
1071  //Try to get the file index in the archive
1072  if (volok) {
1073  found = vol->FileExists( filestr.c_str() );
1074  if (found >= 0)
1076  } else {
1077  found = -1;
1078  }
1079  if (found < 0) {
1080  //AND THEN A VOLUME FILE BASED ON DIRECTORIES[TYPE]
1081  filestr = string( file );
1082  fullpath = root+rootsep+Directories[type]+"."+volume_format;
1083  it = pk3_opened_files.find( fullpath );
1084  failed += "Looking for file in VOLUME : "+fullpath+"... ";
1085  if ( it == pk3_opened_files.end() ) {
1086  //File is not opened so we open it and add it in the pk3 file map
1087  vol = new CPK3;
1088  if ( ( volok = vol->Open( fullpath.c_str() ) ) ) {
1089  failed += " VOLUME OPENED\n";
1090  //We add the resource file to the map only if we could have opened it
1091  std::pair< std::string, CPK3* >pk3_pair( fullpath, vol );
1092  pk3_opened_files.insert( pk3_pair );
1093  } else {
1094  failed += " COULD NOT OPEN VOLUME\n";
1095  }
1096  } else {
1097  failed += " VOLUME FOUND\n";
1098  vol = it->second;
1099  volok = true;
1100  }
1101  //Try to get the file index in the archive
1102  if (volok) {
1103  found = vol->FileExists( filestr.c_str() );
1104  if (found >= 0)
1106  } else {
1107  found = -1;
1108  }
1109  }
1110  }
1111  }
1112  if (found < 0) {
1113  if (!UseVolumes[type])
1114  failed += "\tTRY LOADING : "+nameof( type )+" "+fullpath+"... NOT FOUND\n";
1115  else if (VSFS_DEBUG() > 1)
1116  failed += "\tTRY LOADING in "+nameof( type )+" "+fullpath+" : "+file+"... NOT FOUND\n";
1117  } else {
1118  if (!UseVolumes[type])
1119  failed = "\tTRY LOADING : "+nameof( type )+" "+fullpath+"... SUCCESS";
1120  else if (VSFS_DEBUG() > 1)
1121  failed = "\tTRY LOADING in "+nameof( type )+" "+fullpath+" : "+file+"... SUCCESS";
1122  else
1123  failed.erase();
1124  }
1125  return found;
1126 }
int VSFileSystem::FileExists ( const string &  root,
const string &  filename,
VSFileType  type,
bool  lookinvolume 
)

Definition at line 1127 of file vsfilesystem.cpp.

References FileExists().

1128 {
1129  return FileExists( root, filename.c_str(), type, lookinvolume );
1130 }
int VSFileSystem::FileExistsData ( const char *  filename,
VSFileType  type 
)

Definition at line 1132 of file vsfilesystem.cpp.

References datadir, and FileExists().

Referenced by MeshAnimation::Init().

1133 {
1134  return FileExists( datadir, filename, type );
1135 }
int VSFileSystem::FileExistsData ( const string &  filename,
VSFileType  type 
)

Definition at line 1136 of file vsfilesystem.cpp.

References datadir, and FileExists().

1137 {
1138  return FileExists( datadir, filename, type );
1139 }
int VSFileSystem::FileExistsHome ( const char *  filename,
VSFileType  type 
)

Definition at line 1141 of file vsfilesystem.cpp.

References FileExists(), and homedir.

1142 {
1143  return FileExists( homedir, filename, type );
1144 }
int VSFileSystem::FileExistsHome ( const string &  filename,
VSFileType  type 
)

Definition at line 1145 of file vsfilesystem.cpp.

References FileExists(), and homedir.

1146 {
1147  return FileExists( homedir, filename, type );
1148 }
string VSFileSystem::GetCorrectStarSysPath ( const std::string &  name,
bool autogenerated 
)

Definition at line 371 of file vsfilesystem.cpp.

References f, Network, Ok, VSFileSystem::VSFile::OpenReadOnly(), Shared, and SystemFile.

Referenced by StarSystem::LoadXML(), and NetClient::loginAccept().

372 {
373  autogenerated = false;
374  if (name.length() == 0)
375  return string( "" );
376  string newname( name );
377  if (Network != NULL) {
378  std::string::size_type dot = name.find( "." );
379  if (dot != std::string::npos)
380  newname = name.substr( 0, dot );
381  newname += ".net.system";
382  }
383  VSFile f;
384  VSError err = f.OpenReadOnly( newname, SystemFile );
385  autogenerated = false;
386  if (err <= Ok)
387  autogenerated = (err == Shared);
388  return newname;
389 }
VSError VSFileSystem::GetError ( const char *  str)

Definition at line 1150 of file vsfilesystem.cpp.

References ENOENT, FileNotFound, LocalPermissionDenied, and Unspecified.

Referenced by VSFileSystem::VSFile::Clear(), CreateDirectoryAbs(), and VSFileSystem::VSFile::ReadFull().

1151 {
1152  cerr<<"!!! ERROR/WARNING VSFile : ";
1153  if (str)
1154  cerr<<"on "<<str<<" : ";
1155  if (errno == ENOENT) {
1156  cerr<<"File not found"<<endl;
1157  return FileNotFound;
1158  } else if (errno == EPERM) {
1159  cerr<<"Permission denied"<<endl;
1160  return LocalPermissionDenied;
1161  } else if (errno == EACCES) {
1162  cerr<<"Access denied"<<endl;
1163  return LocalPermissionDenied;
1164  } else {
1165  cerr<<"Unspecified error (maybe to document in VSFile ?)"<<endl;
1166  return Unspecified;
1167  }
1168 }
string VSFileSystem::GetHashName ( const std::string &  name,
const class Vector scale,
int  faction 
)
string VSFileSystem::GetHashName ( const std::string &  name)
std::string VSFileSystem::GetHashName ( const std::string &  name,
const Vector scale,
int  faction 
)

Definition at line 334 of file vsfilesystem.cpp.

References current_directory, current_path, current_subdirectory, XMLSupport::tostring(), and XMLSupport::VectorToString().

335 {
336  std::string result( "" );
337  result = current_path.back()+current_directory.back()+current_subdirectory.back()+name;
338 
339  result += XMLSupport::VectorToString( scale )+"|"+XMLSupport::tostring( faction );
340  return result;
341 }
int VSFileSystem::GetReadBytes ( char *  fmt,
va_list  ap 
)

Definition at line 243 of file vsfilesystem.cpp.

244 {
245  int ret = 0;
246 
247  cerr<<"STARTING ARGLIST"<<endl;
248  while (*fmt) {
249  switch (*fmt++)
250  {
251  case 'd':
252  break;
253  case 'f':
254  break;
255  case 's':
256  break;
257  case 'g':
258  break;
259  case 'n': //Number of bytes
260  ret = va_arg( ap, int );
261  cerr<<"\tFound 'n' : "<<ret<<endl;
262  break;
263  default:
264  cerr<<"\tOther arg"<<endl;
265  }
266  }
267  cerr<<"ENDING ARGLIST"<<endl;
268  return ret;
269 }
string VSFileSystem::GetSharedMeshHashName ( const std::string &  ,
const class Vector scale,
int  faction 
)
std::string VSFileSystem::GetSharedMeshHashName ( const std::string &  name,
const Vector scale,
int  faction 
)

Definition at line 343 of file vsfilesystem.cpp.

References XMLSupport::tostring(), and XMLSupport::VectorToString().

Referenced by Mesh::LoadExistant(), and Mesh::LoadMeshes().

344 {
345  return string( "#" )+XMLSupport::VectorToString( scale )+string( "#" )+name+string( "#" )+XMLSupport::tostring( faction );
346 }
string VSFileSystem::GetSharedSoundHashName ( const std::string &  name)

Definition at line 351 of file vsfilesystem.cpp.

Referenced by AUDCreateSoundMP3(), AUDCreateSoundWAV(), and AUDLoadSoundFile().

352 {
353  return string( "#ssnd#" )+name;
354 }
string VSFileSystem::GetSharedTextureHashName ( const std::string &  name)

Definition at line 347 of file vsfilesystem.cpp.

Referenced by Texture::checkbad(), Texture::checkold(), Texture::modold(), and Texture::setbad().

348 {
349  return string( "#stex#" )+name;
350 }
string VSFileSystem::HOMESUBDIR ( ".vegastrike"  )
void VSFileSystem::InitDataDirectory ( )

Definition at line 552 of file vsfilesystem.cpp.

References c, config_file, datadir, fclose, FileExists(), fopen, HOMESUBDIR, moddir, vegastrike_cwd, and vs_fprintf().

Referenced by InitPaths().

553 {
554  vector< string >data_paths;
555 
556  /* commandline-specified paths come first */
557  if (!datadir.empty())
558  data_paths.push_back( datadir );
559 
560  /* DATA_DIR should no longer be necessary--it will either use the path
561  * to the binary, or the current directory. */
562 #ifdef DATA_DIR
563  data_paths.push_back( DATA_DIR );
564 #endif
565  if ( !vegastrike_cwd.empty() ) {
566  data_paths.push_back( vegastrike_cwd );
567  data_paths.push_back( vegastrike_cwd+"/.." );
568  data_paths.push_back( vegastrike_cwd+"/../data4.x" );
569  data_paths.push_back( vegastrike_cwd+"/../../data4.x" );
570  data_paths.push_back( vegastrike_cwd+"/../../data" );
571  data_paths.push_back( vegastrike_cwd+"/data4.x" );
572  data_paths.push_back( vegastrike_cwd+"/data" );
573  data_paths.push_back( vegastrike_cwd+"/../data" );
574  data_paths.push_back( vegastrike_cwd+"/../Resources" );
575  }
576  data_paths.push_back( "." );
577  data_paths.push_back( ".." );
578  //data_paths.push_back( "../data4.x" ); DELETE 4.x no longer used since .5 release obsolete, removal required.
579  //data_paths.push_back( "../../data4.x" );
580  data_paths.push_back( "../data" );
581  data_paths.push_back( "../../data" );
582  data_paths.push_back( "../Resources" );
583  data_paths.push_back( "../Resources/data" );
584  //data_paths.push_back( "../Resources/data4.x" );
585 
586  //Win32 data should be "."
587  char tmppath[16384];
588  for (vector< string >::iterator vsit = data_paths.begin(); vsit != data_paths.end(); vsit++)
589  //Test if the dir exist and contains config_file
590  if (FileExists( (*vsit), config_file ) >= 0) {
591  cerr<<"Found data in "<<(*vsit)<<endl;
592  if (NULL != getcwd( tmppath, 16384 )) {
593  if ( (*vsit).substr( 0, 1 ) == "." )
594  datadir = string( tmppath )+"/"+(*vsit);
595  else
596  datadir = (*vsit);
597  } else {
598  VSFileSystem::vs_fprintf( stderr, "Cannot get current path: path too long");
599  }
600 
601  if (chdir( datadir.c_str() ) < 0) {
602  cerr<<"Error changing to datadir"<<endl;
603  exit( 1 );
604  }
605  if (NULL != getcwd( tmppath, 16384 )) {
606  datadir = string( tmppath );
607  } else {
608  VSFileSystem::vs_fprintf( stderr, "Cannot get current path: path too long");
609  }
610 
611  cerr<<"Using "<<datadir<<" as data directory"<<endl;
612  break;
613  }
614  data_paths.clear();
615  string versionloc = datadir+"/Version.txt";
616  FILE *version = fopen( versionloc.c_str(), "r" );
617  if (!version) {
618  versionloc = datadir+"Version.txt";
619  version = fopen( versionloc.c_str(), "r" );
620  }
621  if (!version)
622  version = fopen( "Version.txt", "r" );
623  if (version) {
624  string hsd = "";
625  int c;
626  while ( ( c = fgetc( version ) ) != EOF ) {
627  if ( isspace( c ) )
628  break;
629  hsd += (char) c;
630  }
631  fclose( version );
632  if ( hsd.length() ) {
633  HOMESUBDIR = hsd;
634  printf( "Using %s as the home directory\n", hsd.c_str() );
635  }
636  }
637  //Get the mods path
638  moddir = datadir+"/"+string( "mods" );
639  cout<<"Found MODDIR = "<<moddir<<endl;
640 }
void VSFileSystem::InitHomeDirectory ( )

Definition at line 531 of file vsfilesystem.cpp.

References CreateDirectoryAbs(), datadir, DirectoryExists(), homedir, HOMESUBDIR, and VSExit().

Referenced by InitPaths().

532 {
533  //Setup home directory
534  char *chome_path = NULL;
535 #ifndef _WIN32
536  struct passwd *pwent;
537  pwent = getpwuid( getuid() );
538  chome_path = pwent->pw_dir;
539  if ( !DirectoryExists( chome_path ) ) {
540  cerr<<"!!! ERROR : home directory not found"<<endl;
541  VSExit( 1 );
542  }
543  string user_home_path( chome_path );
544  homedir = user_home_path+"/"+HOMESUBDIR;
545 #else
546  homedir = datadir+"/"+HOMESUBDIR;
547 #endif
548  cerr<<"USING HOMEDIR : "<<homedir<<" As the home directory "<<endl;
550 }
void VSFileSystem::InitMods ( )

Definition at line 725 of file vsfilesystem.cpp.

References curmodpath, datadir, VegaConfig::getVariable(), homedir, moddir, modname, Rootdir, selectcurrentdir, selectdirs(), and vs_config.

Referenced by InitPaths().

726 {
727  string curpath;
728  struct dirent **dirlist;
729  //new config program should insert hqtextures variable
730  //with value "hqtextures" in data section.
731  string hq = vs_config->getVariable( "data", "hqtextures", "" );
732  if (hq != "") {
733  //HQ Texture dir sits alongside data dir.
734  selectcurrentdir = datadir+"/..";
735  int ret = scandir( selectcurrentdir.c_str(), &dirlist, selectdirs, 0 );
736  if (ret >= 0) {
737  while (ret--) {
738  string dname( dirlist[ret]->d_name );
739  if (dname == hq) {
740  curpath = selectcurrentdir+"/"+dname;
741  cout<<"\n\nAdding HQ Textures Pack\n\n";
742  Rootdir.push_back( curpath );
743  }
744  }
745  }
746  free( dirlist );
747  }
749  int ret = scandir( selectcurrentdir.c_str(), &dirlist, selectdirs, 0 );
750  if (ret < 0) {
751  return;
752  } else {
753  while (ret--) {
754  string dname( dirlist[ret]->d_name );
755  if (dname == modname) {
756  curpath = moddir+"/"+dname;
757  cout<<"Adding mod path : "<<curpath<<endl;
758  Rootdir.push_back( curpath );
759  }
760  }
761  }
762  free( dirlist );
763  //Scan for mods with standard data subtree
764  curmodpath = homedir+"/mods/";
766  ret = scandir( selectcurrentdir.c_str(), &dirlist, selectdirs, 0 );
767  if (ret < 0) {
768  return;
769  } else {
770  while (ret--) {
771  string dname( dirlist[ret]->d_name );
772  if (dname == modname) {
773  curpath = curmodpath+dname;
774  cout<<"Adding mod path : "<<curpath<<endl;
775  Rootdir.push_back( curpath );
776  }
777  }
778  }
779  free( dirlist );
780 }
void VSFileSystem::InitPaths ( string  conf,
string  subdir 
)

Definition at line 782 of file vsfilesystem.cpp.

References AccountFile, aidir, AiFile, AnimFile, CockpitFile, CommFile, config_file, CreateDirectoryHome(), current_directory, current_path, current_subdirectory, current_type, datadir, Directories, FileExists(), VegaConfig::getVariable(), homedir, i, InitDataDirectory(), InitHomeDirectory(), InitMods(), LoadConfig(), MeshFile, MissionFile, MusicFile, PythonFile, q_volume_format, Rootdir, savedunitpath, SaveFile, sharedanims, sharedcockpits, sharedmeshes, sharedsectors, sharedsounds, sharedsprites, sharedtextures, sharedunits, shareduniverse, sharedvideos, SIMULATION_ATOM, simulation_atom_var, SoundFile, SubDirectories, SystemFile, TextureFile, UnitFile, UnitSaveFile, universe_name, UniverseFile, UnknownFile, UseVolumes, vfmtPK3, vfmtUNK, vfmtVSR, VideoFile, volume_format, vs_config, VSSpriteFile, and ZoneBuffer.

Referenced by main(), AccountServer::start(), and NetServer::start().

783 {
784  config_file = conf;
785 
786  current_path.push_back( "" );
787  current_directory.push_back( "" );
788  current_subdirectory.push_back( "" );
789  current_type.push_back( UnknownFile );
790 
791  int i;
792  for (i = 0; i <= UnknownFile; i++)
793  UseVolumes.push_back( 0 );
794  /************************** Data and home directory settings *************************/
795 
796  InitDataDirectory(); //Need to be first for win32
798  LoadConfig( subdir );
799  //Paths relative to datadir or homedir (both should have the same structure)
800  //Units are in sharedunits/unitname/, sharedunits/subunits/unitname/ or sharedunits/weapons/unitname/ or in sharedunits/faction/unitname/
801  //Meshes are in sharedmeshes/ or in current unit that is being loaded
802  //Textures are in sharedtextures/ or in current unit dir that is being loaded or in the current animation dir that is being loaded or in the current sprite dir that is being loeded
803  //Sounds are in sharedsounds/
804  //Universes are in universe/
805  //Systems are in "sectors"/ config variable
806  //Cockpits are in cockpits/ (also a config var)
807  //Animations are in animations/
808  //VSSprite are in sprites/ or in ./ (when full subpath is provided) or in the current cockpit dir that is being loaded
809  //First allocate an empty directory list for each file type
810  for (i = 0; i < UnknownFile; i++) {
811  vector< string >vec;
812  Directories.push_back( "" );
813  SubDirectories.push_back( vec );
814  }
815  sharedsectors = vs_config->getVariable( "data", "sectors", "sectors" );
816  sharedcockpits = vs_config->getVariable( "data", "cockpits", "cockpits" );
817  shareduniverse = vs_config->getVariable( "data", "universe_path", "universe" );
818  sharedanims = vs_config->getVariable( "data", "animations", "animations" );
819  sharedvideos = vs_config->getVariable( "data", "movies", "movies" );
820  sharedsprites = vs_config->getVariable( "data", "sprites", "sprites" );
821  savedunitpath = vs_config->getVariable( "data", "serialized_xml", "serialized_xml" );
822  sharedtextures = vs_config->getVariable( "data", "sharedtextures", "textures" );
823  sharedsounds = vs_config->getVariable( "data", "sharedsounds", "sounds" );
824  sharedmeshes = vs_config->getVariable( "data", "sharedmeshes", "meshes" );
825  sharedunits = vs_config->getVariable( "data", "sharedunits", "units" );
826  aidir = vs_config->getVariable( "data", "ai_directory", "ai" );
827  universe_name = vs_config->getVariable( "general", "galaxy", "milky_way.xml" );
828 
829  //Setup the directory lists we know about - note these are relative paths to datadir or homedir
830  //----- THE Directories vector contains the resource/volume files name without extension or the main directory to files
832  //Have to put it in first place otherwise VS will find default unit file
833  SubDirectories[UnitFile].push_back( "subunits" );
834  SubDirectories[UnitFile].push_back( "weapons" );
835  SubDirectories[UnitFile].push_back( "" );
836  SubDirectories[UnitFile].push_back( "factions/planets" );
837  SubDirectories[UnitFile].push_back( "factions/upgrades" );
838  SubDirectories[UnitFile].push_back( "factions/neutral" );
839  SubDirectories[UnitFile].push_back( "factions/aera" );
840  SubDirectories[UnitFile].push_back( "factions/confed" );
841  SubDirectories[UnitFile].push_back( "factions/pirates" );
842  SubDirectories[UnitFile].push_back( "factions/rlaan" );
843 
845 
847  SubDirectories[MeshFile].push_back( "mounts" );
848  SubDirectories[MeshFile].push_back( "nav/default" );
849 
851  SubDirectories[TextureFile].push_back( "mounts" );
852  SubDirectories[TextureFile].push_back( "nav/default" );
853 
854  //We will also look in subdirectories with universe name
857 
864 
866  SubDirectories[AiFile].push_back( "events" );
867  SubDirectories[AiFile].push_back( "script" );
868 
869  Directories[MissionFile] = "mission";
870  Directories[CommFile] = "communications";
871  Directories[SaveFile] = "save";
872  Directories[MusicFile] = "music";
873  Directories[PythonFile] = "bases";
874  Directories[AccountFile] = "accounts";
875 
876  simulation_atom_var = atof( vs_config->getVariable( "general", "simulation_atom", "0.1" ).c_str() );
877  cout<<"SIMULATION_ATOM: "<<SIMULATION_ATOM<<endl;
878 
879  /************************* Home directory subdirectories creation ************************/
882  CreateDirectoryHome( sharedtextures+"/backgrounds" );
886  CreateDirectoryHome( "save" );
887 
888  //We will be able to automatically add mods files (set of resources or even directory structure similar to the data tree)
889  //by just adding a subdirectory named with the mod name in the subdirectory "mods"...
890  //I just have to implement that and then add all mods/ subdirs in Rootdir vector
891  Rootdir.push_back( homedir );
892  InitMods();
893  Rootdir.push_back( datadir );
894 
895  //NOTE : UniverseFiles cannot use volumes since some are needed by python
896  //Also : Have to try with systems, not sure it would work well
897  //Setup the use of volumes for certain VSFileType
898  volume_format = vs_config->getVariable( "data", "volume_format", "pk3" );
899  if (volume_format == "vsr")
901 
902  else if (volume_format == "pk3")
904 
905  else
907  if (FileExists( datadir, "/data."+volume_format ) >= 0) {
908  //Every kind of file will use the big volume except Unknown files and python files that needs to remain standard files
909  for (i = 0; i < UnknownFile; i++)
910  UseVolumes[i] = 2;
911  UseVolumes[PythonFile] = 0;
912  UseVolumes[AccountFile] = 0;
913  } else {
914  if (FileExists( datadir, "/"+sharedunits+"."+volume_format ) >= 0) {
915  UseVolumes[UnitFile] = 1;
916  cout<<"Using volume file "<<(datadir+"/"+sharedunits)<<".pk3"<<endl;
917  }
918  if (FileExists( datadir, "/"+sharedmeshes+"."+volume_format ) >= 0) {
919  UseVolumes[MeshFile] = 1;
920  cout<<"Using volume file "<<(datadir+"/"+sharedmeshes)<<".pk3"<<endl;
921  }
922  if (FileExists( datadir, "/"+sharedtextures+"."+volume_format ) >= 0) {
923  UseVolumes[TextureFile] = 1;
924  cout<<"Using volume file "<<(datadir+"/"+sharedtextures)<<".pk3"<<endl;
925  }
926  if (FileExists( datadir, "/"+sharedsounds+"."+volume_format ) >= 0) {
927  UseVolumes[SoundFile] = 1;
928  cout<<"Using volume file "<<(datadir+"/"+sharedsounds)<<".pk3"<<endl;
929  }
930  if (FileExists( datadir, "/"+sharedcockpits+"."+volume_format ) >= 0) {
931  UseVolumes[CockpitFile] = 1;
932  cout<<"Using volume file "<<(datadir+"/"+sharedcockpits)<<".pk3"<<endl;
933  }
934  if (FileExists( datadir, "/"+sharedsprites+"."+volume_format ) >= 0) {
936  cout<<"Using volume file "<<(datadir+"/"+sharedsprites)<<".pk3"<<endl;
937  }
938  if (FileExists( datadir, "/animations."+volume_format ) >= 0) {
939  UseVolumes[AnimFile] = 1;
940  cout<<"Using volume file "<<(datadir+"/animations")<<".pk3"<<endl;
941  }
942  if (FileExists( datadir, "/movies."+volume_format ) >= 0) {
943  UseVolumes[VideoFile] = 1;
944  cout<<"Using volume file "<<(datadir+"/movies")<<".pk3"<<endl;
945  }
946  if (FileExists( datadir, "/communications."+volume_format ) >= 0) {
947  UseVolumes[CommFile] = 1;
948  cout<<"Using volume file "<<(datadir+"/communications")<<".pk3"<<endl;
949  }
950  if (FileExists( datadir, "/mission."+volume_format ) >= 0) {
951  UseVolumes[MissionFile] = 1;
952  cout<<"Using volume file "<<(datadir+"/mission")<<".pk3"<<endl;
953  }
954  if (FileExists( datadir, "/ai."+volume_format ) >= 0) {
955  UseVolumes[AiFile] = 1;
956  cout<<"Using volume file "<<(datadir+"/ai")<<".pk3"<<endl;
957  }
958  UseVolumes[ZoneBuffer] = 0;
959  }
960 }
void VSFileSystem::LoadConfig ( string  subdir)

Definition at line 644 of file vsfilesystem.cpp.

References config_file, CreateDirectoryHome(), createVegaConfig(), datadir, DirectoryExists(), FileExists(), fprintf, VegaConfig::getVariable(), homedir, moddir, modname, vs_config, VSExit(), and weapon_list.

Referenced by InitPaths().

645 {
646  bool found = false;
647  bool foundweapons = false;
648  //First check if we have a config file in homedir+"/"+subdir or in datadir+"/"+subdir
649  weapon_list = "weapon_list.xml";
650  if (subdir != "") {
651  modname = subdir;
652  if ( DirectoryExists( homedir+"/mods/"+subdir ) ) {
653  if (FileExists( homedir+"/mods/"+subdir, config_file ) >= 0) {
654  cout<<"CONFIGFILE - Found a config file in home mod directory, using : "
655  <<(homedir+"/mods/"+subdir+"/"+config_file)<<endl;
656  if (FileExists( homedir+"/mods/"+subdir, "weapon_list.xml" ) >= 0) {
657  weapon_list = homedir+"/mods/"+subdir+"/weapon_list.xml";
658  foundweapons = true;
659  }
660  config_file = homedir+"/mods/"+subdir+"/"+config_file;
661  found = true;
662  }
663  }
664  if (!found)
665  cout<<"WARNING : coudn't find a mod named '"<<subdir<<"' in homedir/mods"<<endl;
666  if ( DirectoryExists( moddir+"/"+subdir ) ) {
667  if (FileExists( moddir+"/"+subdir, config_file ) >= 0) {
668  if (!found)
669  cout<<"CONFIGFILE - Found a config file in mods directory, using : "
670  <<(moddir+"/"+subdir+"/"+config_file)<<endl;
671  if ( (!foundweapons) && FileExists( moddir+"/"+subdir, "weapon_list.xml" ) >= 0 ) {
672  weapon_list = moddir+"/"+subdir+"/weapon_list.xml";
673  foundweapons = true;
674  }
675  if (!found) config_file = moddir+"/"+subdir+"/"+config_file;
676  found = true;
677  }
678  } else {
679  cout<<"ERROR : coudn't find a mod named '"<<subdir<<"' in datadir/mods"<<endl;
680  }
681  //}
682  }
683  if (!found) {
684  //Next check if we have a config file in homedir if we haven't found one for mod
685  if (FileExists( homedir, config_file ) >= 0) {
686  cerr<<"CONFIGFILE - Found a config file in home directory, using : "<<(homedir+"/"+config_file)<<endl;
688  } else {
689  cerr<<"CONFIGFILE - No config found in home : "<<(homedir+"/"+config_file)<<endl;
690  if (FileExists( datadir, config_file ) >= 0) {
691  cerr<<"CONFIGFILE - No home config file found, using datadir config file : "<<(datadir+"/"+config_file)<<endl;
692  //We didn't find a config file in home_path so we load the data_path one
693  }
694  else {
695  cerr<<"CONFIGFILE - No config found in data dir : "<<(datadir+"/"+config_file)<<endl;
696  cerr<<"CONFIG FILE NOT FOUND !!!"<<endl;
697  VSExit( 1 );
698  }
699  }
700  } else if (subdir != "") {
701  printf( "Using Mod Directory %s\n", moddir.c_str() );
702  CreateDirectoryHome( "mods" );
703  CreateDirectoryHome( "mods/"+subdir );
704  homedir = homedir+"/mods/"+subdir;
705  }
706  //Delete the default config in order to reallocate it with the right one (if it is a mod)
707  if (vs_config) {
708  fprintf( stderr, "reallocating vs_config \n" );
709  delete vs_config;
710  }
712 
713  //Now check if there is a data directory specified in it
714  //NOTE : THIS IS NOT A GOOD IDEA TO HAVE A DATADIR SPECIFIED IN THE CONFIG FILE
715  static string data_path( vs_config->getVariable( "data", "datadir", "" ) );
716  if (data_path != "") {
717  //We found a path to data in config file
718  cout<<"DATADIR - Found a datadir in config, using : "<<data_path<<endl;
719  datadir = data_path;
720  } else {
721  cout<<"DATADIR - No datadir specified in config file, using ; "<<datadir<<endl;
722  }
723 }
VSError VSFileSystem::LookForFile ( const string &  file,
VSFileType  type,
VSFileMode  mode 
)
VSError VSFileSystem::LookForFile ( VSFile f,
VSFileType  type,
VSFileMode  mode 
)

Definition at line 1178 of file vsfilesystem.cpp.

References AccountFile, AiFile, AnimFile, CockpitFile, CommFile, current_path, current_subdirectory, current_type, Directories, failed, FileExists(), FileNotFound, VSFileSystem::VSFile::GetFilename(), VSFileSystem::VSFile::GetSubDirectory(), GetUnitDir(), homedir, i, isin_bigvolumes, j, JPEGBuffer, MeshFile, MissionFile, MusicFile, Ok, PythonFile, Rootdir, SaveFile, VSFileSystem::VSFile::SetAltType(), VSFileSystem::VSFile::SetDirectory(), VSFileSystem::VSFile::SetIndex(), VSFileSystem::VSFile::SetRoot(), VSFileSystem::VSFile::SetSubDirectory(), VSFileSystem::VSFile::SetVolume(), Shared, SoundFile, SubDirectories, SystemFile, TextureFile, UnitFile, UnitSaveFile, UniverseFile, UnknownFile, UseVolumes, VideoFile, VSFS_DEBUG(), VSFSNone, VSSpriteFile, and ZoneBuffer.

1179 {
1180  int found = -1, shared = false;
1181  string filepath, curpath, dir, extra( "" ), subdir;
1182  failed.erase();
1183  VSFileType curtype = type;
1184  //First try in the current path
1185  switch (type)
1186  {
1187  case UnitFile:
1188  extra = "/"+GetUnitDir( f.GetFilename() );
1189  break;
1190  case CockpitFile:
1191  //For cockpits we look in subdirectories that have the same name as the cockpit itself
1192  extra = "/"+string( f.GetFilename() );
1193  break;
1194  case AnimFile:
1195  //Animations are always in subdir named like the anim itself
1196  extra += "/"+f.GetFilename();
1197  break;
1198  case UniverseFile:
1199  case SystemFile:
1200  case UnitSaveFile:
1201  case TextureFile:
1202  case SoundFile:
1203  case PythonFile:
1204  case MeshFile:
1205  case CommFile:
1206  case AiFile:
1207  case SaveFile:
1208  case VideoFile:
1209  case VSSpriteFile:
1210  case MissionFile:
1211  case MusicFile:
1212  case AccountFile:
1213  case ZoneBuffer:
1214  case JPEGBuffer:
1215  case UnknownFile:
1216  break;
1217  }
1218  //This test lists all the VSFileType that should be looked for in the current directory
1219  unsigned int i = 0, j = 0;
1220  for (int LC = 0; LC < 2 && found < 0; ( LC += (extra == "" ? 2 : 1) ), extra = "") {
1221  if ( current_path.back() != ""
1222  && (type == TextureFile || type == MeshFile || type == VSSpriteFile || type == AnimFile || type == VideoFile) ) {
1223  for (i = 0; found < 0 && i < Rootdir.size(); i++) {
1224  curpath = Rootdir[i];
1225  subdir = current_subdirectory.back();
1226  if (extra != "")
1227  subdir += extra;
1228  curtype = current_type.back();
1229  found = FileExists( curpath, ( subdir+"/"+f.GetFilename() ).c_str(), curtype );
1230  if (found >= 0) {
1231  shared = false;
1232  f.SetAltType( curtype );
1233  } else {
1234  //Set curtype back to original type if we didn't find the file in the current dir
1235 
1236  curtype = type;
1237  shared = true;
1238  }
1239  }
1240  }
1241  //FIRST LOOK IN HOMEDIR FOR A STANDARD FILE, SO WHEN USING VOLUME WE DO NOT LOOK FIRST IN VOLUMES
1242  if (found < 0 && UseVolumes[curtype]) {
1243  curpath = homedir;
1244  subdir = "";
1245  if (extra != "")
1246  subdir += extra;
1247  found = FileExists( curpath, ( subdir+"/"+f.GetFilename() ).c_str(), type, false );
1248  for (j = 0; found < 0 && j < SubDirectories[curtype].size(); j++) {
1249  subdir = SubDirectories[curtype][j];
1250  if (extra != "")
1251  subdir += extra;
1252  found = FileExists( curpath, ( subdir+"/"+f.GetFilename() ).c_str(), curtype, false );
1253  f.SetVolume( VSFSNone );
1254  }
1255  }
1256  //THEN LOOK IN ALL THE REGISTERED ROOT DIRS
1257  for (i = 0; found < 0 && i < Rootdir.size(); i++) {
1258  curpath = Rootdir[i];
1259  subdir = f.GetSubDirectory();
1260  if (extra != "")
1261  subdir += extra;
1262  found = FileExists( curpath, ( subdir+"/"+f.GetFilename() ).c_str(), curtype );
1263  for (j = 0; found < 0 && j < SubDirectories[curtype].size(); j++) {
1264  curpath = Rootdir[i];
1265  subdir = SubDirectories[curtype][j];
1266  if ( f.GetSubDirectory().length() ) {
1267  if ( subdir.length() ) subdir += "/";
1268  subdir += f.GetSubDirectory();
1269  }
1270  if (extra != "")
1271  subdir += extra;
1272  found = FileExists( curpath, ( subdir+"/"+f.GetFilename() ).c_str(), curtype );
1273  }
1274  }
1275  if (curtype == CockpitFile) {
1276  for (i = 0; found < 0 && i < Rootdir.size(); i++) {
1277  curpath = Rootdir[i];
1278  subdir = "";
1279  found = FileExists( curpath, ( subdir+"/"+f.GetFilename() ).c_str(), type );
1280  for (j = 0; found < 0 && j < SubDirectories[curtype].size(); j++) {
1281  curpath = Rootdir[i];
1282  subdir = SubDirectories[curtype][j];
1283  if (extra != "")
1284  subdir += extra;
1285  found = FileExists( curpath, ( subdir+"/"+f.GetFilename() ).c_str(), curtype );
1286  }
1287  }
1288  }
1289  }
1290  if (VSFS_DEBUG() > 1) {
1291  if (isin_bigvolumes > VSFSNone)
1292  cerr<<failed<<" - INDEX="<<found<<endl<<endl;
1293  else
1294  cerr<<failed<<endl;
1295  }
1296  if (found >= 0) {
1297  if ( (type == SystemFile && i == 0) || (type == SoundFile /*right now only allow shared ones?!*/) /* Rootdir[i]==homedir*/ )
1298  shared = true;
1299  f.SetDirectory( Directories[curtype] );
1300  f.SetSubDirectory( subdir );
1301  f.SetRoot( curpath );
1303  //If we found a file in a volume we store its index in the concerned archive
1304  if (UseVolumes[curtype] && isin_bigvolumes > VSFSNone)
1305  f.SetIndex( found );
1307  if (shared)
1308  return Shared;
1309  else
1310  return Ok;
1311  }
1312  return FileNotFound;
1313 }
string VSFileSystem::MakeSharedPath ( const std::string &  s)

Definition at line 361 of file vsfilesystem.cpp.

References MakeSharedPathReturnHome(), and vs_fprintf().

362 {
363  VSFileSystem::vs_fprintf( stderr, "MakingSharedPath %s", s.c_str() );
364  return MakeSharedPathReturnHome( s )+s;
365 }
std::string VSFileSystem::MakeSharedPathReturnHome ( const std::string &  newpath)

Definition at line 356 of file vsfilesystem.cpp.

References CreateDirectoryHome().

Referenced by MakeSharedPath(), and MakeSharedStarSysPath().

357 {
358  CreateDirectoryHome( newpath );
359  return newpath+string( "/" );
360 }
string VSFileSystem::MakeSharedStarSysPath ( const std::string &  s)

Definition at line 366 of file vsfilesystem.cpp.

References getStarSystemSector(), MakeSharedPathReturnHome(), and sharedsectors.

367 {
368  string syspath = sharedsectors+"/"+getStarSystemSector( s );
369  return MakeSharedPathReturnHome( syspath )+s;
370 }
static void VSFileSystem::pathAppend ( string &  dest,
string &  suffix 
)
static

Definition at line 1904 of file vsfilesystem.cpp.

Referenced by VSFileSystem::VSFile::GetAbsPath(), and VSFileSystem::VSFile::GetFullPath().

1905 {
1906  if ( suffix.empty() )
1907  return;
1908  if (suffix[0] != '/' && !dest.empty() && dest[dest.length()-1] != '/')
1909  dest += "/";
1910  dest += suffix;
1911 }
void VSFileSystem::vs_close ( FILE *  fp)
bool VSFileSystem::vs_feof ( FILE *  fp)

Definition at line 509 of file vsfilesystem.cpp.

Referenced by BaseInterface::Room::Click(), VSFileSystem::VSFile::Eof(), and ReadIntSpace().

510 {
511  return feof( fp );
512 }
int VSFileSystem::vs_fprintf ( FILE *  fp,
const char *  format,
  ... 
)

Definition at line 461 of file vsfilesystem.cpp.

References use_volumes.

Referenced by Unit::Accelerate(), AllocVerticesForSystem(), Unit::ApplyForce(), Unit::ApplyLocalForce(), AUDAddWatchedPlayed(), AUDDeleteSound(), BaseInterface::BaseInterface(), accountXML::beginElement(), Planet::beginElement(), BeamXML::beginElement(), StarSystemGent::beginStar(), BoltDestroyGeneric(), ChangeToProgramDirectory(), BaseInterface::Room::Talk::Click(), ContinuousTerrain::Collide(), Beam::Collide(), BaseUtil::CompPython(), compute_light_dot(), ContinuousTerrain::ContinuousTerrain(), ROLES::discreteLog(), gfx_light::dopickenables(), BaseInterface::Draw(), EnvironmentMapGeneratorMain(), Orders::MatchLinearVelocity::Execute(), AIScript::Execute(), Orders::AggressiveAI::Execute(), Unit::Fire(), Universe::Generate2(), generateStarSystem(), ContinuousTerrain::GetGroundPosIdentTrans(), ROLES::getPriority(), getProgramSource(), ROLES::getRoleEvents(), Technique::getTechnique(), Planet::GetTopPlanet(), GFXReloadDefaultShader(), BaseInterface::GotoLink(), InitDataDirectory(), StarSystem::JumpTo(), LaunchConverter(), Mesh::LoadMeshes(), BaseComputer::loadMissionsMasterList(), Nebula::LoadXML(), main(), MakeSharedPath(), Music::Music(), Unit::ProcessDeleteQueue(), StarSystem::ProcessPendingJumps(), GamePlanet::reactToCollision(), readplanetentity(), Orders::AggressiveAI::ReCommandWing(), Unit::Repair(), Unit::ResolveForces(), FactionUtil::SerializeFaction(), Universe::SetActiveCockpit(), SaveGame::SetPlayerLocation(), Camera::SetPosition(), NavigationSystem::Setup(), Orders::FireAt::ShouldFire(), GameUniverse::StartDraw(), GameUnit< UnitType >::TransferUnitToSystem(), Unit::TransferUnitToSystem(), unpicklights(), winsys_atexit(), winsys_init(), AImissionScript::~AImissionScript(), AIScript::~AIScript(), Orders::AutoLongHaul::~AutoLongHaul(), Orders::ChangeHeading::~ChangeHeading(), CloakFor::~CloakFor(), Orders::FaceDirection::~FaceDirection(), Orders::FaceTarget::~FaceTarget(), Orders::FaceTargetITTS::~FaceTargetITTS(), Orders::FireAt::~FireAt(), FireKeyboard::~FireKeyboard(), FlyByWire::~FlyByWire(), Orders::MatchAngularVelocity::~MatchAngularVelocity(), Orders::MatchLinearVelocity::~MatchLinearVelocity(), Orders::MatchVelocity::~MatchVelocity(), Mesh::~Mesh(), Mission::~Mission(), Orders::MoveTo::~MoveTo(), PythonAI< SuperClass >::~PythonAI(), PythonMissionBaseClass::~PythonMissionBaseClass(), and Unit::~Unit().

462 {
463  if (!use_volumes) {
464  va_list ap;
465  va_start( ap, format );
466 
467  return vfprintf( fp, format, ap );
468  } else {}
469  return 0;
470 }
template<class A >
int VSFileSystem::vs_fscanf ( FILE *  fp,
const char *  format,
A *  a 
)

Definition at line 159 of file vsfilesystem.h.

Referenced by BaseInterface::Room::Click(), and ContinuousTerrain::ContinuousTerrain().

160 {
161  return fscanf( fp, format, a );
162 }
template<class A , class B >
int VSFileSystem::vs_fscanf ( FILE *  fp,
const char *  format,
A *  a,
B *  b 
)

Definition at line 164 of file vsfilesystem.h.

165 {
166  return fscanf( fp, format, a, b );
167 }
template<class A , class B , class C >
int VSFileSystem::vs_fscanf ( FILE *  fp,
const char *  format,
A *  a,
B *  b,
C *  c 
)

Definition at line 169 of file vsfilesystem.h.

170 {
171  return fscanf( fp, format, a, b, c );
172 }
template<class A , class B , class C , class D >
int VSFileSystem::vs_fscanf ( FILE *  fp,
const char *  format,
A *  a,
B *  b,
C *  c,
D *  d 
)

Definition at line 174 of file vsfilesystem.h.

175 {
176  return fscanf( fp, format, a, b, c, d );
177 }
template<class A , class B , class C , class D , class E >
int VSFileSystem::vs_fscanf ( FILE *  fp,
const char *  format,
A *  a,
B *  b,
C *  c,
D *  d,
E *  e 
)

Definition at line 179 of file vsfilesystem.h.

180 {
181  return fscanf( fp, format, a, b, c, d, e );
182 }
template<class A , class B , class C , class D , class E , class F >
int VSFileSystem::vs_fscanf ( FILE *  fp,
const char *  format,
A *  a,
B *  b,
C *  c,
D *  d,
E *  e,
F *  f 
)

Definition at line 184 of file vsfilesystem.h.

185 {
186  return fscanf( fp, format, a, b, c, d, e, f );
187 }
int VSFileSystem::vs_fseek ( FILE *  fp,
long  offset,
int  whence 
)

Definition at line 494 of file vsfilesystem.cpp.

Referenced by LoadString().

495 {
496  return fseek( fp, offset, whence );
497 }
long VSFileSystem::vs_ftell ( FILE *  fp)

Definition at line 499 of file vsfilesystem.cpp.

Referenced by LoadString().

500 {
501  return ftell( fp );
502 }
long VSFileSystem::vs_getsize ( FILE *  fp)

Definition at line 514 of file vsfilesystem.cpp.

References stat::st_size, and use_volumes.

515 {
516  if (!use_volumes) {
517  struct stat st;
518  if (fstat( fileno( fp ), &st ) == 0)
519  return st.st_size;
520  return -1;
521  }
522  return -1;
523 }
FILE * VSFileSystem::vs_open ( const char *  filename,
const char *  mode 
)

Definition at line 397 of file vsfilesystem.cpp.

References datadir, fopen, homedir, use_volumes, and VSFS_DEBUG().

Referenced by BaseInterface::Room::Click(), ContinuousTerrain::ContinuousTerrain(), InterpretPython(), BaseInterface::Load(), LoadString(), LoadTex(), png_write(), Rread(), withAndWithout(), Wwrite(), and BaseInterface::~BaseInterface().

398 {
399  if (VSFS_DEBUG() > 1)
400  cerr<<"-= VS_OPEN in mode "<<mode<<" =- ";
401  FILE *fp;
402  string fullpath = homedir+"/"+string( filename );
403  if ( !use_volumes && (string( mode ) == "rb" || string( mode ) == "r") ) {
404  string output( "" );
405  fp = fopen( fullpath.c_str(), mode );
406  if (!fp) {
407  fullpath = string( filename );
408  output += fullpath+"... NOT FOUND\n\tTry loading : "+fullpath;
409  fp = fopen( fullpath.c_str(), mode );
410  }
411  if (!fp) {
412  fullpath = datadir+"/"+string( filename );
413  output += "... NOT FOUND\n\tTry loading : "+fullpath;
414  fp = fopen( fullpath.c_str(), mode );
415  }
416  if ( VSFS_DEBUG() ) {
417  if (fp) {
418  if (VSFS_DEBUG() > 2)
419  cerr<<fullpath<<" SUCCESS !!!"<<endl;
420  } else {
421  cerr<<output<<" NOT FOUND !!!"<<endl;
422  }
423  }
424  } else {
425  fp = fopen( fullpath.c_str(), mode );
426  if (fp) {
427  if (VSFS_DEBUG() > 2)
428  cerr<<fullpath<<" opened for writing SUCCESS !!!"<<endl;
429  } else if ( VSFS_DEBUG() ) {
430  cerr<<fullpath<<" FAILED !!!"<<endl;
431  }
432  }
433  return fp;
434 
435  return NULL;
436 }
size_t VSFileSystem::vs_read ( void *  ptr,
size_t  size,
size_t  nmemb,
FILE *  fp 
)

Definition at line 438 of file vsfilesystem.cpp.

References use_volumes.

Referenced by LoadString(), ReadIntSpace(), and UnpickleAllMissions().

439 {
440  if (!use_volumes) {
441  return fread( ptr, size, nmemb, fp );
442  } else {}
443  return 0;
444 }
void VSFileSystem::vs_rewind ( FILE *  fp)

Definition at line 504 of file vsfilesystem.cpp.

505 {
506  rewind( fp );
507 }
size_t VSFileSystem::vs_write ( const void *  ptr,
size_t  size,
size_t  nmemb,
FILE *  fp 
)

Definition at line 446 of file vsfilesystem.cpp.

References use_volumes.

447 {
448  if (!use_volumes) {
449  return fwrite( ptr, size, nmemb, fp );
450  } else {}
451  return 0;
452 }

Variable Documentation

string VSFileSystem::aidir

Definition at line 291 of file vsfilesystem.cpp.

Referenced by InitPaths().

string VSFileSystem::config_file

Definition at line 301 of file vsfilesystem.cpp.

Referenced by InitDataDirectory(), InitPaths(), and LoadConfig().

vector< std::string > VSFileSystem::curdir

Definition at line 312 of file vsfilesystem.cpp.

vector< string > VSFileSystem::current_directory

Definition at line 306 of file vsfilesystem.cpp.

Referenced by GetHashName(), InitPaths(), and VSFileSystem::VSFile::OpenReadOnly().

vector< string > VSFileSystem::current_subdirectory
vector< string > VSFileSystem::Directories

Definition at line 282 of file vsfilesystem.cpp.

Referenced by FileExists(), InitPaths(), and LookForFile().

string VSFileSystem::failed

Definition at line 317 of file vsfilesystem.cpp.

Referenced by FileExists(), LookForFile(), and VSFileSystem::VSFile::OpenReadOnly().

string VSFileSystem::HOMESUBDIR

Definition at line 133 of file soundserver.cpp.

Referenced by changehome(), InitDataDirectory(), InitHomeDirectory(), and main().

string VSFileSystem::moddir

Definition at line 297 of file vsfilesystem.cpp.

Referenced by InitDataDirectory(), InitMods(), and LoadConfig().

string VSFileSystem::modname

Definition at line 296 of file vsfilesystem.cpp.

Referenced by AImissionScript::AImissionScript(), InitMods(), and LoadConfig().

vsUMap< string, CPK3 * > VSFileSystem::pk3_opened_files

Definition at line 320 of file vsfilesystem.cpp.

Referenced by FileExists().

vector< string > VSFileSystem::Rootdir
vector< std::vector< std::string > > VSFileSystem::savedcurdir

Definition at line 313 of file vsfilesystem.cpp.

vector< std::string > VSFileSystem::savedpwd

Definition at line 311 of file vsfilesystem.cpp.

string VSFileSystem::savedunitpath
string VSFileSystem::sharedanims

Definition at line 292 of file vsfilesystem.cpp.

Referenced by InitPaths().

string VSFileSystem::sharedcockpits

Definition at line 289 of file vsfilesystem.cpp.

Referenced by InitPaths().

string VSFileSystem::sharedmeshes

Definition at line 287 of file vsfilesystem.cpp.

Referenced by InitPaths().

string VSFileSystem::sharedsectors
string VSFileSystem::sharedsounds

Definition at line 286 of file vsfilesystem.cpp.

Referenced by InitPaths().

string VSFileSystem::sharedsprites

Definition at line 294 of file vsfilesystem.cpp.

Referenced by InitPaths().

string VSFileSystem::sharedtextures
string VSFileSystem::sharedunits

Definition at line 285 of file vsfilesystem.cpp.

Referenced by InitPaths().

string VSFileSystem::shareduniverse

Definition at line 290 of file vsfilesystem.cpp.

Referenced by InitPaths().

string VSFileSystem::sharedvideos

Definition at line 293 of file vsfilesystem.cpp.

Referenced by InitPaths().

vector< vector< string > > VSFileSystem::SubDirectories

Definition at line 281 of file vsfilesystem.cpp.

Referenced by InitPaths(), and LookForFile().

string VSFileSystem::universe_name
bool VSFileSystem::use_volumes

Definition at line 277 of file vsfilesystem.cpp.

Referenced by vs_close(), vs_dprintf(), vs_fprintf(), vs_getsize(), vs_open(), vs_read(), and vs_write().

std::string VSFileSystem::vegastrike_cwd

Definition at line 134 of file vsfilesystem.cpp.

Referenced by ChangeToProgramDirectory(), and InitDataDirectory().

string VSFileSystem::volume_format

Definition at line 278 of file vsfilesystem.cpp.

Referenced by FileExists(), and InitPaths().

string VSFileSystem::weapon_list

Definition at line 302 of file vsfilesystem.cpp.

Referenced by GameUniverse::Init(), Universe::Init(), and LoadConfig().