Skip to content

Commit

Permalink
Remove COMPRESS mode
Browse files Browse the repository at this point in the history
  • Loading branch information
lingeringwillx authored Dec 11, 2023
1 parent b946865 commit 4639b00
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 36 deletions.
23 changes: 3 additions & 20 deletions dbpf-recompress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
25 changes: 9 additions & 16 deletions dbpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<Entry, uint, hashFunction, equalFunction> entriesMap;
entriesMap.reserve(package.entries.size());

Expand Down Expand Up @@ -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);

Expand All @@ -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();
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4639b00

Please sign in to comment.