1
0
Fork 0

Allow extracting password-protected zips (#104)

main-2-0-3
luk3yx 2022-10-18 23:25:08 +13:00 committed by GitHub
parent 1c703d231c
commit dd5407e0cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -69,7 +69,7 @@ core.copy_dir(source,destination,keep_soure) (possible in async calls)
^ returns true/false
core.is_dir(path) (possible in async calls)
^ 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
^ destination folder to extract to
^ returns true/false

View File

@ -649,6 +649,7 @@ int ModApiMainMenu::l_extract_zip(lua_State *L)
{
const char *zipfile = luaL_checkstring(L, 1);
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);
@ -657,7 +658,7 @@ int ModApiMainMenu::l_extract_zip(lua_State *L)
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);
return 1;
}
@ -689,6 +690,14 @@ int ModApiMainMenu::l_extract_zip(lua_State *L)
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");
if (targetfile == NULL) {