summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Lancaster <rlancaste@gmail.com>2016-11-07 06:07:11 (GMT)
committerJasem Mutlaq <mutlaqja@ikarustech.com>2016-11-07 06:07:11 (GMT)
commite93c4bdceeffee13f20aeb5f3db6a392a763634b (patch)
tree390a63bcdc6164f1cf9c7a1df7b92b162b8edece
parent61f2c7bc41c0f179499465c64a0963ce9f4559a4 (diff)
More OSX bundle work to copy data if it does not exist
-rw-r--r--kstars/auxiliary/ksutils.cpp56
-rw-r--r--kstars/auxiliary/ksutils.h6
-rw-r--r--kstars/main.cpp9
3 files changed, 67 insertions, 4 deletions
diff --git a/kstars/auxiliary/ksutils.cpp b/kstars/auxiliary/ksutils.cpp
index 2a8d721..981bc90 100644
--- a/kstars/auxiliary/ksutils.cpp
+++ b/kstars/auxiliary/ksutils.cpp
@@ -625,4 +625,60 @@ QString constGenetiveToAbbrev( const QString &genetive_ ) {
{
}
+#ifdef Q_OS_OSX
+void KStarsData::copyDataFolderFromAppBundleIfNeeded()
+{
+
+ QString dataLocation=QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kstars", QStandardPaths::LocateDirectory);
+ if(dataLocation.isEmpty()) { //If there is no kstars data directory
+ QString dataSourceLocation=QDir(QCoreApplication::applicationDirPath()+"/../Resources/data").absolutePath();
+ QDir writableDir;
+ writableDir.mkdir(KSPaths::writableLocation(QStandardPaths::GenericDataLocation));
+ dataLocation=QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kstars", QStandardPaths::LocateDirectory);
+ if(!dataLocation.isEmpty()&&!dataSourceLocation.isEmpty()){ //If both the users data directory and the default data directory are found.
+ KMessageBox::sorry(0, i18n("No Data Directory in /Library/Application Support/, creating a new one"));
+ KSUtils::copyRecursively(dataSourceLocation, dataLocation);
+ } else{
+ KMessageBox::sorry(0, i18n("Error, no data directories found!"));
+ }
+
+ }
+}
+
+bool KStarsData::copyRecursively(QString sourceFolder, QString destFolder)
+{
+ bool success = false;
+ QDir sourceDir(sourceFolder);
+
+ if(!sourceDir.exists())
+ return false;
+
+ QDir destDir(destFolder);
+ if(!destDir.exists())
+ destDir.mkdir(destFolder);
+
+ QStringList files = sourceDir.entryList(QDir::Files);
+ for(int i = 0; i< files.count(); i++) {
+ QString srcName = sourceFolder + QDir::separator() + files[i];
+ QString destName = destFolder + QDir::separator() + files[i];
+ success = QFile::copy(srcName, destName);
+ if(!success)
+ return false;
+ }
+
+ files.clear();
+ files = sourceDir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
+ for(int i = 0; i< files.count(); i++)
+ {
+ QString srcName = sourceFolder + QDir::separator() + files[i];
+ QString destName = destFolder + QDir::separator() + files[i];
+ success = copyRecursively(srcName, destName);
+ if(!success)
+ return false;
+ }
+
+ return true;
+}
+#endif
+
}
diff --git a/kstars/auxiliary/ksutils.h b/kstars/auxiliary/ksutils.h
index 68b279f..95b3172 100644
--- a/kstars/auxiliary/ksutils.h
+++ b/kstars/auxiliary/ksutils.h
@@ -223,6 +223,12 @@ namespace KSUtils {
static void Write(QTextStream &stream, QtMsgType type, const QString &msg);
};
+
+ #ifdef Q_OS_OSX
+ static void copyDataFolderFromAppBundleIfNeeded();
+ static bool copyRecursively(QString sourceFolder, QString destFolder);
+ #endif
+
}
#endif
diff --git a/kstars/main.cpp b/kstars/main.cpp
index 773870c..f59fb8e 100644
--- a/kstars/main.cpp
+++ b/kstars/main.cpp
@@ -42,6 +42,7 @@
#include "kspaths.h"
#include "kstarsdata.h"
+#include "ksutils.h"
#include "kstarsdatetime.h"
#include "simclock.h"
#include "ksnumbers.h"
@@ -61,15 +62,16 @@ int main(int argc, char *argv[])
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
QApplication app(argc, argv);
+
+#ifdef Q_OS_OSX
+ KSUtils::copyDataFolderFromAppBundleIfNeeded();
+#endif
app.setApplicationVersion(KSTARS_VERSION);
/**
* enable high dpi support
*/
app.setAttribute(Qt::AA_UseHighDpiPixmaps, true);
- QByteArray data = "1";
-
- //qputenv("QSG_RENDER_TIMING", data);
KLocalizedString::setApplicationDomain("kstars");
#ifndef KSTARS_LITE
KCrash::initialize();
@@ -160,7 +162,6 @@ int main(int argc, char *argv[])
<< " Height: " << parser.value( "height" ) << endl;
return 1;
}
-
KStarsData *dat = KStarsData::Create();
QObject::connect( dat, SIGNAL( progressText(QString) ), dat, SLOT( slotConsoleMessage(QString) ) );
dat->initialize();