diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index 4aef685d2..f95b0d796 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -1295,13 +1295,22 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa case NPPM_GETNBSESSIONFILES: { - const TCHAR *sessionFileName = reinterpret_cast(lParam); - if ((!sessionFileName) || (sessionFileName[0] == '\0')) - return 0; - Session session2Load; - if (nppParam.loadSession(session2Load, sessionFileName)) - return session2Load.nbMainFiles() + session2Load.nbSubFiles(); - return 0; + size_t nbSessionFiles = 0; + const TCHAR* sessionFileName = reinterpret_cast(lParam); + BOOL* pbIsValidXML = reinterpret_cast(wParam); + if (pbIsValidXML) + *pbIsValidXML = false; + if (sessionFileName && (sessionFileName[0] != '\0')) + { + Session session2Load; + if (nppParam.loadSession(session2Load, sessionFileName, true)) + { + if (pbIsValidXML) + *pbIsValidXML = true; + nbSessionFiles = session2Load.nbMainFiles() + session2Load.nbSubFiles(); + } + } + return nbSessionFiles; } case NPPM_GETSESSIONFILES: @@ -1313,7 +1322,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa return FALSE; Session session2Load; - if (nppParam.loadSession(session2Load, sessionFileName)) + if (nppParam.loadSession(session2Load, sessionFileName, true)) { size_t i = 0; for ( ; i < session2Load.nbMainFiles() ; ) diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index ff786d0ee..1c45c7299 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -2449,7 +2449,6 @@ bool Notepad_plus::fileLoadSession(const TCHAR *fn) sessionFileName = fn; } - NppParameters& nppParam = NppParameters::getInstance(); const NppGUI & nppGUI = nppParam.getNppGUI(); if (!sessionFileName.empty()) @@ -2466,36 +2465,26 @@ bool Notepad_plus::fileLoadSession(const TCHAR *fn) TCHAR nppFullPath[MAX_PATH]{}; ::GetModuleFileName(NULL, nppFullPath, MAX_PATH); - generic_string args = TEXT("-multiInst -nosession -openSession "); args += TEXT("\""); args += sessionFileName; args += TEXT("\""); - ::ShellExecute(_pPublicInterface->getHSelf(), TEXT("open"), nppFullPath, args.c_str(), TEXT("."), SW_SHOW); - result = true; + if (::ShellExecute(_pPublicInterface->getHSelf(), TEXT("open"), nppFullPath, args.c_str(), TEXT("."), SW_SHOW) > (HINSTANCE)32) + result = true; } else { - bool isAllSuccessful = true; Session session2Load; if (nppParam.loadSession(session2Load, sessionFileName.c_str())) { const bool isSnapshotMode = false; - isAllSuccessful = loadSession(session2Load, isSnapshotMode, sessionFileName.c_str()); - result = true; + result = loadSession(session2Load, isSnapshotMode, sessionFileName.c_str()); + if (isEmptyNpp && nppGUI._multiInstSetting == multiInstOnSession) nppParam.setLoadedSessionFilePath(sessionFileName); } } - if (result == false) - { - _nativeLangSpeaker.messageBox("SessionFileInvalidError", - NULL, - TEXT("Session file is either corrupted or not valid."), - TEXT("Could not Load Session"), - MB_OK); - } } return result; diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index 45a7a5ba9..380304bc7 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -2264,13 +2264,22 @@ void NppParameters::setWorkingDir(const TCHAR * newPath) } } -bool NppParameters::loadSession(Session & session, const TCHAR *sessionFileName) +bool NppParameters::loadSession(Session& session, const TCHAR* sessionFileName, const bool bSuppressErrorMsg) { - TiXmlDocument *pXmlSessionDocument = new TiXmlDocument(sessionFileName); + TiXmlDocument* pXmlSessionDocument = new TiXmlDocument(sessionFileName); bool loadOkay = pXmlSessionDocument->LoadFile(); if (loadOkay) loadOkay = getSessionFromXmlTree(pXmlSessionDocument, session); + if (!loadOkay && !bSuppressErrorMsg) + { + _pNativeLangSpeaker->messageBox("SessionFileInvalidError", + NULL, + TEXT("Session file is either corrupted or not valid."), + TEXT("Could not Load Session"), + MB_OK); + } + delete pXmlSessionDocument; return loadOkay; } diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index 1c73721a5..004eeeb90 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -1659,7 +1659,7 @@ public: return _doPrintAndExit; }; - bool loadSession(Session & session, const TCHAR *sessionFileName); + bool loadSession(Session& session, const TCHAR* sessionFileName, const bool bSuppressErrorMsg = false); void setLoadedSessionFilePath(const std::wstring & loadedSessionFilePath) { _loadedSessionFullFilePath = loadedSessionFilePath;