Allow extracting password-protected zips (#104)
This commit is contained in:
parent
1c703d231c
commit
dd5407e0cb
@ -69,7 +69,7 @@ core.copy_dir(source,destination,keep_soure) (possible in async calls)
|
|||||||
^ returns true/false
|
^ returns true/false
|
||||||
core.is_dir(path) (possible in async calls)
|
core.is_dir(path) (possible in async calls)
|
||||||
^ returns true if path is a valid dir
|
^ returns true if path is a valid dir
|
||||||
core.extract_zip(zipfile,destination) [unzip within path required]
|
core.extract_zip(zipfile, destination[, password]) [unzip within path required]
|
||||||
^ zipfile to extract
|
^ zipfile to extract
|
||||||
^ destination folder to extract to
|
^ destination folder to extract to
|
||||||
^ returns true/false
|
^ returns true/false
|
||||||
|
@ -649,6 +649,7 @@ int ModApiMainMenu::l_extract_zip(lua_State *L)
|
|||||||
{
|
{
|
||||||
const char *zipfile = luaL_checkstring(L, 1);
|
const char *zipfile = luaL_checkstring(L, 1);
|
||||||
const char *destination = luaL_checkstring(L, 2);
|
const char *destination = luaL_checkstring(L, 2);
|
||||||
|
const char *password = lua_isstring(L, 3) ? lua_tostring(L, 3) : "";
|
||||||
|
|
||||||
std::string absolute_destination = fs::RemoveRelativePathComponents(destination);
|
std::string absolute_destination = fs::RemoveRelativePathComponents(destination);
|
||||||
|
|
||||||
@ -657,7 +658,7 @@ int ModApiMainMenu::l_extract_zip(lua_State *L)
|
|||||||
|
|
||||||
io::IFileSystem *fs = RenderingEngine::get_filesystem();
|
io::IFileSystem *fs = RenderingEngine::get_filesystem();
|
||||||
|
|
||||||
if (!fs->addFileArchive(zipfile, false, false, io::EFAT_ZIP)) {
|
if (!fs->addFileArchive(zipfile, false, false, io::EFAT_ZIP, password)) {
|
||||||
lua_pushboolean(L,false);
|
lua_pushboolean(L,false);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -689,6 +690,14 @@ int ModApiMainMenu::l_extract_zip(lua_State *L)
|
|||||||
|
|
||||||
io::IReadFile* toread = opened_zip->createAndOpenFile(i);
|
io::IReadFile* toread = opened_zip->createAndOpenFile(i);
|
||||||
|
|
||||||
|
if (toread == nullptr) {
|
||||||
|
// Wrong password
|
||||||
|
fs->removeFileArchive(fs->getFileArchiveCount()-1);
|
||||||
|
lua_pushboolean(L, false);
|
||||||
|
lua_pushstring(L, "invalid password");
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
FILE *targetfile = fopen(fullpath.c_str(),"wb");
|
FILE *targetfile = fopen(fullpath.c_str(),"wb");
|
||||||
|
|
||||||
if (targetfile == NULL) {
|
if (targetfile == NULL) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user