diff --git a/win-linux/extras/update-daemon/src/classes/csvcmanager.cpp b/win-linux/extras/update-daemon/src/classes/csvcmanager.cpp index 27ece90ff..d124b47a3 100644 --- a/win-linux/extras/update-daemon/src/classes/csvcmanager.cpp +++ b/win-linux/extras/update-daemon/src/classes/csvcmanager.cpp @@ -75,6 +75,9 @@ #define BACKUP_PATH TEXT("/" REG_APP_NAME "Backup") #define PROVIDERS_PATH TEXT("/providers") #define SUCCES_UNPACKED TEXT("/success_unpacked.txt") +#define __GLOBAL_LOCK if (m_lock) {NS_Logger::WriteLog(_T("Blocked in: ") + FUNCTION_INFO); return;} m_lock = true; \ + NS_Logger::WriteLog(_T("Locking and further execution: ") + FUNCTION_INFO); +#define __UNLOCK m_lock = false; NS_Logger::WriteLog(_T("Unlocked in: ") + FUNCTION_INFO); using std::vector; @@ -208,6 +211,7 @@ void CSvcManager::init() if (params.size() == 4) { switch (std::stoi(params[0])) { case MSG_CheckUpdates: { + __GLOBAL_LOCK //DeleteUrlCacheEntry(params[1].c_str()); m_downloadMode = Mode::CHECK_UPDATES; if (m_pDownloader) @@ -216,6 +220,7 @@ void CSvcManager::init() break; } case MSG_LoadUpdates: { + __GLOBAL_LOCK m_downloadMode = Mode::DOWNLOAD_UPDATES; if (m_pDownloader) { tstring ext = (params[2] == TEXT("iss")) ? TEXT(".exe") : @@ -236,7 +241,9 @@ void CSvcManager::init() break; case MSG_StartReplacingFiles: + __GLOBAL_LOCK startReplacingFiles(); + __UNLOCK break; case MSG_ClearTempFiles: @@ -263,12 +270,12 @@ void CSvcManager::init() void CSvcManager::onCompleteUnzip(const int error) { + __UNLOCK if (error == UNZIP_OK) { // Сreate a file about successful unpacking for use in subsequent launches const tstring updPath = NS_File::parentPath(NS_File::appPath()) + UPDATE_PATH; list successList{m_newVersion}; if (!NS_File::writeToFile(updPath + SUCCES_UNPACKED, successList)) { - m_lock = false; return; } if (!sendMessage(MSG_ShowStartInstallMessage)) @@ -284,11 +291,11 @@ void CSvcManager::onCompleteUnzip(const int error) if (error == UNZIP_ABORT) { // Stop unzip } - m_lock = false; } void CSvcManager::onCompleteSlot(const int error, const tstring &filePath) { + __UNLOCK if (error == 0) { switch (m_downloadMode) { case Mode::CHECK_UPDATES: @@ -322,16 +329,14 @@ void CSvcManager::onProgressSlot(const int percent) void CSvcManager::unzipIfNeeded(const tstring &filePath, const tstring &newVersion) { - if (m_lock) - return; - m_lock = true; + __GLOBAL_LOCK m_newVersion = newVersion; const tstring updPath = NS_File::parentPath(NS_File::appPath()) + UPDATE_PATH; auto unzip = [=]()->void { if (!NS_File::dirExists(updPath) && !NS_File::makePath(updPath)) { NS_Logger::WriteLog(TEXT("An error occurred while creating dir: ") + updPath); - m_lock = false; + __UNLOCK return; } m_pUnzip->extractArchive(filePath, updPath); @@ -341,7 +346,7 @@ void CSvcManager::unzipIfNeeded(const tstring &filePath, const tstring &newVersi unzip(); } else { if (isSuccessUnpacked(updPath + SUCCES_UNPACKED, newVersion)) { - m_lock = false; + __UNLOCK if (!sendMessage(MSG_ShowStartInstallMessage)) NS_Logger::WriteLog(DEFAULT_ERROR_MESSAGE); diff --git a/win-linux/src/cupdatemanager.cpp b/win-linux/src/cupdatemanager.cpp index 53230ca2b..6b1d99185 100644 --- a/win-linux/src/cupdatemanager.cpp +++ b/win-linux/src/cupdatemanager.cpp @@ -66,6 +66,9 @@ #ifndef URL_APPCAST_DEV_CHANNEL # define URL_APPCAST_DEV_CHANNEL "" #endif +#define __GLOBAL_LOCK if (m_lock) {CLogger::log("Blocked in: " + FUNCTION_INFO); return;} m_lock = true; \ + CLogger::log("Locking and further execution:" + FUNCTION_INFO); +#define __UNLOCK m_lock = false; CLogger::log("Unlocked in:" + FUNCTION_INFO); using std::vector; @@ -307,7 +310,7 @@ void CUpdateManager::init() void CUpdateManager::criticalMsg(QWidget *parent, const QString &msg) { if (!m_manualCheck) { - m_lock = false; + __UNLOCK return; } #ifdef _WIN32 @@ -317,7 +320,7 @@ void CUpdateManager::criticalMsg(QWidget *parent, const QString &msg) #else CMessage::error(parent, msg); #endif - m_lock = false; + __UNLOCK } void CUpdateManager::clearTempFiles(const QString &except) @@ -342,9 +345,7 @@ void CUpdateManager::checkUpdates(bool manualCheck) if (getUpdateMode() != UpdateMode::DISABLE) m_pIntervalStartTimer->start(); - if (m_lock) - return; - m_lock = true; + __GLOBAL_LOCK AscAppManager::sendCommandTo(0, "updates:link", "lock"); m_manualCheck = manualCheck; m_packageData->clear(); @@ -440,14 +441,14 @@ bool CUpdateManager::sendMessage(int cmd, const tstring ¶m1, const tstring & void CUpdateManager::loadUpdates() { -// if (m_lock) -// return; + __GLOBAL_LOCK if (isSavedPackageValid()) { m_packageData->fileName = m_savedPackageData->fileName; - if (m_packageData->fileType == "archive") + if (m_packageData->fileType == "archive") { + __UNLOCK unzipIfNeeded(); - else { + } else { AscAppManager::sendCommandTo(0, "updates:download", "{\"progress\":\"done\"}"); m_dialogSchedule->addToSchedule("showStartInstallMessage"); } @@ -462,8 +463,8 @@ void CUpdateManager::loadUpdates() void CUpdateManager::installUpdates() { - if (m_lock) - return; + __GLOBAL_LOCK + if (ignoredVersion() != getVersion()) { AscAppManager::sendCommandTo(0, "updates:download", "{\"progress\":\"done\"}"); m_dialogSchedule->addToSchedule("showStartInstallMessage"); @@ -490,9 +491,10 @@ void CUpdateManager::onLoadUpdateFinished(const QString &filePath) } m_packageData->fileName = filePath; savePackageData(m_packageData->version, filePath, m_packageData->fileType); - if (m_packageData->fileType == "archive") + if (m_packageData->fileType == "archive") { + __UNLOCK unzipIfNeeded(); - else { + } else { AscAppManager::sendCommandTo(0, "updates:download", "{\"progress\":\"done\"}"); m_dialogSchedule->addToSchedule("showStartInstallMessage"); } @@ -500,9 +502,7 @@ void CUpdateManager::onLoadUpdateFinished(const QString &filePath) void CUpdateManager::unzipIfNeeded() { - if (m_lock) - return; - m_lock = true; + __GLOBAL_LOCK AscAppManager::sendCommandTo(0, "updates:link", "lock"); AscAppManager::sendCommandTo(0, "updates:download", QString("{\"progress\":\"100\"}")); // TODO: replace with unpacking message @@ -551,10 +551,9 @@ void CUpdateManager::setNewUpdateSetting(const QString& _rate) void CUpdateManager::cancelLoading() { - if (m_lock) - return; AscAppManager::sendCommandTo(0, "updates:checking", QString("{\"version\":\"%1\"}").arg(m_packageData->version)); sendMessage(MSG_StopDownload); + __UNLOCK } void CUpdateManager::skipVersion() @@ -641,13 +640,13 @@ void CUpdateManager::onCheckFinished(bool error, bool updateExist, const QString if ( updateExist ) { switch (getUpdateMode()) { case UpdateMode::SILENT: - m_lock = false; + __UNLOCK loadUpdates(); break; case UpdateMode::ASK: case UpdateMode::DISABLE: if (isSavedPackageValid()) { - m_lock = false; + __UNLOCK loadUpdates(); } else { QString args = QString("{\"version\":\"%1\"}").arg(version); @@ -658,7 +657,7 @@ void CUpdateManager::onCheckFinished(bool error, bool updateExist, const QString } } else { AscAppManager::sendCommandTo(0, "updates:checking", "{\"version\":\"no\"}"); - m_lock = false; + __UNLOCK; } } else { m_dialogSchedule->addToSchedule("criticalMsg", changelog); @@ -673,7 +672,7 @@ void CUpdateManager::showUpdateMessage(QWidget *parent) { getVersion(), QString(VER_FILEVERSION_STR)), WinDlg::DlgBtns::mbSkipRemindDownload); - m_lock = false; + __UNLOCK switch (result) { case WinDlg::DLG_RESULT_DOWNLOAD: loadUpdates(); @@ -698,7 +697,7 @@ void CUpdateManager::showStartInstallMessage(QWidget *parent) getVersion(), QString(VER_FILEVERSION_STR)), WinDlg::DlgBtns::mbSkipRemindSaveandinstall); - m_lock = false; + __UNLOCK switch (result) { case WinDlg::DLG_RESULT_INSTALL: { m_restartForUpdate = true;