From c12a8cf5bb12f92797b984a15493518804e1a769 Mon Sep 17 00:00:00 2001
From: DonLakeFlyer <don@thegagnes.com>
Date: Sat, 7 Apr 2018 13:59:56 -0700
Subject: [PATCH] Add Crash Log Directory

---
 src/Settings/AppSettings.cc | 77 +++++++++++++++++++------------------
 src/Settings/AppSettings.h  |  3 ++
 2 files changed, 43 insertions(+), 37 deletions(-)

diff --git a/src/Settings/AppSettings.cc b/src/Settings/AppSettings.cc
index 3e8b950e8..1b9c7364b 100644
--- a/src/Settings/AppSettings.cc
+++ b/src/Settings/AppSettings.cc
@@ -53,30 +53,31 @@ const char* AppSettings::telemetryDirectory =       "Telemetry";
 const char* AppSettings::missionDirectory =         "Missions";
 const char* AppSettings::logDirectory =             "Logs";
 const char* AppSettings::videoDirectory =           "Video";
+const char* AppSettings::crashDirectory =           "CrashLogs";
 
 AppSettings::AppSettings(QObject* parent)
-    : SettingsGroup(appSettingsGroupName, QString() /* root settings group */, parent)
-    , _offlineEditingFirmwareTypeFact(NULL)
-    , _offlineEditingVehicleTypeFact(NULL)
-    , _offlineEditingCruiseSpeedFact(NULL)
-    , _offlineEditingHoverSpeedFact(NULL)
-    , _offlineEditingAscentSpeedFact(NULL)
-    , _offlineEditingDescentSpeedFact(NULL)
-    , _batteryPercentRemainingAnnounceFact(NULL)
-    , _defaultMissionItemAltitudeFact(NULL)
-    , _telemetrySaveFact(NULL)
-    , _telemetrySaveNotArmedFact(NULL)
-    , _audioMutedFact(NULL)
-    , _virtualJoystickFact(NULL)
-    , _appFontPointSizeFact(NULL)
-    , _indoorPaletteFact(NULL)
-    , _showLargeCompassFact(NULL)
-    , _savePathFact(NULL)
-    , _autoLoadMissionsFact(NULL)
-    , _mapboxTokenFact(NULL)
-    , _esriTokenFact(NULL)
-    , _defaultFirmwareTypeFact(NULL)
-    , _gstDebugFact(NULL)
+    : SettingsGroup                         (appSettingsGroupName, QString() /* root settings group */, parent)
+    , _offlineEditingFirmwareTypeFact       (NULL)
+    , _offlineEditingVehicleTypeFact        (NULL)
+    , _offlineEditingCruiseSpeedFact        (NULL)
+    , _offlineEditingHoverSpeedFact         (NULL)
+    , _offlineEditingAscentSpeedFact        (NULL)
+    , _offlineEditingDescentSpeedFact       (NULL)
+    , _batteryPercentRemainingAnnounceFact  (NULL)
+    , _defaultMissionItemAltitudeFact       (NULL)
+    , _telemetrySaveFact                    (NULL)
+    , _telemetrySaveNotArmedFact            (NULL)
+    , _audioMutedFact                       (NULL)
+    , _virtualJoystickFact                  (NULL)
+    , _appFontPointSizeFact                 (NULL)
+    , _indoorPaletteFact                    (NULL)
+    , _showLargeCompassFact                 (NULL)
+    , _savePathFact                         (NULL)
+    , _autoLoadMissionsFact                 (NULL)
+    , _mapboxTokenFact                      (NULL)
+    , _esriTokenFact                        (NULL)
+    , _defaultFirmwareTypeFact              (NULL)
+    , _gstDebugFact                         (NULL)
 {
     QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
     qmlRegisterUncreatableType<AppSettings>("QGroundControl.SettingsManager", 1, 0, "AppSettings", "Reference only");
@@ -118,6 +119,7 @@ void AppSettings::_checkSavePathDirectories(void)
         savePathDir.mkdir(missionDirectory);
         savePathDir.mkdir(logDirectory);
         savePathDir.mkdir(videoDirectory);
+        savePathDir.mkdir(crashDirectory);
     }
 }
 
@@ -279,67 +281,68 @@ Fact* AppSettings::savePath(void)
 
 QString AppSettings::missionSavePath(void)
 {
-    QString fullPath;
-
     QString path = savePath()->rawValue().toString();
     if (!path.isEmpty() && QDir(path).exists()) {
         QDir dir(path);
         return dir.filePath(missionDirectory);
     }
 
-    return fullPath;
+    return QString();
 }
 
 QString AppSettings::parameterSavePath(void)
 {
-    QString fullPath;
-
     QString path = savePath()->rawValue().toString();
     if (!path.isEmpty() && QDir(path).exists()) {
         QDir dir(path);
         return dir.filePath(parameterDirectory);
     }
 
-    return fullPath;
+    return QString();
 }
 
 QString AppSettings::telemetrySavePath(void)
 {
-    QString fullPath;
-
     QString path = savePath()->rawValue().toString();
     if (!path.isEmpty() && QDir(path).exists()) {
         QDir dir(path);
         return dir.filePath(telemetryDirectory);
     }
 
-    return fullPath;
+    return QString();
 }
 
 QString AppSettings::logSavePath(void)
 {
-    QString fullPath;
-
     QString path = savePath()->rawValue().toString();
     if (!path.isEmpty() && QDir(path).exists()) {
         QDir dir(path);
         return dir.filePath(logDirectory);
     }
 
-    return fullPath;
+    return QString();
 }
 
 QString AppSettings::videoSavePath(void)
 {
-    QString fullPath;
-
     QString path = savePath()->rawValue().toString();
     if (!path.isEmpty() && QDir(path).exists()) {
         QDir dir(path);
         return dir.filePath(videoDirectory);
     }
 
-    return fullPath;
+    return QString();
+}
+
+QString AppSettings::crashSavePath(void)
+{
+    QString path = savePath()->rawValue().toString();
+    if (!path.isEmpty() && QDir(path).exists()) {
+        QDir dir(path);
+        return dir.filePath(crashDirectory);
+    }
+
+    return QString();
 }
 
 Fact* AppSettings::autoLoadMissions(void)
diff --git a/src/Settings/AppSettings.h b/src/Settings/AppSettings.h
index 6b421aa35..108f6658b 100644
--- a/src/Settings/AppSettings.h
+++ b/src/Settings/AppSettings.h
@@ -47,6 +47,7 @@ public:
     Q_PROPERTY(QString telemetrySavePath    READ telemetrySavePath  NOTIFY savePathsChanged)
     Q_PROPERTY(QString logSavePath          READ logSavePath        NOTIFY savePathsChanged)
     Q_PROPERTY(QString videoSavePath        READ videoSavePath      NOTIFY savePathsChanged)
+    Q_PROPERTY(QString crashSavePath        READ crashSavePath      NOTIFY savePathsChanged)
 
     Q_PROPERTY(QString planFileExtension        MEMBER planFileExtension        CONSTANT)
     Q_PROPERTY(QString missionFileExtension     MEMBER missionFileExtension     CONSTANT)
@@ -83,6 +84,7 @@ public:
     QString telemetrySavePath   (void);
     QString logSavePath         (void);
     QString videoSavePath         (void);
+    QString crashSavePath         (void);
 
     static MAV_AUTOPILOT offlineEditingFirmwareTypeFromFirmwareType(MAV_AUTOPILOT firmwareType);
     static MAV_TYPE offlineEditingVehicleTypeFromVehicleType(MAV_TYPE vehicleType);
@@ -128,6 +130,7 @@ public:
     static const char* missionDirectory;
     static const char* logDirectory;
     static const char* videoDirectory;
+    static const char* crashDirectory;
 
 signals:
     void savePathsChanged(void);
-- 
2.22.0