* Maintains and returns the cache directory for PROJ resource files. * * PROJ resources may change with different versions of Mapper. * This function creates the directory if it is missing, * but also resets it on Mapper version changes. */
| 104 | * but also resets it on Mapper version changes. |
| 105 | */ |
| 106 | QDir ensureProjCacheDirectory() |
| 107 | { |
| 108 | auto cache = QDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)); |
| 109 | auto const proj = QStringLiteral("proj"); |
| 110 | auto const version_filename = QStringLiteral("proj/org.openorienteering.mapper"); |
| 111 | if (cache.exists(proj)) |
| 112 | { |
| 113 | QFile version_file(cache.filePath(version_filename)); |
| 114 | if (!version_file.open(QIODevice::ReadOnly) |
| 115 | || version_file.readAll() != APP_VERSION) |
| 116 | { |
| 117 | qDebug("PROJ cache version mismatch"); |
| 118 | auto proj_dir = cache; |
| 119 | if (!proj_dir.cd(proj) || !proj_dir.removeRecursively()) |
| 120 | qDebug("Failed to remove PROJ cache"); |
| 121 | } |
| 122 | } |
| 123 | if (!cache.exists(proj)) |
| 124 | { |
| 125 | qDebug("Creating PROJ cache, version '" APP_VERSION "'"); |
| 126 | if (cache.mkpath(proj)) |
| 127 | { |
| 128 | QFile version_file(cache.filePath(version_filename)); |
| 129 | if (!version_file.open(QIODevice::WriteOnly) |
| 130 | || version_file.write(APP_VERSION) != qstrlen(APP_VERSION)) |
| 131 | { |
| 132 | qDebug("Failed to write PROJ cache version file"); |
| 133 | } |
| 134 | } |
| 135 | else |
| 136 | { |
| 137 | qDebug("Could not create a PROJ cache"); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | cache.cd(proj); |
| 142 | return cache; |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Provides a cache directory for RROJ resource files. |
no test coverage detected