Skip to content
Snippets Groups Projects
Commit f6e689cf authored by Vicki Pfau's avatar Vicki Pfau
Browse files

src: Actually fix zips

parent 7f4d2354
No related branches found
No related tags found
No related merge requests found
...@@ -238,7 +238,6 @@ void MovieBK2::close() { ...@@ -238,7 +238,6 @@ void MovieBK2::close() {
if (!m_state.empty()) { if (!m_state.empty()) {
auto state = m_zip->openFile("Core.bin", true); auto state = m_zip->openFile("Core.bin", true);
state->write(m_state.data(), m_state.size()); state->write(m_state.data(), m_state.size());
state->flush();
} }
} }
m_zip->close(); m_zip->close();
......
...@@ -22,9 +22,12 @@ void Zip::close() { ...@@ -22,9 +22,12 @@ void Zip::close() {
if (!m_zip) { if (!m_zip) {
return; return;
} }
m_files.clear(); for (auto& file : m_files) {
file->close();
}
zip_close(m_zip); zip_close(m_zip);
m_zip = nullptr; m_zip = nullptr;
m_files.clear();
} }
Zip::File* Zip::openFile(const std::string& name, bool write) { Zip::File* Zip::openFile(const std::string& name, bool write) {
...@@ -51,14 +54,6 @@ Zip::File::File(zip_t* zip, const std::string& name, zip_file_t* file) ...@@ -51,14 +54,6 @@ Zip::File::File(zip_t* zip, const std::string& name, zip_file_t* file)
, m_name(name) { , m_name(name) {
} }
Zip::File::~File() {
if (m_file) {
zip_fclose(m_file);
} else {
flush();
}
}
string Zip::File::readline() { string Zip::File::readline() {
auto pos = m_buffer.end(); auto pos = m_buffer.end();
pos = find(m_buffer.begin(), m_buffer.end(), '\n'); pos = find(m_buffer.begin(), m_buffer.end(), '\n');
...@@ -97,17 +92,17 @@ ssize_t Zip::File::write(const void* buffer, size_t size) { ...@@ -97,17 +92,17 @@ ssize_t Zip::File::write(const void* buffer, size_t size) {
return size; return size;
} }
bool Zip::File::flush() { void Zip::File::close() {
if (!m_buffer.size()) { if (m_file) {
return false; zip_fclose(m_file);
} } else if (m_buffer.size()) {
zip_source_t* source = zip_source_buffer(m_zip, static_cast<void*>(&m_buffer.front()), m_buffer.size(), 0); zip_source_t* source = zip_source_buffer(m_zip, static_cast<void*>(&m_buffer.front()), m_buffer.size(), 0);
if (!source) { if (!source) {
return false; return;
} }
zip_int64_t i = zip_file_add(m_zip, m_name.c_str(), source, ZIP_FL_OVERWRITE); zip_int64_t i = zip_file_add(m_zip, m_name.c_str(), source, ZIP_FL_OVERWRITE);
if (i < 0) { if (i < 0) {
return false; return;
}
} }
return true;
} }
...@@ -14,15 +14,15 @@ public: ...@@ -14,15 +14,15 @@ public:
public: public:
File(zip_t*, const std::string& name, zip_file_t* = nullptr); File(zip_t*, const std::string& name, zip_file_t* = nullptr);
File(File&) = delete; File(File&) = delete;
~File();
std::string readline(); std::string readline();
ssize_t read(void* buffer, size_t size); ssize_t read(void* buffer, size_t size);
ssize_t write(const void* buffer, size_t size); ssize_t write(const void* buffer, size_t size);
bool flush();
private: private:
void close();
friend class Zip;
zip_t* m_zip; zip_t* m_zip;
zip_file_t* m_file; zip_file_t* m_file;
std::vector<char> m_buffer; std::vector<char> m_buffer;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment