added forgotten files
This commit is contained in:
@@ -5,10 +5,10 @@
|
||||
#include "tier1/commandline.h"
|
||||
|
||||
CUtlVector<CUtlString> tier2_CompiledFiles = {
|
||||
"tier2/fileformats/ini.cpp",
|
||||
"tier2/fileformats/json.cpp",
|
||||
"tier2/filesystem.cpp",
|
||||
"tier2/filesystem_libc.cpp",
|
||||
"fileformats/ini.cpp",
|
||||
"fileformats/json.cpp",
|
||||
"filesystem.cpp",
|
||||
"filesystem_libc.cpp",
|
||||
};
|
||||
CUtlString tier2_lib;
|
||||
|
||||
|
||||
32
tier2/build.cpp
Normal file
32
tier2/build.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "helper.h"
|
||||
#include "c.h"
|
||||
#include "ld.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "tier1/commandline.h"
|
||||
|
||||
CUtlVector<CUtlString> tier2_CompiledFiles = {
|
||||
"fileformats/ini.cpp",
|
||||
"fileformats/json.cpp",
|
||||
"filesystem.cpp",
|
||||
};
|
||||
|
||||
|
||||
DECLARE_BUILD_STAGE(tier2)
|
||||
{
|
||||
V_printf("%s\n", Plat_GetWorkingDir());
|
||||
CProject_t compileProject = {};
|
||||
LinkProject_t ldProject = {};
|
||||
|
||||
compileProject.m_szName = "tier2";
|
||||
compileProject.files = tier2_CompiledFiles;
|
||||
compileProject.includeDirectories = {"../public"};
|
||||
compileProject.bFPIC = true;
|
||||
ldProject = ccompiler->Compile(&compileProject);
|
||||
ldProject.linkType = ELINK_STATIC_LIBRARY;
|
||||
|
||||
CUtlString szOutputProject = linker->Link(&ldProject);
|
||||
|
||||
ADD_OUTPUT_LIBRARY(szOutputProject)
|
||||
|
||||
return 0;
|
||||
};
|
||||
@@ -92,16 +92,15 @@ public:
|
||||
IINIFile *CINIManager::ReadFile( const char *psz )
|
||||
{
|
||||
IFileHandle *pFile;
|
||||
CUtlBuffer<char> data;
|
||||
const char *szData;
|
||||
|
||||
pFile = filesystem->Open(psz, FILEMODE_READ);
|
||||
if (!pFile)
|
||||
return NULL;
|
||||
data = CUtlBuffer<char>(pFile->Size()+1);
|
||||
uint32_t nSize = pFile->Read(data.GetMemory(), pFile->Size());
|
||||
pFile->Close();
|
||||
szData = filesystem->ReadString(pFile);
|
||||
filesystem->Close(pFile);
|
||||
|
||||
return ReadString(data.GetMemory());
|
||||
return ReadString(szData);
|
||||
}
|
||||
|
||||
IINIFile *CINIManager::ReadString( const char *psz )
|
||||
|
||||
BIN
tier2/fileformats/ini.o
Normal file
BIN
tier2/fileformats/ini.o
Normal file
Binary file not shown.
@@ -1,121 +1,4 @@
|
||||
#include "tier1/utlbuffer.h"
|
||||
#include "tier2/ifilesystem.h"
|
||||
#include "tier1/interface.h"
|
||||
#include "tier0/lib.h"
|
||||
#include <cstdio>
|
||||
|
||||
size_t IFileHandle::Write( const void *pData, size_t nDataSize )
|
||||
{
|
||||
return m_pFileSystem->Write(this, pData, nDataSize);
|
||||
}
|
||||
IFileSystem *filesystem;
|
||||
|
||||
size_t IFileHandle::Read( void *pData, size_t nDataSize )
|
||||
{
|
||||
return m_pFileSystem->Read(this, pData, nDataSize);
|
||||
}
|
||||
|
||||
size_t IFileHandle::Seek( ESeekMode eSeekMode, size_t nOffset )
|
||||
{
|
||||
return m_pFileSystem->Seek(this, eSeekMode, nOffset);
|
||||
}
|
||||
|
||||
size_t IFileHandle::Tell( void )
|
||||
{
|
||||
return m_pFileSystem->Tell(this);
|
||||
}
|
||||
|
||||
size_t IFileHandle::Size( void )
|
||||
{
|
||||
return m_pFileSystem->Size(this);
|
||||
}
|
||||
|
||||
void IFileHandle::Close( void )
|
||||
{
|
||||
m_pFileSystem->Close(this);
|
||||
}
|
||||
|
||||
|
||||
class CFileSystem : public IFileSystem
|
||||
{
|
||||
public:
|
||||
virtual void Init() override {
|
||||
};
|
||||
virtual void Shutdown() override {
|
||||
|
||||
};
|
||||
|
||||
virtual IFileHandle *Open( const char *szFileName, int eOpCode ) override
|
||||
{
|
||||
IFileSystem *pFileSystem;
|
||||
IFileHandle *pHandle = NULL;
|
||||
|
||||
for ( pFileSystem = g_pFileSystems; pFileSystem; pFileSystem = pFileSystem->m_pNext )
|
||||
{
|
||||
pHandle = pFileSystem->Open(szFileName, eOpCode);
|
||||
if (pHandle) return pHandle;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
virtual size_t Write( IFileHandle *pFile, const void *pData, size_t nDataSize ) override
|
||||
{
|
||||
return pFile->Write(pData, nDataSize);
|
||||
}
|
||||
|
||||
virtual size_t Read( IFileHandle *pFile, void *pData, size_t nDataSize ) override
|
||||
{
|
||||
return pFile->Read(pData, nDataSize);
|
||||
}
|
||||
|
||||
virtual size_t Seek( IFileHandle *pFile, ESeekMode eSeekMode, size_t nOffset ) override
|
||||
{
|
||||
return pFile->Seek(eSeekMode, nOffset);
|
||||
}
|
||||
|
||||
virtual size_t Tell( IFileHandle *pFile ) override
|
||||
{
|
||||
return pFile->Tell();
|
||||
}
|
||||
virtual size_t Size( IFileHandle *pFile ) override
|
||||
{
|
||||
return pFile->Size();
|
||||
}
|
||||
virtual void Close( IFileHandle *pFile ) override
|
||||
{
|
||||
|
||||
}
|
||||
virtual CUtlBuffer<unsigned char> Read( IFileHandle *pFile ) override
|
||||
{
|
||||
CUtlBuffer<unsigned char> buffer;
|
||||
buffer = CUtlBuffer<unsigned char>(Size(pFile));
|
||||
|
||||
Read(pFile, buffer.GetMemory(), buffer.GetSize());
|
||||
|
||||
return buffer;
|
||||
}
|
||||
virtual const char *ReadString( IFileHandle *pFile ) override {
|
||||
char *szString = (char*)V_malloc(Size(pFile)+1);
|
||||
Read(pFile, szString, Size(pFile));
|
||||
szString[Size(pFile)] = 0;
|
||||
return szString;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
static CFileSystem s_fileSystem;
|
||||
IFileSystem *filesystem = &s_fileSystem;
|
||||
|
||||
IFileSystem *g_pFileSystems;
|
||||
|
||||
CFileSystemRegistry::CFileSystemRegistry( InstantiateFileSystemFn fn, const char *szFileSystem )
|
||||
{
|
||||
IFileSystem *pFileSystem = fn();
|
||||
pFileSystem->RegisterFileSystem();
|
||||
}
|
||||
|
||||
void IFileSystem::RegisterFileSystem()
|
||||
{
|
||||
m_pNext = g_pFileSystems;
|
||||
g_pFileSystems = this;
|
||||
};
|
||||
|
||||
BIN
tier2/filesystem.o
Normal file
BIN
tier2/filesystem.o
Normal file
Binary file not shown.
@@ -1,124 +0,0 @@
|
||||
#include "tier2/ifilesystem.h"
|
||||
#include "tier1/interface.h"
|
||||
#include "tier0/lib.h"
|
||||
#include "errno.h"
|
||||
|
||||
class CLIBCFileHandle : public IFileHandle
|
||||
{
|
||||
public:
|
||||
FILE *m_pFile;
|
||||
size_t m_nSize;
|
||||
|
||||
};
|
||||
|
||||
class CLIBCFileSystem : public IFileSystem
|
||||
{
|
||||
public:
|
||||
virtual void Init() override {
|
||||
|
||||
};
|
||||
virtual void Shutdown() override {};
|
||||
|
||||
virtual IFileHandle *Open( const char *szFileName, int eOpCode ) override
|
||||
{
|
||||
const char *szOperation;
|
||||
FILE *pFile;
|
||||
CLIBCFileHandle *pHandle = NULL;
|
||||
|
||||
switch (eOpCode)
|
||||
{
|
||||
case FILEMODE_READ:
|
||||
szOperation = "rb";
|
||||
break;
|
||||
case FILEMODE_WRITE:
|
||||
szOperation = "wb";
|
||||
break;
|
||||
default:
|
||||
V_printf("Operation is not supported\n");
|
||||
break;
|
||||
}
|
||||
|
||||
pFile = V_fopen(szFileName, szOperation);
|
||||
if (!pFile)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pHandle = new CLIBCFileHandle;
|
||||
pHandle->m_pFileSystem = this;
|
||||
pHandle->m_pFile = pFile;
|
||||
pHandle->Seek(SEEKMODE_RELATIVE_END, 0);
|
||||
pHandle->m_nSize = pHandle->Tell();
|
||||
pHandle->Seek(SEEKMODE_RELATIVE_START, 0);
|
||||
return pHandle;
|
||||
}
|
||||
virtual size_t Write( IFileHandle *pFile, const void *pData, size_t nDataSize ) override
|
||||
{
|
||||
CLIBCFileHandle *pHandle = (CLIBCFileHandle*)pFile;
|
||||
if (!pHandle)
|
||||
return 0;
|
||||
return V_fwrite( pData, 1, nDataSize, pHandle->m_pFile);
|
||||
}
|
||||
virtual size_t Read( IFileHandle *pFile, void *pData, size_t nDataSize ) override
|
||||
{
|
||||
CLIBCFileHandle *pHandle = (CLIBCFileHandle*)pFile;
|
||||
if (!pHandle)
|
||||
return 0;
|
||||
return V_fread( pData, 1, nDataSize, pHandle->m_pFile );
|
||||
}
|
||||
|
||||
virtual size_t Seek( IFileHandle *pFile, ESeekMode eSeekMode, size_t nOffset ) override
|
||||
{
|
||||
CLIBCFileHandle *pHandle = (CLIBCFileHandle*)pFile;
|
||||
int eLibcSeekMode = 0;
|
||||
|
||||
if (!pHandle)
|
||||
return 0;
|
||||
|
||||
switch (eSeekMode) {
|
||||
case SEEKMODE_RELATIVE_CURRENT:
|
||||
eLibcSeekMode = SEEK_CUR;
|
||||
break;
|
||||
case SEEKMODE_RELATIVE_END:
|
||||
eLibcSeekMode = SEEK_END;
|
||||
break;
|
||||
case SEEKMODE_RELATIVE_START:
|
||||
eLibcSeekMode = SEEK_SET;
|
||||
break;
|
||||
}
|
||||
|
||||
return V_fseek( pHandle->m_pFile, nOffset, eLibcSeekMode );
|
||||
}
|
||||
|
||||
virtual size_t Tell( IFileHandle *pFile ) override
|
||||
{
|
||||
CLIBCFileHandle *pHandle = (CLIBCFileHandle*)pFile;
|
||||
if (!pHandle)
|
||||
return 0;
|
||||
return V_ftell(pHandle->m_pFile);
|
||||
}
|
||||
|
||||
virtual size_t Size( IFileHandle *pFile ) override
|
||||
{
|
||||
CLIBCFileHandle *pHandle = (CLIBCFileHandle*)pFile;
|
||||
if (!pHandle)
|
||||
return 0;
|
||||
return pHandle->m_nSize;
|
||||
}
|
||||
|
||||
|
||||
|
||||
virtual void Close( IFileHandle *pFile ) override
|
||||
{
|
||||
CLIBCFileHandle *pHandle = (CLIBCFileHandle*)pFile;
|
||||
if (!pHandle)
|
||||
return;
|
||||
V_fclose(pHandle->m_pFile);
|
||||
delete pHandle;
|
||||
}
|
||||
|
||||
virtual CUtlBuffer<unsigned char> Read( IFileHandle *pFile ) override { return NULL; };
|
||||
virtual const char *ReadString( IFileHandle *pFile ) override { return NULL; };
|
||||
};
|
||||
|
||||
EXPOSE_FILESYSTEM(CLIBCFileSystem, "sysfs");
|
||||
Reference in New Issue
Block a user