Skip to content

Commit

Permalink
Merge pull request #84 from neheb/clang
Browse files Browse the repository at this point in the history
various cleanups
  • Loading branch information
antony-jr authored Dec 24, 2022
2 parents 5c174ed + 99a73ee commit d87e86c
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 88 deletions.
2 changes: 1 addition & 1 deletion include/qarchive_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion include/qarchivecompressor_p.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion include/qarchiveextractor_p.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
90 changes: 30 additions & 60 deletions src/qarchive_enums.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
}
38 changes: 14 additions & 24 deletions src/qarchivecompressor_p.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/qarchiveextractor_p.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions tests/QArchiveTestCases.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class QArchiveTestCases {
TestCase8OutputDir,
Test8OutputFile,
TemporaryFilePath;
protected:
const QString Test1OutputContents = "TEST1SUCCESS!";
const QString Test2OutputContents = "TEST2SUCCESS!";
const QString Test3Output1Contents = "TEST3SUCCESS1!";
Expand Down

0 comments on commit d87e86c

Please sign in to comment.