Portable mode for windows (#2794)

* Portable mode for windows

* fix start menu in portable mode

* Make gcc an happy puppy

* Clean old installation if we are installing over an old portable mode installation

* Default to Desktop\CockatricePortable

* Settings dialog fixes

* wording
This commit is contained in:
ctrlaltca 2017-07-08 11:22:29 +02:00 committed by GitHub
parent 1565309146
commit 1366e5970e
13 changed files with 217 additions and 86 deletions

View file

@ -130,6 +130,21 @@ GeneralSettingsPage::GeneralSettingsPage()
QPushButton *tokenDatabasePathButton = new QPushButton("...");
connect(tokenDatabasePathButton, SIGNAL(clicked()), this, SLOT(tokenDatabasePathButtonClicked()));
if(settingsCache->getIsPortableBuild())
{
deckPathEdit->setEnabled(false);
replaysPathEdit->setEnabled(false);
picsPathEdit->setEnabled(false);
cardDatabasePathEdit->setEnabled(false);
tokenDatabasePathEdit->setEnabled(false);
deckPathButton->setVisible(false);
replaysPathButton->setVisible(false);
picsPathButton->setVisible(false);
cardDatabasePathButton->setVisible(false);
tokenDatabasePathButton->setVisible(false);
}
QGridLayout *pathsGrid = new QGridLayout;
pathsGrid->addWidget(&deckPathLabel, 0, 0);
pathsGrid->addWidget(deckPathEdit, 0, 1);
@ -273,7 +288,14 @@ void GeneralSettingsPage::retranslateUi()
personalGroupBox->setTitle(tr("Personal settings"));
languageLabel.setText(tr("Language:"));
picDownloadCheckBox.setText(tr("Download card pictures on the fly"));
pathsGroupBox->setTitle(tr("Paths"));
if(settingsCache->getIsPortableBuild())
{
pathsGroupBox->setTitle(tr("Paths (editing disabled in portable mode)"));
} else {
pathsGroupBox->setTitle(tr("Paths"));
}
deckPathLabel.setText(tr("Decks directory:"));
replaysPathLabel.setText(tr("Replays directory:"));
picsPathLabel.setText(tr("Pictures directory:"));

View file

@ -10,12 +10,10 @@
QString SettingsCache::getDataPath()
{
return
#ifdef PORTABLE_BUILD
qApp->applicationDirPath() + "/data/";
#else
QStandardPaths::writableLocation(QStandardPaths::DataLocation);
#endif
if(isPortableBuild)
return qApp->applicationDirPath() + "/data/";
else
return QStandardPaths::writableLocation(QStandardPaths::DataLocation);
}
QString SettingsCache::getSettingsPath()
@ -25,9 +23,8 @@ QString SettingsCache::getSettingsPath()
void SettingsCache::translateLegacySettings()
{
#ifdef PORTABLE_BUILD
return;
#endif
if(isPortableBuild)
return;
//Layouts
QFile layoutFile(getSettingsPath()+"layouts/deckLayout.ini");
@ -148,6 +145,11 @@ QString SettingsCache::getSafeConfigFilePath(QString configEntry, QString defaul
}
SettingsCache::SettingsCache()
{
// first, figure out if we are running in portable mode
isPortableBuild = QFile::exists(qApp->applicationDirPath() + "/portable.dat");
if(isPortableBuild)
qDebug() << "Portable mode enabled";
// define a dummy context that will be used where needed
QString dummy = QT_TRANSLATE_NOOP("i18n", "English");

View file

@ -115,6 +115,7 @@ private:
QString getSafeConfigFilePath(QString configEntry, QString defaultPath) const;
bool rememberGameSettings;
QList<ReleaseChannel*> releaseChannels;
bool isPortableBuild;
public:
SettingsCache();
@ -198,6 +199,7 @@ public:
MessageSettings& messages() const { return *messageSettings; }
GameFiltersSettings& gameFilters() const { return *gameFiltersSettings; }
LayoutsSettings& layouts() const { return *layoutsSettings; }
bool getIsPortableBuild() const { return isPortableBuild; }
public slots:
void setMainWindowGeometry(const QByteArray &_mainWindowGeometry);
void setTokenDialogGeometry(const QByteArray &_tokenDialog);

View file

@ -106,13 +106,8 @@ QStringMap & SoundEngine::getAvailableThemes()
availableThemes.clear();
// load themes from user profile dir
dir =
#ifdef PORTABLE_BUILD
qApp->applicationDirPath() +
#else
QStandardPaths::standardLocations(QStandardPaths::DataLocation).first() +
#endif
"/sounds";
dir = settingsCache->getDataPath() + "/sounds";
foreach(QString themeName, dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name))
{

View file

@ -38,13 +38,7 @@ QStringMap & ThemeManager::getAvailableThemes()
availableThemes.clear();
// load themes from user profile dir
dir =
#ifdef PORTABLE_BUILD
qApp->applicationDirPath() +
#else
QStandardPaths::standardLocations(QStandardPaths::DataLocation).first() +
#endif
"/themes";
dir = settingsCache->getDataPath() + "/themes";
foreach(QString themeName, dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name))
{