From 494b4bc0dba79511ca7673b7995a2205efdc8bfa Mon Sep 17 00:00:00 2001 From: Don HO Date: Sat, 9 Feb 2019 22:52:13 +0100 Subject: [PATCH] Fix crash on exit after creating or importing a UDL And fix deletion userDefineLang.xml file bug on exit. --- PowerEditor/src/Parameters.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index 42a54c0f..28cf5293 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -2888,14 +2888,17 @@ Default UDL + Created + Imported void NppParameters::writeDefaultUDL() { bool firstCleanDone = false; + std::vector deleteState; for (auto udl : _pXmlUserLangsDoc) { if (!_pXmlUserLangDoc) { _pXmlUserLangDoc = new TiXmlDocument(_userDefineLangPath); + _pXmlUserLangDoc->InsertEndChild(TiXmlElement(TEXT("NotepadPlus"))); } bool toDelete = (udl._indexRange.second - udl._indexRange.first) == 0; + deleteState.push_back(toDelete); if ((!udl._udlXmlDoc || udl._udlXmlDoc == _pXmlUserLangDoc) && udl._isDirty && !toDelete) // new created or/and imported UDL plus _pXmlUserLangDoc (if exist) { TiXmlNode *root = _pXmlUserLangDoc->FirstChild(TEXT("NotepadPlus")); @@ -2915,17 +2918,28 @@ void NppParameters::writeDefaultUDL() } } - if (firstCleanDone) + bool deleteAll = true; + for (bool del : deleteState) + { + if (!del) + { + deleteAll = false; + break; + } + } + + if (firstCleanDone) // at least one udl is for saving, the udl to be deleted are ignored { _pXmlUserLangDoc->SaveFile(); } - else + else if (deleteAll) { if (::PathFileExists(_userDefineLangPath.c_str())) { ::DeleteFile(_userDefineLangPath.c_str()); } } + // else nothing to change, do nothing } void NppParameters::writeNonDefaultUDL()