Changeset View
Changeset View
Standalone View
Standalone View
kstars/auxiliary/ksutils.cpp
Show First 20 Lines • Show All 1091 Lines • ▼ Show 20 Line(s) | |||||
1092 | #ifdef Q_OS_OSX | 1092 | #ifdef Q_OS_OSX | ||
1093 | return "/usr/local/etc/astrometry.cfg"; | 1093 | return "/usr/local/etc/astrometry.cfg"; | ||
1094 | #endif | 1094 | #endif | ||
1095 | if (flat.isEmpty() == false) | 1095 | if (flat.isEmpty() == false) | ||
1096 | return flat + "/etc/astrometry.cfg"; | 1096 | return flat + "/etc/astrometry.cfg"; | ||
1097 | else | 1097 | else | ||
1098 | return snap + "/etc/astrometry.cfg"; | 1098 | return snap + "/etc/astrometry.cfg"; | ||
1099 | } | 1099 | } | ||
1100 | else if (option == "AstrometryIndexFileLocation") | ||||
1101 | { | ||||
1102 | #ifdef Q_OS_OSX | ||||
1103 | return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/Astrometry/"; | ||||
1104 | #endif | ||||
1105 | if (flat.isEmpty() == false) | ||||
1106 | return flat + "/usr/share/astrometry/"; | ||||
1107 | else | ||||
1108 | return snap + "/usr/share/astrometry/"; | ||||
1109 | } | ||||
1100 | else if (option == "XplanetPath") | 1110 | else if (option == "XplanetPath") | ||
1101 | { | 1111 | { | ||
1102 | #ifdef Q_OS_OSX | 1112 | #ifdef Q_OS_OSX | ||
1103 | return "/usr/local/bin/xplanet"; | 1113 | return "/usr/local/bin/xplanet"; | ||
1104 | #endif | 1114 | #endif | ||
1105 | if (flat.isEmpty() == false) | 1115 | if (flat.isEmpty() == false) | ||
1106 | return flat + "/bin/xplanet"; | 1116 | return flat + "/bin/xplanet"; | ||
1107 | else | 1117 | else | ||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Line(s) | 1153 | { | |||
1167 | 1177 | | |||
1168 | return true; //This means the data directory is good to go now that we created it from the default. | 1178 | return true; //This means the data directory is good to go now that we created it from the default. | ||
1169 | } | 1179 | } | ||
1170 | //This will copy any of the critical KStars files from the app bundle to application support if they are missing. | 1180 | //This will copy any of the critical KStars files from the app bundle to application support if they are missing. | ||
1171 | copyResourcesFolderFromAppBundle("kstars"); | 1181 | copyResourcesFolderFromAppBundle("kstars"); | ||
1172 | return true; //This means the data directory was good to go from the start and the wizard did not run. | 1182 | return true; //This means the data directory was good to go from the start and the wizard did not run. | ||
1173 | } | 1183 | } | ||
1174 | 1184 | | |||
1175 | void configureDefaultAstrometry() | 1185 | bool getAstrometryDataDir(QString &dataDir) | ||
1176 | { | | |||
1177 | QDir writableDir; | | |||
1178 | QString astrometryPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/Astrometry/"; | | |||
1179 | if (!astrometryPath.isEmpty()) | | |||
1180 | { | 1186 | { | ||
1181 | writableDir.mkdir(astrometryPath); | 1187 | QString confPath; | ||
1182 | astrometryPath = | 1188 | | ||
1183 | QStandardPaths::locate(QStandardPaths::GenericDataLocation, "Astrometry", QStandardPaths::LocateDirectory); | 1189 | if (Options::astrometryConfFileIsInternal()) | ||
1184 | if (astrometryPath.isEmpty()) | 1190 | confPath = QCoreApplication::applicationDirPath() + "/astrometry/bin/astrometry.cfg"; | ||
1185 | KMessageBox::sorry( | | |||
1186 | 0, i18n("The Astrometry Index File Directory does not exist and was not able to be created.")); | | |||
1187 | else | 1191 | else | ||
1192 | confPath = Options::astrometryConfFile(); | ||||
1193 | | ||||
1194 | QFile confFile(confPath); | ||||
1195 | | ||||
1196 | if (confFile.open(QIODevice::ReadOnly) == false) | ||||
1188 | { | 1197 | { | ||
1189 | QString confPath = QCoreApplication::applicationDirPath() + "/astrometry/bin/astrometry.cfg"; | 1198 | KMessageBox::error(nullptr, i18n("Astrometry configuration file corrupted or missing: %1\nPlease set the " | ||
1199 | "configuration file full path in INDI options.", | ||||
1200 | Options::astrometryConfFile())); | ||||
1201 | return false; | ||||
1202 | } | ||||
1203 | | ||||
1204 | QTextStream in(&confFile); | ||||
1205 | QString line; | ||||
1206 | while (!in.atEnd()) | ||||
1207 | { | ||||
1208 | line = in.readLine(); | ||||
1209 | if (line.isEmpty() || line.startsWith('#')) | ||||
1210 | continue; | ||||
1211 | | ||||
1212 | line = line.trimmed(); | ||||
1213 | if (line.startsWith(QLatin1String("add_path"))) | ||||
1214 | { | ||||
1215 | dataDir = line.trimmed().mid(9).trimmed(); | ||||
1216 | return true; | ||||
1217 | } | ||||
1218 | } | ||||
1219 | | ||||
1220 | KMessageBox::error(nullptr, i18n("Unable to find data dir in astrometry configuration file.")); | ||||
1221 | return false; | ||||
1222 | } | ||||
1223 | | ||||
1224 | bool setAstrometryDataDir(QString dataDir) | ||||
1225 | { | ||||
1226 | if(Options::astrometryIndexFileLocation()!=dataDir) | ||||
1227 | Options::setAstrometryIndexFileLocation(dataDir); | ||||
1228 | QString confPath; | ||||
1229 | if (Options::astrometryConfFileIsInternal()) | ||||
1230 | confPath = QCoreApplication::applicationDirPath() + "/astrometry/bin/astrometry.cfg"; | ||||
1231 | else | ||||
1232 | confPath = Options::astrometryConfFile(); | ||||
1233 | | ||||
1190 | QFile confFile(confPath); | 1234 | QFile confFile(confPath); | ||
1191 | QString contents; | 1235 | QString contents; | ||
1192 | if (confFile.open(QIODevice::ReadOnly) == false) | 1236 | if (confFile.open(QIODevice::ReadOnly) == false) | ||
1193 | KMessageBox::error(0, i18n("Internal Astrometry Configuration File Read Error.")); | 1237 | { | ||
1238 | KMessageBox::error(0, i18n("Astrometry Configuration File Read Error.")); | ||||
1239 | return false; | ||||
1240 | } | ||||
1194 | else | 1241 | else | ||
1195 | { | 1242 | { | ||
1196 | QTextStream in(&confFile); | 1243 | QTextStream in(&confFile); | ||
1197 | QString line; | 1244 | QString line; | ||
1198 | bool foundPathBefore = false; | 1245 | bool foundPathBefore = false; | ||
1199 | bool fileNeedsUpdating = false; | 1246 | bool fileNeedsUpdating = false; | ||
1200 | while (!in.atEnd()) | 1247 | while (!in.atEnd()) | ||
1201 | { | 1248 | { | ||
1202 | line = in.readLine(); | 1249 | line = in.readLine(); | ||
1203 | if (line.trimmed().startsWith(QLatin1String("add_path"))) | 1250 | if (line.trimmed().startsWith(QLatin1String("add_path"))) | ||
1204 | { | 1251 | { | ||
1205 | if (!foundPathBefore) //This will ensure there is not more than one add_path line in the file. | 1252 | if (!foundPathBefore) //This will ensure there is not more than one add_path line in the file. | ||
1206 | { | 1253 | { | ||
1207 | foundPathBefore = true; | 1254 | foundPathBefore = true; | ||
1208 | QString dataDir = line.trimmed().mid(9).trimmed(); | 1255 | QString dataDirInFile = line.trimmed().mid(9).trimmed(); | ||
1209 | if (dataDir != astrometryPath) //Update to the correct path. | 1256 | if (dataDirInFile != dataDir) //Update to the correct path. | ||
1210 | { | 1257 | { | ||
1211 | contents += "add_path " + astrometryPath + '\n'; | 1258 | contents += "add_path " + dataDir + '\n'; | ||
1212 | fileNeedsUpdating = true; | 1259 | fileNeedsUpdating = true; | ||
1213 | } | 1260 | } | ||
1214 | } | 1261 | } | ||
1215 | } | 1262 | } | ||
1216 | else | 1263 | else | ||
1217 | { | 1264 | { | ||
1218 | contents += line + '\n'; | 1265 | contents += line + '\n'; | ||
1219 | } | 1266 | } | ||
1220 | } | 1267 | } | ||
1221 | confFile.close(); | 1268 | confFile.close(); | ||
1222 | if (fileNeedsUpdating) | 1269 | if (fileNeedsUpdating) | ||
1223 | { | 1270 | { | ||
1224 | if (confFile.open(QIODevice::WriteOnly) == false) | 1271 | if (confFile.open(QIODevice::WriteOnly) == false) | ||
1272 | { | ||||
1225 | KMessageBox::error(0, i18n("Internal Astrometry Configuration File Write Error.")); | 1273 | KMessageBox::error(0, i18n("Internal Astrometry Configuration File Write Error.")); | ||
1274 | return false; | ||||
1275 | } | ||||
1226 | else | 1276 | else | ||
1227 | { | 1277 | { | ||
1228 | QTextStream out(&confFile); | 1278 | QTextStream out(&confFile); | ||
1229 | out << contents; | 1279 | out << contents; | ||
1230 | confFile.close(); | 1280 | confFile.close(); | ||
1231 | } | 1281 | } | ||
1232 | } | 1282 | } | ||
1233 | } | 1283 | } | ||
1284 | return true; | ||||
1285 | } | ||||
1286 | | ||||
1287 | bool configureAstrometry() | ||||
1288 | { | ||||
1289 | QString astrometryDataDir; | ||||
1290 | if (KSUtils::getAstrometryDataDir(astrometryDataDir) == false) | ||||
1291 | return false; | ||||
1292 | if(Options::astrometryIndexFileLocation()!=astrometryDataDir) | ||||
1293 | { | ||||
1294 | if (KMessageBox::warningYesNo( | ||||
1295 | nullptr, i18n("The Astrometry Index File Location Stored in KStars: \n %1 \n does not match the Index file location in the config file: \n %2 \n Do you want to update the config file?", Options::astrometryIndexFileLocation(), astrometryDataDir), | ||||
1296 | i18n("Update Config File?")) == KMessageBox::Yes) | ||||
1297 | { | ||||
1298 | astrometryDataDir=Options::astrometryIndexFileLocation(); | ||||
1299 | setAstrometryDataDir(astrometryDataDir); | ||||
1300 | } | ||||
1301 | else | ||||
1302 | { | ||||
1303 | return false; | ||||
1234 | } | 1304 | } | ||
1235 | } | 1305 | } | ||
1306 | if (QDir(astrometryDataDir).exists() == false) | ||||
1307 | { | ||||
1308 | if (KMessageBox::warningYesNo( | ||||
1309 | nullptr, i18n("The selected Astrometry Index File Location:\n %1 \n does not exist. Do you want to make the directory?", astrometryDataDir), | ||||
1310 | i18n("Make Astrometry Index File Directory?")) == KMessageBox::Yes) | ||||
1311 | { | ||||
1312 | if(QDir(astrometryDataDir).mkdir(astrometryDataDir)) | ||||
1313 | { | ||||
1314 | KMessageBox::information(nullptr, i18n("The Astrometry Index File Location was created.")); | ||||
1315 | } | ||||
1316 | else | ||||
1317 | { | ||||
1318 | KMessageBox::sorry(nullptr, i18n("The Astrometry Index File Directory does not exist and was not able to be created.")); | ||||
1319 | } | ||||
1320 | } | ||||
1321 | else | ||||
1322 | { | ||||
1323 | | ||||
1324 | return false; | ||||
1325 | } | ||||
1326 | } | ||||
1327 | | ||||
1328 | //If the Index File Directories match and the directory exists, we are good to go. | ||||
1329 | return true; | ||||
1236 | } | 1330 | } | ||
1237 | 1331 | | |||
1238 | bool copyRecursively(QString sourceFolder, QString destFolder) | 1332 | bool copyRecursively(QString sourceFolder, QString destFolder) | ||
1239 | { | 1333 | { | ||
1240 | QDir sourceDir(sourceFolder); | 1334 | QDir sourceDir(sourceFolder); | ||
1241 | 1335 | | |||
1242 | if (!sourceDir.exists()) | 1336 | if (!sourceDir.exists()) | ||
1243 | return false; | 1337 | return false; | ||
▲ Show 20 Lines • Show All 51 Lines • Show Last 20 Lines |