From 9d9292805d5112aaa6cc85364cafd5e702586d9a Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 25 Apr 2022 16:19:47 -0400 Subject: Fixed issue with installing zips containing directory listings --- src/lib/mods.cc | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/lib/mods.cc b/src/lib/mods.cc index 07f48da..979ecbf 100644 --- a/src/lib/mods.cc +++ b/src/lib/mods.cc @@ -170,6 +170,7 @@ bool libbible::installModFromZip(string filename) { unzClose(zipfile); return false; } + cout << "Unzipping " << filename << "\n"; char read_buffer[READ_SIZE]; ulong i; for(i = 0; i < global_info.number_entry; i++) { @@ -179,6 +180,7 @@ bool libbible::installModFromZip(string filename) { return false; } string fname = basedir + string(read_buffer); + cout << "Unpacking " << fname << "\n"; size_t pos = fname.find_last_of(delim); if(pos != string::npos) { string path = fname.substr(0, pos); @@ -189,26 +191,28 @@ bool libbible::installModFromZip(string filename) { unzClose(zipfile); return false; } - FILE *out = fopen(fname.c_str(), "wb"); - if(out == NULL) { - unzCloseCurrentFile(zipfile); - unzClose(zipfile); - return false; - } - int bytesRead; - do { - bytesRead = unzReadCurrentFile(zipfile, read_buffer, READ_SIZE); - if(bytesRead < 0) { - printf("error %d\n", bytesRead); + if(pos != fname.size()-1) { // It is not a directory + FILE *out = fopen(fname.c_str(), "wb"); + if(out == NULL) { unzCloseCurrentFile(zipfile); unzClose(zipfile); return false; } - if(bytesRead > 0) { - fwrite(read_buffer, bytesRead, 1, out); - } - } while(bytesRead > 0); - fclose(out); + int bytesRead; + do { + bytesRead = unzReadCurrentFile(zipfile, read_buffer, READ_SIZE); + if(bytesRead < 0) { + printf("error %d\n", bytesRead); + unzCloseCurrentFile(zipfile); + unzClose(zipfile); + return false; + } + if(bytesRead > 0) { + fwrite(read_buffer, bytesRead, 1, out); + } + } while(bytesRead > 0); + fclose(out); + } unzCloseCurrentFile(zipfile); unzGoToNextFile(zipfile); } -- cgit v1.2.3