mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
refacto: rendering engine singleton removal step 1 (filesystem)
Make the RenderingEngine filesystem member non accessible from everywhere This permits also to determine that some lua code has directly a logic to extract zip file. Move this logic inside client, it's not the lua stack role to perform a such complex operation Found also another irrlicht <1.8 compat code to remove
This commit is contained in:
parent
bc1888ff21
commit
e34d28af9f
5 changed files with 84 additions and 86 deletions
|
@ -34,9 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "serverlist.h"
|
||||
#include "mapgen/mapgen.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include <IFileArchive.h>
|
||||
#include <IFileSystem.h>
|
||||
#include "client/client.h"
|
||||
#include "client/renderingengine.h"
|
||||
#include "network/networkprotocol.h"
|
||||
|
||||
|
@ -630,74 +628,7 @@ int ModApiMainMenu::l_extract_zip(lua_State *L)
|
|||
|
||||
if (ModApiMainMenu::mayModifyPath(absolute_destination)) {
|
||||
fs::CreateAllDirs(absolute_destination);
|
||||
|
||||
io::IFileSystem *fs = RenderingEngine::get_filesystem();
|
||||
|
||||
if (!fs->addFileArchive(zipfile, false, false, io::EFAT_ZIP)) {
|
||||
lua_pushboolean(L,false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
sanity_check(fs->getFileArchiveCount() > 0);
|
||||
|
||||
/**********************************************************************/
|
||||
/* WARNING this is not threadsafe!! */
|
||||
/**********************************************************************/
|
||||
io::IFileArchive* opened_zip =
|
||||
fs->getFileArchive(fs->getFileArchiveCount()-1);
|
||||
|
||||
const io::IFileList* files_in_zip = opened_zip->getFileList();
|
||||
|
||||
unsigned int number_of_files = files_in_zip->getFileCount();
|
||||
|
||||
for (unsigned int i=0; i < number_of_files; i++) {
|
||||
std::string fullpath = destination;
|
||||
fullpath += DIR_DELIM;
|
||||
fullpath += files_in_zip->getFullFileName(i).c_str();
|
||||
std::string fullpath_dir = fs::RemoveLastPathComponent(fullpath);
|
||||
|
||||
if (!files_in_zip->isDirectory(i)) {
|
||||
if (!fs::PathExists(fullpath_dir) && !fs::CreateAllDirs(fullpath_dir)) {
|
||||
fs->removeFileArchive(fs->getFileArchiveCount()-1);
|
||||
lua_pushboolean(L,false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
io::IReadFile* toread = opened_zip->createAndOpenFile(i);
|
||||
|
||||
FILE *targetfile = fopen(fullpath.c_str(),"wb");
|
||||
|
||||
if (targetfile == NULL) {
|
||||
fs->removeFileArchive(fs->getFileArchiveCount()-1);
|
||||
lua_pushboolean(L,false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
char read_buffer[1024];
|
||||
long total_read = 0;
|
||||
|
||||
while (total_read < toread->getSize()) {
|
||||
|
||||
unsigned int bytes_read =
|
||||
toread->read(read_buffer,sizeof(read_buffer));
|
||||
if ((bytes_read == 0 ) ||
|
||||
(fwrite(read_buffer, 1, bytes_read, targetfile) != bytes_read))
|
||||
{
|
||||
fclose(targetfile);
|
||||
fs->removeFileArchive(fs->getFileArchiveCount()-1);
|
||||
lua_pushboolean(L,false);
|
||||
return 1;
|
||||
}
|
||||
total_read += bytes_read;
|
||||
}
|
||||
|
||||
fclose(targetfile);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fs->removeFileArchive(fs->getFileArchiveCount()-1);
|
||||
lua_pushboolean(L,true);
|
||||
lua_pushboolean(L, getClient(L)->extractZipFile(zipfile, destination));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue