From 0a44575e492cb734aae0b2375a2784189028aa1e Mon Sep 17 00:00:00 2001 From: Tsu Jan Date: Mon, 28 Jun 2021 08:41:25 +0430 Subject: [PATCH] Determine archive's modifiability from its mimetype Not from its extension. --- NEWS | 2 +- backends.cpp | 14 ++++++-------- data/translations/arqiver.ts | 24 ++++++++++++------------ data/translations/arqiver_eo.ts | 24 ++++++++++++------------ data/translations/arqiver_hu.ts | 24 ++++++++++++------------ data/translations/arqiver_nl.ts | 24 ++++++++++++------------ data/translations/arqiver_pl.ts | 24 ++++++++++++------------ data/translations/arqiver_pt_BR.ts | 24 ++++++++++++------------ data/translations/arqiver_ru.ts | 24 ++++++++++++------------ mainWin.cpp | 2 +- 10 files changed, 92 insertions(+), 94 deletions(-) diff --git a/NEWS b/NEWS index 4fb4d43..3035012 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,5 @@ Latest version: - 27 Jun 2021, V0.8.0 + 28 Jun 2021, V0.8.0 See "ChangeLog" for changes. diff --git a/backends.cpp b/backends.cpp index f590dc1..acb1801 100644 --- a/backends.cpp +++ b/backends.cpp @@ -170,15 +170,13 @@ void Backend::loadFile(const QString& path, bool withPassword) { } bool Backend::canModify() const { - static QStringList validEXT; - if (validEXT.isEmpty()) { - validEXT << ".zip" << ".tar.gz" << ".pdf.gz" << ".svgz" << ".tgz" << ".tar.xz" << ".txz" << ".tar.bz" << ".tbz" << ".tar.bz2" << ".tbz2" << ".tar" << ".tar.lzma" << ".tar.zst" << ".tzst" << ".tlz" << ".cpio" << /*".pax" <<*/ ".ar" << /*".shar" <<*/ ".gz" << ".7z"; + static QStringList validMimeTypes; + if (validMimeTypes.isEmpty()) { + validMimeTypes << "application/zip" << "application/x-compressed-tar" << "application/x-gzpdf" << "image/svg+xml-compressed" << "application/x-xz-compressed-tar" << "application/x-bzip-compressed-tar" << "application/x-tar" << "application/x-lzma-compressed-tar" << "application/x-zstd-compressed-tar" << "application/x-cpio" << /*".pax" <<*/ "application/x-archive" << /*".shar" <<*/ "application/gzip" << "application/x-7z-compressed"; } - for (int i = 0; i < validEXT.length(); i++) { - if (filepath_.endsWith(validEXT.at(i))) - return true; - } - return false; + QMimeDatabase mimeDatabase; + QString mimeTypeName = mimeDatabase.mimeTypeForFile(QFileInfo(filepath_)).name(); + return validMimeTypes.contains(mimeTypeName); } QString Backend::currentFile() const { diff --git a/data/translations/arqiver.ts b/data/translations/arqiver.ts index a962a25..dea4fca 100644 --- a/data/translations/arqiver.ts +++ b/data/translations/arqiver.ts @@ -12,38 +12,38 @@ Arqiver::Backend - - - + + + Could not read archive - - + + Archive Loaded - - + + Modification Finished - - + + Extraction Finished - - + + Extraction Failed - + %1 is missing from your system. Please install it for this kind of archive! diff --git a/data/translations/arqiver_eo.ts b/data/translations/arqiver_eo.ts index 5d81aba..0138fe2 100644 --- a/data/translations/arqiver_eo.ts +++ b/data/translations/arqiver_eo.ts @@ -12,38 +12,38 @@ Arqiver::Backend - - - + + + Could not read archive La arkivo ne legeblis - - + + Archive Loaded Arkivo Ŝargita - - + + Modification Finished Modifado Farita - - + + Extraction Finished Ekstraktado Farita - - + + Extraction Failed Ekstraktado Malsukcesis - + %1 is missing from your system. Please install it for this kind of archive! %1 mankas al via sistemo. diff --git a/data/translations/arqiver_hu.ts b/data/translations/arqiver_hu.ts index aa24e1f..ab1f52a 100644 --- a/data/translations/arqiver_hu.ts +++ b/data/translations/arqiver_hu.ts @@ -12,38 +12,38 @@ Arqiver::Backend - - - + + + Could not read archive Nem sikerült olvasni az archívumot - - + + Archive Loaded Archívum betöltve - - + + Modification Finished A módosítás kész - - + + Extraction Finished A kibontás kész - - + + Extraction Failed A kibontás sikertelen - + %1 is missing from your system. Please install it for this kind of archive! %1 hiányzik a rendszeréből. diff --git a/data/translations/arqiver_nl.ts b/data/translations/arqiver_nl.ts index 4c762d7..34db1b1 100644 --- a/data/translations/arqiver_nl.ts +++ b/data/translations/arqiver_nl.ts @@ -12,38 +12,38 @@ Arqiver::Backend - - - + + + Could not read archive Kan archief niet uitlezen - - + + Archive Loaded Archief geladen - - + + Modification Finished Bewerking voltooid - - + + Extraction Finished Uitpakken voltooid - - + + Extraction Failed - + %1 is missing from your system. Please install it for this kind of archive! %1 is niet geïnstalleerd. diff --git a/data/translations/arqiver_pl.ts b/data/translations/arqiver_pl.ts index 3193df1..3e3ea24 100644 --- a/data/translations/arqiver_pl.ts +++ b/data/translations/arqiver_pl.ts @@ -12,38 +12,38 @@ Arqiver::Backend - - - + + + Could not read archive Nie udało się odczytać archiwum - - + + Archive Loaded Załadowano archiwum - - + + Modification Finished Zakończono modyfikowanie - - + + Extraction Finished Zakończono rozpakowywanie - - + + Extraction Failed - + %1 is missing from your system. Please install it for this kind of archive! W Twoim systemie brakuje %1. diff --git a/data/translations/arqiver_pt_BR.ts b/data/translations/arqiver_pt_BR.ts index f9bf886..9491e19 100644 --- a/data/translations/arqiver_pt_BR.ts +++ b/data/translations/arqiver_pt_BR.ts @@ -12,38 +12,38 @@ Arqiver::Backend - - - + + + Could not read archive Não foi possível ler o arquivo - - + + Archive Loaded Arquivo Carregado - - + + Modification Finished Modificação Concluída - - + + Extraction Finished Extração Concluída - - + + Extraction Failed Extração Falhou - + %1 is missing from your system. Please install it for this kind of archive! %1 está ausente do seu sistema. diff --git a/data/translations/arqiver_ru.ts b/data/translations/arqiver_ru.ts index dce52f5..aecb394 100644 --- a/data/translations/arqiver_ru.ts +++ b/data/translations/arqiver_ru.ts @@ -12,38 +12,38 @@ Arqiver::Backend - - - + + + Could not read archive Не удалось прочитать архив - - + + Archive Loaded Архив загружен - - + + Modification Finished Модификация завершена - - + + Extraction Finished Распаковка завершена - - + + Extraction Failed Ошибка распаковки - + %1 is missing from your system. Please install it for this kind of archive! %1 отсутствует в вашей системе. diff --git a/mainWin.cpp b/mainWin.cpp index ba019d3..cc63818 100644 --- a/mainWin.cpp +++ b/mainWin.cpp @@ -1480,7 +1480,7 @@ void mainWin::procFinished(bool success, const QString& msg) { ui->actionExtractSel->setEnabled(hasSelection); ui->actionRemoveFile->setEnabled(hasSelection && canmodify_ && !BACKEND->isGzip()); ui->actionAddDir->setEnabled(canmodify_ && !BACKEND->isGzip()); - ui->actionPassword->setEnabled(BACKEND->is7z()); + ui->actionPassword->setEnabled(BACKEND->is7z() && canmodify_); } if (!(updateTree_ && success) // otherwise, the cursor will be restored in updateTree()