- uncouple the file system from the engine's Printf function.
This is needed to use it in non GZDoom based projects.
This commit is contained in:
parent
9b790d23a8
commit
7fee89d1f5
23 changed files with 270 additions and 243 deletions
|
|
@ -152,7 +152,7 @@ struct FileSystem::LumpRecord
|
|||
|
||||
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
|
||||
|
||||
static void PrintLastError ();
|
||||
static void PrintLastError (FileSystemMessageFunc Printf);
|
||||
|
||||
// PUBLIC DATA DEFINITIONS -------------------------------------------------
|
||||
|
||||
|
|
@ -162,7 +162,7 @@ FileSystem fileSystem;
|
|||
|
||||
FileSystem::FileSystem()
|
||||
{
|
||||
// This is needed to initialize the LumpRecord array, which depends on data only available here.
|
||||
// Cannot be defaulted! This is needed to initialize the LumpRecord array, which depends on data only available here.
|
||||
}
|
||||
|
||||
FileSystem::~FileSystem ()
|
||||
|
|
@ -199,14 +199,14 @@ void FileSystem::DeleteAll ()
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
void FileSystem::InitSingleFile(const char* filename, bool quiet)
|
||||
bool FileSystem::InitSingleFile(const char* filename, FileSystemMessageFunc Printf)
|
||||
{
|
||||
TArray<FString> filenames;
|
||||
filenames.Push(filename);
|
||||
InitMultipleFiles(filenames, true);
|
||||
return InitMultipleFiles(filenames, nullptr, Printf);
|
||||
}
|
||||
|
||||
void FileSystem::InitMultipleFiles (TArray<FString> &filenames, bool quiet, LumpFilterInfo* filter, bool allowduplicates, FILE* hashfile)
|
||||
bool FileSystem::InitMultipleFiles (TArray<FString> &filenames, LumpFilterInfo* filter, FileSystemMessageFunc Printf, bool allowduplicates, FILE* hashfile)
|
||||
{
|
||||
int numfiles;
|
||||
|
||||
|
|
@ -232,7 +232,7 @@ void FileSystem::InitMultipleFiles (TArray<FString> &filenames, bool quiet, Lump
|
|||
|
||||
for(unsigned i=0;i<filenames.Size(); i++)
|
||||
{
|
||||
AddFile (filenames[i], nullptr, quiet, filter, hashfile);
|
||||
AddFile (filenames[i], nullptr, filter, Printf, hashfile);
|
||||
|
||||
if (i == (unsigned)MaxIwadIndex) MoveLumpsInFolder("after_iwad/");
|
||||
FStringf path("filter/%s", Files.Last()->GetHash().GetChars());
|
||||
|
|
@ -242,13 +242,13 @@ void FileSystem::InitMultipleFiles (TArray<FString> &filenames, bool quiet, Lump
|
|||
NumEntries = FileInfo.Size();
|
||||
if (NumEntries == 0)
|
||||
{
|
||||
if (!quiet) I_FatalError("W_InitMultipleFiles: no files found");
|
||||
else return;
|
||||
return false;
|
||||
}
|
||||
if (filter && filter->postprocessFunc) filter->postprocessFunc();
|
||||
|
||||
// [RH] Set up hash table
|
||||
InitHashChains ();
|
||||
return true;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
|
@ -308,7 +308,7 @@ int FileSystem::AddFromBuffer(const char* name, const char* type, char* data, in
|
|||
// [RH] Removed reload hack
|
||||
//==========================================================================
|
||||
|
||||
void FileSystem::AddFile (const char *filename, FileReader *filer, bool quiet, LumpFilterInfo* filter, FILE* hashfile)
|
||||
void FileSystem::AddFile (const char *filename, FileReader *filer, LumpFilterInfo* filter, FileSystemMessageFunc Printf, FILE* hashfile)
|
||||
{
|
||||
int startlump;
|
||||
bool isdir = false;
|
||||
|
|
@ -319,10 +319,10 @@ void FileSystem::AddFile (const char *filename, FileReader *filer, bool quiet, L
|
|||
// Does this exist? If so, is it a directory?
|
||||
if (!DirEntryExists(filename, &isdir))
|
||||
{
|
||||
if (!quiet)
|
||||
if (Printf)
|
||||
{
|
||||
Printf(TEXTCOLOR_RED "%s: File or Directory not found\n", filename);
|
||||
PrintLastError();
|
||||
Printf(FSMessageLevel::Error, "%s: File or Directory not found\n", filename);
|
||||
PrintLastError(Printf);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
@ -331,10 +331,10 @@ void FileSystem::AddFile (const char *filename, FileReader *filer, bool quiet, L
|
|||
{
|
||||
if (!filereader.OpenFile(filename))
|
||||
{ // Didn't find file
|
||||
if (!quiet)
|
||||
if (Printf)
|
||||
{
|
||||
Printf(TEXTCOLOR_RED "%s: File not found\n", filename);
|
||||
PrintLastError();
|
||||
Printf(FSMessageLevel::Error, "%s: File not found\n", filename);
|
||||
PrintLastError(Printf);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
@ -342,19 +342,20 @@ void FileSystem::AddFile (const char *filename, FileReader *filer, bool quiet, L
|
|||
}
|
||||
else filereader = std::move(*filer);
|
||||
|
||||
if (!batchrun && !quiet) Printf (" adding %s", filename);
|
||||
startlump = NumEntries;
|
||||
|
||||
FResourceFile *resfile;
|
||||
|
||||
|
||||
if (!isdir)
|
||||
resfile = FResourceFile::OpenResourceFile(filename, filereader, quiet, false, filter);
|
||||
resfile = FResourceFile::OpenResourceFile(filename, filereader, false, filter, Printf);
|
||||
else
|
||||
resfile = FResourceFile::OpenDirectory(filename, quiet, filter);
|
||||
resfile = FResourceFile::OpenDirectory(filename, filter, Printf);
|
||||
|
||||
if (resfile != NULL)
|
||||
{
|
||||
if (!quiet && !batchrun) Printf(", %d lumps\n", resfile->LumpCount());
|
||||
if (!batchrun && Printf)
|
||||
Printf(FSMessageLevel::Message, "adding %s, %d lumps\n", filename, resfile->LumpCount());
|
||||
|
||||
uint32_t lumpstart = FileInfo.Size();
|
||||
|
||||
|
|
@ -376,11 +377,11 @@ void FileSystem::AddFile (const char *filename, FileReader *filer, bool quiet, L
|
|||
FString path;
|
||||
path.Format("%s:%s", filename, lump->getName());
|
||||
auto embedded = lump->NewReader();
|
||||
AddFile(path, &embedded, quiet, filter, hashfile);
|
||||
AddFile(path, &embedded, filter, Printf, hashfile);
|
||||
}
|
||||
}
|
||||
|
||||
if (hashfile && !quiet)
|
||||
if (hashfile)
|
||||
{
|
||||
uint8_t cksum[16];
|
||||
char cksumout[33];
|
||||
|
|
@ -1647,7 +1648,7 @@ __declspec(dllimport) void * __stdcall LocalFree (void *);
|
|||
__declspec(dllimport) unsigned long __stdcall GetLastError ();
|
||||
}
|
||||
|
||||
static void PrintLastError ()
|
||||
static void PrintLastError (FileSystemMessageFunc Printf)
|
||||
{
|
||||
char *lpMsgBuf;
|
||||
FormatMessageA(0x1300 /*FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
|
|
@ -1660,14 +1661,14 @@ static void PrintLastError ()
|
|||
0,
|
||||
NULL
|
||||
);
|
||||
Printf (TEXTCOLOR_RED " %s\n", lpMsgBuf);
|
||||
Printf (FSMessageLevel::Error, " %s\n", lpMsgBuf);
|
||||
// Free the buffer.
|
||||
LocalFree( lpMsgBuf );
|
||||
}
|
||||
#else
|
||||
static void PrintLastError ()
|
||||
static void PrintLastError (FileSystemMessageFunc Printf)
|
||||
{
|
||||
Printf (TEXTCOLOR_RED " %s\n", strerror(errno));
|
||||
Printf(FSMessageLevel::Error, " %s\n", strerror(errno));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -1681,21 +1682,3 @@ FResourceLump* FileSystem::GetFileAt(int no)
|
|||
{
|
||||
return FileInfo[no].lump;
|
||||
}
|
||||
|
||||
#include "c_dispatch.h"
|
||||
|
||||
CCMD(fs_dir)
|
||||
{
|
||||
int numfiles = fileSystem.GetNumEntries();
|
||||
|
||||
for (int i = 0; i < numfiles; i++)
|
||||
{
|
||||
auto container = fileSystem.GetResourceFileFullName(fileSystem.GetFileContainer(i));
|
||||
auto fn1 = fileSystem.GetFileFullName(i);
|
||||
auto fns = fileSystem.GetFileShortName(i);
|
||||
auto fnid = fileSystem.GetResourceId(i);
|
||||
auto length = fileSystem.FileLength(i);
|
||||
bool hidden = fileSystem.FindFile(fn1) != i;
|
||||
Printf(PRINT_HIGH | PRINT_NONOTIFY, "%s%-64s %-15s (%5d) %10d %s %s\n", hidden ? TEXTCOLOR_RED : TEXTCOLOR_UNTRANSLATED, fn1, fns, fnid, length, container, hidden ? "(h)" : "");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue