Commit e93c4bdc authored by Robert Lancaster's avatar Robert Lancaster Committed by Jasem Mutlaq
Browse files

More OSX bundle work to copy data if it does not exist

parent 61f2c7bc
......@@ -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
}
......@@ -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
......@@ -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();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment