Several enhancements for code

Close #15516
This commit is contained in:
Don Ho 2024-08-05 14:44:04 +02:00
parent 9fb538d125
commit b78b3bdef0
17 changed files with 52 additions and 63 deletions

View File

@ -68,7 +68,7 @@ std::string getFileContent(const wchar_t *file2read)
do do
{ {
lenFile = fread(data, 1, blockSize, fp); lenFile = fread(data, 1, blockSize, fp);
if (lenFile <= 0) break; if (lenFile == 0) break;
wholeFileContent.append(data, lenFile); wholeFileContent.append(data, lenFile);
} }
while (lenFile > 0); while (lenFile > 0);
@ -94,11 +94,11 @@ char getDriveLetter()
wstring relativeFilePathToFullFilePath(const wchar_t *relativeFilePath) wstring relativeFilePathToFullFilePath(const wchar_t *relativeFilePath)
{ {
wstring fullFilePathName; wstring fullFilePathName;
wchar_t fullFileName[MAX_PATH];
BOOL isRelative = ::PathIsRelative(relativeFilePath); BOOL isRelative = ::PathIsRelative(relativeFilePath);
if (isRelative) if (isRelative)
{ {
wchar_t fullFileName[MAX_PATH];
::GetFullPathName(relativeFilePath, MAX_PATH, fullFileName, NULL); ::GetFullPathName(relativeFilePath, MAX_PATH, fullFileName, NULL);
fullFilePathName += fullFileName; fullFilePathName += fullFileName;
} }
@ -953,7 +953,7 @@ bool matchInExcludeDirList(const wchar_t* dirName, const std::vector<wstring>& p
return false; return false;
} }
bool allPatternsAreExclusion(const std::vector<wstring> patterns) bool allPatternsAreExclusion(const std::vector<wstring>& patterns)
{ {
bool oneInclusionPatternFound = false; bool oneInclusionPatternFound = false;
for (size_t i = 0, len = patterns.size(); i < len; ++i) for (size_t i = 0, len = patterns.size(); i < len; ++i)
@ -1096,8 +1096,6 @@ bool isCertificateValidated(const wstring & fullFilePath, const wstring & subjec
CERT_INFO CertInfo{}; CERT_INFO CertInfo{};
LPTSTR szName = NULL; LPTSTR szName = NULL;
wstring subjectName;
try { try {
// Get message handle and store handle from the signed file. // Get message handle and store handle from the signed file.
result = CryptQueryObject(CERT_QUERY_OBJECT_FILE, result = CryptQueryObject(CERT_QUERY_OBJECT_FILE,
@ -1182,7 +1180,7 @@ bool isCertificateValidated(const wstring & fullFilePath, const wstring & subjec
} }
// check Subject name. // check Subject name.
subjectName = szName; wstring subjectName = szName;
if (subjectName != subjectName2check) if (subjectName != subjectName2check)
{ {
throw wstring(L"Certificate checking error: the certificate is not matched."); throw wstring(L"Certificate checking error: the certificate is not matched.");

View File

@ -75,7 +75,7 @@ std::wstring relativeFilePathToFullFilePath(const wchar_t *relativeFilePath);
void writeFileContent(const wchar_t *file2write, const char *content2write); void writeFileContent(const wchar_t *file2write, const char *content2write);
bool matchInList(const wchar_t *fileName, const std::vector<std::wstring> & patterns); bool matchInList(const wchar_t *fileName, const std::vector<std::wstring> & patterns);
bool matchInExcludeDirList(const wchar_t* dirName, const std::vector<std::wstring>& patterns, size_t level); bool matchInExcludeDirList(const wchar_t* dirName, const std::vector<std::wstring>& patterns, size_t level);
bool allPatternsAreExclusion(const std::vector<std::wstring> patterns); bool allPatternsAreExclusion(const std::vector<std::wstring>& patterns);
class WcharMbcsConvertor final class WcharMbcsConvertor final
{ {

View File

@ -78,7 +78,7 @@ bool SecurityGuard::checkSha256(const std::wstring& filePath, NppModule module2c
for (size_t i = 0; i < 32; i++) for (size_t i = 0; i < 32; i++)
wsprintf(sha2hashStr + i * 2, L"%02x", sha2hash[i]); wsprintf(sha2hashStr + i * 2, L"%02x", sha2hash[i]);
std::vector<std::wstring>* moduleSha256 = nullptr; const std::vector<std::wstring>* moduleSha256 = nullptr;
if (module2check == nm_gup) if (module2check == nm_gup)
moduleSha256 = &_gupSha256; moduleSha256 = &_gupSha256;
@ -87,7 +87,7 @@ bool SecurityGuard::checkSha256(const std::wstring& filePath, NppModule module2c
else else
return false; return false;
for (auto i : *moduleSha256) for (const auto& i : *moduleSha256)
{ {
if (i == sha2hashStr) if (i == sha2hashStr)
{ {

View File

@ -29,7 +29,6 @@ MiniDumper::MiniDumper()
bool MiniDumper::writeDump(EXCEPTION_POINTERS * pExceptionInfo) bool MiniDumper::writeDump(EXCEPTION_POINTERS * pExceptionInfo)
{ {
wchar_t szDumpPath[MAX_PATH];
wchar_t szScratch[MAX_PATH]; wchar_t szScratch[MAX_PATH];
LPCTSTR szResult = NULL; LPCTSTR szResult = NULL;
bool retval = false; bool retval = false;
@ -41,6 +40,7 @@ bool MiniDumper::writeDump(EXCEPTION_POINTERS * pExceptionInfo)
MINIDUMPWRITEDUMP pDump = (MINIDUMPWRITEDUMP)::GetProcAddress( hDll, "MiniDumpWriteDump" ); MINIDUMPWRITEDUMP pDump = (MINIDUMPWRITEDUMP)::GetProcAddress( hDll, "MiniDumpWriteDump" );
if (pDump) if (pDump)
{ {
wchar_t szDumpPath[MAX_PATH];
::GetModuleFileName(NULL, szDumpPath, MAX_PATH); ::GetModuleFileName(NULL, szDumpPath, MAX_PATH);
::PathRemoveFileSpec(szDumpPath); ::PathRemoveFileSpec(szDumpPath);
wcscat_s(szDumpPath, L"\\NppDump.dmp"); wcscat_s(szDumpPath, L"\\NppDump.dmp");

View File

@ -358,12 +358,12 @@ bool PluginsManager::loadPlugins(const wchar_t* dir, const PluginViewList* plugi
Version nppVer; Version nppVer;
nppVer.setVersionFrom(nppFullPathName); nppVer.setVersionFrom(nppFullPathName);
const wchar_t* incompatibleWarning = L"%s's version %s is not compatible to this version of Notepad++ (v%s).\r\nAs a result the plugin cannot be loaded.";
const wchar_t* incompatibleWarningWithSolution = L"%s's version %s is not compatible to this version of Notepad++ (v%s).\r\nAs a result the plugin cannot be loaded.\r\n\r\nGo to Updates section and update your plugin to %s for solving the compatibility issue.";
// get plugin folder // get plugin folder
if (hFindFolder != INVALID_HANDLE_VALUE && (foundData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) if (hFindFolder != INVALID_HANDLE_VALUE && (foundData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{ {
const wchar_t* incompatibleWarning = L"%s's version %s is not compatible to this version of Notepad++ (v%s).\r\nAs a result the plugin cannot be loaded.";
const wchar_t* incompatibleWarningWithSolution = L"%s's version %s is not compatible to this version of Notepad++ (v%s).\r\nAs a result the plugin cannot be loaded.\r\n\r\nGo to Updates section and update your plugin to %s for solving the compatibility issue.";
wstring foundFileName = foundData.cFileName; wstring foundFileName = foundData.cFileName;
if (foundFileName != L"." && foundFileName != L".." && wcsicmp(foundFileName.c_str(), L"Config") != 0) if (foundFileName != L"." && foundFileName != L".." && wcsicmp(foundFileName.c_str(), L"Config") != 0)
{ {
@ -441,7 +441,6 @@ bool PluginsManager::loadPlugins(const wchar_t* dir, const PluginViewList* plugi
{ {
wstring pluginsFullPathFilter2 = pluginsFolder; wstring pluginsFullPathFilter2 = pluginsFolder;
pathAppend(pluginsFullPathFilter2, foundFileName2); pathAppend(pluginsFullPathFilter2, foundFileName2);
wstring pluginsFolderPath2 = pluginsFullPathFilter2;
wstring dllName2 = foundFileName2; wstring dllName2 = foundFileName2;
dllName2 += L".dll"; dllName2 += L".dll";
pathAppend(pluginsFullPathFilter2, dllName2); pathAppend(pluginsFullPathFilter2, dllName2);
@ -630,13 +629,12 @@ HMENU PluginsManager::initMenu(HMENU hMenu, bool enablePluginAdmin)
{ {
_hPluginsMenu = ::GetSubMenu(hMenu, MENUINDEX_PLUGINS); _hPluginsMenu = ::GetSubMenu(hMenu, MENUINDEX_PLUGINS);
int i = 1;
if (nbPlugin > 0) if (nbPlugin > 0)
::InsertMenu(_hPluginsMenu, 0, MF_BYPOSITION | MF_SEPARATOR, 0, L""); ::InsertMenu(_hPluginsMenu, 0, MF_BYPOSITION | MF_SEPARATOR, 0, L"");
if (enablePluginAdmin) if (enablePluginAdmin)
{ {
int i = 1;
::InsertMenu(_hPluginsMenu, i++, MF_BYPOSITION, IDM_SETTING_PLUGINADM, L"Plugins Admin..."); ::InsertMenu(_hPluginsMenu, i++, MF_BYPOSITION, IDM_SETTING_PLUGINADM, L"Plugins Admin...");
::InsertMenu(_hPluginsMenu, i++, MF_BYPOSITION | MF_SEPARATOR, 0, L""); ::InsertMenu(_hPluginsMenu, i++, MF_BYPOSITION | MF_SEPARATOR, 0, L"");
} }

View File

@ -3217,7 +3217,7 @@ bool scanToUrlStart(wchar_t *text, int textLen, int start, int* distance, int* s
// The query pattern going through looks like this: // The query pattern going through looks like this:
// - ?abc;def;fgh="i j k"&'l m n'+opq // - ?abc;def;fgh="i j k"&'l m n'+opq
// //
void scanToUrlEnd(wchar_t *text, int textLen, int start, int* distance) void scanToUrlEnd(const wchar_t *text, int textLen, int start, int* distance)
{ {
int p = start; int p = start;
wchar_t q = 0; wchar_t q = 0;
@ -9048,7 +9048,7 @@ void Notepad_plus::changedHistoryGoTo(int idGoTo)
} }
} }
HMENU Notepad_plus::createMenuFromMenu(HMENU hSourceMenu, std::vector<int>& commandIds) HMENU Notepad_plus::createMenuFromMenu(HMENU hSourceMenu, const std::vector<int>& commandIds)
{ {
HMENU hNewMenu = ::CreatePopupMenu(); HMENU hNewMenu = ::CreatePopupMenu();
for (const auto& cmdID : commandIds) for (const auto& cmdID : commandIds)

View File

@ -655,7 +655,7 @@ private:
void clearChangesHistory(); void clearChangesHistory();
void changedHistoryGoTo(int idGoTo); void changedHistoryGoTo(int idGoTo);
HMENU createMenuFromMenu(HMENU hSourceMenu, std::vector<int>& commandIds); HMENU createMenuFromMenu(HMENU hSourceMenu, const std::vector<int>& commandIds);
BOOL notifyTBShowMenu(LPNMTOOLBARW lpnmtb, const char* menuPosId); BOOL notifyTBShowMenu(LPNMTOOLBARW lpnmtb, const char* menuPosId);
BOOL notifyTBShowMenu(LPNMTOOLBARW lpnmtb, const char* menuPosId, std::vector<int> cmdIDs); BOOL notifyTBShowMenu(LPNMTOOLBARW lpnmtb, const char* menuPosId, std::vector<int> cmdIDs);
}; };

View File

@ -228,7 +228,7 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const wchar_t *cmdL
fileNames.clear(); fileNames.clear();
wstring nppThemeDir = nppDir.c_str(); // <- should use the pointer to avoid the constructor of copy wstring nppThemeDir = nppDir; // <- should use the pointer to avoid the constructor of copy
pathAppend(nppThemeDir, L"themes\\"); pathAppend(nppThemeDir, L"themes\\");
// Set theme directory to their installation directory // Set theme directory to their installation directory

View File

@ -487,7 +487,6 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
{ {
// Find in files function code should be here due to the number of parameters (2) cannot be passed via WM_COMMAND // Find in files function code should be here due to the number of parameters (2) cannot be passed via WM_COMMAND
constexpr int strSize = FINDREPLACE_MAXLENGTH; constexpr int strSize = FINDREPLACE_MAXLENGTH;
wchar_t str[strSize]{};
bool isFirstTime = !_findReplaceDlg.isCreated(); bool isFirstTime = !_findReplaceDlg.isCreated();
_findReplaceDlg.doDialog(FIND_DLG, _nativeLangSpeaker.isRTL()); _findReplaceDlg.doDialog(FIND_DLG, _nativeLangSpeaker.isRTL());
@ -495,6 +494,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
const NppGUI & nppGui = nppParam.getNppGUI(); const NppGUI & nppGui = nppParam.getNppGUI();
if (nppGui._fillFindFieldWithSelected) if (nppGui._fillFindFieldWithSelected)
{ {
wchar_t str[strSize]{};
_pEditView->getGenericSelectedText(str, strSize, nppGui._fillFindFieldSelectCaret); _pEditView->getGenericSelectedText(str, strSize, nppGui._fillFindFieldSelectCaret);
_findReplaceDlg.setSearchText(str); _findReplaceDlg.setSearchText(str);
} }

View File

@ -192,7 +192,7 @@ void Notepad_plus::command(int id)
case IDM_FILE_OPENFOLDERASWORSPACE: case IDM_FILE_OPENFOLDERASWORSPACE:
{ {
NativeLangSpeaker* pNativeSpeaker = NppParameters::getInstance().getNativeLangSpeaker(); const NativeLangSpeaker* pNativeSpeaker = NppParameters::getInstance().getNativeLangSpeaker();
wstring openWorkspaceStr = pNativeSpeaker->getAttrNameStr(L"Select a folder to add in Folder as Workspace panel", wstring openWorkspaceStr = pNativeSpeaker->getAttrNameStr(L"Select a folder to add in Folder as Workspace panel",
FOLDERASWORKSPACE_NODE, "SelectFolderFromBrowserString"); FOLDERASWORKSPACE_NODE, "SelectFolderFromBrowserString");
wstring folderPath = folderBrowser(_pPublicInterface->getHSelf(), openWorkspaceStr); wstring folderPath = folderBrowser(_pPublicInterface->getHSelf(), openWorkspaceStr);
@ -977,7 +977,7 @@ void Notepad_plus::command(int id)
{ {
if (_pFileBrowser == nullptr) // first launch, check in params to open folders if (_pFileBrowser == nullptr) // first launch, check in params to open folders
{ {
NppParameters& nppParam = NppParameters::getInstance(); const NppParameters& nppParam = NppParameters::getInstance();
launchFileBrowser(nppParam.getFileBrowserRoots(), nppParam.getFileBrowserSelectedItemPath()); launchFileBrowser(nppParam.getFileBrowserRoots(), nppParam.getFileBrowserSelectedItemPath());
if (_pFileBrowser != nullptr) if (_pFileBrowser != nullptr)
{ {
@ -1384,7 +1384,7 @@ void Notepad_plus::command(int id)
if (_findReplaceDlg.isCreated()) if (_findReplaceDlg.isCreated())
{ {
FindOption op = _findReplaceDlg.getCurrentOptions(); FindOption op = _findReplaceDlg.getCurrentOptions();
NppParameters& nppParams = NppParameters::getInstance(); const NppParameters& nppParams = NppParameters::getInstance();
if ((id == IDM_SEARCH_FINDPREV) && (op._searchType == FindRegex) && !nppParams.regexBackward4PowerUser()) if ((id == IDM_SEARCH_FINDPREV) && (op._searchType == FindRegex) && !nppParams.regexBackward4PowerUser())
{ {
// regex upward search is disabled // regex upward search is disabled
@ -2452,7 +2452,7 @@ void Notepad_plus::command(int id)
// Don't put the quots for Edge, otherwise it doesn't work // Don't put the quots for Edge, otherwise it doesn't work
//fullCurrentPath = L"\""; //fullCurrentPath = L"\"";
wstring fullCurrentPath = currentBuf->getFullPathName(); fullCurrentPath = currentBuf->getFullPathName();
//fullCurrentPath += L"\""; //fullCurrentPath += L"\"";
::ShellExecute(NULL, L"open", L"shell:Appsfolder\\Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge", fullCurrentPath.c_str(), NULL, SW_SHOW); ::ShellExecute(NULL, L"open", L"shell:Appsfolder\\Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge", fullCurrentPath.c_str(), NULL, SW_SHOW);
@ -2685,8 +2685,6 @@ void Notepad_plus::command(int id)
case IDM_VIEW_SUMMARY: case IDM_VIEW_SUMMARY:
{ {
wstring characterNumber = L"";
Buffer * curBuf = _pEditView->getCurrentBuffer(); Buffer * curBuf = _pEditView->getCurrentBuffer();
int64_t fileLen = curBuf->getFileLength(); int64_t fileLen = curBuf->getFileLength();
@ -2694,6 +2692,7 @@ void Notepad_plus::command(int id)
NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker(); NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker();
if (pNativeSpeaker) if (pNativeSpeaker)
{ {
wstring characterNumber = L"";
if (fileLen != -1) if (fileLen != -1)
{ {
@ -2886,7 +2885,6 @@ void Notepad_plus::command(int id)
if (_pEditView->execute(SCI_CANUNDO) == TRUE) if (_pEditView->execute(SCI_CANUNDO) == TRUE)
{ {
wstring msg, title;
int answer = _nativeLangSpeaker.messageBox("LoseUndoAbilityWarning", int answer = _nativeLangSpeaker.messageBox("LoseUndoAbilityWarning",
_pPublicInterface->getHSelf(), _pPublicInterface->getHSelf(),
L"You should save the current modification.\rAll the saved modifications can not be undone.\r\rContinue?", L"You should save the current modification.\rAll the saved modifications can not be undone.\r\rContinue?",
@ -2969,7 +2967,7 @@ void Notepad_plus::command(int id)
{ {
int index = id - IDM_FORMAT_ENCODE; int index = id - IDM_FORMAT_ENCODE;
EncodingMapper& em = EncodingMapper::getInstance(); const EncodingMapper& em = EncodingMapper::getInstance();
int encoding = em.getEncodingFromIndex(index); int encoding = em.getEncodingFromIndex(index);
if (encoding == -1) if (encoding == -1)
{ {
@ -2980,7 +2978,6 @@ void Notepad_plus::command(int id)
Buffer* buf = _pEditView->getCurrentBuffer(); Buffer* buf = _pEditView->getCurrentBuffer();
if (buf->isDirty()) if (buf->isDirty())
{ {
wstring warning, title;
int answer = _nativeLangSpeaker.messageBox("SaveCurrentModifWarning", int answer = _nativeLangSpeaker.messageBox("SaveCurrentModifWarning",
_pPublicInterface->getHSelf(), _pPublicInterface->getHSelf(),
L"You should save the current modification.\rAll the saved modifications can not be undone.\r\rContinue?", L"You should save the current modification.\rAll the saved modifications can not be undone.\r\rContinue?",
@ -2998,7 +2995,6 @@ void Notepad_plus::command(int id)
if (_pEditView->execute(SCI_CANUNDO) == TRUE) if (_pEditView->execute(SCI_CANUNDO) == TRUE)
{ {
wstring msg, title;
int answer = _nativeLangSpeaker.messageBox("LoseUndoAbilityWarning", int answer = _nativeLangSpeaker.messageBox("LoseUndoAbilityWarning",
_pPublicInterface->getHSelf(), _pPublicInterface->getHSelf(),
L"You should save the current modification.\rAll the saved modifications can not be undone.\r\rContinue?", L"You should save the current modification.\rAll the saved modifications can not be undone.\r\rContinue?",
@ -3342,7 +3338,7 @@ void Notepad_plus::command(int id)
L"Editing contextMenu", L"Editing contextMenu",
MB_OK|MB_APPLMODAL); MB_OK|MB_APPLMODAL);
NppParameters& nppParams = NppParameters::getInstance(); const NppParameters& nppParams = NppParameters::getInstance();
BufferID bufID = doOpen((nppParams.getContextMenuPath())); BufferID bufID = doOpen((nppParams.getContextMenuPath()));
switchToFile(bufID); switchToFile(bufID);
break; break;
@ -4230,7 +4226,7 @@ void Notepad_plus::command(int id)
else if ((id >= ID_USER_CMD) && (id < ID_USER_CMD_LIMIT)) else if ((id >= ID_USER_CMD) && (id < ID_USER_CMD_LIMIT))
{ {
int i = id - ID_USER_CMD; int i = id - ID_USER_CMD;
vector<UserCommand> & theUserCommands = (NppParameters::getInstance()).getUserCommandList(); const vector<UserCommand> & theUserCommands = (NppParameters::getInstance()).getUserCommandList();
UserCommand ucmd = theUserCommands[i]; UserCommand ucmd = theUserCommands[i];
Command cmd(string2wstring(ucmd.getCmd(), CP_UTF8)); Command cmd(string2wstring(ucmd.getCmd(), CP_UTF8));

View File

@ -262,9 +262,6 @@ BufferID Notepad_plus::doOpen(const wstring& fileName, bool isRecursive, bool is
} }
_lastRecentFileList.remove(longFileName); _lastRecentFileList.remove(longFileName);
wstring fileName2Find;
wstring gs_fileName{ targetFileName };
// "fileName" could be: // "fileName" could be:
// 1. full file path to open or create // 1. full file path to open or create
@ -277,6 +274,7 @@ BufferID Notepad_plus::doOpen(const wstring& fileName, bool isRecursive, bool is
// if case 1 & 2 not found, search case 3 // if case 1 & 2 not found, search case 3
if (foundBufID == BUFFER_INVALID) if (foundBufID == BUFFER_INVALID)
{ {
wstring fileName2Find;
fileName2Find = longFileName; fileName2Find = longFileName;
foundBufID = MainFileManager.getBufferFromName(fileName2Find.c_str()); foundBufID = MainFileManager.getBufferFromName(fileName2Find.c_str());
} }
@ -1652,7 +1650,7 @@ bool Notepad_plus::fileSave(BufferID id)
// Get the current file's directory // Get the current file's directory
wstring path = fn; wstring path = fn;
::PathRemoveFileSpec(path); ::PathRemoveFileSpec(path);
fn_bak = path.c_str(); fn_bak = path;
fn_bak += L"\\"; fn_bak += L"\\";
// If verbose, save it in a sub folder // If verbose, save it in a sub folder
@ -1906,7 +1904,7 @@ bool Notepad_plus::fileSaveAs(BufferID id, bool isSaveCopy)
if (res && isSaveCopy && fDlg.getOpenTheCopyAfterSaveAsCopy()) if (res && isSaveCopy && fDlg.getOpenTheCopyAfterSaveAsCopy())
{ {
BufferID bid = doOpen(fn.c_str()); BufferID bid = doOpen(fn);
if (bid != BUFFER_INVALID) if (bid != BUFFER_INVALID)
{ {
switchToFile(bid); switchToFile(bid);
@ -2605,9 +2603,9 @@ bool Notepad_plus::fileLoadSession(const wchar_t *fn)
{ {
CustomFileDialog fDlg(_pPublicInterface->getHSelf()); CustomFileDialog fDlg(_pPublicInterface->getHSelf());
const wchar_t *ext = NppParameters::getInstance().getNppGUI()._definedSessionExt.c_str(); const wchar_t *ext = NppParameters::getInstance().getNppGUI()._definedSessionExt.c_str();
wstring sessionExt = L"";
if (*ext != '\0') if (*ext != '\0')
{ {
wstring sessionExt = L"";
if (*ext != '.') if (*ext != '.')
sessionExt += L"."; sessionExt += L".";
sessionExt += ext; sessionExt += ext;
@ -2703,9 +2701,9 @@ const wchar_t * Notepad_plus::fileSaveSession(size_t nbFile, wchar_t ** fileName
CustomFileDialog fDlg(_pPublicInterface->getHSelf()); CustomFileDialog fDlg(_pPublicInterface->getHSelf());
const wchar_t *ext = NppParameters::getInstance().getNppGUI()._definedSessionExt.c_str(); const wchar_t *ext = NppParameters::getInstance().getNppGUI()._definedSessionExt.c_str();
wstring sessionExt = L"";
if (*ext != '\0') if (*ext != '\0')
{ {
wstring sessionExt = L"";
if (*ext != '.') if (*ext != '.')
sessionExt += L"."; sessionExt += L".";
sessionExt += ext; sessionExt += ext;

View File

@ -283,7 +283,6 @@ BOOL Notepad_plus::notify(SCNotification *notification)
int iView = isFromPrimary?MAIN_VIEW:SUB_VIEW; int iView = isFromPrimary?MAIN_VIEW:SUB_VIEW;
if (buf->isDirty()) if (buf->isDirty())
{ {
wstring msg, title;
_nativeLangSpeaker.messageBox("CannotMoveDoc", _nativeLangSpeaker.messageBox("CannotMoveDoc",
_pPublicInterface->getHSelf(), _pPublicInterface->getHSelf(),
L"Document is modified, save it then try again.", L"Document is modified, save it then try again.",

View File

@ -2288,7 +2288,7 @@ void NppParameters::setWorkingDir(const wchar_t * newPath)
if (doesDirectoryExist(_nppGUI._defaultDirExp)) if (doesDirectoryExist(_nppGUI._defaultDirExp))
_currentDirectory = _nppGUI._defaultDirExp; _currentDirectory = _nppGUI._defaultDirExp;
else else
_currentDirectory = _nppPath.c_str(); _currentDirectory = _nppPath;
} }
} }

View File

@ -441,7 +441,7 @@ wstring Buffer::getFileTime(fileTimeType ftt) const
} }
void Buffer::setPosition(const Position & pos, ScintillaEditView * identifier) void Buffer::setPosition(const Position & pos, const ScintillaEditView * identifier)
{ {
int index = indexOfReference(identifier); int index = indexOfReference(identifier);
if (index == -1) if (index == -1)
@ -450,7 +450,7 @@ void Buffer::setPosition(const Position & pos, ScintillaEditView * identifier)
} }
Position& Buffer::getPosition(ScintillaEditView* identifier) Position& Buffer::getPosition(const ScintillaEditView* identifier)
{ {
int index = indexOfReference(identifier); int index = indexOfReference(identifier);
return _positions.at(index); return _positions.at(index);
@ -522,7 +522,7 @@ int Buffer::addReference(ScintillaEditView * identifier)
} }
int Buffer::removeReference(ScintillaEditView * identifier) int Buffer::removeReference(const ScintillaEditView * identifier)
{ {
int indexToPop = indexOfReference(identifier); int indexToPop = indexOfReference(identifier);
if (indexToPop == -1) if (indexToPop == -1)
@ -560,25 +560,25 @@ void Buffer::setDeferredReload() // triggers a reload on the next Document acces
bool Buffer::allowBraceMach() const bool Buffer::allowBraceMach() const
{ {
NppGUI& nppGui = NppParameters::getInstance().getNppGUI(); const NppGUI& nppGui = NppParameters::getInstance().getNppGUI();
return (!_isLargeFile || nppGui._largeFileRestriction._allowBraceMatch) || !nppGui._largeFileRestriction._isEnabled; return (!_isLargeFile || nppGui._largeFileRestriction._allowBraceMatch) || !nppGui._largeFileRestriction._isEnabled;
} }
bool Buffer::allowAutoCompletion() const bool Buffer::allowAutoCompletion() const
{ {
NppGUI& nppGui = NppParameters::getInstance().getNppGUI(); const NppGUI& nppGui = NppParameters::getInstance().getNppGUI();
return (!_isLargeFile || nppGui._largeFileRestriction._allowAutoCompletion) || !nppGui._largeFileRestriction._isEnabled; return (!_isLargeFile || nppGui._largeFileRestriction._allowAutoCompletion) || !nppGui._largeFileRestriction._isEnabled;
} }
bool Buffer::allowSmartHilite() const bool Buffer::allowSmartHilite() const
{ {
NppGUI& nppGui = NppParameters::getInstance().getNppGUI(); const NppGUI& nppGui = NppParameters::getInstance().getNppGUI();
return (!_isLargeFile || nppGui._largeFileRestriction._allowSmartHilite) || !nppGui._largeFileRestriction._isEnabled; return (!_isLargeFile || nppGui._largeFileRestriction._allowSmartHilite) || !nppGui._largeFileRestriction._isEnabled;
} }
bool Buffer::allowClickableLink() const bool Buffer::allowClickableLink() const
{ {
NppGUI& nppGui = NppParameters::getInstance().getNppGUI(); const NppGUI& nppGui = NppParameters::getInstance().getNppGUI();
return (!_isLargeFile || nppGui._largeFileRestriction._allowClickableLink) || !nppGui._largeFileRestriction._isEnabled; return (!_isLargeFile || nppGui._largeFileRestriction._allowClickableLink) || !nppGui._largeFileRestriction._isEnabled;
} }
@ -711,7 +711,7 @@ BufferID FileManager::loadFile(const wchar_t* filename, Document doc, int encodi
// * the auto-completion feature will be disabled for large files // * the auto-completion feature will be disabled for large files
// * the session snapshotsand periodic backups feature will be disabled for large files // * the session snapshotsand periodic backups feature will be disabled for large files
// * the backups on save feature will be disabled for large files // * the backups on save feature will be disabled for large files
NppGUI& nppGui = NppParameters::getInstance().getNppGUI(); const NppGUI& nppGui = NppParameters::getInstance().getNppGUI();
bool isLargeFile = false; bool isLargeFile = false;
if (nppGui._largeFileRestriction._isEnabled) if (nppGui._largeFileRestriction._isEnabled)
isLargeFile = fileSize >= nppGui._largeFileRestriction._largeFileSizeDefInByte; isLargeFile = fileSize >= nppGui._largeFileRestriction._largeFileSizeDefInByte;
@ -765,11 +765,11 @@ BufferID FileManager::loadFile(const wchar_t* filename, Document doc, int encodi
loadedFileFormat._eolFormat = EolType::unknown; loadedFileFormat._eolFormat = EolType::unknown;
loadedFileFormat._language = L_TEXT; loadedFileFormat._language = L_TEXT;
bool res = loadFileData(doc, fileSize, backupFileName ? backupFileName : fullpath, data, &UnicodeConvertor, loadedFileFormat); bool loadRes = loadFileData(doc, fileSize, backupFileName ? backupFileName : fullpath, data, &UnicodeConvertor, loadedFileFormat);
delete[] data; delete[] data;
if (res) if (loadRes)
{ {
Buffer* newBuf = new Buffer(this, _nextBufferID, doc, DOC_REGULAR, fullpath, isLargeFile); Buffer* newBuf = new Buffer(this, _nextBufferID, doc, DOC_REGULAR, fullpath, isLargeFile);
BufferID id = newBuf; BufferID id = newBuf;
@ -893,7 +893,7 @@ bool FileManager::reloadBufferDeferred(BufferID id)
bool FileManager::deleteFile(BufferID id) bool FileManager::deleteFile(BufferID id)
{ {
Buffer* buf = getBufferByID(id); const Buffer* buf = getBufferByID(id);
wstring fileNamePath = buf->getFullPathName(); wstring fileNamePath = buf->getFullPathName();
// Make sure to form a string with double '\0' terminator. // Make sure to form a string with double '\0' terminator.
@ -1014,7 +1014,7 @@ bool FileManager::backupCurrentBuffer()
const int temBufLen = 32; const int temBufLen = 32;
wchar_t tmpbuf[temBufLen]; wchar_t tmpbuf[temBufLen];
time_t ltime = time(0); time_t ltime = time(0);
struct tm* today = localtime(&ltime); const struct tm* today = localtime(&ltime);
if (!today) if (!today)
return false; return false;
@ -1574,7 +1574,7 @@ bool FileManager::loadFileData(Document doc, int64_t fileSize, const wchar_t * f
} }
else // x64 else // x64
{ {
NppGUI& nppGui = NppParameters::getInstance().getNppGUI(); const NppGUI& nppGui = NppParameters::getInstance().getNppGUI();
if (!nppGui._largeFileRestriction._suppress2GBWarning) if (!nppGui._largeFileRestriction._suppress2GBWarning)
{ {
int res = pNativeSpeaker->messageBox("WantToOpenHugeFile", int res = pNativeSpeaker->messageBox("WantToOpenHugeFile",
@ -1654,7 +1654,7 @@ bool FileManager::loadFileData(Document doc, int64_t fileSize, const wchar_t * f
if (isFirstTime) if (isFirstTime)
{ {
NppGUI& nppGui = NppParameters::getInstance().getNppGUI(); const NppGUI& nppGui = NppParameters::getInstance().getNppGUI();
// check if file contain any BOM // check if file contain any BOM
if (Utf8_16_Read::determineEncoding((unsigned char *)data, lenFile) != uni8Bit) if (Utf8_16_Read::determineEncoding((unsigned char *)data, lenFile) != uni8Bit)
@ -1831,7 +1831,7 @@ int FileManager::getFileNameFromBuffer(BufferID id, wchar_t * fn2copy)
if (getBufferIndexByID(id) == -1) if (getBufferIndexByID(id) == -1)
return -1; return -1;
Buffer* buf = getBufferByID(id); const Buffer* buf = getBufferByID(id);
if (fn2copy) if (fn2copy)
lstrcpy(fn2copy, buf->getFullPathName()); lstrcpy(fn2copy, buf->getFullPathName());

View File

@ -228,8 +228,8 @@ public:
void setDirty(bool dirty); void setDirty(bool dirty);
void setPosition(const Position & pos, ScintillaEditView * identifier); void setPosition(const Position & pos, const ScintillaEditView * identifier);
Position & getPosition(ScintillaEditView * identifier); Position & getPosition(const ScintillaEditView * identifier);
void setHeaderLineState(const std::vector<size_t> & folds, ScintillaEditView * identifier); void setHeaderLineState(const std::vector<size_t> & folds, ScintillaEditView * identifier);
const std::vector<size_t> & getHeaderLineState(const ScintillaEditView * identifier) const; const std::vector<size_t> & getHeaderLineState(const ScintillaEditView * identifier) const;
@ -268,7 +268,7 @@ public:
//these two return reference count after operation //these two return reference count after operation
int addReference(ScintillaEditView * identifier); //if ID not registered, creates a new Position for that ID and new foldstate int addReference(ScintillaEditView * identifier); //if ID not registered, creates a new Position for that ID and new foldstate
int removeReference(ScintillaEditView * identifier); //reduces reference. If zero, Document is purged int removeReference(const ScintillaEditView * identifier); //reduces reference. If zero, Document is purged
void setHideLineChanged(bool isHide, size_t location); void setHideLineChanged(bool isHide, size_t location);

View File

@ -404,7 +404,7 @@ void FunctionCallTip::showCalltip()
callTipText << L"\001" << _currentOverload + 1 << L" of " << _currentNbOverloads << L"\002"; callTipText << L"\001" << _currentOverload + 1 << L" of " << _currentNbOverloads << L"\002";
} }
callTipText << _retVals.at(_currentOverload) << TEXT(' ') << _funcName << TEXT(' ') << _start; callTipText << _retVals.at(_currentOverload) << ' ' << _funcName << ' ' << _start;
int highlightstart = 0; int highlightstart = 0;
int highlightend = 0; int highlightend = 0;
@ -418,7 +418,7 @@ void FunctionCallTip::showCalltip()
} }
callTipText << params.at(i); callTipText << params.at(i);
if (i < nbParams - 1) if (i < nbParams - 1)
callTipText << _param << TEXT(' '); callTipText << _param << ' ';
} }
callTipText << _stop; callTipText << _stop;

View File

@ -253,7 +253,7 @@ std::wstring getLocalizationPathFromParam(ParamVector & params)
if (!getParamVal('L', params, locStr)) if (!getParamVal('L', params, locStr))
return L""; return L"";
locStr = stringToLower(stringReplace(locStr, L"_", L"-")); // convert to lowercase format with "-" as separator locStr = stringToLower(stringReplace(locStr, L"_", L"-")); // convert to lowercase format with "-" as separator
return NppParameters::getLocPathFromStr(locStr.c_str()); return NppParameters::getLocPathFromStr(locStr);
} }
intptr_t getNumberFromParam(char paramName, ParamVector & params, bool & isParamePresent) intptr_t getNumberFromParam(char paramName, ParamVector & params, bool & isParamePresent)