diff --git a/src/app/iconloader.cpp b/src/app/iconloader.cpp index d8672bd6d..ddc17fb6f 100755 --- a/src/app/iconloader.cpp +++ b/src/app/iconloader.cpp @@ -104,13 +104,39 @@ void generateButtons(const int minWidgetDim, const int buttonDim) { } void IconLoader::generateAll(const int minWidgetDim, const int buttonDim) { + const QString minDimStr = QString::number(minWidgetDim); const QDir eDir(eSettings::sSettingsDir()); QDir iconsDir(eSettings::sSettingsDir() + "/icons"); #ifdef QT_DEBUG iconsDir.removeRecursively(); #endif - const QString mkPath = "icons/" + QString::number(minWidgetDim); + const QString mkPath = "icons/" + minDimStr; if(!eDir.mkpath(mkPath)) RuntimeThrow("Failed to mkpath '" + mkPath + "'"); + QDir iconsSizeDir(eSettings::sIconsDir()); + + const int enveIconsVersion = 0; + QFile verFile(iconsSizeDir.filePath("ver")); + bool removeIcons = false; + if(!verFile.exists()) { + removeIcons = true; + } else { + const auto verData = verFile.readAll(); + const int foundVersion = verData.toInt(); + if(enveIconsVersion != foundVersion) { + removeIcons = true; + } + } + if(removeIcons) { + iconsSizeDir.removeRecursively(); + if(!eDir.mkpath(mkPath)) RuntimeThrow("Failed to mkpath '" + mkPath + "'"); + } + + if(verFile.open(QIODevice::WriteOnly)) { + const auto verIntData = reinterpret_cast(&enveIconsVersion); + const auto verData = QByteArray::fromRawData(verIntData, sizeof(int)); + verFile.write(verData); + verFile.close(); + } QDirIterator noInterIt(":/icons/noInterpolation"); while(noInterIt.hasNext()) { @@ -120,7 +146,7 @@ void IconLoader::generateAll(const int minWidgetDim, const int buttonDim) { int targetWidth = qCeil(img.width()*minWidgetDim/22.); if(qAbs(targetWidth - img.width()) % 2 == 1) targetWidth--; const auto scaled = img.scaledToWidth(targetWidth, Qt::TransformationMode::SmoothTransformation); - scaled.save(iconsDir.filePath(QString::number(minWidgetDim) + "/" + fileName)); + scaled.save(iconsSizeDir.filePath(fileName)); } QDirIterator baseIt(":/icons"); @@ -128,7 +154,7 @@ void IconLoader::generateAll(const int minWidgetDim, const int buttonDim) { const auto path = baseIt.next(); if(baseIt.fileInfo().isDir()) continue; const auto fileName = baseIt.fileName().chopped(4); - const auto pngPath = iconsDir.filePath(QString::number(minWidgetDim) + "/" + fileName + ".png"); + const auto pngPath = iconsSizeDir.filePath(fileName + ".png"); generate(path, minWidgetDim/22., pngPath); } generateButtons(minWidgetDim, buttonDim);