Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore process working directory at end of performXMLCheck() to fix issue #179 #180

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions ToolsXmlValidate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@

#include <string>

#include <direct.h>

using namespace QuickXml;

int performXMLCheck(int informIfNoError) {
dbgln("performXMLCheck()");

// Save process preexisting current working directory and drive.
int prevDrive = _getdrive();
wchar_t* prevPath = _wgetdcwd(prevDrive, NULL, MAX_PATH);

// 0. change current folder
TCHAR currenPath[MAX_PATH] = { '\0' };
::SendMessage(nppData._nppHandle, NPPM_GETCURRENTDIRECTORY, MAX_PATH, (LPARAM)currenPath);
Expand Down Expand Up @@ -59,6 +65,13 @@ int performXMLCheck(int informIfNoError) {
displayXMLErrors(wrapper->getLastErrors(), hCurrentEditView, L"XML Parsing error");
}

// Restore process preexisting current working directory (drive restored implicitly).
if (prevPath)
{
_wchdir(prevPath);
free(prevPath);
}

delete wrapper;

return res;
Expand Down