Skip to content

Commit

Permalink
True Portable Mode
Browse files Browse the repository at this point in the history
If 'portable.txt' exists in the same folder as friction(.exe) a 'config' folder will be created there and your configs, presets, shaders, whatever follows that specific Friction portable folder.

This also means you can have completely different configs for multiple builds of Friction.
  • Loading branch information
rodlie committed Aug 16, 2024
1 parent ced77ef commit e16534a
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 40 deletions.
1 change: 0 additions & 1 deletion src/app/GUI/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include <QMessageBox>
#include <QAudioOutput>
#include <QSpacerItem>
#include <QSettings>
#include <QMargins>
#include <iostream>

Expand Down
52 changes: 45 additions & 7 deletions src/core/appsupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,25 @@ QVariant AppSupport::getSettings(const QString &group,
const QString &key,
const QVariant &fallback)
{
QVariant variant;
if (AppSupport::isAppPortable()) {
QSettings settings(QString("%1/friction.conf").arg(getAppConfigPath()),
QSettings::IniFormat);
return getSettings(&settings, group, key, fallback);
}
QSettings settings;
settings.beginGroup(group);
variant = settings.value(key, fallback);
settings.endGroup();
return getSettings(&settings, group, key, fallback);
}

QVariant AppSupport::getSettings(QSettings *settings,
const QString &group,
const QString &key,
const QVariant &fallback)
{
QVariant variant;
if (!settings) { return variant; }
settings->beginGroup(group);
variant = settings->value(key, fallback);
settings->endGroup();
return variant;
}

Expand All @@ -64,8 +78,24 @@ void AppSupport::setSettings(const QString &group,
const QVariant &value,
bool append)
{
if (AppSupport::isAppPortable()) {
QSettings settings(QString("%1/friction.conf").arg(getAppConfigPath()),
QSettings::IniFormat);
setSettings(&settings, group, key, value, append);
return;
}
QSettings settings;
settings.beginGroup(group);
setSettings(&settings, group, key, value, append);
}

void AppSupport::setSettings(QSettings *settings,
const QString &group,
const QString &key,
const QVariant &value,
bool append)
{
if (!settings) { return; }
settings->beginGroup(group);
QVariant result;
if (append) {
QVariant orig = getSettings(group, key);
Expand All @@ -80,8 +110,8 @@ void AppSupport::setSettings(const QString &group,
result = text;
} else { append = false; }
}
settings.setValue(key, append ? result : value);
settings.endGroup();
settings->setValue(key, append ? result : value);
settings->endGroup();
}

const QString AppSupport::getAppName()
Expand Down Expand Up @@ -187,6 +217,9 @@ const QString AppSupport::getAppConfigPath()
QString path = QString::fromUtf8("%1/%2")
.arg(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation),
getAppName());
if (isAppPortable()) {
path = QString("%1/config").arg(getAppPath());
}
QDir dir(path);
if (!dir.exists()) { dir.mkpath(path); }
return path;
Expand Down Expand Up @@ -644,3 +677,8 @@ const QPair<QStringList, bool> AppSupport::hasWriteAccess()

return result;
}

bool AppSupport::isAppPortable()
{
return QFile::exists(QString("%1/portable.txt").arg(getAppPath()));
}
11 changes: 11 additions & 0 deletions src/core/appsupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <QVariant>
#include <QPair>
#include <QStringList>
#include <QSettings>

#include "hardwareenums.h"

Expand All @@ -50,10 +51,19 @@ class CORE_EXPORT AppSupport : public QObject
static QVariant getSettings(const QString &group,
const QString &key,
const QVariant &fallback = QVariant());
static QVariant getSettings(QSettings *settings,
const QString &group,
const QString &key,
const QVariant &fallback = QVariant());
static void setSettings(const QString &group,
const QString &key,
const QVariant &value,
bool append = false);
static void setSettings(QSettings *settings,
const QString &group,
const QString &key,
const QVariant &value,
bool append = false);
static const QString getAppName();
static const QString getAppDisplayName();
static const QString getAppDomain();
Expand Down Expand Up @@ -108,6 +118,7 @@ class CORE_EXPORT AppSupport : public QObject
static const QString filterFormatsName(const QString &text);
static int getProjectVersion(const QString &fileName = QString());
static const QPair<QStringList,bool> hasWriteAccess();
static bool isAppPortable();
};

#endif // APPSUPPORT_H
11 changes: 4 additions & 7 deletions src/ui/widgets/performancesettingswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,12 @@ void PerformanceSettingsWidget::setupRasterEffectWidgets()

void PerformanceSettingsWidget::saveRasterEffectsSupport()
{
QSettings settings;
settings.beginGroup("RasterEffects");
for (const auto &box : mRasterEffectsHardwareSupport) {
settings.setValue(QString("%1HardwareSupport")
.arg(box->itemData(0,
RASTER_HW_SUPPORT_ID).toString()),
box->currentData());
AppSupport::setSettings("RasterEffects",
QString("%1HardwareSupport")
.arg(box->itemData(0, RASTER_HW_SUPPORT_ID).toString()),
box->currentData());
}
settings.endGroup();
}

void PerformanceSettingsWidget::restoreDefaultRasterEffectsSupport()
Expand Down
40 changes: 15 additions & 25 deletions src/ui/widgets/uilayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <QLabel>
#include <QPushButton>
#include <QHBoxLayout>
#include <QSettings>
#include <QDebug>

#define UI_CONF_GROUP "uiLayout"
Expand Down Expand Up @@ -182,11 +181,8 @@ void UIDock::addWidget(QWidget *widget)
void UIDock::writeSettings()
{
qDebug() << "==> write dock conf" << mLabel << mPos << mIndex;
QSettings settings;
settings.beginGroup(UI_CONF_GROUP);
settings.setValue(QString(UI_CONF_KEY_POS).arg(getId()), mPos);
settings.setValue(QString(UI_CONF_KEY_INDEX).arg(getId()), mIndex);
settings.endGroup();
AppSupport::setSettings(UI_CONF_GROUP, QString(UI_CONF_KEY_POS).arg(getId()), mPos);
AppSupport::setSettings(UI_CONF_GROUP, QString(UI_CONF_KEY_INDEX).arg(getId()), mIndex);
}

UILayout::UILayout(QWidget *parent)
Expand Down Expand Up @@ -228,16 +224,13 @@ UILayout::~UILayout()

void UILayout::readSettings()
{
QSettings settings;
settings.beginGroup(UI_CONF_GROUP);
bool firstrun = settings.value(UI_CONF_KEY_MAIN).isNull();
restoreState(settings.value(UI_CONF_KEY_MAIN).toByteArray());
mLeft->restoreState(settings.value(UI_CONF_KEY_LEFT).toByteArray());
mMiddle->restoreState(settings.value(UI_CONF_KEY_MIDDLE).toByteArray());
mRight->restoreState(settings.value(UI_CONF_KEY_RIGHT).toByteArray());
mTop->restoreState(settings.value(UI_CONF_KEY_TOP).toByteArray());
mBottom->restoreState(settings.value(UI_CONF_KEY_BOTTOM).toByteArray());
settings.endGroup();
bool firstrun = AppSupport::getSettings(UI_CONF_GROUP, UI_CONF_KEY_MAIN).isNull();
restoreState(AppSupport::getSettings(UI_CONF_GROUP, UI_CONF_KEY_MAIN).toByteArray());
mLeft->restoreState(AppSupport::getSettings(UI_CONF_GROUP, UI_CONF_KEY_LEFT).toByteArray());
mMiddle->restoreState(AppSupport::getSettings(UI_CONF_GROUP, UI_CONF_KEY_MIDDLE).toByteArray());
mRight->restoreState(AppSupport::getSettings(UI_CONF_GROUP, UI_CONF_KEY_RIGHT).toByteArray());
mTop->restoreState(AppSupport::getSettings(UI_CONF_GROUP, UI_CONF_KEY_TOP).toByteArray());
mBottom->restoreState(AppSupport::getSettings(UI_CONF_GROUP, UI_CONF_KEY_BOTTOM).toByteArray());

if (firstrun) {
setSizes({300, 1024, 300});
Expand All @@ -246,15 +239,12 @@ void UILayout::readSettings()

void UILayout::writeSettings()
{
QSettings settings;
settings.beginGroup(UI_CONF_GROUP);
settings.setValue(UI_CONF_KEY_MAIN, saveState());
settings.setValue(UI_CONF_KEY_LEFT, mLeft->saveState());
settings.setValue(UI_CONF_KEY_MIDDLE, mMiddle->saveState());
settings.setValue(UI_CONF_KEY_RIGHT, mRight->saveState());
settings.setValue(UI_CONF_KEY_TOP, mTop->saveState());
settings.setValue(UI_CONF_KEY_BOTTOM, mBottom->saveState());
settings.endGroup();
AppSupport::setSettings(UI_CONF_GROUP, UI_CONF_KEY_MAIN, saveState());
AppSupport::setSettings(UI_CONF_GROUP, UI_CONF_KEY_LEFT, mLeft->saveState());
AppSupport::setSettings(UI_CONF_GROUP, UI_CONF_KEY_MIDDLE, mMiddle->saveState());
AppSupport::setSettings(UI_CONF_GROUP, UI_CONF_KEY_RIGHT, mRight->saveState());
AppSupport::setSettings(UI_CONF_GROUP, UI_CONF_KEY_TOP, mTop->saveState());
AppSupport::setSettings(UI_CONF_GROUP, UI_CONF_KEY_BOTTOM, mBottom->saveState());
}

void UILayout::addDocks(std::vector<Item> items)
Expand Down

0 comments on commit e16534a

Please sign in to comment.