|
42 | 42 | #include <QRegularExpression>
|
43 | 43 |
|
44 | 44 | TimezoneNameMap StelLocationMgr::locationDBToIANAtranslations;
|
45 |
| - |
| 45 | +QString StelLocationMgr::tzfFileName = "data/timezone.tab"; |
46 | 46 | QList<GeoRegion> StelLocationMgr::regions;
|
47 | 47 | QMap<QString, QString> StelLocationMgr::countryCodeToRegionMap;
|
48 | 48 | QMap<QString, QString> StelLocationMgr::countryNameToCodeMap;
|
@@ -1184,35 +1184,46 @@ void StelLocationMgr::loadCountries()
|
1184 | 1184 |
|
1185 | 1185 | void StelLocationMgr::loadTimeZones()
|
1186 | 1186 | {
|
1187 |
| - QFile tzFile(":/data/timezone.tab"); |
| 1187 | + QString tzFilePath = StelFileMgr::findFile(tzfFileName, StelFileMgr::File); |
| 1188 | + if (tzFilePath.isEmpty()) |
| 1189 | + { |
| 1190 | + tzFilePath = StelFileMgr::findFile(tzfFileName, StelFileMgr::New); |
| 1191 | + // Create a default TZF (time zone fixes) file |
| 1192 | + QFile tzSrc(":/data/timezone.tab"); |
| 1193 | + if (!tzSrc.copy(tzFilePath)) |
| 1194 | + { |
| 1195 | + qWarning() << "Cannot copy time zones file to " + QDir::toNativeSeparators(tzFilePath); |
| 1196 | + return; |
| 1197 | + } |
| 1198 | + } |
| 1199 | + QFile tzFile(tzFilePath); |
| 1200 | + |
1188 | 1201 | if(tzFile.open(QFile::ReadOnly | QFile::Text))
|
1189 | 1202 | {
|
1190 |
| - if (locationDBToIANAtranslations.isEmpty()) |
| 1203 | + locationDBToIANAtranslations.clear(); |
| 1204 | + QString line; |
| 1205 | + int readOk=0; |
| 1206 | + locationDBToIANAtranslations.insert("", "UTC"); |
| 1207 | + while(!tzFile.atEnd()) |
1191 | 1208 | {
|
1192 |
| - QString line; |
1193 |
| - int readOk=0; |
1194 |
| - locationDBToIANAtranslations.insert("", "UTC"); |
1195 |
| - while(!tzFile.atEnd()) |
1196 |
| - { |
1197 |
| - line = QString::fromUtf8(tzFile.readLine()); |
1198 |
| - if (line.startsWith("//") || line.startsWith("#") || line.isEmpty()) |
1199 |
| - continue; |
| 1209 | + line = QString::fromUtf8(tzFile.readLine()); |
| 1210 | + if (line.startsWith("//") || line.startsWith("#") || line.isEmpty()) |
| 1211 | + continue; |
1200 | 1212 |
|
1201 |
| - if (!line.isEmpty()) |
1202 |
| - { |
1203 |
| - #if (QT_VERSION>=QT_VERSION_CHECK(5, 14, 0)) |
1204 |
| - QStringList list=line.split("\t", Qt::KeepEmptyParts); |
1205 |
| - #else |
1206 |
| - QStringList list=line.split("\t", QString::KeepEmptyParts); |
1207 |
| - #endif |
| 1213 | + if (!line.isEmpty()) |
| 1214 | + { |
| 1215 | + #if (QT_VERSION>=QT_VERSION_CHECK(5, 14, 0)) |
| 1216 | + QStringList list=line.split("\t", Qt::KeepEmptyParts); |
| 1217 | + #else |
| 1218 | + QStringList list=line.split("\t", QString::KeepEmptyParts); |
| 1219 | + #endif |
1208 | 1220 |
|
1209 |
| - // The first entry is the DB name, the second is as we display it in the program. |
1210 |
| - locationDBToIANAtranslations.insert(list.at(0).trimmed().toLocal8Bit(), list.at(1).trimmed().toLocal8Bit()); |
1211 |
| - readOk++; |
1212 |
| - } |
| 1221 | + // The first entry is the DB name, the second is as we display it in the program. |
| 1222 | + locationDBToIANAtranslations.insert(list.at(0).trimmed().toLocal8Bit(), list.at(1).trimmed().toLocal8Bit()); |
| 1223 | + readOk++; |
1213 | 1224 | }
|
1214 |
| - qDebug() << "Loaded" << readOk << "fixes for time zones"; |
1215 | 1225 | }
|
| 1226 | + qDebug() << "Loaded" << readOk << "fixes for time zones"; |
1216 | 1227 | tzFile.close();
|
1217 | 1228 | }
|
1218 | 1229 | }
|
|
0 commit comments