mirror of
https://github.com/notepad-plus-plus/notepad-plus-plus.git
synced 2025-07-23 22:04:55 +02:00
Fix missing session invalid error for user session & enhance NPPM_GETNBSESSIONFILES
New specs of NPPM_GETNBSESSIONFILES (which is retro-compatible): ====================== NPPM_GETNBSESSIONFILES Retrieves the number of files to load in the session sessionFileName. sessionFileName should be a full path name of an xml file. Parameters: wParam [out] BOOL* isValidXML, if this pointer is null, then this parameter will be ignored. TRUE if XML is valid, otherwise FALSE. lParam [in] const TCHAR * sessionFileName Return value: Returns 0 if sessionFileName is an empty string/NULL, or XML session file is corrupted/invalid, else the number of files. ====================== Other minor improvements: - checking also for a possible ShellExecute errors - removing the isAllSuccessful boolean, as it is no longer needed. Fix #14228, close #14232
This commit is contained in:
parent
08794510be
commit
72c5175b33
@ -1295,13 +1295,22 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
|
||||
|
||||
case NPPM_GETNBSESSIONFILES:
|
||||
{
|
||||
const TCHAR *sessionFileName = reinterpret_cast<const TCHAR *>(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<const TCHAR*>(lParam);
|
||||
BOOL* pbIsValidXML = reinterpret_cast<BOOL*>(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() ; )
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user