swift
Loading...
Searching...
No Matches
fsdirectories.cpp
1// SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#include <QDir>
7#include <QDomDocument>
8#include <QDomNodeList>
9#include <QFileInfo>
10#include <QList>
11#include <QPair>
12#include <QSettings>
13#include <QStandardPaths>
14#include <QStringBuilder>
15#include <QStringList>
16#include <QTextStream>
17#include <QVariant>
18
19#include "config/buildconfig.h"
20#include "misc/directoryutils.h"
21#include "misc/fileutils.h"
22#include "misc/logmessage.h"
23#include "misc/stringutils.h"
25
26using namespace swift::config;
27
28namespace swift::misc::simulation::fscommon
29{
30 using FsRegistryPathPair = QList<QPair<QString, QString>>;
31
33 {
35 return cats;
36 }
37
38 QString fsxDirFromRegistryImpl()
39 {
40 QString fsxPath;
41 const FsRegistryPathPair fsxRegistryPathPairs = {
42 { QStringLiteral("HKEY_CURRENT_USER\\Software\\Microsoft\\Microsoft Games\\Flight Simulator\\10.0"),
43 QStringLiteral("AppPath") },
44 { QStringLiteral(
45 "HKEY_CURRENT_USER\\Software\\Microsoft\\Microsoft Games\\Flight Simulator - Steam Edition\\10.0"),
46 QStringLiteral("AppPath") },
47 { QStringLiteral("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Microsoft Games\\Flight Simulator\\10.0"),
48 QStringLiteral("SetupPath") },
49 { QStringLiteral(
50 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Microsoft Games\\Flight Simulator\\10.0"),
51 QStringLiteral("SetupPath") }
52 };
53
54 for (const auto &registryPair : fsxRegistryPathPairs)
55 {
56 const QSettings fsxRegistry(registryPair.first, QSettings::NativeFormat);
57 fsxPath = fsxRegistry.value(registryPair.second).toString().trimmed();
58
59 if (fsxPath.isEmpty())
60 {
61 continue;
62 }
64
65 // if path does NOT exists we continue to search, maybe another one does
66 const QDir dir(fsxPath);
67 if (dir.exists())
68 {
69 break;
70 }
71 fsxPath.clear();
72 }
74 }
75
77 {
78 static const QString fsxPath(fsxDirFromRegistryImpl());
79 return fsxPath;
80 }
81
82 QString fsxDirImpl()
83 {
85 if (!dir.isEmpty())
86 {
87 return dir;
88 }
89 QStringList someDefaultDirs(
90 { "C:/Program Files (x86)/Microsoft Games/Microsoft Flight Simulator X", "C:/FSX" });
92 {
93 // developer directories
94 someDefaultDirs.push_back("P:/FSX (MSI)");
95 }
96 return CFileUtils::findFirstExisting(someDefaultDirs);
97 }
98
100 {
101 static const QString dir(fsxDirImpl());
102 return dir;
103 }
104
105 static QString msfsDirImpl()
106 {
107 // first we look for a standard installation
109 for (const QString &path : locations)
110 {
111 const QString msfsPackage = CFileUtils::appendFilePaths(CFileUtils::appendFilePaths(path, "Packages"),
112 "Microsoft.FlightSimulator_8wekyb3d8bbwe");
113 const QDir d(msfsPackage);
114 if (!d.exists())
115 {
116 continue;
117 }
118 return msfsPackage;
119 }
120 // then we look for steam-edition
121 for (QString path : locations)
122 {
123 // there seems to be no constant for the roaming directory, so we have to do some magic
124 // https://doc.qt.io/qt-6/qstandardpaths.html
125 path.replace("Local", "Roaming");
126 const QString msfsPackage = CFileUtils::appendFilePaths(path, "Microsoft Flight Simulator");
127 const QString fileName = CFileUtils::appendFilePaths(msfsPackage, "UserCfg.opt");
128 const QFileInfo fi(fileName);
129 if (!fi.exists())
130 {
131 continue;
132 }
133 return msfsPackage;
134 }
135 return {};
136 }
137
139 {
140 static const QString dir(msfsDirImpl());
141 return dir;
142 }
143
144 QString msfsPackagesDirImpl()
145 {
146 QString userCfg = "";
147
148 QString msfsDirectory(CFsDirectories::msfsDir());
149
150 // for Steam edition
151 if (msfsDirectory.contains("Roaming", Qt::CaseInsensitive))
152 {
153 userCfg = CFileUtils::appendFilePaths(msfsDirectory, "UserCfg.opt");
154 }
155 else
156 {
157 userCfg =
158 CFileUtils::appendFilePaths(CFileUtils::appendFilePaths(msfsDirectory, "LocalCache"), "UserCfg.opt");
159 }
160
162 if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
163 {
164 return {};
165 }
166
167 QTextStream in(&file);
168 while (!in.atEnd())
169 {
170 QString line = in.readLine();
171 if (line.contains("InstalledPackagesPath"))
172 {
173 // change the split separator because of path names with multiple spaces in Steamedition
174 QStringList split = line.split("\"");
175 // we have 2 quotation marks in the line so 3 parts
176 if (split.size() != 3)
177 {
178 return {};
179 }
180 QString packagePath = split[1].remove("\"");
181 const QDir dir(packagePath);
182 if (dir.exists())
183 {
184 return packagePath;
185 }
186 }
187 }
188 return {};
189 }
190
192 {
193 static const QString dir(msfsPackagesDirImpl());
194 return dir;
195 }
196
197 static QString msfs2024DirImpl()
198 {
200 for (const QString &path : locations)
201 {
202 const QString msfs2024Package = CFileUtils::appendFilePaths(CFileUtils::appendFilePaths(path, "Packages"),
203 "Microsoft.Limitless_8wekyb3d8bbwe");
204 const QDir d(msfs2024Package);
205 if (!d.exists())
206 {
207 continue;
208 }
209 return msfs2024Package;
210 }
211 // then we look for steam-edition
212 for (QString path : locations)
213 {
214 // there seems to be no constant for the roaming directory, so we have to do some magic
215 // https://doc.qt.io/qt-6/qstandardpaths.html
216 path.replace("Local", "Roaming");
217 const QString msfsPackage = CFileUtils::appendFilePaths(path, "Microsoft Flight Simulator 2024");
218 const QString fileName = CFileUtils::appendFilePaths(msfsPackage, "UserCfg.opt");
219 const QFileInfo fi(fileName);
220 if (!fi.exists())
221 {
222 continue;
223 }
224 return msfsPackage;
225 }
226 return {};
227 }
228
230 {
231 static const QString dir(msfs2024DirImpl());
232 return dir;
233 }
234
235 QString msfs2024PackagesDirImpl()
236 {
237 QString userCfg = "";
238
239 QString msfs2024Directory(CFsDirectories::msfs2024Dir());
240 // for Steam edition
241 if (msfs2024Directory.contains("Roaming", Qt::CaseInsensitive))
242 {
243 userCfg = CFileUtils::appendFilePaths(msfs2024Directory, "UserCfg.opt");
244 }
245 else
246 {
247 userCfg = CFileUtils::appendFilePaths(CFileUtils::appendFilePaths(msfs2024Directory, "LocalCache"),
248 "UserCfg.opt");
249 }
250
251 QFile file(userCfg);
252 if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
253 {
254 return {};
255 }
256
257 QTextStream in(&file);
258 while (!in.atEnd())
259 {
260 QString line = in.readLine();
261 if (line.contains("InstalledPackagesPath"))
262 {
263 // change the split separator because of path names with multiple spaces in Steamedition
264 QStringList split = line.split("\"");
265 // we have 2 quotation marks in the line so 3 parts
266 if (split.size() != 3)
267 {
268 return {};
269 }
270 QString packagePath = split[1].remove("\"");
271 const QDir dir(packagePath);
272 if (dir.exists())
273 {
274 return packagePath;
275 }
276 }
277 }
278 return {};
279 }
280
282 {
283 static const QString dir(msfs2024PackagesDirImpl());
284 return dir;
285 }
286
287 QString fsxSimObjectsDirFromRegistryImpl()
288 {
290 if (fsxPath.isEmpty())
291 {
292 return {};
293 }
295 }
296
298 {
299 static const QString fsxPath(fsxSimObjectsDirFromRegistryImpl());
300 return fsxPath;
301 }
302
303 QString fsxSimObjectsDirImpl()
304 {
306 if (dir.isEmpty())
307 {
308 return {};
309 }
311 }
312
313 QString msfsSimObjectsDirImpl()
314 {
316 if (dir.isEmpty())
317 {
318 return {};
319 }
320 return CFileUtils::normalizeFilePathToQtStandard(msfsPackagesDirImpl());
321 }
322
323 QString msfs2024SimObjectsDirImpl()
324 {
325 QString dir(CFsDirectories::msfs2024Dir());
326 if (dir.isEmpty())
327 {
328 return {};
329 }
330 return CFileUtils::normalizeFilePathToQtStandard(msfs2024PackagesDirImpl());
331 }
332
334 {
335 static const QString dir(fsxSimObjectsDirImpl());
336 return dir;
337 }
338
340 {
341 static const QString dir(msfsSimObjectsDirImpl());
342 return dir;
343 }
344
346 {
347 static const QString dir(msfs2024SimObjectsDirImpl());
348 return dir;
349 }
351 {
352 if (simDir.isEmpty())
353 {
354 return {};
355 }
357 }
358
360 {
361 static const QStringList exclude { "SimObjects/Animals", "SimObjects/Misc", "SimObjects/GroundVehicles",
362 "SimObjects/Boats" };
363 return exclude;
364 }
365
367 {
368 static const QStringList exclude {
369 "OneStore/asobo-discovery",
370 "OneStore/asobo-flight",
371 "OneStore/asobo-landingchallenge",
372 "OneStore/asobo-mission",
373 "OneStore/asobo-tutorials",
374 "OneStore/asobo-vcockpits",
375 "OneStore/asobo-simobjects",
376 "OneStore/asobo-services",
377 "OneStore/asobo-vcockpits",
378 "OneStore/asobo-l",
379 "OneStore/asobo-m",
380 "OneStore/asobo-vfx",
381 "OneStore/fs",
382 "OneStore/esd",
383 "OneStore/microsoft-airport",
384 "OneStore/microsoft-bushtrip",
385 "OneStore/microsoft-discovery",
386 "landingchallenge",
387 "tutorials",
388 "point-of-interest",
389 "airport",
390
391 };
392 return exclude;
393 }
394
396 {
397 static const QStringList exclude { "PassiveAircraft", "STUB", "ZZZZ" };
398 return exclude;
399 }
400
401 QString p3dDirFromRegistryImpl()
402 {
403 QString p3dPath;
404 FsRegistryPathPair p3dRegistryPathPairs = {
405 // latest versions first
406 { QStringLiteral("HKEY_CURRENT_USER\\Software\\Lockheed Martin\\Prepar3d v6"), QStringLiteral("AppPath") },
407 { QStringLiteral("HKEY_CURRENT_USER\\Software\\Lockheed Martin\\Prepar3d v5"), QStringLiteral("AppPath") },
408 { QStringLiteral("HKEY_CURRENT_USER\\Software\\Lockheed Martin\\Prepar3d v4"), QStringLiteral("AppPath") },
409 { QStringLiteral("HKEY_CURRENT_USER\\Software\\Lockheed Martin\\Prepar3d v3"), QStringLiteral("AppPath") },
410 { QStringLiteral("HKEY_CURRENT_USER\\Software\\Lockheed Martin\\Prepar3d v2"), QStringLiteral("AppPath") },
411 { QStringLiteral("HKEY_CURRENT_USER\\Software\\LockheedMartin\\Prepar3d"), QStringLiteral("AppPath") }
412 };
413 for (const auto &registryPair : p3dRegistryPathPairs)
414 {
415 const QSettings p3dRegistry(registryPair.first, QSettings::NativeFormat);
416 p3dPath = p3dRegistry.value(registryPair.second).toString().trimmed();
417
418 if (p3dPath.isEmpty())
419 {
420 continue;
421 }
423
424 // if path does NOT exists we continue to search, maybe another one does
425 const QDir dir(p3dPath);
426 if (dir.exists())
427 {
428 break;
429 }
430 p3dPath.clear();
431 }
432 return p3dPath;
433 }
434
436 {
437 static const QString p3dPath = CFileUtils::normalizeFilePathToQtStandard(p3dDirFromRegistryImpl());
438 return p3dPath;
439 }
440
441 QString p3dDirImpl()
442 {
444 if (!dir.isEmpty())
445 {
446 return dir;
447 }
448 const QStringList someDefaultDirs({ "C:/Program Files (x86)/Lockheed Martin/Prepar3D v4",
449 "C:/Program Files (x86)/Lockheed Martin/Prepar3D v3",
450 "C:/Program Files (x86)/Lockheed Martin/Prepar3D v2",
451 "C:/Program Files (x86)/Lockheed Martin/Prepar3D" });
452 return CFileUtils::findFirstExisting(someDefaultDirs);
453 }
454
456 {
457 static const QString dir(p3dDirImpl());
458 return dir;
459 }
460
461 QString p3dSimObjectsDirFromRegistryImpl()
462 {
464 if (p3dPath.isEmpty())
465 {
466 return {};
467 }
469 }
470
472 {
473 static const QString p3dPath(p3dSimObjectsDirFromRegistryImpl());
474 return p3dPath;
475 }
476
477 QString p3dSimObjectsDirImpl()
478 {
480 if (dir.isEmpty())
481 {
482 return {};
483 }
485 }
486
488 {
489 static const QString dir(p3dSimObjectsDirImpl());
490 return dir;
491 }
492
494 {
495 // finding the user settings only works on P3D machine
498 simObjectsDir.isEmpty() ? CFsDirectories::fsxSimObjectsDir() : simObjectsDir);
499 if (!sod.isEmpty() && !allPaths.contains(sod, Qt::CaseInsensitive))
500 {
501 // case insensitive is important here
502 allPaths.push_front(sod);
503 }
504
505 allPaths.removeAll({}); // remove all empty
506 allPaths.removeDuplicates();
507 allPaths.sort(Qt::CaseInsensitive);
508 return allPaths;
509 }
510
512 {
513 Q_UNUSED(simObjectsDir);
514 static const QStringList Path { CFsDirectories::msfsSimObjectsDir() };
515 return Path;
516 }
517
519 {
520 Q_UNUSED(simObjectsDir);
522 return Path;
523 }
525 const QString &versionHint)
526 {
527 // finding the user settings only works on P3D machine
530 simObjectsDir.isEmpty() ? CFsDirectories::p3dSimObjectsDir() : simObjectsDir);
531 if (!sod.isEmpty() && !allPaths.contains(sod, Qt::CaseInsensitive))
532 {
533 // case insensitive is important here
534 allPaths.push_front(sod);
535 }
536
537 allPaths.removeAll({}); // remove all empty
538 allPaths.removeDuplicates();
539 allPaths.sort(Qt::CaseInsensitive);
540 return allPaths;
541 }
542
544 {
545 if (candidate.isEmpty())
546 {
547 return "v5";
548 }
549 if (candidate.contains("v5", Qt::CaseInsensitive))
550 {
551 return QStringLiteral("v5");
552 }
553 if (candidate.contains("v4", Qt::CaseInsensitive))
554 {
555 return QStringLiteral("v4");
556 }
557
558 if (candidate.contains("5", Qt::CaseInsensitive))
559 {
560 return QStringLiteral("v5");
561 }
562 if (candidate.contains("4", Qt::CaseInsensitive))
563 {
564 return QStringLiteral("v4");
565 }
566
567 return "v5"; // that is the future (in 2020)
568 }
569
571 {
572 if (simDir.isEmpty())
573 {
574 return {};
575 }
577 }
578
580 {
581 static const QStringList exclude {
582 // FSX
583 "SimObjects/Animals",
584 "SimObjects/Misc",
585 "SimObjects/GroundVehicles",
586 "SimObjects/Boats",
587
588 // P3D new
589 "SimObjects/Avatars",
590 "SimObjects/Countermeasures",
591 "SimObjects/Submersible",
592 "SimObjects/Weapons",
593 };
594 return exclude;
595 }
596
598 {
599 static const QString cfgFile("add-ons.cfg");
600 return CFsDirectories::findP3dConfigFiles(cfgFile, versionHint);
601 }
602
604 {
605 static const QString cfgFile("simobjects.cfg");
606 return CFsDirectories::findP3dConfigFiles(cfgFile, versionHint);
607 }
608
609 QSet<QString> CFsDirectories::findP3dConfigFiles(const QString &configFile, const QString &versionHint)
610 {
611 // locations will be swift paths, I will go one level up and then search for Lockheed Martin
613 QSet<QString> files;
614 for (const QString &path : locations)
615 {
616 const QString pathUp = CFileUtils::appendFilePaths(CFileUtils::pathUp(path), "Lockheed Martin");
617 const QDir d(pathUp);
618 if (!d.exists())
619 {
620 continue;
621 }
622 CLogMessage(static_cast<CFsDirectories *>(nullptr)).info(u"P3D config dir: '%1'") << d.absolutePath();
623
624 // all versions sub directories
625 // looking for "add-ons.cfg" or simobjects.cfg
626 const QStringList entries = d.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
627 for (const QString &entry : entries)
628 {
629 // right version or just one file
630 if (entry.contains(versionHint, Qt::CaseInsensitive))
631 {
632 const QString f = CFileUtils::appendFilePaths(d.absolutePath(), entry, configFile);
633 const QFileInfo fi(f);
634 if (fi.exists())
635 {
636 files.insert(f);
637 CLogMessage(static_cast<CFsDirectories *>(nullptr)).info(u"P3D config file: '%1'") << f;
638 }
639 } // contains
640 } // entries
641 }
642 return files;
643 }
644
646 const QString &pathPrefix)
647 {
648 if (configFiles.isEmpty())
649 {
650 return {};
651 }
652 QSet<QString> paths;
653 for (const QString &configFile : configFiles)
654 {
655 // manually parsing because QSettings did not work properly
656 const QString fileContent = CFileUtils::readFileToString(configFile);
657 if (fileContent.isEmpty())
658 {
659 continue;
660 }
661 const QList<QStringView> lines = splitLinesRefs(fileContent);
662 static const QString p("Path=");
663 for (const QStringView line : lines)
664 {
665 const qsizetype i = line.lastIndexOf(p, -1, Qt::CaseInsensitive);
666 if (i < 0 || line.endsWith('='))
667 {
668 continue;
669 }
670 const QStringView path = line.mid(i + p.length());
672 pathPrefix.isEmpty() ? path.toString() :
674 if (!checked || dir.exists())
675 {
676 paths.insert(dir.absolutePath());
677 }
678 }
679 }
680 return paths;
681 }
682
684 {
685 if (addOnPaths.isEmpty())
686 {
687 return {};
688 }
689 QSet<QString> simObjectPaths;
690 for (const QString &addOnPath : addOnPaths)
691 {
692 const QString filename = CFileUtils::appendFilePaths(addOnPath, "add-on.xml");
693 QDomDocument doc;
694 QFile file(filename);
695 if (!file.open(QIODevice::ReadOnly) || !doc.setContent(&file))
696 {
697 continue;
698 }
699
700 CLogMessage(static_cast<CFsDirectories *>(nullptr)).info(u"Reading '%1' from addon path: '%2'")
701 << file.fileName() << addOnPath;
702
703 const QDomNodeList components = doc.elementsByTagName("AddOn.Component");
704 for (int i = 0; i < components.size(); i++)
705 {
706 const QDomNode component = components.item(i);
707 const QDomElement category = component.firstChildElement("Category");
708 const QString categoryValue = category.text();
709 if (!caseInsensitiveStringCompare(categoryValue, QStringLiteral("SimObjects")))
710 {
711 continue;
712 }
713 const QDomElement path = component.firstChildElement("Path");
715 const bool correctPath = pathValue.contains("Airplanes", Qt::CaseInsensitive) ||
716 pathValue.contains("Rotorcraft", Qt::CaseInsensitive);
717 if (!correctPath)
718 {
719 continue;
720 }
721
722 // absolute or relative path
723 const QString fp = QStringView { pathValue }.left(3).contains(':') ?
724 pathValue :
725 CFileUtils::appendFilePaths(addOnPath, pathValue);
726
727 CLogMessage(static_cast<CFsDirectories *>(nullptr)).info(u"Testing '%1' as addon path: '%2'")
728 << fp << addOnPath;
729
730 if (!checked || QDir(fp).exists())
731 {
733
734 CLogMessage(static_cast<CFsDirectories *>(nullptr)).info(u"P3D SimObjects path: '%1'") << fp;
735 }
736 } // components
737 } // paths
738
739 return simObjectPaths;
740 }
741
743 {
744 // all add-ons.cfg files
745 const QStringList addOnConfigFiles = CFsDirectories::findP3dAddOnConfigFiles(versionHint).values();
746
747 // all PATH values in those files
748 const QStringList addOnPaths = CFsDirectories::allConfigFilesPathValues(addOnConfigFiles, true, {}).values();
749
750 // based on all paths of all config files search the XML files
752 return all;
753 }
754
759
761 {
763 QStringList files;
764 for (const QString &path : locations)
765 {
766 const QString file = CFileUtils::appendFilePaths(CFileUtils::pathUp(path), "Microsoft/FSX/fsx.cfg");
767 const QFileInfo fi(file);
768 if (fi.exists())
769 {
770 files.push_back(fi.absoluteFilePath());
771
772 CLogMessage(static_cast<CFsDirectories *>(nullptr)).info(u"FSX config file: '%1'")
773 << fi.absoluteFilePath();
774 }
775 }
776 return files;
777 }
778
780 {
781 QSet<QString> paths;
782 for (const QString &fsxFile : fsxFiles)
783 {
784 paths.unite(CFsDirectories::fsxSimObjectsPaths(fsxFile, checked));
785 }
786 return paths;
787 }
788
790 {
791 QSet<QString> paths;
792 for (const QString &msfsFile : msfsFiles)
793 {
794 paths.unite(CFsDirectories::msfsSimObjectsPaths(msfsFile, checked));
795 }
796 return paths;
797 }
798
800 {
801 const QString fileContent = CFileUtils::readFileToString(fsxFile);
802 if (fileContent.isEmpty())
803 {
804 return {};
805 }
806 const QList<QStringView> lines = splitLinesRefs(fileContent);
807 static const QString p("SimObjectPaths.");
808
809 const QFileInfo fsxFileInfo(fsxFile);
810 const QString relPath = fsxFileInfo.absolutePath();
811
812 QSet<QString> paths;
813 for (const QStringView line : lines)
814 {
815 const qsizetype i1 = line.lastIndexOf(p, -1, Qt::CaseInsensitive);
816 if (i1 < 0)
817 {
818 continue;
819 }
820 const qsizetype i2 = line.lastIndexOf('=');
821 if (i2 < 0 || i1 >= i2 || line.endsWith('='))
822 {
823 continue;
824 }
825 const QStringView path = line.mid(i2 + 1);
827
828 CLogMessage(static_cast<CFsDirectories *>(nullptr)).info(u"FSX SimObjects path checked: '%1' in '%2'")
829 << line << fsxFile;
830
831 // ignore exclude patterns
833 {
834 continue;
835 }
836
837 // make absolute
838 if (!QStringView { soPath }.left(3).contains(':'))
839 {
840 soPath = CFileUtils::appendFilePaths(relPath, soPath);
841 }
842
843 const QDir dir(soPath); // always absolute path now
844 if (checked && !dir.exists())
845 {
846 // skip, not existing
847
848 CLogMessage(static_cast<CFsDirectories *>(nullptr))
849 .info(u"FSX SimObjects path skipped, not existing: '%1' in '%2'")
850 << dir.absolutePath() << fsxFile;
851
852 continue;
853 }
854
855 const QString afp = dir.absolutePath().toLower();
857 {
858
859 CLogMessage(static_cast<CFsDirectories *>(nullptr))
860 .info(u"FSX SimObjects path: Skipping '%1' from '%2', no '%3' file")
861 << afp << fsxFile << airFileFilter();
862
863 continue;
864 }
865
866 paths.insert(afp);
867
868 CLogMessage(static_cast<CFsDirectories *>(nullptr)).info(u"FSX SimObjects path: '%1' from '%2'")
869 << afp << fsxFile;
870 }
871 return paths;
872 }
873
875 {
876 const QString fileContent = CFileUtils::readFileToString(msfsFile);
877 if (fileContent.isEmpty())
878 {
879 return {};
880 }
881 const QList<QStringView> lines = splitLinesRefs(fileContent);
882 static const QString p("SimObjectPaths.");
883
884 const QFileInfo fsxFileInfo(msfsFile);
885 const QString relPath = fsxFileInfo.absolutePath();
886
887 QSet<QString> paths;
888 for (const QStringView line : lines)
889 {
890 const qsizetype i1 = line.lastIndexOf(p, -1, Qt::CaseInsensitive);
891 if (i1 < 0)
892 {
893 continue;
894 }
895 const qsizetype i2 = line.lastIndexOf('=');
896 if (i2 < 0 || i1 >= i2 || line.endsWith('='))
897 {
898 continue;
899 }
900 const QStringView path = line.mid(i2 + 1);
902
903 CLogMessage(static_cast<CFsDirectories *>(nullptr)).info(u"MSFS SimObjects path checked: '%1' in '%2'")
904 << line << msfsFile;
905
906 // ignore exclude patterns
908 {
909 continue;
910 }
911
912 // make absolute
913 if (!QStringView(soPath).left(3).contains(':'))
914 {
915 soPath = CFileUtils::appendFilePaths(relPath, soPath);
916 }
917
918 const QDir dir(soPath); // always absolute path now
919 if (checked && !dir.exists())
920 {
921 // skip, not existing
922 CLogMessage(static_cast<CFsDirectories *>(nullptr))
923 .info(u"FSX SimObjects path skipped, not existing: '%1' in '%2'")
924 << dir.absolutePath() << msfsFile;
925
926 continue;
927 }
928
929 const QString afp = dir.absolutePath().toLower();
931 {
932
933 CLogMessage(static_cast<CFsDirectories *>(nullptr))
934 .info(u"FSX SimObjects path: Skipping '%1' from '%2', no '%3' file")
935 << afp << msfsFile << airFileFilter();
936
937 continue;
938 }
939
940 paths.insert(afp);
941
942 CLogMessage(static_cast<CFsDirectories *>(nullptr)).info(u"FSX SimObjects path: '%1' from '%2'")
943 << afp << msfsFile;
944 }
945 return paths;
946 }
947
949 {
950 static const QString a("*.air");
951 return a;
952 }
953
954} // namespace swift::misc::simulation::fscommon
static bool isLocalDeveloperDebugBuild()
Local build for developers.
static bool containsFileInDir(const QString &dir, const QString &filter, bool recursively)
Any file with filter like "*.txt".
static QString pathUp(const QString &path)
One path up.
static QString findFirstExisting(const QStringList &filesOrDirectory)
Find first existing file or directory (means exists on file system).
static QString appendFilePathsAndFixUnc(const QString &path1, const QString &path2)
Append file paths.
static QString appendFilePaths(const QString &path1, const QString &path2)
Append file paths.
static QString readFileToString(const QString &fileNameAndPath)
Read file into string.
Definition fileutils.cpp:83
static QString normalizeFilePathToQtStandard(const QString &filePath)
Normalize file path to Qt standard, e.g by turning \ to /.
static const QString & driver()
Driver.
static const QString & validation()
Validation.
Class for emitting a log message.
Definition logmessage.h:27
Derived & info(const char16_t(&format)[N])
Set the severity to info, providing a format string.
static const QString & fsxSimObjectsDirFromRegistry()
FSX's simObject directory from registry.
static QSet< QString > allConfigFilesPathValues(const QStringList &configFiles, bool checked, const QString &pathPrefix)
All PATH values from the config files.
static QStringList p3dSimObjectsDirPlusAddOnXmlSimObjectsPaths(const QString &simObjectsDir, const QString &versionHint)
P3D's simObject dir and the add on dirs.
static const QString & msfsSimObjectsDir()
MSFS's simobject dir, resolved from multiple sources.
static const QStringList & msfs2024SimObjectsExcludeDirectoryPatterns()
Exclude directories for simObjects.
static const QStringList & msfs20SimObjectsExcludeDirectoryPatterns()
Exclude directories for simObjects.
static const QString & fsxDirFromRegistry()
FSX directory obtained from registry.
static const QString & msfs2024SimObjectsDir()
MSFS's simobject dir, resolved from multiple sources.
static const QString & p3dDirFromRegistry()
P3D directory obtained from registry.
static QString fsxSimObjectsDirFromSimDir(const QString &simDir)
FSX aircraft dir, relative to simulator directory.
static QStringList fsxSimObjectsDirPlusAddOnXmlSimObjectsPaths(const QString &simObjectsDir="")
FSX's simObject dir and the add on dirs.
static QStringList msfs2024SimObjectsDirPath(const QString &simObjectsDir="")
MSFS2024's simObject dir and the add on dirs.
static const QString & fsxDir()
FSX directory from different sources.
static const QString & msfs2024Dir()
MSFS directory from different sources.
static const QStringList & fsxSimObjectsExcludeDirectoryPatterns()
Exclude directories for simObjects.
static const QStringList & p3dSimObjectsExcludeDirectoryPatterns()
Exclude directories for simObjects.
static QSet< QString > msfsSimObjectsPaths(const QStringList &msfsFiles, bool checked)
Get all the SimObjects paths from msfs.cfg.
static const QString & msfs2024PackagesDir()
MSFS's packages dir.
static QString p3dSimObjectsDirFromSimDir(const QString &simDir)
P3D aircraft dir, relative to simulator directory.
static QStringList findFsxConfigFiles()
Find the config files (fsx.cfg).
static const QString & p3dSimObjectsDirFromRegistry()
P3D's simObject directory from registry.
static QSet< QString > fsxSimObjectsPaths(const QStringList &fsxFiles, bool checked)
Get all the SimObjects paths from fsx.cfg.
static const QStringList & getLogCategories()
Log categories.
static QSet< QString > findP3dSimObjectsConfigFiles(const QString &versionHint="v5")
Find the config files (simobjects.cfg).
static const QString & fsxSimObjectsDir()
FSX's simobject dir, resolved from multiple sources.
static QString guessP3DVersion(const QString &candidate)
Guess the P3D version such as v4, v5.
static QSet< QString > allP3dAddOnXmlSimObjectPaths(const QStringList &addOnPaths, bool checked)
All add-on paths from the XML add-on files "add-on.xml".
static QSet< QString > allFsxSimObjectPaths()
Get all the SimObjects paths from all config files.
static const QString & p3dDir()
P3D directory from different sources.
static QSet< QString > findP3dAddOnConfigFiles(const QString &versionHint="v5")
Find the config files (add-ons.cfg).
static const QString & msfsDir()
MSFS directory from different sources.
static const QString & p3dSimObjectsDir()
P3D's simObject dir, resolved from multiple sources.
static const QString & airFileFilter()
.air file filter
static QStringList msfsSimObjectsDirPath(const QString &simObjectsDir="")
MSFS's simObject dir and the add on dirs.
static const QString & msfsPackagesDir()
MSFS's packages dir.
SWIFT_MISC_EXPORT bool caseInsensitiveStringCompare(const QString &c1, const QString &c2)
Case insensitive string compare.
SWIFT_MISC_EXPORT QList< QStringView > splitLinesRefs(const QString &s)
Split a string into multiple lines. Blank lines are skipped.
SWIFT_MISC_EXPORT bool containsAny(const QString &testString, const QStringList &any, Qt::CaseSensitivity cs)
Contains any string of the list?
QString absolutePath() const const
bool exists() const const
QString fromNativeSeparators(const QString &pathName)
QDomNodeList elementsByTagName(const QString &tagname) const const
QDomDocument::ParseResult setContent(QAnyStringView text, QDomDocument::ParseOptions options)
QString text() const const
QDomElement firstChildElement(const QString &tagName, const QString &namespaceURI) const const
QDomNode item(int index) const const
int size() const const
virtual QString fileName() const const override
bool open(FILE *fh, QIODeviceBase::OpenMode mode, QFileDevice::FileHandleFlags handleFlags)
QString absoluteFilePath() const const
QString absolutePath() const const
bool exists(const QString &path)
bool isEmpty() const const
void push_back(QList< T >::parameter_type value)
void push_front(QList< T >::parameter_type value)
qsizetype removeAll(const AT &t)
QSet< T >::iterator insert(QSet< T >::const_iterator it, const T &value)
QSet< T > & unite(QSet< T > &&other)
QList< T > values() const const
QStringList standardLocations(QStandardPaths::StandardLocation type)
void clear()
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
qsizetype lastIndexOf(QChar ch, Qt::CaseSensitivity cs) const const
qsizetype length() const const
QString mid(qsizetype position, qsizetype n) &&
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
QString toLower() const const
QString trimmed() const const
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const
qsizetype removeDuplicates()
void sort(Qt::CaseSensitivity cs)
QStringView left(qsizetype length) const const
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
QString toString() const const
CaseInsensitive
std::vector< std::string > split(const std::string &str, size_t maxSplitCount=0, const std::string &delimiter=" ")
Split string by delimiter and maxSplitCount times.
Definition qtfreeutils.h:70