diff --git a/include/qarchive_enums.hpp b/include/qarchive_enums.hpp index 0919532..2071508 100644 --- a/include/qarchive_enums.hpp +++ b/include/qarchive_enums.hpp @@ -67,7 +67,7 @@ enum : short { * These codes are used to represent Archive formats in form * of a short integer. */ -enum : short { +enum formats : short { TarFormat = 200, ZipFormat, SevenZipFormat, diff --git a/include/qarchivecompressor_p.hpp b/include/qarchivecompressor_p.hpp index cee75ac..271de5e 100644 --- a/include/qarchivecompressor_p.hpp +++ b/include/qarchivecompressor_p.hpp @@ -18,7 +18,7 @@ namespace QArchive { class CompressorPrivate : public QObject { Q_OBJECT public: - CompressorPrivate(bool memoryMode = false); + explicit CompressorPrivate(bool memoryMode = false); ~CompressorPrivate() override; CompressorPrivate(const CompressorPrivate&) = delete; CompressorPrivate& operator=(const CompressorPrivate&) = delete; diff --git a/include/qarchiveextractor_p.hpp b/include/qarchiveextractor_p.hpp index 8cabc32..5f12b51 100644 --- a/include/qarchiveextractor_p.hpp +++ b/include/qarchiveextractor_p.hpp @@ -35,7 +35,7 @@ class MutableMemoryFile { class ExtractorPrivate : public QObject { Q_OBJECT public: - ExtractorPrivate(bool memoryMode = false); + explicit ExtractorPrivate(bool memoryMode = false); ~ExtractorPrivate() override; ExtractorPrivate(const ExtractorPrivate&) = delete; ExtractorPrivate& operator=(const ExtractorPrivate&) = delete; diff --git a/src/qarchive_enums.cc b/src/qarchive_enums.cc index 2c0e3ab..0e143c2 100644 --- a/src/qarchive_enums.cc +++ b/src/qarchive_enums.cc @@ -4,95 +4,65 @@ using namespace QArchive; QString QArchive::errorCodeToString(short errorCode) { - QString errorString; switch(errorCode) { case NoError: - errorString = QString("QArchive::NoError"); - break; + return "QArchive::NoError"; case NotEnoughMemory: - errorString = QString("QArchive::NotEnoughMemory"); - break; + return "QArchive::NotEnoughMemory"; case NoPermissionToWrite: - errorString = QString("QArchive::NoPermissionToWrite"); - break; + return "QArchive::NoPermissionToWrite"; case ArchiveNotGiven: - errorString = QString("QArchive::ArchiveNotGiven"); - break; + return "QArchive::ArchiveNotGiven"; case ArchiveDoesNotExists: - errorString = QString("QArchive::ArchiveDoesNotExists"); - break; + return "QArchive::ArchiveDoesNotExists"; case ArchiveReadError: - errorString = QString("QArchive::ArchiveReadError"); - break; + return "QArchive::ArchiveReadError"; case ArchiveWriteError: - errorString = QString("QArchive::ArchiveWriteError"); - break; + return "QArchive::ArchiveWriteError"; case ArchiveHeaderWriteError: - errorString = QString("QArchive::ArchiveHeaderWriteError"); - break; + return "QArchive::ArchiveHeaderWriteError"; case ArchiveCorrupted: - errorString = QString("QArchive::ArchiveCorrupted"); - break; + return "QArchive::ArchiveCorrupted"; case ArchiveIsNotReadable: - errorString = QString("QArchive::ArchiveIsNotReadable"); - break; + return "QArchive::ArchiveIsNotReadable"; case ArchiveIsNotOpened: - errorString = QString("QArchive::ArchiveIsNotOpened"); - break; + return "QArchive::ArchiveIsNotOpened"; case ArchivePasswordNeeded: - errorString = QString("QArchive::ArchivePasswordNeeded"); - break; + return "QArchive::ArchivePasswordNeeded"; case ArchivePasswordIncorrect: - errorString = QString("QArchive::ArchivePasswordIncorrect"); - break; + return "QArchive::ArchivePasswordIncorrect"; case CannotOpenArchive: - errorString = QString("QArchive::CannotOpenArchive"); - break; + return "QArchive::CannotOpenArchive"; case NoPermissionToReadArchive: - errorString = QString("QArchive::NoPermissionToReadArchive"); - break; + return "QArchive::NoPermissionToReadArchive"; case InvalidOutputDirectory: - errorString = QString("QArchive::InvalidOutputDirectory"); - break; + return "QArchive::InvalidOutputDirectory"; case InvalidArchiveFile: - errorString = QString("QArchive::InvalidArchiveFile"); - break; + return "QArchive::InvalidArchiveFile"; case ArchiveFileNameNotGiven: - errorString = QString("QArchive::ArchiveFileNameNotGiven"); - break; + return "QArchive::ArchiveFileNameNotGiven"; case ArchiveFileAlreadyExists: - errorString = QString("QArchive::ArchiveFileAlreadyExists"); - break; + return "QArchive::ArchiveFileAlreadyExists"; case ArchiveWriteOpenError: - errorString = QString("QArchive::ArchiveWriteOpenError"); - break; + return "QArchive::ArchiveWriteOpenError"; case ArchiveFatalError: - errorString = QString("QArchive::ArchiveFatalError"); - break; + return "QArchive::ArchiveFatalError"; case FileDoesNotExist: - errorString = QString("QArchive::FileDoesNotExist"); - break; + return "QArchive::FileDoesNotExist"; case DiskReadError: - errorString = QString("QArchive::DiskReadError"); - break; + return "QArchive::DiskReadError"; case DiskOpenError: - errorString = QString("QArchive::DiskOpenError"); - break; + return "QArchive::DiskOpenError"; case NoPermissionToReadFile: - errorString = QString("QArchive::NoPermissionToReadFile"); - break; + return "QArchive::NoPermissionToReadFile"; case NoFilesToCompress: - errorString = QString("QArchive::NoFilesToCompress"); - break; + return "QArchive::NoFilesToCompress"; case CannotOpenFile: - errorString = QString("QArchive::CannotOpenFile"); - break; + return "QArchive::CannotOpenFile"; case IODeviceSequential: - errorString = QString("QArchive::IODeviceSequential"); - break; + return "QArchive::IODeviceSequential"; default: - errorString = QString("QArchive::UnknownError"); - break; + return "QArchive::UnknownError"; } - return errorString; + return ""; } diff --git a/src/qarchivecompressor_p.cc b/src/qarchivecompressor_p.cc index ef5c41c..8b2fd16 100644 --- a/src/qarchivecompressor_p.cc +++ b/src/qarchivecompressor_p.cc @@ -411,30 +411,20 @@ bool CompressorPrivate::guessArchiveFormat() { } auto ext = QFileInfo(m_TemporaryFile->fileName()).suffix().toLower(); - if(ext == "bz") { - m_ArchiveFormat = BZipFormat; - } else if(ext == "bz2") { - m_ArchiveFormat = BZip2Format; - } else if(ext == "gz") { - m_ArchiveFormat = GZipFormat; - } else if(ext == "xz") { - m_ArchiveFormat = XzFormat; - } else if(ext == "tar") { - m_ArchiveFormat = TarFormat; - } else if(ext == "xar") { - m_ArchiveFormat = XarFormat; - } else if(ext == "zip") { - m_ArchiveFormat = ZipFormat; - } else if(ext == "7z") { - m_ArchiveFormat = SevenZipFormat; - } else if(ext == "zstd") { - m_ArchiveFormat = ZstdFormat; - } else { - m_ArchiveFormat = 0; - return false; - } - - return true; + m_ArchiveFormat = [ext] { + if (ext == "bz") return BZipFormat; + if (ext == "bz2") return BZip2Format; + if (ext == "gz") return GZipFormat; + if (ext == "xz") return XzFormat; + if (ext == "tar") return TarFormat; + if (ext == "xar") return XarFormat; + if (ext == "zip") return ZipFormat; + if (ext == "7z") return SevenZipFormat; + if (ext == "zstd") return ZstdFormat; + return formats(0); + }(); + + return m_ArchiveFormat != 0; } // Confirms all the files that are stagged for compression , Returns true diff --git a/src/qarchiveextractor_p.cc b/src/qarchiveextractor_p.cc index da16962..4f618ab 100644 --- a/src/qarchiveextractor_p.cc +++ b/src/qarchiveextractor_p.cc @@ -106,7 +106,6 @@ static QJsonObject getArchiveEntryInformation(archive_entry *entry, bool bExclud roundedSize = 0; } else if(roundedSize < 1024) { sizeUnits = "Bytes"; - roundedSize = roundedSize; } else if(roundedSize >= 1024 && roundedSize < 1048576) { sizeUnits = "KiB"; roundedSize /= 1024; diff --git a/tests/QArchiveTestCases.hpp b/tests/QArchiveTestCases.hpp index 321332f..0f149a8 100644 --- a/tests/QArchiveTestCases.hpp +++ b/tests/QArchiveTestCases.hpp @@ -88,6 +88,7 @@ class QArchiveTestCases { TestCase8OutputDir, Test8OutputFile, TemporaryFilePath; + protected: const QString Test1OutputContents = "TEST1SUCCESS!"; const QString Test2OutputContents = "TEST2SUCCESS!"; const QString Test3Output1Contents = "TEST3SUCCESS1!";