Fix .zip extraction (mod store)
authorngosang <diegodelasheras@gmail.com>
Thu, 22 Jan 2015 16:09:29 +0000 (17:09 +0100)
committerCraig Robbins <kde.psych@gmail.com>
Sat, 14 Feb 2015 11:00:13 +0000 (21:00 +1000)
src/script/lua_api/l_mainmenu.cpp

index 28c3d193d6cc715b7d9d7c93e4ba9502bc6c5c4e..0d8365106e123c3187c349bafe272a5d17f99191 100644 (file)
@@ -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()) {