Merge pull request #3919 from hamarb123/develop
Stop application freezes on macOS by moving data to MultiMC.app/Data
This commit is contained in:
commit
0c466bc530
@ -262,6 +262,10 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv)
|
|||||||
xdgDataHome = QDir::homePath() + QLatin1String("/.local/share");
|
xdgDataHome = QDir::homePath() + QLatin1String("/.local/share");
|
||||||
dataPath = xdgDataHome + "/multimc";
|
dataPath = xdgDataHome + "/multimc";
|
||||||
adjustedBy += "XDG standard " + dataPath;
|
adjustedBy += "XDG standard " + dataPath;
|
||||||
|
#elif defined(Q_OS_MAC)
|
||||||
|
QDir foo(FS::PathCombine(applicationDirPath(), "../../Data"));
|
||||||
|
dataPath = foo.absolutePath();
|
||||||
|
adjustedBy += "Fallback to special Mac location " + dataPath;
|
||||||
#else
|
#else
|
||||||
dataPath = applicationDirPath();
|
dataPath = applicationDirPath();
|
||||||
adjustedBy += "Fallback to binary path " + dataPath;
|
adjustedBy += "Fallback to binary path " + dataPath;
|
||||||
@ -306,6 +310,63 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(Q_OS_MAC)
|
||||||
|
// move user data to new location if on macOS and it still exists in Contents/MacOS
|
||||||
|
QDir fi(applicationDirPath());
|
||||||
|
QString originalData = fi.absolutePath();
|
||||||
|
// if the config file exists in Contents/MacOS, then user data is still there and needs to moved
|
||||||
|
if (QFileInfo::exists(FS::PathCombine(originalData, "multimc.cfg")))
|
||||||
|
{
|
||||||
|
if (!QFileInfo::exists(FS::PathCombine(originalData, "dontmovemacdata")))
|
||||||
|
{
|
||||||
|
QMessageBox::StandardButton askMoveDialogue;
|
||||||
|
askMoveDialogue = QMessageBox::question(nullptr, "MultiMC 5", "Would you like to move application data to a new data location? It will improve MultiMC's performance, but if you switch to older versions it will look like instances have disappeared. If you select no, you can migrate later in settings. You should select yes unless you're commonly switching between different versions of MultiMC (eg. develop and stable).", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
|
||||||
|
if (askMoveDialogue == QMessageBox::Yes)
|
||||||
|
{
|
||||||
|
qDebug() << "On macOS and found config file in old location, moving user data...";
|
||||||
|
QDir dir;
|
||||||
|
QStringList dataFiles {
|
||||||
|
"*.log", // MultiMC-@.log
|
||||||
|
"accounts.json",
|
||||||
|
"accounts",
|
||||||
|
"assets",
|
||||||
|
"cache",
|
||||||
|
"icons",
|
||||||
|
"instances",
|
||||||
|
"libraries",
|
||||||
|
"meta",
|
||||||
|
"metacache",
|
||||||
|
"mods",
|
||||||
|
"multimc.cfg",
|
||||||
|
"themes",
|
||||||
|
"translations"
|
||||||
|
};
|
||||||
|
QDirIterator files(originalData, dataFiles);
|
||||||
|
while (files.hasNext()) {
|
||||||
|
QString filePath(files.next());
|
||||||
|
QString fileName(files.fileName());
|
||||||
|
if (!dir.rename(filePath, FS::PathCombine(dataPath, fileName)))
|
||||||
|
{
|
||||||
|
qWarning() << "Failed to move " << fileName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dataPath = originalData;
|
||||||
|
QDir::setCurrent(dataPath);
|
||||||
|
QFile file(originalData + "/dontmovemacdata");
|
||||||
|
file.open(QIODevice::WriteOnly);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dataPath = originalData;
|
||||||
|
QDir::setCurrent(dataPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Establish the mechanism for communication with an already running MultiMC that uses the same data path.
|
* Establish the mechanism for communication with an already running MultiMC that uses the same data path.
|
||||||
* If there is one, tell it what the user actually wanted to do and exit.
|
* If there is one, tell it what the user actually wanted to do and exit.
|
||||||
|
@ -29,6 +29,9 @@
|
|||||||
#include "BuildConfig.h"
|
#include "BuildConfig.h"
|
||||||
#include "themes/ITheme.h"
|
#include "themes/ITheme.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QProcess>
|
||||||
|
|
||||||
// FIXME: possibly move elsewhere
|
// FIXME: possibly move elsewhere
|
||||||
enum InstSortMode
|
enum InstSortMode
|
||||||
{
|
{
|
||||||
@ -78,6 +81,13 @@ MultiMCPage::MultiMCPage(QWidget *parent) : QWidget(parent), ui(new Ui::MultiMCP
|
|||||||
}
|
}
|
||||||
connect(ui->fontSizeBox, SIGNAL(valueChanged(int)), SLOT(refreshFontPreview()));
|
connect(ui->fontSizeBox, SIGNAL(valueChanged(int)), SLOT(refreshFontPreview()));
|
||||||
connect(ui->consoleFont, SIGNAL(currentFontChanged(QFont)), SLOT(refreshFontPreview()));
|
connect(ui->consoleFont, SIGNAL(currentFontChanged(QFont)), SLOT(refreshFontPreview()));
|
||||||
|
|
||||||
|
//move mac data button
|
||||||
|
QFile file(QDir::current().absolutePath() + "/dontmovemacdata");
|
||||||
|
if (!file.exists())
|
||||||
|
{
|
||||||
|
ui->migrateDataFolderMacBtn->setVisible(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiMCPage::~MultiMCPage()
|
MultiMCPage::~MultiMCPage()
|
||||||
@ -146,6 +156,13 @@ void MultiMCPage::on_modsDirBrowseBtn_clicked()
|
|||||||
ui->modsDirTextBox->setText(cooked_dir);
|
ui->modsDirTextBox->setText(cooked_dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void MultiMCPage::on_migrateDataFolderMacBtn_clicked()
|
||||||
|
{
|
||||||
|
QFile file(QDir::current().absolutePath() + "/dontmovemacdata");
|
||||||
|
file.remove();
|
||||||
|
QProcess::startDetached(qApp->arguments()[0]);
|
||||||
|
qApp->quit();
|
||||||
|
}
|
||||||
|
|
||||||
void MultiMCPage::refreshUpdateChannelList()
|
void MultiMCPage::refreshUpdateChannelList()
|
||||||
{
|
{
|
||||||
|
@ -67,6 +67,7 @@ slots:
|
|||||||
void on_instDirBrowseBtn_clicked();
|
void on_instDirBrowseBtn_clicked();
|
||||||
void on_modsDirBrowseBtn_clicked();
|
void on_modsDirBrowseBtn_clicked();
|
||||||
void on_iconsDirBrowseBtn_clicked();
|
void on_iconsDirBrowseBtn_clicked();
|
||||||
|
void on_migrateDataFolderMacBtn_clicked();
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Updates the list of update channels in the combo box.
|
* Updates the list of update channels in the combo box.
|
||||||
|
@ -157,6 +157,13 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="migrateDataFolderMacBtn">
|
||||||
|
<property name="text">
|
||||||
|
<string>Move MultiMC data to new location (will restart MultiMC)</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="verticalSpacer_2">
|
<spacer name="verticalSpacer_2">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
Loading…
Reference in New Issue
Block a user