Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Updater|All Games: Ask to save before installing update
The Updater will now prompt the user the save the game, if a map
is in progress when one attempts to start the update installation.

This required adding a few new interfaces between the engine and
the game:

- The engine will ask the game whether it looks like the game should
  be saved (DD_GAME_RECOMMENDS_SAVING) via the game's GetInteger method.

- The game will notify the engine when a save has been written using
  a new public function called Game_Notify(). This will allow the
  engine to re-show the download dialog (or start the installation
  outright; currently the user has to manually start the install
  in the dialog).
  • Loading branch information
skyjake committed Sep 15, 2012
1 parent c1204c6 commit 51df7ec
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 12 deletions.
20 changes: 16 additions & 4 deletions doomsday/engine/api/dd_share.h
Expand Up @@ -303,9 +303,11 @@ enum {
DD_TORCH_GREEN,
DD_TORCH_BLUE,
DD_TORCH_ADDITIVE,
DD_TM_FLOOR_Z, ///< output from P_CheckPosition
DD_TM_CEILING_Z, ///< output from P_CheckPosition
DD_SHIFT_DOWN
DD_TM_FLOOR_Z, ///< output from P_CheckPosition
DD_TM_CEILING_Z, ///< output from P_CheckPosition
DD_SHIFT_DOWN,
DD_GAME_RECOMMENDS_SAVING, ///< engine asks whether game should be saved (e.g., when upgrading) (game's GetInteger)
DD_NOTIFY_GAME_SAVED ///< savegame was written
};

/// Bounding box coordinates.
Expand Down Expand Up @@ -368,6 +370,16 @@ typedef struct gameinfo_s {
const char* identityKey;
} GameInfo;

/**
* Provides a way for games (or other plugins) to notify the engine of game-related
* important events.
*
* @param notification One of the DD_NOTIFY_* enums.
* @param param Additional arguments about the notification, dependin
* on the notification type.
*/
void Game_Notify(int notification, void* param);

/**
* @defgroup resourceFlags Resource Flags
* @ingroup apiFlags resource
Expand Down Expand Up @@ -758,7 +770,7 @@ typedef struct ddmobj_base_s {
enum {
DDSMM_AFTER_LOADING, ///< After loading a savegame...
DDSMM_FINALIZE, ///< After everything else is done.
DDSMM_INITIALIZE, ///< Before anything else if done.
DDSMM_INITIALIZE ///< Before anything else if done.
};

/// Sector reverb data indices. @ingroup map
Expand Down
16 changes: 16 additions & 0 deletions doomsday/engine/portable/src/game.c
Expand Up @@ -25,6 +25,7 @@
#include "dd_main.h"
#include "de_console.h"
#include "de_filesys.h"
#include "updater/downloaddialog.h"

#include "game.h"
#include "abstractresource.h"
Expand Down Expand Up @@ -304,3 +305,18 @@ Game* Game_FromDef(const GameDef* def)

return game;
}

void Game_Notify(int notification, void* param)
{
DENG_UNUSED(param);

switch(notification)
{
case DD_NOTIFY_GAME_SAVED:
// If an update has been downloaded and is ready to go, we should
// re-show the dialog now that the user has saved the game as
// prompted.
Updater_RaiseCompletedDownloadDialog();
break;
}
}
30 changes: 29 additions & 1 deletion doomsday/engine/portable/src/updater.cpp
Expand Up @@ -46,7 +46,9 @@
#include <stdlib.h>
#include "sys_system.h"
#include "dd_version.h"
#include "dd_def.h"
#include "dd_types.h"
#include "dd_main.h"
#include "con_main.h"
#include "nativeui.h"
#include "window.h"
Expand Down Expand Up @@ -130,13 +132,21 @@ struct Updater::Instance
UpdateAvailableDialog* availableDlg;
UpdaterSettingsDialog* settingsDlg;
bool backToFullscreen;
bool savingSuggested;

VersionInfo latestVersion;
QString latestPackageUri;
QString latestPackageUri2; // fallback location
QString latestLogUri;

Instance(Updater* up) : self(up), network(0), download(0), availableDlg(0), settingsDlg(0), backToFullscreen(false)
Instance(Updater* up)
: self(up),
network(0),
download(0),
availableDlg(0),
settingsDlg(0),
backToFullscreen(false),
savingSuggested(false)
{
network = new QNetworkAccessManager(self);

Expand Down Expand Up @@ -468,6 +478,23 @@ void Updater::downloadCompleted(int result)
if(result == DownloadDialog::Accepted)
{
// Autosave the game.
// Well, we can't do that yet so just remind the user about saving.
if(!d->savingSuggested && gx.GetInteger(DD_GAME_RECOMMENDS_SAVING))
{
d->savingSuggested = true;

const char* buttons[] = { "I'll Save First", "Discard Progress && Install", NULL };
if(Sys_MessageBoxWithButtons(MBT_INFORMATION, DOOMSDAY_NICENAME,
"Installing the update will discard unsaved progress in the game.",
"Doomsday will be shut down before the installation can start. "
"The game is not saved automatically, so you will have to "
"save the game before installing the update.",
buttons) == 0)
{
Con_Execute(CMDS_DDAY, "savegame", false, false);
return;
}
}

// Check the signature of the downloaded file.

Expand All @@ -478,6 +505,7 @@ void Updater::downloadCompleted(int result)
// The download dialgo can be dismissed now.
d->download->deleteLater();
d->download = 0;
d->savingSuggested = false;
}

void Updater::settingsDialogClosed(int /*result*/)
Expand Down
25 changes: 20 additions & 5 deletions doomsday/engine/portable/src/updater/downloaddialog.cpp
Expand Up @@ -37,7 +37,7 @@
#include <de/Log>
#include <QDebug>

static bool downloadInProgress;
static DownloadDialog* downloadInProgress;

struct DownloadDialog::Instance
{
Expand Down Expand Up @@ -110,7 +110,7 @@ struct DownloadDialog::Instance
LOG_INFO("Downloading %s, saving as: %s") << uri.toString() << savedFilePath;

// Global state flag.
downloadInProgress = true;
downloadInProgress = self;
}

void setProgressText(de::String text)
Expand All @@ -132,7 +132,7 @@ DownloadDialog::DownloadDialog(de::String downloadUri, de::String fallbackUri, Q

DownloadDialog::~DownloadDialog()
{
downloadInProgress = false;
downloadInProgress = 0;
delete d;
}

Expand All @@ -142,11 +142,16 @@ de::String DownloadDialog::downloadedFilePath() const
return d->savedFilePath;
}

bool DownloadDialog::isReadyToInstall() const
{
return d->fileReady;
}

void DownloadDialog::finished(QNetworkReply* reply)
{
LOG_AS("Download");

downloadInProgress = false;
downloadInProgress = 0;
reply->deleteLater();
d->reply = 0;

Expand Down Expand Up @@ -269,5 +274,15 @@ void DownloadDialog::replyMetaDataChanged()

int Updater_IsDownloadInProgress(void)
{
return downloadInProgress;
return downloadInProgress != 0;
}

void Updater_RaiseCompletedDownloadDialog(void)
{
if(downloadInProgress && downloadInProgress->isReadyToInstall())
{
downloadInProgress->show();
downloadInProgress->raise();
downloadInProgress->activateWindow();
}
}
4 changes: 4 additions & 0 deletions doomsday/engine/portable/src/updater/downloaddialog.h
Expand Up @@ -49,6 +49,8 @@ class DownloadDialog : public UpdaterDialog
* successfully.
*/
de::String downloadedFilePath() const;

bool isReadyToInstall() const;

signals:
void downloadFailed(QString uri);
Expand All @@ -72,6 +74,8 @@ extern "C" {

int Updater_IsDownloadInProgress(void);

void Updater_RaiseCompletedDownloadDialog(void);

#ifdef __cplusplus
} // extern "C"
#endif
Expand Down
9 changes: 7 additions & 2 deletions doomsday/plugins/common/src/g_game.c
Expand Up @@ -3003,12 +3003,17 @@ void G_DoSaveGame(void)
p.name = name;
p.slot = gaSaveGameSlot;
/// @todo Use progress bar mode and update progress during the setup.
didSave = 0 == BusyMode_RunNewTaskWithName(BUSYF_ACTIVITY | /*BUSYF_PROGRESS_BAR |*/ (verbose? BUSYF_CONSOLE_OUTPUT : 0),
G_SaveStateWorker, &p, "Saving game...");
didSave = (BusyMode_RunNewTaskWithName(BUSYF_ACTIVITY | /*BUSYF_PROGRESS_BAR |*/ (verbose? BUSYF_CONSOLE_OUTPUT : 0),
G_SaveStateWorker, &p, "Saving game...") != 0);
if(didSave)
{
//Hu_MenuUpdateGameSaveWidgets();
P_SetMessage(&players[CONSOLEPLAYER], TXT_GAMESAVED, false);

// Notify the engine that the game was saved.
/// @todo After the engine has the primary responsibility of
/// saving the game, this notification is unnecessary.
Game_Notify(DD_NOTIFY_GAME_SAVED, NULL);
}
G_SetGameAction(GA_NONE);
}
Expand Down

0 comments on commit 51df7ec

Please sign in to comment.