Skip to content

Commit

Permalink
Enhancement: allow custom config file and data
Browse files Browse the repository at this point in the history
  • Loading branch information
chengxinlun committed Jul 14, 2017
1 parent 7acd8b6 commit 25c32e5
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
4 changes: 3 additions & 1 deletion android/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<!-- Splash screen -->
</activity>
</application>
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="24"/>
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="23"/>
<supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/>
<uses-feature android:glEsVersion="0x00020000"/>
<uses-feature android:name="android.hardware.sensor.accelerometer" android:required="true"/>
Expand All @@ -46,6 +46,8 @@
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:required="false"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>

</manifest>
36 changes: 27 additions & 9 deletions src/core/StelFileMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

// Initialize static members.
QStringList StelFileMgr::fileLocations;
QString StelFileMgr::cuserDir;
QString StelFileMgr::userDir;
QString StelFileMgr::screenshotDir;
QString StelFileMgr::installDir;
Expand All @@ -57,26 +58,43 @@ void StelFileMgr::init()
#elif defined(Q_OS_MAC)
userDir = QDir::homePath() + "/Library/Application Support/Stellarium";
#else
userDir = QDir::homePath() + "/.stellarium";
// Modifiable config file (Cheng Xinlun, May 14 2017)
// TODO: request permissions on running
userDir = QDir::homePath() + "/.stellarium";
cuserDir = QString::fromLocal8Bit(qgetenv("EXTERNAL_STORAGE")) + "/stellarium";
#endif

if (!QFile(userDir).exists())
if (!QFile(cuserDir).exists())
{
qWarning() << "User config directory does not exist: " << QDir::toNativeSeparators(userDir);
qWarning() << "User config directory does not exist: " << QDir::toNativeSeparators(cuserDir);
}
try
{
makeSureDirExistsAndIsWritable(userDir);
makeSureDirExistsAndIsWritable(cuserDir);
fileLocations.append(cuserDir); // Higher priority than default dir
}
catch (std::runtime_error &e)
{
qFatal("Error: cannot create user config directory: %s", e.what());
{
qWarning() << "Cannot write to SD card, will not add custom user directory";
}

// Default user location
if (!QFile(userDir).exists())
{
qWarning() << "User config directory does not exist: " << QDir::toNativeSeparators(userDir);
}
try
{
makeSureDirExistsAndIsWritable(userDir);
}
catch (std::runtime_error &e)
{
qFatal("Error: cannot create user config directory: %s", e.what());
}
// OK, now we have the userDir set, add it to the search path
fileLocations.append(userDir);


// OK, now we have the userDir set, add it to the search path
fileLocations.append(userDir);

// Determine install data directory location

// If we are running from the build tree, we use the files from the current directory
Expand Down
3 changes: 3 additions & 0 deletions src/core/StelFileMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ class StelFileMgr

static QStringList fileLocations;

// Custom user dir
static QString cuserDir;

//! Used to store the user data directory
static QString userDir;

Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ int main(int argc, char **argv)
if (configFileFullPath.isEmpty())
qFatal("Could not create configuration file %s.", qPrintable(configName));
}

qDebug() << "Config file: " << configFileFullPath;
QSettings* confSettings = NULL;
if (StelFileMgr::exists(configFileFullPath))
{
Expand Down

0 comments on commit 25c32e5

Please sign in to comment.