Remove #ifdefs for USE_VFS

This commit is contained in:
Asdow
2023-10-08 16:45:06 +03:00
parent eca4086d30
commit 4b1de56b01
34 changed files with 9 additions and 1916 deletions
-16
View File
@@ -171,17 +171,6 @@ BINKFLIC *BinkOpenFlic( const CHAR8 *cFilename )
ErrorMsg("BINK ERROR: Out of flic slots, cannot open another");
return(NULL);
}
#ifndef USE_VFS
// Attempt opening the filename
if(!(pBink->hFileHandle = FileOpen( const_cast<CHAR8*>(cFilename), FILE_OPEN_EXISTING | FILE_ACCESS_READ, FALSE ) ) )
{
ErrorMsg("BINK ERROR: Can't open the BINK file");
return(NULL);
}
//Get the real file handle for the file man handle for the smacker file
HANDLE hFile = GetRealFileHandleFromFileManFileHandle( pBink->hFileHandle );
#else
vfs::Path introname(cFilename);
vfs::Path dir,filename;
introname.splitLast(dir,filename);
@@ -207,11 +196,7 @@ BINKFLIC *BinkOpenFlic( const CHAR8 *cFilename )
SGP_RETHROW(_BS(L"Intro file \"") << filename << L"\" could not be extracted" << _BS::wget, ex);
}
}
#endif
#ifndef USE_VFS
if( !( pBink->BinkHandle = BinkOpen((CHAR8 *)hFile, BINKFILEHANDLE ) ) ) //| SMACKTRACKS
#else
vfs::Path tempfilename;
try
{
@@ -226,7 +211,6 @@ BINKFLIC *BinkOpenFlic( const CHAR8 *cFilename )
SGP_RETHROW(L"Temporary intro file could not be read", ex);
}
if( !( pBink->BinkHandle = BinkOpen(tempfilename.to_string().c_str(), BINKNOTHREADEDIO /*BINKFILEHANDLE*/ ) ) ) //| SMACKTRACKS
#endif
{
ErrorMsg("BINK ERROR: Bink won't open the BINK file");
return(NULL);
-18
View File
@@ -194,19 +194,6 @@ SMKFLIC *SmkOpenFlic(const CHAR8 *cFilename)
return(NULL);
}
#ifndef USE_VFS
// Attempt opening the filename
if(!(pSmack->hFileHandle=FileOpen(cFilename, FILE_OPEN_EXISTING | FILE_ACCESS_READ, FALSE)))
{
ErrorMsg("SMK ERROR: Can't open the SMK file");
return(NULL);
}
HANDLE hFile;
//Get the real file handle for the file man handle for the smacker file
hFile = GetRealFileHandleFromFileManFileHandle( pSmack->hFileHandle );
#else
vfs::Path introname(cFilename);
vfs::Path dir,filename;
introname.splitLast(dir,filename);
@@ -232,7 +219,6 @@ SMKFLIC *SmkOpenFlic(const CHAR8 *cFilename)
SGP_RETHROW(_BS(L"Intro file \"") << filename << L"\" could not be extracted" << _BS::wget, ex);
}
}
#endif
// Allocate a Smacker buffer for video decompression
if(!(pSmack->SmackBuffer=SmackBufferOpen(hDisplayWindow,SMACKAUTOBLIT,SCREEN_WIDTH,SCREEN_HEIGHT,0,0)))
@@ -240,9 +226,6 @@ SMKFLIC *SmkOpenFlic(const CHAR8 *cFilename)
ErrorMsg("SMK ERROR: Can't allocate a Smacker decompression buffer");
return(NULL);
}
#ifndef USE_VFS
if(!(pSmack->SmackHandle=SmackOpen((CHAR8 *)hFile, SMACKFILEHANDLE | SMACKTRACKS, SMACKAUTOEXTRA)))
#else
// if(!(pSmack->SmackHandle=SmackOpen(cFilename, SMACKTRACKS, SMACKAUTOEXTRA)))
vfs::Path tempfilename;
try
@@ -258,7 +241,6 @@ SMKFLIC *SmkOpenFlic(const CHAR8 *cFilename)
SGP_RETHROW(L"Temporary intro file could not be read", ex);
}
if(!(pSmack->SmackHandle=SmackOpen(tempfilename.to_string().c_str(), SMACKTRACKS, SMACKAUTOEXTRA)))
#endif
{
ErrorMsg("SMK ERROR: Smacker won't open the SMK file");
return(NULL);
-20
View File
@@ -62,30 +62,10 @@ static struct LiveLog {
void LiveMessage( CHAR8 *strMessage)
{
#ifndef USE_VFS
FILE *OutFile;
if ((OutFile = fopen("Log.txt", "a+t")) != NULL)
{
fprintf(OutFile, "%s\n", strMessage);
fclose(OutFile);
}
#else
SGP_LOG(s_LiveLog.id, strMessage);
#endif
}
void MPDebugMsg( CHAR8 *strMessage)
{
#ifndef USE_VFS
FILE *OutFile;
if ((OutFile = fopen("MPDebug.txt", "a+t")) != NULL)
{
fprintf(OutFile, "%s\n", strMessage);
fclose(OutFile);
}
#else
static vfs::Log& mpMsg = *vfs::Log::create(L"MPDebug.txt", true);
mpMsg << strMessage << vfs::Log::endl;
#endif
}
+1 -110
View File
@@ -12,9 +12,7 @@
#include <vfs/Core/vfs.h>
#ifdef USE_VFS
std::set<vfs::Path,vfs::Path::Less> CIniReader::m_merge_files;
#endif
std::stack<std::string> iniErrorMessages;
template<typename ValueType>
@@ -32,26 +30,14 @@ void PushErrorMessage(std::string const& filename,
iniErrorMessages.push(errMessage.str());
}
#ifdef USE_VFS
void CIniReader::RegisterFileForMerging(vfs::Path const& filename)
{
m_merge_files.insert(filename);
}
#endif
CIniReader::CIniReader(const STR8 szFileName)
{
memset(m_szFileName,0,sizeof(m_szFileName));
#ifndef USE_VFS
// Snap: Look for the INI file in the custom Data directory.
// If not there, leave at default location.
if ( gCustomDataCat.FindFile(szFileName) ) {
sprintf(m_szFileName, "%s\\%s", gCustomDataCat.GetRootDir().c_str(), szFileName);
}
else {
sprintf(m_szFileName, "%s\\%s", gDefaultDataCat.GetRootDir().c_str(), szFileName);
}
#else
strncpy(m_szFileName,szFileName, std::min<int>(strlen(szFileName), sizeof(m_szFileName)-1));
if(m_merge_files.find(szFileName) == m_merge_files.end())
{
@@ -81,7 +67,6 @@ CIniReader::CIniReader(const STR8 szFileName)
if(getVFS()->fileExists(OvrFileName))
m_oProps.initFromIniFile(vfs::Path(OvrFileName));
}
#endif
}
CIniReader::CIniReader(const STR8 szFileName, BOOLEAN Force_Custom_Data_Path)
@@ -89,32 +74,6 @@ CIniReader::CIniReader(const STR8 szFileName, BOOLEAN Force_Custom_Data_Path)
memset(m_szFileName,0,sizeof(m_szFileName));
// ary-05/05/2009 : force custom data path for potential non existing file -or- force default data path
// : Also, flag file detection to allow functions to determine course of action for case of file [not found/is found].
#ifndef USE_VFS
if ( Force_Custom_Data_Path )
{
if ( gCustomDataCat.FindFile(szFileName) )
{
CIniReader_File_Found = TRUE;
}
else
{
CIniReader_File_Found = FALSE;
}
sprintf(m_szFileName, "%s\\%s", gCustomDataCat.GetRootDir().c_str(), szFileName);
}
else
{
if ( gDefaultDataCat.FindFile(szFileName) )
{
CIniReader_File_Found = TRUE;
}
else
{
CIniReader_File_Found = FALSE;
}
sprintf(m_szFileName, "%s\\%s", gDefaultDataCat.GetRootDir().c_str(), szFileName);
}
#else
strncpy(m_szFileName,szFileName, std::min<int>(strlen(szFileName), sizeof(m_szFileName)-1));
if(m_merge_files.find(szFileName) == m_merge_files.end())
{
@@ -137,38 +96,24 @@ CIniReader::CIniReader(const STR8 szFileName, BOOLEAN Force_Custom_Data_Path)
rev_order.pop();
}
}
#endif
}
void CIniReader::Clear()
{
#ifndef USE_VFS
memset(m_szFileName, 0, MAX_PATH);
#else
memset(m_szFileName, 0, MAX_PATH);
m_oProps.clearContainer();
#endif
}
int CIniReader::ReadInteger(const STR8 szSection, const STR8 szKey, int iDefaultValue)
{
#ifndef USE_VFS
return GetPrivateProfileInt(szSection, szKey, iDefaultValue, m_szFileName);
#else
return (int)(m_oProps.getIntProperty(szSection, szKey, iDefaultValue));
#endif
}
int CIniReader::ReadInteger(const STR8 szSection, const STR8 szKey, int defaultValue, int minValue, int maxValue)
{
#ifndef USE_VFS
int iniValueReadFromFile = (int)(GetPrivateProfileInt(szSection, szKey, defaultValue, m_szFileName));
#else
int iniValueReadFromFile = (int)(m_oProps.getIntProperty(szSection, szKey, defaultValue));
#endif
//AssertGE(iniValueReadFromFile, minValue);
//AssertLE(iniValueReadFromFile, maxValue);
if (iniValueReadFromFile < minValue)
@@ -200,15 +145,7 @@ int CIniReader::ReadInteger(const STR8 szSection, const STR8 szKey, int defaultV
double CIniReader::ReadDouble(const STR8 szSection, const STR8 szKey, double defaultValue, double minValue, double maxValue)
{
double iniValueReadFromFile;
#ifndef USE_VFS
char szResult[255];
char szDefault[255];
sprintf(szDefault, "%f", defaultValue);
GetPrivateProfileString(szSection, szKey, szDefault, szResult, 255, m_szFileName);
iniValueReadFromFile = (float) atof(szResult);
#else
iniValueReadFromFile = m_oProps.getFloatProperty(szSection, szKey, defaultValue);
#endif
//AssertGE(iniValueReadFromFile, minValue);
//AssertLE(iniValueReadFromFile, maxValue);
if (iniValueReadFromFile < minValue)
@@ -227,15 +164,7 @@ double CIniReader::ReadDouble(const STR8 szSection, const STR8 szKey, double def
FLOAT CIniReader::ReadFloat(const STR8 szSection, const STR8 szKey, FLOAT defaultValue, FLOAT minValue, FLOAT maxValue)
{
FLOAT iniValueReadFromFile;
#ifndef USE_VFS
char szResult[255];
char szDefault[255];
sprintf(szDefault, "%f", defaultValue);
GetPrivateProfileString(szSection, szKey, szDefault, szResult, 255, m_szFileName);
iniValueReadFromFile = (FLOAT) atof(szResult);
#else
iniValueReadFromFile = (FLOAT) m_oProps.getFloatProperty(szSection, szKey, (float)defaultValue);
#endif
//AssertGE(iniValueReadFromFile, minValue);
//AssertLE(iniValueReadFromFile, maxValue);
@@ -329,18 +258,6 @@ void CIniReader::ReadINT32Array(const STR8 szSection, const STR8 szKey, std::vec
BOOLEAN CIniReader::ReadBoolean(const STR8 szSection, const STR8 szKey, bool defaultValue, bool bolDisplayError)
{
#ifndef USE_VFS
char szResult[255];
char szDefault[255];
sprintf(szDefault, "%s", defaultValue? "TRUE" : "FALSE");
GetPrivateProfileString(szSection, szKey, szDefault, szResult, 255, m_szFileName);
for (int idx=0; (szResult[idx] != 0) && (idx < 255); ++idx)
szResult[idx] = toupper(szResult[idx]);
if (strcmp(szResult, "TRUE") == 0)
return TRUE;
else if (strcmp(szResult, "FALSE") == 0)
return FALSE;
#else
vfs::String str = m_oProps.getStringProperty(szSection, szKey, L"");
if( vfs::StrCmp::Equal(str, L"true") )
{
@@ -353,7 +270,7 @@ BOOLEAN CIniReader::ReadBoolean(const STR8 szSection, const STR8 szKey, bool def
std::string szResult = str.utf8();
char szDefault[255];
sprintf(szDefault, "%s", defaultValue? "TRUE" : "FALSE");
#endif
if(bolDisplayError){
std::stringstream errMessage;
errMessage << "The value [" << szSection << "][" << szKey << "] = \"" << szResult << "\" "
@@ -370,14 +287,10 @@ BOOLEAN CIniReader::ReadBoolean(const STR8 szSection, const STR8 szKey, bool def
void CIniReader::ReadString(const STR8 szSection, const STR8 szKey, const STR8 szDefaultValue, STR8 input_buffer, size_t buffer_size)
{
#ifndef USE_VFS
GetPrivateProfileString(szSection, szKey, szDefaultValue, input_buffer, buffer_size, m_szFileName);
#else
std::string s = m_oProps.getStringProperty(szSection, szKey, szDefaultValue).utf8();
int len = std::min<unsigned int>(s.length(),buffer_size-1);
strncpy(input_buffer, s.c_str(), len);
input_buffer[len] = 0;
#endif
}
// WANNE - MP: Old version, currently used by Multiplayer
@@ -386,12 +299,8 @@ STR8 CIniReader::ReadString(const STR8 szSection, const STR8 szKey, const STR8 s
// >>>>> Memory Leak <<<<<
STR8 szResult = new char[255];
memset(szResult, 0x00, 255);
#ifndef USE_VFS
GetPrivateProfileString(szSection, szKey, szDefaultValue, szResult, 255, m_szFileName);
#else
std::string s = m_oProps.getStringProperty(szSection, szKey, szDefaultValue).utf8();
strncpy(szResult, s.c_str(), std::min<int>(s.length(),254));
#endif
return szResult;
}
@@ -429,20 +338,7 @@ UINT32 CIniReader::ReadUINT32(const STR8 szSection, const STR8 szKey, UINT32 def
UINT32 CIniReader::ReadUINT(const STR8 szSection, const STR8 szKey, UINT32 defaultValue, UINT32 minValue, UINT32 maxValue )
{
UINT32 iniValueReadFromFile;
#ifndef USE_VFS
STR8 szResult = new char[255];
STR8 szDefault = new char[255];
memset(szResult, 0x00, 255);
memset(szDefault, 0x00, 255);
sprintf(szDefault, "%u", defaultValue);
this->ReadString (szSection , szKey , szDefault, szResult, (size_t) 255 );
iniValueReadFromFile = (UINT32) strtoul(szResult,NULL,0);
#else
iniValueReadFromFile = (UINT32) m_oProps.getUIntProperty(szSection, szKey, defaultValue);
#endif
//AssertGE(iniValueReadFromFile, minValue);
//AssertLE(iniValueReadFromFile, maxValue);
@@ -457,10 +353,5 @@ UINT32 CIniReader::ReadUINT(const STR8 szSection, const STR8 szKey, UINT32 defau
iniValueReadFromFile = maxValue;
}
#ifndef USE_VFS
delete [] szResult ;
delete [] szDefault ;
#endif
return iniValueReadFromFile;
}
+1 -5
View File
@@ -56,18 +56,14 @@ public:
BOOLEAN Is_CIniReader_File_Found(void) {return (CIniReader_File_Found);}
void Clear();
#ifdef USE_VFS
static void RegisterFileForMerging(vfs::Path const& filename);
#endif
private:
vfs::PropertyContainer m_oProps;
char m_szFileName[MAX_PATH];
BOOLEAN CIniReader_File_Found;
UINT32 ReadUINT(const STR8 szSection, const STR8 szKey, UINT32 defaultValue, UINT32 minValue, UINT32 maxValue);
#ifdef USE_VFS
static std::set<vfs::Path, vfs::Path::Less> m_merge_files;
#endif
};
#endif//INIREADER_H
#endif//INIREADER_H
-14
View File
@@ -1522,22 +1522,8 @@ static struct DebugMessageLog {
void WriteMessageToFile( const STR16 pString )
{
#ifdef JA2BETAVERSION
#ifndef USE_VFS
FILE *fp;
fp = fopen( "DebugMessage.txt", "a" );
if( fp == NULL )
{
return;
}
fprintf( fp, "%S\n", pString );
fclose( fp );
#else
SGP_LOG(s_DebugMessageLog.id, pString);
#endif
#endif
}