mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-25 23:39:45 -05:00
Fix resolving resources when running from build directory
* Copy wordlists to build dir share folder * Change resource path resolution to only test the provided directory, not finding a specific file
This commit is contained in:
parent
c830f85c09
commit
6f5e13815c
@ -19,6 +19,9 @@ add_subdirectory(translations)
|
||||
file(GLOB wordlists_files "wordlists/*.wordlist")
|
||||
install(FILES ${wordlists_files} DESTINATION ${DATA_INSTALL_DIR}/wordlists)
|
||||
|
||||
# Copy wordlists to build dir for use in tests
|
||||
file(COPY "wordlists" DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
if(UNIX AND NOT APPLE AND NOT HAIKU)
|
||||
install(DIRECTORY icons/application/ DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor
|
||||
FILES_MATCHING PATTERN "keepassx*.png" PATTERN "keepassx*.svg"
|
||||
|
@ -224,19 +224,18 @@ Resources::Resources()
|
||||
{
|
||||
const QString appDirPath = QCoreApplication::applicationDirPath();
|
||||
#if defined(Q_OS_UNIX) && !(defined(Q_OS_MACOS) && defined(WITH_APP_BUNDLE))
|
||||
testResourceDir(KEEPASSX_DATA_DIR) || testResourceDir(QStringLiteral("%1/../%2").arg(appDirPath, KEEPASSX_DATA_DIR))
|
||||
|| testResourceDir(QStringLiteral("%1/%2").arg(KEEPASSX_PREFIX_DIR, KEEPASSX_DATA_DIR));
|
||||
trySetResourceDir(KEEPASSX_DATA_DIR) || trySetResourceDir(QString("%1/../%2").arg(appDirPath, KEEPASSX_DATA_DIR))
|
||||
|| trySetResourceDir(QString("%1/%2").arg(KEEPASSX_PREFIX_DIR, KEEPASSX_DATA_DIR));
|
||||
#elif defined(Q_OS_MACOS) && defined(WITH_APP_BUNDLE)
|
||||
testResourceDir(appDirPath + QStringLiteral("/../Resources"));
|
||||
trySetResourceDir(appDirPath + QStringLiteral("/../Resources"));
|
||||
#elif defined(Q_OS_WIN)
|
||||
testResourceDir(appDirPath + QStringLiteral("/share"));
|
||||
trySetResourceDir(appDirPath + QStringLiteral("/share"));
|
||||
#endif
|
||||
|
||||
if (m_dataPath.isEmpty()) {
|
||||
// Last ditch check if we are running from inside the src or test build directory
|
||||
testResourceDir(appDirPath + QStringLiteral("/../../share"))
|
||||
|| testResourceDir(appDirPath + QStringLiteral("/../share"))
|
||||
|| testResourceDir(appDirPath + QStringLiteral("/../../../share"));
|
||||
trySetResourceDir(appDirPath + QStringLiteral("/../share"))
|
||||
|| trySetResourceDir(appDirPath + QStringLiteral("/../../share"));
|
||||
}
|
||||
|
||||
if (m_dataPath.isEmpty()) {
|
||||
@ -244,10 +243,11 @@ Resources::Resources()
|
||||
}
|
||||
}
|
||||
|
||||
bool Resources::testResourceDir(const QString& dir)
|
||||
bool Resources::trySetResourceDir(const QString& path)
|
||||
{
|
||||
if (QFile::exists(dir + QStringLiteral("/icons/application/256x256/apps/keepassxc.png"))) {
|
||||
m_dataPath = QDir::cleanPath(dir);
|
||||
QDir dir(path);
|
||||
if (dir.exists()) {
|
||||
m_dataPath = dir.canonicalPath();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -42,7 +42,7 @@ public:
|
||||
|
||||
private:
|
||||
Resources();
|
||||
bool testResourceDir(const QString& dir);
|
||||
bool trySetResourceDir(const QString& path);
|
||||
|
||||
static Resources* m_instance;
|
||||
|
||||
|
@ -49,22 +49,9 @@ void Translator::installTranslators()
|
||||
// Always try to load english last
|
||||
languages << "en_US";
|
||||
|
||||
const QStringList paths = {
|
||||
#ifdef QT_DEBUG
|
||||
QString("%1/share/translations").arg(KEEPASSX_BINARY_DIR),
|
||||
#endif
|
||||
resources()->dataPath("translations")};
|
||||
|
||||
bool translationsLoaded = false;
|
||||
for (const QString& path : paths) {
|
||||
installQtTranslator(languages, path);
|
||||
if (installTranslator(languages, path)) {
|
||||
translationsLoaded = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!translationsLoaded) {
|
||||
const auto path = resources()->dataPath("translations");
|
||||
installQtTranslator(languages, path);
|
||||
if (!installTranslator(languages, path)) {
|
||||
// couldn't load configured language or fallback
|
||||
qWarning("Couldn't load translations.");
|
||||
}
|
||||
@ -117,40 +104,31 @@ bool Translator::installQtTranslator(const QStringList& languages, const QString
|
||||
*/
|
||||
QList<QPair<QString, QString>> Translator::availableLanguages()
|
||||
{
|
||||
const QStringList paths = {
|
||||
#ifdef QT_DEBUG
|
||||
QString("%1/share/translations").arg(KEEPASSX_BINARY_DIR),
|
||||
#endif
|
||||
resources()->dataPath("translations")};
|
||||
|
||||
QList<QPair<QString, QString>> languages;
|
||||
languages.append(QPair<QString, QString>("system", "System default"));
|
||||
|
||||
QRegularExpression regExp("^keepassx_([a-zA-Z_]+)\\.qm$", QRegularExpression::CaseInsensitiveOption);
|
||||
for (const QString& path : paths) {
|
||||
const QStringList fileList = QDir(path).entryList();
|
||||
for (const QString& filename : fileList) {
|
||||
QRegularExpressionMatch match = regExp.match(filename);
|
||||
if (match.hasMatch()) {
|
||||
QString langcode = match.captured(1);
|
||||
if (langcode == "en") {
|
||||
continue;
|
||||
}
|
||||
|
||||
QLocale locale(langcode);
|
||||
QString languageStr = QLocale::languageToString(locale.language());
|
||||
if (langcode == "la") {
|
||||
// langcode "la" (Latin) is translated into "C" by QLocale::languageToString()
|
||||
languageStr = "Latin";
|
||||
}
|
||||
QString countryStr;
|
||||
if (langcode.contains("_")) {
|
||||
countryStr = QString(" (%1)").arg(QLocale::countryToString(locale.country()));
|
||||
}
|
||||
|
||||
QPair<QString, QString> language(langcode, languageStr + countryStr);
|
||||
languages.append(language);
|
||||
const QStringList fileList = QDir(resources()->dataPath("translations")).entryList();
|
||||
for (const QString& filename : fileList) {
|
||||
QRegularExpressionMatch match = regExp.match(filename);
|
||||
if (match.hasMatch()) {
|
||||
QString langcode = match.captured(1);
|
||||
if (langcode == "en") {
|
||||
continue;
|
||||
}
|
||||
|
||||
QLocale locale(langcode);
|
||||
QString languageStr = QLocale::languageToString(locale.language());
|
||||
if (langcode == "la") {
|
||||
// langcode "la" (Latin) is translated into "C" by QLocale::languageToString()
|
||||
languageStr = "Latin";
|
||||
}
|
||||
if (langcode.contains("_")) {
|
||||
languageStr += QString(" (%1)").arg(QLocale::countryToString(locale.country()));
|
||||
}
|
||||
|
||||
QPair<QString, QString> language(langcode, languageStr);
|
||||
languages.append(language);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -770,6 +770,9 @@ void TestGui::testDicewareEntryEntropy()
|
||||
auto* spinBoxWordCount = dicewareWidget->findChild<QSpinBox*>("spinBoxWordCount");
|
||||
spinBoxWordCount->setValue(6);
|
||||
|
||||
// Confirm a password was generated
|
||||
QVERIFY(!pwGeneratorWidget->getGeneratedPassword().isEmpty());
|
||||
|
||||
// Verify entropy and strength
|
||||
auto* entropyLabel = pwGeneratorWidget->findChild<QLabel*>("entropyLabel");
|
||||
auto* strengthLabel = pwGeneratorWidget->findChild<QLabel*>("strengthLabel");
|
||||
|
Loading…
Reference in New Issue
Block a user