[xSwiftBus] Automatically find and load CSL packages

ref T657
This commit is contained in:
Roland Rossgotterer
2019-05-06 13:56:40 +02:00
committed by Klaus Basan
parent a7509669f9
commit 61adfefa7a
5 changed files with 37 additions and 65 deletions

View File

@@ -85,6 +85,12 @@ namespace XSwiftBus
{
if (! s_legacyDataOK) { return false; }
findAllCslPackages(g_xplanePath);
for (const auto &package : m_cslPackages)
{
loadPlanesPackage(package);
}
if (! m_initialized)
{
auto err = XPMPMultiplayerInit(preferences, preferences);
@@ -139,6 +145,34 @@ namespace XSwiftBus
}
}
void CTraffic::findAllCslPackages(const std::string &path)
{
char nameBuffer[65536];
char *indices[4096];
int returnedFiles;
int totalFiles;
// Remove trailing /
std::string dir = path.substr(0, path.size() - 1);
XPLMGetDirectoryContents(dir.c_str(), 0, nameBuffer, sizeof(nameBuffer), indices, sizeof(indices) / sizeof(char*), &totalFiles, &returnedFiles);
for (int i = 0; i < returnedFiles; i++)
{
std::string fileName(indices[i]);
if (fileName == "xsb_aircraft.txt")
{
const std::string seperator = "/\\";
const std::size_t sepPos = dir.find_last_of(seperator);
std::string parentPath = dir.substr(0, sepPos);
m_cslPackages.insert(parentPath);
}
else
{
std::string filePath(path + fileName + g_sep);
findAllCslPackages(filePath);
}
}
}
void CTraffic::emitSimFrame()
{
if (m_emitSimFrame) { sendDBusSignal("simFrame"); }
@@ -526,16 +560,6 @@ namespace XSwiftBus
cleanup();
});
}
else if (message.getMethodName() == "loadPlanesPackage")
{
std::string path;
message.beginArgumentRead();
message.getArgument(path);
queueDBusCall([ = ]()
{
sendDBusReply(sender, serial, loadPlanesPackage(path));
});
}
else if (message.getMethodName() == "setDefaultIcao")
{
std::string defaultIcao;