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

View file

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