Skip to content

Commit

Permalink
Determine archive's modifiability from its mimetype
Browse files Browse the repository at this point in the history
Not from its extension.
  • Loading branch information
tsujan committed Jun 28, 2021
1 parent fe061f1 commit 0a44575
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 94 deletions.
2 changes: 1 addition & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Latest version:

27 Jun 2021, V0.8.0
28 Jun 2021, V0.8.0

See "ChangeLog" for changes.
14 changes: 6 additions & 8 deletions backends.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
24 changes: 12 additions & 12 deletions data/translations/arqiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,38 @@
<context>
<name>Arqiver::Backend</name>
<message>
<location filename="../../backends.cpp" line="1026"/>
<location filename="../../backends.cpp" line="1057"/>
<location filename="../../backends.cpp" line="1100"/>
<location filename="../../backends.cpp" line="1024"/>
<location filename="../../backends.cpp" line="1055"/>
<location filename="../../backends.cpp" line="1098"/>
<source>Could not read archive</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../backends.cpp" line="1060"/>
<location filename="../../backends.cpp" line="1105"/>
<location filename="../../backends.cpp" line="1058"/>
<location filename="../../backends.cpp" line="1103"/>
<source>Archive Loaded</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../backends.cpp" line="1067"/>
<location filename="../../backends.cpp" line="1153"/>
<location filename="../../backends.cpp" line="1065"/>
<location filename="../../backends.cpp" line="1151"/>
<source>Modification Finished</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../backends.cpp" line="1088"/>
<location filename="../../backends.cpp" line="1122"/>
<location filename="../../backends.cpp" line="1086"/>
<location filename="../../backends.cpp" line="1120"/>
<source>Extraction Finished</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../backends.cpp" line="1091"/>
<location filename="../../backends.cpp" line="1141"/>
<location filename="../../backends.cpp" line="1089"/>
<location filename="../../backends.cpp" line="1139"/>
<source>Extraction Failed</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../backends.cpp" line="1250"/>
<location filename="../../backends.cpp" line="1248"/>
<source>%1 is missing from your system.
Please install it for this kind of archive!</source>
<translation type="unfinished"></translation>
Expand Down
24 changes: 12 additions & 12 deletions data/translations/arqiver_eo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,38 @@
<context>
<name>Arqiver::Backend</name>
<message>
<location filename="../../backends.cpp" line="1026"/>
<location filename="../../backends.cpp" line="1057"/>
<location filename="../../backends.cpp" line="1100"/>
<location filename="../../backends.cpp" line="1024"/>
<location filename="../../backends.cpp" line="1055"/>
<location filename="../../backends.cpp" line="1098"/>
<source>Could not read archive</source>
<translation>La arkivo ne legeblis</translation>
</message>
<message>
<location filename="../../backends.cpp" line="1060"/>
<location filename="../../backends.cpp" line="1105"/>
<location filename="../../backends.cpp" line="1058"/>
<location filename="../../backends.cpp" line="1103"/>
<source>Archive Loaded</source>
<translation>Arkivo Ŝargita</translation>
</message>
<message>
<location filename="../../backends.cpp" line="1067"/>
<location filename="../../backends.cpp" line="1153"/>
<location filename="../../backends.cpp" line="1065"/>
<location filename="../../backends.cpp" line="1151"/>
<source>Modification Finished</source>
<translation>Modifado Farita</translation>
</message>
<message>
<location filename="../../backends.cpp" line="1088"/>
<location filename="../../backends.cpp" line="1122"/>
<location filename="../../backends.cpp" line="1086"/>
<location filename="../../backends.cpp" line="1120"/>
<source>Extraction Finished</source>
<translation>Ekstraktado Farita</translation>
</message>
<message>
<location filename="../../backends.cpp" line="1091"/>
<location filename="../../backends.cpp" line="1141"/>
<location filename="../../backends.cpp" line="1089"/>
<location filename="../../backends.cpp" line="1139"/>
<source>Extraction Failed</source>
<translation>Ekstraktado Malsukcesis</translation>
</message>
<message>
<location filename="../../backends.cpp" line="1250"/>
<location filename="../../backends.cpp" line="1248"/>
<source>%1 is missing from your system.
Please install it for this kind of archive!</source>
<translation>%1 mankas al via sistemo.
Expand Down
24 changes: 12 additions & 12 deletions data/translations/arqiver_hu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,38 @@
<context>
<name>Arqiver::Backend</name>
<message>
<location filename="../../backends.cpp" line="1026"/>
<location filename="../../backends.cpp" line="1057"/>
<location filename="../../backends.cpp" line="1100"/>
<location filename="../../backends.cpp" line="1024"/>
<location filename="../../backends.cpp" line="1055"/>
<location filename="../../backends.cpp" line="1098"/>
<source>Could not read archive</source>
<translation>Nem sikerült olvasni az archívumot</translation>
</message>
<message>
<location filename="../../backends.cpp" line="1060"/>
<location filename="../../backends.cpp" line="1105"/>
<location filename="../../backends.cpp" line="1058"/>
<location filename="../../backends.cpp" line="1103"/>
<source>Archive Loaded</source>
<translation>Archívum betöltve</translation>
</message>
<message>
<location filename="../../backends.cpp" line="1067"/>
<location filename="../../backends.cpp" line="1153"/>
<location filename="../../backends.cpp" line="1065"/>
<location filename="../../backends.cpp" line="1151"/>
<source>Modification Finished</source>
<translation>A módosítás kész</translation>
</message>
<message>
<location filename="../../backends.cpp" line="1088"/>
<location filename="../../backends.cpp" line="1122"/>
<location filename="../../backends.cpp" line="1086"/>
<location filename="../../backends.cpp" line="1120"/>
<source>Extraction Finished</source>
<translation>A kibontás kész</translation>
</message>
<message>
<location filename="../../backends.cpp" line="1091"/>
<location filename="../../backends.cpp" line="1141"/>
<location filename="../../backends.cpp" line="1089"/>
<location filename="../../backends.cpp" line="1139"/>
<source>Extraction Failed</source>
<translation>A kibontás sikertelen</translation>
</message>
<message>
<location filename="../../backends.cpp" line="1250"/>
<location filename="../../backends.cpp" line="1248"/>
<source>%1 is missing from your system.
Please install it for this kind of archive!</source>
<translation>%1 hiányzik a rendszeréből.
Expand Down
24 changes: 12 additions & 12 deletions data/translations/arqiver_nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,38 @@
<context>
<name>Arqiver::Backend</name>
<message>
<location filename="../../backends.cpp" line="1026"/>
<location filename="../../backends.cpp" line="1057"/>
<location filename="../../backends.cpp" line="1100"/>
<location filename="../../backends.cpp" line="1024"/>
<location filename="../../backends.cpp" line="1055"/>
<location filename="../../backends.cpp" line="1098"/>
<source>Could not read archive</source>
<translation>Kan archief niet uitlezen</translation>
</message>
<message>
<location filename="../../backends.cpp" line="1060"/>
<location filename="../../backends.cpp" line="1105"/>
<location filename="../../backends.cpp" line="1058"/>
<location filename="../../backends.cpp" line="1103"/>
<source>Archive Loaded</source>
<translation>Archief geladen</translation>
</message>
<message>
<location filename="../../backends.cpp" line="1067"/>
<location filename="../../backends.cpp" line="1153"/>
<location filename="../../backends.cpp" line="1065"/>
<location filename="../../backends.cpp" line="1151"/>
<source>Modification Finished</source>
<translation>Bewerking voltooid</translation>
</message>
<message>
<location filename="../../backends.cpp" line="1088"/>
<location filename="../../backends.cpp" line="1122"/>
<location filename="../../backends.cpp" line="1086"/>
<location filename="../../backends.cpp" line="1120"/>
<source>Extraction Finished</source>
<translation>Uitpakken voltooid</translation>
</message>
<message>
<location filename="../../backends.cpp" line="1091"/>
<location filename="../../backends.cpp" line="1141"/>
<location filename="../../backends.cpp" line="1089"/>
<location filename="../../backends.cpp" line="1139"/>
<source>Extraction Failed</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../backends.cpp" line="1250"/>
<location filename="../../backends.cpp" line="1248"/>
<source>%1 is missing from your system.
Please install it for this kind of archive!</source>
<translation>%1 is niet geïnstalleerd.
Expand Down
24 changes: 12 additions & 12 deletions data/translations/arqiver_pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,38 @@
<context>
<name>Arqiver::Backend</name>
<message>
<location filename="../../backends.cpp" line="1026"/>
<location filename="../../backends.cpp" line="1057"/>
<location filename="../../backends.cpp" line="1100"/>
<location filename="../../backends.cpp" line="1024"/>
<location filename="../../backends.cpp" line="1055"/>
<location filename="../../backends.cpp" line="1098"/>
<source>Could not read archive</source>
<translation>Nie udało się odczytać archiwum</translation>
</message>
<message>
<location filename="../../backends.cpp" line="1060"/>
<location filename="../../backends.cpp" line="1105"/>
<location filename="../../backends.cpp" line="1058"/>
<location filename="../../backends.cpp" line="1103"/>
<source>Archive Loaded</source>
<translation>Załadowano archiwum</translation>
</message>
<message>
<location filename="../../backends.cpp" line="1067"/>
<location filename="../../backends.cpp" line="1153"/>
<location filename="../../backends.cpp" line="1065"/>
<location filename="../../backends.cpp" line="1151"/>
<source>Modification Finished</source>
<translation>Zakończono modyfikowanie</translation>
</message>
<message>
<location filename="../../backends.cpp" line="1088"/>
<location filename="../../backends.cpp" line="1122"/>
<location filename="../../backends.cpp" line="1086"/>
<location filename="../../backends.cpp" line="1120"/>
<source>Extraction Finished</source>
<translation>Zakończono rozpakowywanie</translation>
</message>
<message>
<location filename="../../backends.cpp" line="1091"/>
<location filename="../../backends.cpp" line="1141"/>
<location filename="../../backends.cpp" line="1089"/>
<location filename="../../backends.cpp" line="1139"/>
<source>Extraction Failed</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../backends.cpp" line="1250"/>
<location filename="../../backends.cpp" line="1248"/>
<source>%1 is missing from your system.
Please install it for this kind of archive!</source>
<translation>W Twoim systemie brakuje %1.
Expand Down
24 changes: 12 additions & 12 deletions data/translations/arqiver_pt_BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,38 @@
<context>
<name>Arqiver::Backend</name>
<message>
<location filename="../../backends.cpp" line="1026"/>
<location filename="../../backends.cpp" line="1057"/>
<location filename="../../backends.cpp" line="1100"/>
<location filename="../../backends.cpp" line="1024"/>
<location filename="../../backends.cpp" line="1055"/>
<location filename="../../backends.cpp" line="1098"/>
<source>Could not read archive</source>
<translation>Não foi possível ler o arquivo</translation>
</message>
<message>
<location filename="../../backends.cpp" line="1060"/>
<location filename="../../backends.cpp" line="1105"/>
<location filename="../../backends.cpp" line="1058"/>
<location filename="../../backends.cpp" line="1103"/>
<source>Archive Loaded</source>
<translation>Arquivo Carregado</translation>
</message>
<message>
<location filename="../../backends.cpp" line="1067"/>
<location filename="../../backends.cpp" line="1153"/>
<location filename="../../backends.cpp" line="1065"/>
<location filename="../../backends.cpp" line="1151"/>
<source>Modification Finished</source>
<translation>Modificação Concluída</translation>
</message>
<message>
<location filename="../../backends.cpp" line="1088"/>
<location filename="../../backends.cpp" line="1122"/>
<location filename="../../backends.cpp" line="1086"/>
<location filename="../../backends.cpp" line="1120"/>
<source>Extraction Finished</source>
<translation>Extração Concluída</translation>
</message>
<message>
<location filename="../../backends.cpp" line="1091"/>
<location filename="../../backends.cpp" line="1141"/>
<location filename="../../backends.cpp" line="1089"/>
<location filename="../../backends.cpp" line="1139"/>
<source>Extraction Failed</source>
<translation>Extração Falhou</translation>
</message>
<message>
<location filename="../../backends.cpp" line="1250"/>
<location filename="../../backends.cpp" line="1248"/>
<source>%1 is missing from your system.
Please install it for this kind of archive!</source>
<translation>%1 está ausente do seu sistema.
Expand Down
24 changes: 12 additions & 12 deletions data/translations/arqiver_ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,38 @@
<context>
<name>Arqiver::Backend</name>
<message>
<location filename="../../backends.cpp" line="1026"/>
<location filename="../../backends.cpp" line="1057"/>
<location filename="../../backends.cpp" line="1100"/>
<location filename="../../backends.cpp" line="1024"/>
<location filename="../../backends.cpp" line="1055"/>
<location filename="../../backends.cpp" line="1098"/>
<source>Could not read archive</source>
<translation>Не удалось прочитать архив</translation>
</message>
<message>
<location filename="../../backends.cpp" line="1060"/>
<location filename="../../backends.cpp" line="1105"/>
<location filename="../../backends.cpp" line="1058"/>
<location filename="../../backends.cpp" line="1103"/>
<source>Archive Loaded</source>
<translation>Архив загружен</translation>
</message>
<message>
<location filename="../../backends.cpp" line="1067"/>
<location filename="../../backends.cpp" line="1153"/>
<location filename="../../backends.cpp" line="1065"/>
<location filename="../../backends.cpp" line="1151"/>
<source>Modification Finished</source>
<translation>Модификация завершена</translation>
</message>
<message>
<location filename="../../backends.cpp" line="1088"/>
<location filename="../../backends.cpp" line="1122"/>
<location filename="../../backends.cpp" line="1086"/>
<location filename="../../backends.cpp" line="1120"/>
<source>Extraction Finished</source>
<translation>Распаковка завершена</translation>
</message>
<message>
<location filename="../../backends.cpp" line="1091"/>
<location filename="../../backends.cpp" line="1141"/>
<location filename="../../backends.cpp" line="1089"/>
<location filename="../../backends.cpp" line="1139"/>
<source>Extraction Failed</source>
<translation>Ошибка распаковки</translation>
</message>
<message>
<location filename="../../backends.cpp" line="1250"/>
<location filename="../../backends.cpp" line="1248"/>
<source>%1 is missing from your system.
Please install it for this kind of archive!</source>
<translation>%1 отсутствует в вашей системе.
Expand Down
2 changes: 1 addition & 1 deletion mainWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 0a44575

Please sign in to comment.