Skip to content

Commit

Permalink
Improve loading process of engine's path at startup.
Browse files Browse the repository at this point in the history
  • Loading branch information
fr33mind committed Mar 22, 2017
1 parent ab7c6ca commit 6833ee7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
17 changes: 16 additions & 1 deletion editor/belle.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,25 @@ Belle::Belle(QWidget *widget)
connect(mUi.scenesTabWidget, SIGNAL(currentChanged(int)), this, SLOT(scenesTabWidgetPageChanged(int)));

restoreSettings();
Engine::loadDefaultPath();
Engine::loadPath();
}

void Belle::afterShow()
{
if (mSettings->contains("Project/enginePath")) {
//if its a new version and Engine didn't already correct its path, ask user.
if (mSettings->value("version", "").toString() != VERSION_STR &&
Engine::defaultPath() != Engine::path() &&
Engine::isValidPath(Engine::defaultPath())) {
QMessageBox::StandardButton btn = QMessageBox::question(this, tr("Update engine path?"),
tr("Some settings of a previous version of Belle were found.\n"
" Currently the engine path is set to:\n\"%1\".\n\n"
"Do you wish to update it to:\n\"%2\"?").arg(Engine::path()).arg(Engine::defaultPath()));
if (btn == QMessageBox::Yes)
Engine::setPath(Engine::defaultPath());
}
}

loadEmptyProject();

if (!Engine::isValid()) {
Expand All @@ -267,6 +281,7 @@ void Belle::afterShow()
void Belle::saveSettings()
{
//save settings
mSettings->setValue("version", VERSION_STR);
mSettings->setValue("showBuiltinBrowserMessage", mShowBuiltinBrowserMessage);
mSettings->setValue("showWebSafeFontsMessage", ChooseFontWidget::showWebSafeFontsMessage());
mSettings->beginGroup("Window");
Expand Down
26 changes: 20 additions & 6 deletions editor/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@ QString Engine::path()
return mPath;
}

bool Engine::loadPath()
{
bool defaultLoaded = loadDefaultPath();

if (isValidPath(mPath))
return true;

if (defaultLoaded) {
mPath = mDefaultPath;
return isValidPath(mPath);
}

return false;
}

bool Engine::isValid()
{
return isValidPath(mPath);
Expand All @@ -81,30 +96,29 @@ QString Engine::defaultPath()
return mDefaultPath;
}

void Engine::loadDefaultPath()
bool Engine::loadDefaultPath()
{
#if defined(Q_OS_MAC)
if (mDefaultPath == ENGINE_DEFAULT_PATH) {
mDefaultPath = QCoreApplication::applicationDirPath() +
QDir::separator() + ENGINE_DEFAULT_PATH;

if (mPath == ENGINE_DEFAULT_PATH)
mPath = mDefaultPath;
}
#endif

if (isValidPath(mDefaultPath))
return;
return true;

QStringList paths;
paths << "engine";

foreach(const QString& path, paths) {
if (isValidPath(path)) {
mDefaultPath = path;
break;
return true;
}
}

return false;
}

QString Engine::browserPath()
Expand Down
3 changes: 2 additions & 1 deletion editor/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ class Engine {
static bool isValidPath(const QString&);
static bool isValid();
static QString path();
static bool loadPath();
static QString defaultPath();
static void loadDefaultPath();
static bool loadDefaultPath();
static void setPath(const QString&);
static bool pathChanged();
static QString browserPath();
Expand Down

0 comments on commit 6833ee7

Please sign in to comment.