From 4639b00b5af1f584597631876dea0bd165d455c2 Mon Sep 17 00:00:00 2001 From: lingeringwillx <111698406+lingeringwillx@users.noreply.github.com> Date: Tue, 12 Dec 2023 01:06:57 +0300 Subject: [PATCH] Remove COMPRESS mode --- dbpf-recompress.cpp | 23 +++-------------------- dbpf.h | 25 +++++++++---------------- 2 files changed, 12 insertions(+), 36 deletions(-) diff --git a/dbpf-recompress.cpp b/dbpf-recompress.cpp index 1bdc18d..ae4934b 100644 --- a/dbpf-recompress.cpp +++ b/dbpf-recompress.cpp @@ -108,7 +108,7 @@ int wmain(int argc, wchar_t *argv[]) { dbpf::Package oldPackage = package; //copy //optimization: if the package file has the compressor's signature then skip it - if(mode != dbpf::DECOMPRESS && package.signature_in_package) { + if(mode == dbpf::RECOMPRESS && package.signature_in_package) { mode = dbpf::SKIP; file.close(); } @@ -119,25 +119,8 @@ int wmain(int argc, wchar_t *argv[]) { continue; } - //optimization: for COMPRESS mode skip the package file if all of it's entries are compressed - //note: this is not the default mode - if(mode == dbpf::COMPRESS) { - bool all_entries_compressed = true; - - for(auto& entry: package.entries) { - if(!entry.compressed) { - all_entries_compressed = false; - break; - } - } - - if(all_entries_compressed) { - mode = dbpf::SKIP; - file.close(); - } - //optimization: for DECOMPRESS mode skip the package file if all of it's entries are decompressed - } else if(mode == dbpf::DECOMPRESS) { + if(mode == dbpf::DECOMPRESS) { bool all_entries_decompressed = true; for(auto& entry: package.entries) { @@ -236,7 +219,7 @@ bool validatePackage(dbpf::Package& oldPackage, dbpf::Package& newPackage, fstre return false; } - if(mode != dbpf::DECOMPRESS) { + if(mode == dbpf::RECOMPRESS) { //should only have one hole for the compressor signature if(newPackage.header.holeIndexEntryCount != 1) { wcout << displayPath << L": Wrong hole index count" << endl; diff --git a/dbpf.h b/dbpf.h index 0116963..0c6dd25 100644 --- a/dbpf.h +++ b/dbpf.h @@ -58,13 +58,12 @@ namespace dbpf { } /* compression mode - COMPRESS: compress uncompress entries only - DECOMPRESS: decompress the package RECOMPRESS: decompress the package's entries then compress them again, can result in better compression if the older compression is weak + DECOMPRESS: decompress the package SKIP: don't do anything with the package */ - enum Mode { COMPRESS, DECOMPRESS, RECOMPRESS, SKIP }; + enum Mode { RECOMPRESS, DECOMPRESS, SKIP }; //representing the header of a package file struct Header { @@ -390,14 +389,13 @@ namespace dbpf { if(header[4] == 0x10 && header[5] == 0xFB) { entry.compressed = true; - entry.uncompressedSize = getUncompressedSize(header); } } } } //check if entries with repeated TGIRs exist (we don't want to compress those) - if(mode != DECOMPRESS) { + if(mode == RECOMPRESS) { unordered_map entriesMap; entriesMap.reserve(package.entries.size()); @@ -435,10 +433,7 @@ namespace dbpf { putInt(buffer, pos, package.header.indexMajorVersion); pos += 24; //skip index and hole info, update later putInt(buffer, pos, package.header.indexMinorVersion); - - for(uint i = 0; i < package.header.remainder.size(); i++) { - buffer[pos++] = package.header.remainder[i]; - } + copy(package.header.remainder.begin(), package.header.remainder.end(), buffer.begin() + 64); writeFile(newFile, buffer); @@ -454,12 +449,10 @@ namespace dbpf { bytes content = readFile(oldFile, entry.location, entry.size); omp_unset_lock(&lock); - if(mode == DECOMPRESS) { - content = decompressEntry(entry, content); - } else if(mode == RECOMPRESS) { + if(mode == RECOMPRESS) { content = recompressEntry(entry, content); - } else { - content = compressEntry(entry, content); + } else if(mode == DECOMPRESS) { + content = decompressEntry(entry, content); } entry.size = content.size(); @@ -543,7 +536,7 @@ namespace dbpf { //write compressor signature as a hole and write the hole index uint holeIndexLocation = indexEnd; - if(mode != DECOMPRESS) { + if(mode == RECOMPRESS) { uint holeLocation = holeIndexLocation + 8; uint fileSize = holeLocation + 8; @@ -571,7 +564,7 @@ namespace dbpf { putInt(buffer, pos, indexStart); //index location putInt(buffer, pos, indexEnd - indexStart); //index size - if(mode != DECOMPRESS) { + if(mode == RECOMPRESS) { putInt(buffer, pos, 1); //hole index entry count putInt(buffer, pos, holeIndexLocation); //hole index location putInt(buffer, pos, 8); //hole index size