Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updater|Win32: Ask to stop Snowberry if it is running
As Windows cannot update files that are in use, we must ask the user to quit Snowberry before the installer is started.
- Loading branch information
Showing
4 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
doomsday/engine/portable/src/updater/processcheckdialog.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* @file processcheckdialog.cpp | ||
* Dialog for checking running processes on Windows. @ingroup updater | ||
* | ||
* @authors Copyright © 2012 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* | ||
* @par License | ||
* GPL: http://www.gnu.org/licenses/gpl.html | ||
* | ||
* <small>This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by the | ||
* Free Software Foundation; either version 2 of the License, or (at your | ||
* option) any later version. This program is distributed in the hope that it | ||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty | ||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
* Public License for more details. You should have received a copy of the GNU | ||
* General Public License along with this program; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA</small> | ||
*/ | ||
|
||
#include "processcheckdialog.h" | ||
#include <QMessageBox> | ||
#include <QProcess> | ||
#include <QDebug> | ||
|
||
#ifdef WIN32 | ||
|
||
static bool isProcessRunning(const char* name) | ||
{ | ||
QProcess wmic; | ||
wmic.start("wmic.exe", QStringList() << "PROCESS" << "get" << "Caption"); | ||
if(!wmic.waitForStarted()) return false; | ||
if(!wmic.waitForFinished()) return false; | ||
|
||
QByteArray result = wmic.readAll(); | ||
foreach(QString p, QString(result).split("\n", QString::SkipEmptyParts)) | ||
{ | ||
if(!p.trimmed().compare(QLatin1String(name), Qt::CaseInsensitive)) | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
boolean Updater_AskToStopProcess(const char* processName, const char* message) | ||
{ | ||
while(isProcessRunning(processName)) | ||
{ | ||
// Show a notification dialog. | ||
QMessageBox msg(QMessageBox::Warning, "Files In Use", message, | ||
QMessageBox::Retry | QMessageBox::Ignore); | ||
msg.setInformativeText(QString("(There is a running process called <b>%1</b>.)").arg(processName)); | ||
if(msg.exec() == QMessageBox::Ignore) | ||
{ | ||
return !isProcessRunning(processName); | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
#endif // WIN32 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* @file processcheckdialog.h | ||
* Dialog for checking running processes on Windows. @ingroup updater | ||
* | ||
* Windows cannot overwrite files that are in use. Thus the updater needs | ||
* to ensure that all Snowberry is shut down before starting an update. | ||
* | ||
* @authors Copyright © 2012 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* | ||
* @par License | ||
* GPL: http://www.gnu.org/licenses/gpl.html | ||
* | ||
* <small>This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by the | ||
* Free Software Foundation; either version 2 of the License, or (at your | ||
* option) any later version. This program is distributed in the hope that it | ||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty | ||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
* Public License for more details. You should have received a copy of the GNU | ||
* General Public License along with this program; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA</small> | ||
*/ | ||
|
||
#ifndef LIBDENG_PROCESSCHECKDIALOG_H | ||
#define LIBDENG_PROCESSCHECKDIALOG_H | ||
|
||
#include <de/types.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
// This is only for Windows. | ||
#ifdef WIN32 | ||
|
||
/** | ||
* Asks the user to stop a process if it is found to be running. | ||
* | ||
* @param processName Name of the process to check for (e.g., "snowberry.exe"). | ||
* @param message Message to display to the user if the process is | ||
* running. Should describe why the process needs to be | ||
* stopped. | ||
* | ||
* @return @c true, if the process has been stopped. Otherwise @c false, | ||
* the process is still running. | ||
*/ | ||
boolean Updater_AskToStopProcess(const char* processName, const char* message); | ||
|
||
#endif // WIN32 | ||
|
||
#ifdef __cplusplus | ||
} // extern "C" | ||
#endif | ||
|
||
#endif // LIBDENG_PROCESSCHECKDIALOG_H |