OSX: Handle zonebg for first time installations

If none of the gameboard images is set and and the user’s data
directory doesn’t contain a “zonebg” directory, create the directory,
copy contents from cockatrice’s app bundle and sets the config
accordingly.
This commit is contained in:
Fabio Bas 2014-06-22 23:21:29 +02:00
parent 2b371fd96b
commit 45c71c09cd
4 changed files with 51 additions and 1 deletions

View file

@ -202,7 +202,8 @@ if(APPLE)
install(CODE "
file(WRITE \"\${CMAKE_INSTALL_PREFIX}/${qtconf_dest_dir}/qt.conf\" \"[Paths]
Plugins = Plugins
Translations = Resources/translations\")
Translations = Resources/translations
Data = Resources\")
" COMPONENT Runtime)
install(CODE "

View file

@ -126,6 +126,28 @@ int main(int argc, char *argv[])
QDir().mkpath(dataDir + "/pics");
settingsCache->setPicsPath(dataDir + "/pics");
}
#ifdef Q_OS_MAC
if(settingsCache->getHandBgPath().isEmpty() &&
settingsCache->getStackBgPath().isEmpty() &&
settingsCache->getTableBgPath().isEmpty() &&
settingsCache->getPlayerBgPath().isEmpty())
{
QString srcDir = QLibraryInfo::location(QLibraryInfo::DataPath);
QString destDir = dataDir + "/zonebg";
QDir tmpDir(destDir);
if(!tmpDir.exists())
{
// try to install the default images for the current user and set the settigs value
settingsCache->copyPath(srcDir + "/zonebg", destDir);
settingsCache->setHandBgPath(destDir + "/fabric_green.png");
settingsCache->setStackBgPath(destDir + "/fabric_red.png");
settingsCache->setTableBgPath(destDir + "/fabric_blue.png");
settingsCache->setPlayerBgPath(destDir + "/fabric_gray.png");
}
}
#endif
if (!db->getLoadSuccess() || !QDir(settingsCache->getDeckPath()).exists() || settingsCache->getDeckPath().isEmpty() || settingsCache->getPicsPath().isEmpty() || !QDir(settingsCache->getPicsPath()).exists()) {
DlgSettings dlgSettings;
dlgSettings.show();

View file

@ -1,5 +1,6 @@
#include "settingscache.h"
#include <QSettings>
#include <QDir>
SettingsCache::SettingsCache()
{
@ -256,3 +257,28 @@ void SettingsCache::setMainWindowGeometry(const QByteArray &_mainWindowGeometry)
mainWindowGeometry = _mainWindowGeometry;
settings->setValue("interface/main_window_geometry", mainWindowGeometry);
}
void SettingsCache::copyPath(const QString &src, const QString &dst)
{
// test source && return if inexistent
QDir dir(src);
if (! dir.exists())
return;
// test destination && create if inexistent
QDir tmpDir(dst);
if (!tmpDir.exists())
{
tmpDir.setPath(QDir::rootPath());
tmpDir.mkdir(dst);
}
foreach (QString d, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
QString dst_path = dst + QDir::separator() + d;
dir.mkpath(dst_path);
copyPath(src+ QDir::separator() + d, dst_path);
}
foreach (QString f, dir.entryList(QDir::Files)) {
QFile::copy(src + QDir::separator() + f, dst + QDir::separator() + f);
}
}

View file

@ -89,6 +89,7 @@ public:
bool getIgnoreUnregisteredUsers() const { return ignoreUnregisteredUsers; }
QString getPicUrl() const { return picUrl; }
QString getPicUrlHq() const { return picUrlHq; }
void copyPath(const QString &src, const QString &dst);
public slots:
void setMainWindowGeometry(const QByteArray &_mainWindowGeometry);
void setLang(const QString &_lang);