123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- // Filename:- stringed_interface.cpp
- //
- // This file contains functions that StringEd wants to call to do things like load/save, they can be modified
- // for use ingame, but must remain functionally the same...
- //
- // Please try and put modifications for whichever games this is used for inside #defines, so I can copy the same file
- // into each project.
- //
- //////////////////////////////////////////////////
- //
- // stuff common to all qcommon files...
- #include "../server/server.h"
- #include "../game/q_shared.h"
- #include "qcommon.h"
- //
- //////////////////////////////////////////////////
- #pragma warning ( disable : 4511 ) // copy constructor could not be generated
- #pragma warning ( disable : 4512 ) // assignment operator could not be generated
- #pragma warning ( disable : 4663 ) // C++ language change: blah blah template crap blah blah
- #include "stringed_interface.h"
- #include "stringed_ingame.h"
- #include <string>
- using namespace std;
- #ifdef _STRINGED
- #include <stdlib.h>
- #include <memory.h>
- #include "generic.h"
- #endif
- // this just gets the binary of the file into memory, so I can parse it. Called by main SGE loader
- //
- // returns either char * of loaded file, else NULL for failed-to-open...
- //
- unsigned char *SE_LoadFileData( const char *psFileName, int *piLoadedLength /* = 0 */)
- {
- unsigned char *psReturn = NULL;
- if ( piLoadedLength )
- {
- *piLoadedLength = 0;
- }
- #ifdef _STRINGED
- if (psFileName[1] == ':')
- {
- // full-path filename...
- //
- FILE *fh = fopen( psFileName, "rb" );
- if (fh)
- {
- long lLength = filesize(fh);
- if (lLength > 0)
- {
- psReturn = (unsigned char *) malloc( lLength + 1);
- if (psReturn)
- {
- int iBytesRead = fread( psReturn, 1, lLength, fh );
- if (iBytesRead != lLength)
- {
- // error reading file!!!...
- //
- free(psReturn);
- psReturn = NULL;
- }
- else
- {
- psReturn[ lLength ] = '\0';
- if ( piLoadedLength )
- {
- *piLoadedLength = iBytesRead;
- }
- }
- fclose(fh);
- }
- }
- }
- }
- else
- #endif
- {
- // local filename, so prepend the base dir etc according to game and load it however (from PAK?)
- //
- unsigned char *pvLoadedData;
- int iLen = FS_ReadFile( psFileName, (void **)&pvLoadedData );
- if (iLen>0)
- {
- psReturn = pvLoadedData;
- if ( piLoadedLength )
- {
- *piLoadedLength = iLen;
- }
- }
- }
- return psReturn;
- }
- // called by main SGE code after loaded data has been parsedinto internal structures...
- //
- void SE_FreeFileDataAfterLoad( unsigned char *psLoadedFile )
- {
- #ifdef _STRINGED
- if ( psLoadedFile )
- {
- free( psLoadedFile );
- }
- #else
- if ( psLoadedFile )
- {
- FS_FreeFile( psLoadedFile );
- }
- #endif
- }
- #ifndef _STRINGED
- // quake-style method of doing things since their file-list code doesn't have a 'recursive' flag...
- //
- int giFilesFound;
- static void SE_R_ListFiles( const char *psExtension, const char *psDir, string &strResults )
- {
- // Com_Printf(va("Scanning Dir: %s\n",psDir));
- char **sysFiles, **dirFiles;
- int numSysFiles, i, numdirs;
- dirFiles = FS_ListFiles( psDir, "/", &numdirs);
- for (i=0;i<numdirs;i++)
- {
- if (dirFiles[i][0] && dirFiles[i][0] != '.') // skip blanks, plus ".", ".." etc
- {
- char sDirName[MAX_QPATH];
- sprintf(sDirName, "%s/%s", psDir, dirFiles[i]);
- //
- // for some reason the quake filesystem in this game now returns an extra slash on the end,
- // didn't used to. Sigh...
- //
- if (sDirName[strlen(sDirName)-1] == '/')
- {
- sDirName[strlen(sDirName)-1] = '\0';
- }
- SE_R_ListFiles( psExtension, sDirName, strResults );
- }
- }
- sysFiles = FS_ListFiles( psDir, psExtension, &numSysFiles );
- for(i=0; i<numSysFiles; i++)
- {
- char sFilename[MAX_QPATH];
- sprintf(sFilename,"%s/%s", psDir, sysFiles[i]);
-
- // Com_Printf("%sFound file: %s",!i?"\n":"",sFilename);
- strResults += sFilename;
- strResults += ';';
- giFilesFound++;
- // read it in...
- //
- /* byte *pbData = NULL;
- int iSize = FS_ReadFile( sFilename, (void **)&pbData);
- if (pbData)
- {
- FS_FreeFile( pbData );
- }
- */
- }
- FS_FreeFileList( sysFiles );
- FS_FreeFileList( dirFiles );
- }
- #endif
- // replace this with a call to whatever your own code equivalent is.
- //
- // expected result is a ';'-delineated string (including last one) containing file-list search results
- //
- int SE_BuildFileList( const char *psStartDir, string &strResults )
- {
- #ifndef _STRINGED
- giFilesFound = 0;
- strResults = "";
- SE_R_ListFiles( sSE_INGAME_FILE_EXTENSION, psStartDir, strResults );
- return giFilesFound;
- #else
- // .ST files...
- //
- int iFilesFound = BuildFileList( va("%s\\*%s",psStartDir, sSE_INGAME_FILE_EXTENSION), // LPCSTR psPathAndFilter,
- true // bool bRecurseSubDirs
- );
- extern string strResult;
- strResults = strResult;
- return iFilesFound;
- #endif
- }
- /////////////////////// eof ///////////////////////
|