mirror of
https://github.com/ONLYOFFICE/desktop-apps.git
synced 2026-02-10 18:05:16 +08:00
[win] online-installer: add check for closing app instance
This commit is contained in:
@ -92,6 +92,9 @@ sr_Cyrl_RS.MSG_ERR_ALREADY_RUNNING =Апликација већ ради.
|
||||
;he.MSG_ERR_ALREADY_RUNNING =היישום כבר פועל.
|
||||
sq.MSG_ERR_ALREADY_RUNNING =Aplikacioni tashmë po funksionon.
|
||||
|
||||
en.MSG_ERR_TRY_CLOSE_APP =Setup has detected that %1 is currently running. It'll be closed automatically.
|
||||
ru.MSG_ERR_TRY_CLOSE_APP =Обнаружен запущенный экземпляр %1. Он будет закрыт автоматически.
|
||||
|
||||
en.MSG_ERR_CLOSE_APP =Setup has detected that %1 is currently running. Please close all instances of it.
|
||||
en_GB.MSG_ERR_CLOSE_APP =Setup has detected that %1 is currently running. Please close all instances of it.
|
||||
ru.MSG_ERR_CLOSE_APP =Обнаружен запущенный экземпляр %1. Пожалуйста, закройте все экземпляры приложения.
|
||||
|
||||
@ -39,10 +39,7 @@ int WINAPI _tWinMain(_In_ HINSTANCE hInst, _In_opt_ HINSTANCE hPrevInstance, _In
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (HWND hWnd = FindWindow(WINDOW_CLASS_NAME, NULL)) {
|
||||
wstring msg(_TR(MSG_ERR_CLOSE_APP));
|
||||
NS_Utils::Replace(msg, L"%1", _T(WINDOW_NAME));
|
||||
NS_Utils::ShowMessage(msg);
|
||||
if (!NS_Utils::checkAndWaitForAppClosure()) {
|
||||
CloseHandle(hMutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -381,6 +381,11 @@ void MainWindow::startUpdate()
|
||||
NS_Utils::Replace(url, _T("<file>"), url_filename);
|
||||
|
||||
CDownloader *dnl = startDownload(url, tmp_path, [=]() {
|
||||
if (!NS_Utils::checkAndWaitForAppClosure(nativeWindowHandle())) {
|
||||
m_bar->setProgress(0);
|
||||
m_comntInfoLbl->setText(_TR(LABEL_ERR_CANCELLED), true);
|
||||
return;
|
||||
}
|
||||
m_bar->pulse(true);
|
||||
wstring args = L"/c \"" + tmp_path;
|
||||
args += (m_package == L"msi") ? L" /qn\"" : L" /UPDATE /VERYSILENT /NOLAUNCH\"";
|
||||
@ -448,6 +453,11 @@ void MainWindow::startUpdate()
|
||||
// }
|
||||
|
||||
// CDownloader *dnl = startDownload(url, tmp_path, [=]() {
|
||||
// if (!NS_Utils::checkAndWaitForAppClosure(nativeWindowHandle())) {
|
||||
// m_bar->setProgress(0);
|
||||
// m_comntInfoLbl->setText(_TR(LABEL_ERR_CANCELLED), true);
|
||||
// return;
|
||||
// }
|
||||
// m_bar->pulse(true);
|
||||
// wstring cmd = (m_package == L"msi") ? L"msiexec" : L"cmd",
|
||||
// args = (m_package == L"msi") ? L"/fvamus \"" : L"/c \"";
|
||||
@ -483,6 +493,12 @@ void MainWindow::startUpdate()
|
||||
void MainWindow::startUninstall()
|
||||
{
|
||||
m_cancelBtn->setDisabled(true);
|
||||
if (!NS_Utils::checkAndWaitForAppClosure(nativeWindowHandle())) {
|
||||
m_bar->setProgress(0);
|
||||
m_comntInfoLbl->setText(_TR(LABEL_ERR_CANCELLED), true);
|
||||
createCloseAndBackButtons();
|
||||
return;
|
||||
}
|
||||
m_bar->pulse(true);
|
||||
wstring args = L"/c \"" + m_uninst_cmd;
|
||||
args += (m_package == L"msi") ? L" /qn\"" : L" /VERYSILENT\"";
|
||||
@ -599,6 +615,8 @@ void MainWindow::createSelectionPage()
|
||||
wstring msg = m_uninsRadio->isChecked() ? _TR(MSG_REMOVE) : /*m_repRadio->isChecked() ? _TR(MSG_REPAIR) :*/ _TR(MSG_UPDATE);
|
||||
NS_Utils::Replace(msg, L"%1", _T(WINDOW_NAME));
|
||||
if (IDOK == MessageBox(nativeWindowHandle(), msg.c_str(), _TR(CAPTION), MB_ICONWARNING | MB_OKCANCEL | MB_DEFBUTTON2)) {
|
||||
if (!NS_Utils::checkAndWaitForAppClosure(nativeWindowHandle()))
|
||||
return;
|
||||
m_cenPanel->disconnect(m_resize_conn);
|
||||
m_updRadio->close();
|
||||
// m_repRadio->close();
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
#define CAPTION
|
||||
#define MSG_ERR_SYSTEM
|
||||
#define MSG_ERR_ALREADY_RUNNING
|
||||
#define MSG_ERR_TRY_CLOSE_APP
|
||||
#define MSG_ERR_CLOSE_APP
|
||||
#define MSG_REMOVE
|
||||
#define MSG_REPAIR
|
||||
|
||||
@ -173,6 +173,36 @@ namespace NS_Utils
|
||||
return false;
|
||||
}
|
||||
|
||||
bool checkAndWaitForAppClosure(HWND parent)
|
||||
{
|
||||
bool accept = true;
|
||||
if (HWND app_hwnd = FindWindow(WINDOW_CLASS_NAME, NULL)) {
|
||||
wstring caption(_T(" "));
|
||||
caption.append(_TR(CAPTION));
|
||||
wstring msg(_TR(MSG_ERR_TRY_CLOSE_APP));
|
||||
NS_Utils::Replace(msg, L"%1", _T(WINDOW_NAME));
|
||||
accept = (IDOK == MessageBox(parent, msg.c_str(), caption.c_str(), MB_ICONINFORMATION | MB_SERVICE_NOTIFICATION_NT3X | MB_APPLMODAL | MB_OKCANCEL | MB_DEFBUTTON1));
|
||||
if (accept) {
|
||||
PostMessage(app_hwnd, UM_INSTALL_UPDATE, 0, 0);
|
||||
Sleep(1000);
|
||||
while(true) {
|
||||
if ((app_hwnd = FindWindow(WINDOW_CLASS_NAME, NULL)) != nullptr) {
|
||||
wstring msg(_TR(MSG_ERR_CLOSE_APP));
|
||||
NS_Utils::Replace(msg, L"%1", _T(WINDOW_NAME));
|
||||
int result = MessageBox(parent, msg.c_str(), caption.c_str(), MB_ICONWARNING | MB_SERVICE_NOTIFICATION_NT3X | MB_APPLMODAL | MB_OKCANCEL | MB_DEFBUTTON1);
|
||||
if (result != IDOK) {
|
||||
accept = false;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return accept;
|
||||
}
|
||||
|
||||
void InstalledVerInfo(LPCWSTR value, wstring &name, wstring &arch)
|
||||
{
|
||||
if (!name.empty())
|
||||
|
||||
@ -56,6 +56,7 @@ void ShowMessage(wstring str, bool showError = false);
|
||||
bool IsRtlLanguage(unsigned long lcid);
|
||||
bool IsWin64();
|
||||
bool IsAppInstalled(wstring &path, wstring *arch = nullptr);
|
||||
bool checkAndWaitForAppClosure(HWND parent = nullptr);
|
||||
void InstalledVerInfo(LPCWSTR value, wstring &name, wstring &arch);
|
||||
void Replace(wstring &str, const wstring &from, const wstring &to);
|
||||
wstring MsiGetProperty(LPCWSTR prodCode, LPCWSTR propName);
|
||||
|
||||
Reference in New Issue
Block a user