mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-07-03 06:24:32 +00:00
Revert "added partial VFS support - enough to read static data from any source"
This reverts commit fa3e9e7329
.
This commit is contained in:
parent
fa3e9e7329
commit
56c6833220
56 changed files with 608 additions and 4023 deletions
328
BBGE/Base.cpp
328
BBGE/Base.cpp
|
@ -20,7 +20,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
*/
|
||||
#include "Base.h"
|
||||
#include "Core.h"
|
||||
#include "VFSDir.h"
|
||||
|
||||
#ifdef BBGE_BUILD_WINDOWS
|
||||
#include <shellapi.h>
|
||||
|
@ -273,28 +272,30 @@ std::string upperCase(const std::string &s1)
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool exists(const std::string &f, bool makeFatal /* = false */, bool skipVFS /* = false */)
|
||||
bool exists(const std::string &f, bool makeFatal)
|
||||
{
|
||||
if (f.empty())
|
||||
return false;
|
||||
|
||||
if(!skipVFS)
|
||||
{
|
||||
if(core->vfs.GetFile(core->adjustFilenameCase(f).c_str()))
|
||||
return true;
|
||||
}
|
||||
|
||||
FILE *file = fopen(core->adjustFilenameCase(f).c_str(), "rb");
|
||||
if (!file)
|
||||
/*
|
||||
if (!PHYSFS_exists(f.c_str()))
|
||||
{
|
||||
if (makeFatal)
|
||||
*/
|
||||
/*
|
||||
std::ostringstream os;
|
||||
os << "checking to see if [" << f << "] exists";
|
||||
debugLog(os.str());
|
||||
*/
|
||||
|
||||
FILE *file = fopen(core->adjustFilenameCase(f).c_str(), "rb");
|
||||
if (!file)
|
||||
{
|
||||
errorLog(std::string("Could not open [" + f + "]"));
|
||||
exit(0);
|
||||
if (makeFatal)
|
||||
{
|
||||
errorLog(std::string("Could not open [" + f + "]"));
|
||||
exit(0);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
fclose(file);
|
||||
fclose(file);
|
||||
//}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -447,20 +448,107 @@ void debugLog(const std::string &s)
|
|||
// delete[] when no longer needed.
|
||||
char *readFile(std::string path, unsigned long *size_ret)
|
||||
{
|
||||
ttvfs::VFSFile *vf = core->vfs.GetFile(path.c_str());
|
||||
if(!vf)
|
||||
return NULL;
|
||||
vf->getBuf(); // force size calc early
|
||||
// we can never know how the memory was allocated;
|
||||
// because the buffer is expected to be deleted with delete[],
|
||||
// it has to be explicitly copied to memory allocated with new[].
|
||||
unsigned long s = vf->size();
|
||||
char *buf = new char[s + 1];
|
||||
memcpy(buf, vf->getBuf(), s + 1);
|
||||
core->addVFSFileForDrop(vf);
|
||||
if(size_ret)
|
||||
*size_ret = s;
|
||||
return buf;
|
||||
FILE *f = fopen(path.c_str(), "rb");
|
||||
if (!f)
|
||||
return NULL;
|
||||
|
||||
long fileSize;
|
||||
if (fseek(f, 0, SEEK_END) != 0
|
||||
|| (fileSize = ftell(f)) < 0
|
||||
|| fseek(f, 0, SEEK_SET) != 0)
|
||||
{
|
||||
debugLog(path + ": Failed to get file size");
|
||||
fclose(f);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *buffer = new char[fileSize + 1];
|
||||
if (!buffer)
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << path << ": Not enough memory for file ("
|
||||
<< (fileSize+1) << " bytes)";
|
||||
debugLog(os.str());
|
||||
fclose(f);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
long bytesRead = fread(buffer, 1, fileSize, f);
|
||||
if (bytesRead != fileSize)
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << path << ": Failed to read file (only got "
|
||||
<< bytesRead << " of " << fileSize << " bytes)";
|
||||
debugLog(os.str());
|
||||
fclose(f);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
if (size_ret)
|
||||
*size_ret = fileSize;
|
||||
buffer[fileSize] = 0;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/*
|
||||
void pForEachFile(std::string path, std::string type, void callback(const std::string &filename, int param), int param)
|
||||
{
|
||||
char **rc = PHYSFS_enumerateFiles(path.c_str());
|
||||
char **i;
|
||||
|
||||
for (i = rc; *i != NULL; i++)
|
||||
{
|
||||
std::string s(*i);
|
||||
int p=0;
|
||||
if ((p=s.find('.'))!=std::string::npos)
|
||||
{
|
||||
std::string ext = s.susbtr(p, s.getLength2D());
|
||||
if (ext == type)
|
||||
{
|
||||
callback(fielnameafhghaha
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PHYSFS_freeList(rc);
|
||||
}
|
||||
*/
|
||||
|
||||
void doSingleFile(const std::string &path, const std::string &type, std::string filename, void callback(const std::string &filename, int param), int param)
|
||||
{
|
||||
if (filename.size()>4)
|
||||
{
|
||||
std::string search = filename;
|
||||
stringToLower(search);
|
||||
std::string filetype = filename.substr(search.size()-4, search.size());
|
||||
//stringToUpper(filetype);
|
||||
//debugLog("comparing: " + filetype + " and: " + type);
|
||||
//if (filetype==type)
|
||||
debugLog("checking:" + search + " for type:" + type);
|
||||
if (search.find(type)!=std::string::npos)
|
||||
{
|
||||
debugLog("callback");
|
||||
callback(path+filename, param);
|
||||
}
|
||||
else
|
||||
{
|
||||
debugLog("not the same");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string stripEndlineForUnix(const std::string &in)
|
||||
{
|
||||
std::string out;
|
||||
for (int i = 0; i < in.size(); i++)
|
||||
{
|
||||
if (int(in[i]) != 13)
|
||||
{
|
||||
out+= in[i];
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
void forEachFile(std::string path, std::string type, void callback(const std::string &filename, intptr_t param), intptr_t param)
|
||||
|
@ -472,29 +560,167 @@ void forEachFile(std::string path, std::string type, void callback(const std::st
|
|||
//HACK: MAC:
|
||||
debugLog("forEachFile - path: " + path + " type: " + type);
|
||||
|
||||
ttvfs::VFSDir *vd = core->vfs.GetDir(path.c_str(), false);
|
||||
if(!vd)
|
||||
{
|
||||
debugLog("Path '" + path + "' does not exist");
|
||||
return;
|
||||
}
|
||||
#if defined(BBGE_BUILD_UNIX)
|
||||
DIR *dir=0;
|
||||
dir = opendir(path.c_str());
|
||||
if (dir)
|
||||
{
|
||||
dirent *file=0;
|
||||
while ( (file=readdir(dir)) != NULL )
|
||||
{
|
||||
if (file->d_name && strlen(file->d_name) > 4)
|
||||
{
|
||||
debugLog(file->d_name);
|
||||
char *extension=strrchr(file->d_name,'.');
|
||||
if (extension)
|
||||
{
|
||||
debugLog(extension);
|
||||
if (extension!=NULL)
|
||||
{
|
||||
if (strcasecmp(extension,type.c_str())==0)
|
||||
{
|
||||
callback(path + std::string(file->d_name), param);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
}
|
||||
else
|
||||
{
|
||||
debugLog("FAILED TO OPEN DIR");
|
||||
}
|
||||
#endif
|
||||
|
||||
for(ttvfs::ConstFileIter it = vd->fileIter(); it != vd->fileIterEnd(); ++it)
|
||||
#ifdef BBGE_BUILD_WINDOWS
|
||||
BOOL fFinished;
|
||||
HANDLE hList;
|
||||
TCHAR szDir[MAX_PATH+1];
|
||||
WIN32_FIND_DATA FileData;
|
||||
|
||||
int end = path.size()-1;
|
||||
if (path[end] != '/')
|
||||
path[end] += '/';
|
||||
|
||||
// Get the proper directory path
|
||||
// \\ %s\\*
|
||||
|
||||
|
||||
|
||||
if (type.find('.')==std::string::npos)
|
||||
{
|
||||
type = "." + type;
|
||||
}
|
||||
|
||||
|
||||
//std::string add = "%s*" + type;
|
||||
|
||||
//sprintf(szDir, "%s*", path.c_str());
|
||||
sprintf(szDir, "%s\\*", path.c_str());
|
||||
|
||||
stringToUpper(type);
|
||||
|
||||
// Get the first file
|
||||
hList = FindFirstFile(szDir, &FileData);
|
||||
if (hList == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
const ttvfs::VFSFile *f = it->second;
|
||||
const char *e = strrchr(f->name(), '.');
|
||||
if (e)
|
||||
//printf("No files found\n\n");
|
||||
debugLog("No files of type " + type + " found in path " + path);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Traverse through the directory structure
|
||||
fFinished = FALSE;
|
||||
while (!fFinished)
|
||||
{
|
||||
std::string exs(e);
|
||||
stringToLower(exs);
|
||||
if(exs != type)
|
||||
continue;
|
||||
}
|
||||
else if(type.size())
|
||||
continue;
|
||||
// Check the object is a directory or not
|
||||
//printf("%*s%s\n", indent, "", FileData.cFileName);
|
||||
std::string filename = FileData.cFileName;
|
||||
//debugLog("found: " + filename);
|
||||
if (filename.size()>4)
|
||||
{
|
||||
|
||||
callback(path + f->name(), param);
|
||||
std::string filetype = filename.substr(filename.size()-4, filename.size());
|
||||
stringToUpper(filetype);
|
||||
//debugLog("comparing: " + filetype + " and: " + type);
|
||||
if (filetype==type)
|
||||
{
|
||||
callback(path+filename, param);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!FindNextFile(hList, &FileData))
|
||||
{
|
||||
/*
|
||||
if (GetLastError() == ERROR_NO_MORE_FILES)
|
||||
{
|
||||
fFinished = TRUE;
|
||||
}
|
||||
*/
|
||||
fFinished = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FindClose(hList);
|
||||
#endif
|
||||
}
|
||||
|
||||
std::vector<std::string> getFileList(std::string path, std::string type, int param)
|
||||
{
|
||||
std::vector<std::string> list;
|
||||
|
||||
#ifdef BBGE_BUILD_WINDOWS
|
||||
BOOL fFinished;
|
||||
HANDLE hList;
|
||||
TCHAR szDir[MAX_PATH+1];
|
||||
WIN32_FIND_DATA FileData;
|
||||
|
||||
// Get the proper directory path
|
||||
sprintf(szDir, "%s\\*", path.c_str());
|
||||
|
||||
|
||||
// Get the first file
|
||||
hList = FindFirstFile(szDir, &FileData);
|
||||
if (hList == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
printf("No files found\n\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Traverse through the directory structure
|
||||
fFinished = FALSE;
|
||||
while (!fFinished)
|
||||
{
|
||||
// Check the object is a directory or not
|
||||
//printf("%*s%s\n", indent, "", FileData.cFileName);
|
||||
std::string filename = FileData.cFileName;
|
||||
if (filename.size()>4 && filename.substr(filename.size()-4, filename.size())==type)
|
||||
{
|
||||
//callback(path+filename, param);
|
||||
list.push_back (filename);
|
||||
}
|
||||
|
||||
|
||||
if (!FindNextFile(hList, &FileData))
|
||||
{
|
||||
/*
|
||||
if (GetLastError() == ERROR_NO_MORE_FILES)
|
||||
{
|
||||
fFinished = TRUE;
|
||||
}
|
||||
*/
|
||||
fFinished = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FindClose(hList);
|
||||
#endif
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
std::string msg(const std::string &message)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue