mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-23 07:15:35 +08:00
refs #487 add XPlane path utilities
This commit is contained in:
committed by
Mathew Sutcliffe
parent
e3319f0dae
commit
35cb4e2067
@@ -78,4 +78,8 @@ blackmisc {
|
||||
macx-clang: PRE_TARGETDEPS += $$DestRoot/lib/libblackmisc.dylib
|
||||
}
|
||||
LIBS *= -lblackmisc
|
||||
|
||||
win32 {
|
||||
LIBS *= -lShell32
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ HEADERS += *.h \
|
||||
$$PWD/simulation/*.h \
|
||||
$$PWD/simulation/fscommon/*.h \
|
||||
$$PWD/simulation/fsx/*.h \
|
||||
$$PWD/simulation/xplane/*.h \
|
||||
$$PWD/weather/*.h
|
||||
|
||||
SOURCES += *.cpp \
|
||||
@@ -50,8 +51,13 @@ SOURCES += *.cpp \
|
||||
$$PWD/simulation/*.cpp \
|
||||
$$PWD/simulation/fscommon/*.cpp \
|
||||
$$PWD/simulation/fsx/*.cpp \
|
||||
$$PWD/simulation/xplane/*.cpp \
|
||||
$$PWD/weather/*.cpp
|
||||
|
||||
win32 {
|
||||
LIBS *= -lShell32
|
||||
}
|
||||
|
||||
DESTDIR = $$DestRoot/lib
|
||||
DLLDESTDIR = $$DestRoot/bin
|
||||
|
||||
|
||||
120
src/blackmisc/simulation/xplane/xplaneutil.cpp
Normal file
120
src/blackmisc/simulation/xplane/xplaneutil.cpp
Normal file
@@ -0,0 +1,120 @@
|
||||
/* Copyright (C) 2015
|
||||
* swift Project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "xplaneutil.h"
|
||||
#include <QDir>
|
||||
#include <QTextStream>
|
||||
#include <QtGlobal>
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
#include <Shlobj.h>
|
||||
#endif
|
||||
|
||||
using namespace BlackMisc;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Simulation
|
||||
{
|
||||
namespace XPlane
|
||||
{
|
||||
|
||||
// Returns the last path from filePath, which does exist on the file system
|
||||
QString getLastExistingPathFromFile(const QString &filePath)
|
||||
{
|
||||
QFileInfo fileInfo(filePath);
|
||||
if (!fileInfo.exists()) { return {}; }
|
||||
QFile file(fileInfo.absoluteFilePath());
|
||||
if (!file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
QString lastLine;
|
||||
QTextStream ts(&file);
|
||||
while (!ts.atEnd())
|
||||
{
|
||||
QString pathToCheck = ts.readLine();
|
||||
if (QFileInfo(pathToCheck).exists()) { lastLine = pathToCheck; }
|
||||
}
|
||||
return lastLine;
|
||||
}
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
QString getWindowsLocalAppDataPath()
|
||||
{
|
||||
QString result;
|
||||
TCHAR szLocalAppDataPath[MAX_PATH];
|
||||
if(SUCCEEDED(SHGetFolderPath(NULL,
|
||||
CSIDL_LOCAL_APPDATA,
|
||||
NULL,
|
||||
0,
|
||||
szLocalAppDataPath)))
|
||||
{
|
||||
result = QString::fromWCharArray(szLocalAppDataPath);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
QString CXPlaneUtil::xplane9Dir()
|
||||
{
|
||||
QString xplaneInstallFilePath;
|
||||
QString xplaneInstallFile = QStringLiteral("/x-plane_install.txt");
|
||||
#if defined(Q_OS_WIN)
|
||||
xplaneInstallFilePath = getWindowsLocalAppDataPath() + xplaneInstallFile;
|
||||
#elif defined (Q_OS_LINUX)
|
||||
xplaneInstallFilePath = QDir::homePath() + QStringLiteral("/.x-plane") + xplaneInstallFile;
|
||||
#elif defined (Q_OS_OSX)
|
||||
xplaneInstallFilePath = QDir::homePath() + QStringLiteral("/Library/Preferences") + xplaneInstallFile;
|
||||
#endif
|
||||
return getLastExistingPathFromFile(xplaneInstallFilePath);
|
||||
}
|
||||
|
||||
QString CXPlaneUtil::xplane10Dir()
|
||||
{
|
||||
QString xplaneInstallFilePath;
|
||||
QString xplaneInstallFile = QStringLiteral("/x-plane_install_10.txt");
|
||||
#if defined(Q_OS_WIN)
|
||||
xplaneInstallFilePath = getWindowsLocalAppDataPath() + xplaneInstallFile;
|
||||
#elif defined (Q_OS_UNIX)
|
||||
xplaneInstallFilePath = QDir::homePath() + QStringLiteral("/.x-plane") + xplaneInstallFile;
|
||||
#elif defined (Q_OS_OSX)
|
||||
xplaneInstallFilePath = QDir::homePath() + QStringLiteral("/Library/Preferences") + xplaneInstallFile;
|
||||
#endif
|
||||
return getLastExistingPathFromFile(xplaneInstallFilePath);
|
||||
}
|
||||
|
||||
QString CXPlaneUtil::xbusLegacyDir()
|
||||
{
|
||||
QString legacyPath("/Resources/plugins/xbus/LegacyData");
|
||||
// Return the first non empty path, we can find.
|
||||
if (!xplane10Dir().isEmpty())
|
||||
{
|
||||
QString xbusLegacy = xplane10Dir() + legacyPath;
|
||||
if (QDir(xbusLegacy).exists())
|
||||
{
|
||||
return xbusLegacy;
|
||||
}
|
||||
}
|
||||
|
||||
if (!xplane9Dir().isEmpty())
|
||||
{
|
||||
QString xbusLegacy = xplane9Dir() + legacyPath;
|
||||
if (QDir(xbusLegacy).exists())
|
||||
{
|
||||
return xbusLegacy;
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
} // namespace
|
||||
47
src/blackmisc/simulation/xplane/xplaneutil.h
Normal file
47
src/blackmisc/simulation/xplane/xplaneutil.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/* Copyright (C) 2015
|
||||
* swift Project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKMISC_SIMULATION_XPLANE_XPLANEUTIL_H
|
||||
#define BLACKMISC_SIMULATION_XPLANE_XPLANEUTIL_H
|
||||
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include <QString>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Simulation
|
||||
{
|
||||
namespace XPlane
|
||||
{
|
||||
//! XPlane utils
|
||||
class BLACKMISC_EXPORT CXPlaneUtil
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
CXPlaneUtil() = delete;
|
||||
|
||||
//! XPlane 9 directory
|
||||
//! \todo Test on OSX
|
||||
static QString xplane9Dir();
|
||||
|
||||
//! XPlane 10 directory
|
||||
//! \todo Test on OSX
|
||||
static QString xplane10Dir();
|
||||
|
||||
//! XBus legacy directory
|
||||
static QString xbusLegacyDir();
|
||||
};
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
#endif // guard
|
||||
Reference in New Issue
Block a user