File indexing completed on 2024-12-22 05:05:25

0001 /*
0002    SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "compareimportfile.h"
0008 #include "comparefilehelper.h"
0009 #include "generatelistfilefromarchive.h"
0010 #include "loadlistfromfile.h"
0011 #include <QTest>
0012 
0013 CompareImportFile::CompareImportFile() = default;
0014 
0015 CompareImportFile::~CompareImportFile() = default;
0016 
0017 void CompareImportFile::compareFile()
0018 {
0019     GenerateListFileFromArchive archive(mArchiveFilePath);
0020     // qDebug() << " archive " << archive.listFile();
0021 
0022     LoadListFromFile f(mListFilePath + QStringLiteral("/list.txt"));
0023     const QStringList archiveList = archive.listFile();
0024     const bool equal = (f.fileList() == archiveList);
0025     if (!equal) {
0026         qDebug() << "Requested : " << f.fileList();
0027         qDebug() << "List File : " << archiveList;
0028     }
0029     QVERIFY(equal);
0030     for (QString file : archiveList) {
0031         file.replace(QStringLiteral("configs/"), QStringLiteral("config/"));
0032         if (file == QLatin1StringView("information/exportdatatype.xml") || file == QLatin1StringView("information/VERSION_2")) {
0033             continue;
0034         }
0035         // TODO verify with qt6 path
0036         const QString kxmguiPath{QStringLiteral("share/kxmlgui5/")};
0037         file.replace(QStringLiteral("config/kleopatra.rc"), kxmguiPath + QStringLiteral("kleopatra/kleopatra.rc"));
0038         file.replace(QStringLiteral("config/akonadiconsoleui.rc"), kxmguiPath + QStringLiteral("akonadiconsole/akonadiconsoleui.rc"));
0039         file.replace(QStringLiteral("config/kmail_part.rc"), kxmguiPath + QStringLiteral("kmail2/kmail_part.rc"));
0040         file.replace(QStringLiteral("config/kmcomposerui.rc"), kxmguiPath + QStringLiteral("kmail2/kmcomposerui.rc"));
0041         file.replace(QStringLiteral("config/kmmainwin.rc"), kxmguiPath + QStringLiteral("kmail2/kmmainwin.rc"));
0042         file.replace(QStringLiteral("config/kmreadermainwin.rc"), kxmguiPath + QStringLiteral("kmail2/kmmainwin.rc"));
0043         file.replace(QStringLiteral("config/kontactsummary_part.rc"), kxmguiPath + QStringLiteral("kontactsummary/kontactsummary_part.rc"));
0044         file.replace(QStringLiteral("config/kwatchgnupgui.rc"), kxmguiPath + QStringLiteral("kwatchgnupg/kwatchgnupgui.rc"));
0045         if (file.endsWith(QLatin1StringView("ui.rc")) && !file.contains(QStringLiteral("kmcomposerui.rc"))
0046             && !file.contains(QStringLiteral("akonadiconsoleui.rc")) && !file.contains(QStringLiteral("kwatchgnupgui.rc"))) {
0047             QString fileName = file;
0048             fileName.remove(QStringLiteral("config/"));
0049             const QString fileuirc = fileName;
0050             fileName.remove(QStringLiteral("ui.rc"));
0051             file = kxmguiPath + fileName + QLatin1Char('/') + fileuirc;
0052         }
0053 
0054         // file.replace(QStringLiteral("identities/"), QStringLiteral("config/"));
0055         file.replace(QStringLiteral("transports/"), QStringLiteral("config/"));
0056         // Allow to remove some file from resources path
0057         if (file.startsWith(mExcludePath)) {
0058             continue;
0059         }
0060         CompareFileHelper::compareFile(mListFilePath + QStringLiteral("/references/") + file, mInstallPath + QLatin1Char('/') + file);
0061     }
0062 }
0063 
0064 QString CompareImportFile::archiveFilePath() const
0065 {
0066     return mArchiveFilePath;
0067 }
0068 
0069 void CompareImportFile::setArchiveFilePath(const QString &archiveFilePath)
0070 {
0071     mArchiveFilePath = archiveFilePath;
0072 }
0073 
0074 QString CompareImportFile::listFilePath() const
0075 {
0076     return mListFilePath;
0077 }
0078 
0079 void CompareImportFile::setListFilePath(const QString &listFilePath)
0080 {
0081     mListFilePath = listFilePath;
0082 }
0083 
0084 QString CompareImportFile::installPath() const
0085 {
0086     return mInstallPath;
0087 }
0088 
0089 void CompareImportFile::setInstallPath(const QString &installPath)
0090 {
0091     mInstallPath = installPath;
0092 }
0093 
0094 QString CompareImportFile::excludePath() const
0095 {
0096     return mExcludePath;
0097 }
0098 
0099 void CompareImportFile::setExcludePath(const QString &excludePath)
0100 {
0101     mExcludePath = excludePath;
0102 }