free qprocess on oracle update fail (#4134)

* free qprocess on oracle update fail

reload the database whenever oracle exits
search for oracle in ../oracle so you can use it from the build dir

* only ask for the db updater once
This commit is contained in:
ebbit1q 2020-10-21 16:31:18 +02:00 committed by GitHub
parent b8cd3af21f
commit 8cbc4c91f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 11 deletions

View file

@ -769,8 +769,8 @@ void MainWindow::createMenus()
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), localServer(nullptr), bHasActivated(false), cardUpdateProcess(nullptr),
logviewDialog(nullptr)
: QMainWindow(parent), localServer(nullptr), bHasActivated(false), askedForDbUpdater(false),
cardUpdateProcess(nullptr), logviewDialog(nullptr)
{
connect(&SettingsCache::instance(), SIGNAL(pixmapCacheSizeChanged(int)), this, SLOT(pixmapCacheSizeChanged(int)));
pixmapCacheSizeChanged(SettingsCache::instance().getPixmapCacheSize());
@ -1003,6 +1003,10 @@ void MainWindow::showWindowIfHidden()
void MainWindow::cardDatabaseLoadingFailed()
{
if (askedForDbUpdater) {
return;
}
askedForDbUpdater = true;
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Card database"));
msgBox.setIcon(QMessageBox::Question);
@ -1109,17 +1113,34 @@ void MainWindow::actCheckCardUpdates()
if (dir.exists(binaryName)) {
updaterCmd = dir.absoluteFilePath(binaryName);
} else { // try and find the directory oracle is stored in the build directory
QDir findLocalDir(dir);
findLocalDir.cdUp();
findLocalDir.cd(getCardUpdaterBinaryName());
if (findLocalDir.exists(binaryName)) {
dir = findLocalDir;
updaterCmd = dir.absoluteFilePath(binaryName);
}
}
if (updaterCmd.isEmpty()) {
QMessageBox::warning(this, tr("Error"),
tr("Unable to run the card database updater: ") + dir.absoluteFilePath(binaryName));
exitCardDatabaseUpdate();
return;
}
cardUpdateProcess->start(updaterCmd, QStringList());
}
void MainWindow::exitCardDatabaseUpdate()
{
cardUpdateProcess->deleteLater();
cardUpdateProcess = nullptr;
QtConcurrent::run(db, &CardDatabase::loadCardDatabases);
}
void MainWindow::cardUpdateError(QProcess::ProcessError err)
{
QString error;
@ -1145,18 +1166,13 @@ void MainWindow::cardUpdateError(QProcess::ProcessError err)
break;
}
cardUpdateProcess->deleteLater();
cardUpdateProcess = nullptr;
exitCardDatabaseUpdate();
QMessageBox::warning(this, tr("Error"), tr("The card database updater exited with an error: %1").arg(error));
}
void MainWindow::cardUpdateFinished(int, QProcess::ExitStatus)
{
cardUpdateProcess->deleteLater();
cardUpdateProcess = nullptr;
QtConcurrent::run(db, &CardDatabase::loadCardDatabases);
exitCardDatabaseUpdate();
}
void MainWindow::actCheckServerUpdates()

View file

@ -116,11 +116,11 @@ private:
void createTrayIcon();
void createTrayActions();
int getNextCustomSetPrefix(QDir dataDir);
// TODO: add a preference item to choose updater name for other games
inline QString getCardUpdaterBinaryName()
{
return "oracle";
};
void exitCardDatabaseUpdate();
QList<QMenu *> tabMenus;
QMenu *cockatriceMenu, *dbMenu, *helpMenu, *trayIconMenu;
@ -132,7 +132,7 @@ private:
RemoteClient *client;
QThread *clientThread;
LocalServer *localServer;
bool bHasActivated;
bool bHasActivated, askedForDbUpdater;
QMessageBox serverShutdownMessageBox;
QProcess *cardUpdateProcess;
DlgViewLog *logviewDialog;