Skip to content

Commit

Permalink
feat: Re-enable rar support (#144)
Browse files Browse the repository at this point in the history
This re-enables attempted support for .rar files. It will attempt to
decompress with Rar5 first, and fallback to the older Rar method if that
fails.

If both methods fail, the user will get an error notification with the
error messages from both attempts.

I tested with the main .rar files from
<https://github.com/ssokolow/rar-test-files>. This successfully
extracted the `testfile.rar5.rar` file, but still fails on the
`testfile.rar3.rar` file, so support will probably still be spotty.
  • Loading branch information
SnazzyPanda authored May 25, 2024
1 parent 99c0201 commit c549fbf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
25 changes: 18 additions & 7 deletions Lampray/Filesystem/lampExtract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,24 @@ Lamp::Core::FS::lampReturn Lamp::Core::FS::lampExtract::extract(const Base::lamp
true, Base::lampLog::LMP_EXTRACTIONFALED);
}
} else if (std::regex_match((std::string)mod->ArchivePath, std::regex("^.*\\.(rar)$"))) {

// Rar Extraction Goes Here!

//[mod->ArchivePath] Path to the archive to extract

//[workingDir + "/ext/" + std::filesystem::path(mod->ArchivePath).filename().stem().string()] Folder path for files to extract to.

try {
bit7z::Bit7zLibrary lib{Lamp::Core::lampConfig::getInstance().bit7zLibaryLocation};
bit7z::BitArchiveReader reader{lib, mod->ArchivePath, bit7z::BitFormat::Rar5};
reader.test();
reader.extract(workingDir + "/ext/" + std::filesystem::path(mod->ArchivePath).filename().stem().string());
return Base::lampLog::getInstance().pLog({1, "Extraction Successful. : "+ mod->ArchivePath}, Base::lampLog::LOG);
} catch (const bit7z::BitException &ex) {
try {
bit7z::Bit7zLibrary lib{Lamp::Core::lampConfig::getInstance().bit7zLibaryLocation};
bit7z::BitArchiveReader reader{lib, mod->ArchivePath, bit7z::BitFormat::Rar};
reader.test();
reader.extract(workingDir + "/ext/" + std::filesystem::path(mod->ArchivePath).filename().stem().string());
return Base::lampLog::getInstance().pLog({1, "Extraction Successful. : "+ mod->ArchivePath}, Base::lampLog::LOG);
} catch (const bit7z::BitException &ex2) {
return Base::lampLog::getInstance().pLog({0, "Could not extract file : "+ mod->ArchivePath + "\nMessages:\n" + ex.what() + "\n" + ex2.what()},
Base::lampLog::ERROR, true, Base::lampLog::LMP_EXTRACTIONFALED);
}
}
} else if (std::regex_match((std::string)mod->ArchivePath, std::regex("^.*\\.(7z)$"))) {
try {
bit7z::Bit7zLibrary lib{Lamp::Core::lampConfig::getInstance().bit7zLibaryLocation};
Expand Down
4 changes: 1 addition & 3 deletions Lampray/Filesystem/lampIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,7 @@ void Lamp::Core::FS::lampIO::fileDrop(const char *inputPath) {
std::filesystem::path path(inputPath);
std::error_code ec;
if (std::filesystem::is_regular_file(path, ec)) {
// Reenable rar support here.
//if (std::regex_match(path.filename().string(), std::regex("^.*\\.(zip|rar|7z)$"))) {
if (std::regex_match(path.filename().string(), std::regex("^.*\\.(zip|7z)$"))) {
if (std::regex_match(path.filename().string(), std::regex("^.*\\.(zip|rar|7z)$"))) {
std::filesystem::path targetDIR = Core::lampConfig::getInstance().archiveDataPath +
Lamp::Games::getInstance().currentGame->Ident().ReadableName; // Roi Danton many thanks again!
auto target = targetDIR / path.filename();
Expand Down

0 comments on commit c549fbf

Please sign in to comment.