From e102cbd840c3dc3d52865868369aea3b8ee21028 Mon Sep 17 00:00:00 2001
From: ngosang <diegodelasheras@gmail.com>
Date: Thu, 22 Jan 2015 17:09:29 +0100
Subject: [PATCH] Fix .zip extraction (mod store)

---
 src/script/lua_api/l_mainmenu.cpp | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp
index 28c3d193d..0d8365106 100644
--- a/src/script/lua_api/l_mainmenu.cpp
+++ b/src/script/lua_api/l_mainmenu.cpp
@@ -859,19 +859,19 @@ int ModApiMainMenu::l_extract_zip(lua_State *L)
 
 		unsigned int number_of_files = files_in_zip->getFileCount();
 
-		for (unsigned int i=0; i < number_of_files;  i++) {
+		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::CreateAllDirs(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;
 				}
-			}
-			else {
+
 				io::IReadFile* toread = opened_zip->createAndOpenFile(i);
 
 				FILE *targetfile = fopen(fullpath.c_str(),"wb");
@@ -883,7 +883,7 @@ int ModApiMainMenu::l_extract_zip(lua_State *L)
 				}
 
 				char read_buffer[1024];
-				unsigned int total_read = 0;
+				long total_read = 0;
 
 				while (total_read < toread->getSize()) {
 
-- 
GitLab