From 0858dfa4afc4353653e9cf3fc47f8b23f18f48c2 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Thu, 4 Jul 2024 18:37:00 +0200 Subject: [PATCH] Use GetFileAttributes instead of PathFileExists Ref: https://github.com/notepad-plus-plus/nppShell/pull/64#discussion_r1664890166 Ref: https://devblogs.microsoft.com/oldnewthing/20071023-00/?p=24713 Fix #14839, close #15400 --- PowerEditor/src/MISC/Common/Common.cpp | 69 +++++++++------ PowerEditor/src/MISC/Common/Common.h | 7 ++ PowerEditor/src/MISC/Common/FileInterface.cpp | 6 +- .../MISC/PluginsManager/PluginsManager.cpp | 10 +-- PowerEditor/src/Notepad_plus.cpp | 22 ++--- PowerEditor/src/Notepad_plus_Window.cpp | 8 +- PowerEditor/src/NppBigSwitch.cpp | 6 +- PowerEditor/src/NppCommands.cpp | 18 ++-- PowerEditor/src/NppIO.cpp | 51 +++++------ PowerEditor/src/NppNotification.cpp | 2 +- PowerEditor/src/Parameters.cpp | 88 +++++++++---------- PowerEditor/src/ScintillaComponent/Buffer.cpp | 26 +++--- .../WinControls/FileBrowser/fileBrowser.cpp | 19 ++-- .../FunctionList/functionListPanel.cpp | 8 +- .../WinControls/PluginsAdmin/pluginsAdmin.cpp | 6 +- .../WinControls/Preference/preferenceDlg.cpp | 4 +- .../WinControls/ProjectPanel/ProjectPanel.cpp | 12 +-- .../src/WinControls/ToolBar/ToolBar.cpp | 4 +- PowerEditor/src/winmain.cpp | 2 +- 19 files changed, 196 insertions(+), 172 deletions(-) diff --git a/PowerEditor/src/MISC/Common/Common.cpp b/PowerEditor/src/MISC/Common/Common.cpp index 7e57d329c..1b99f5609 100644 --- a/PowerEditor/src/MISC/Common/Common.cpp +++ b/PowerEditor/src/MISC/Common/Common.cpp @@ -54,7 +54,7 @@ wstring commafyInt(size_t n) std::string getFileContent(const wchar_t *file2read) { - if (!::PathFileExists(file2read)) + if (!doesFileExist(file2read)) return ""; const size_t blockSize = 1024; @@ -1217,7 +1217,7 @@ bool isAssoCommandExisting(LPCTSTR FullPathName) { bool isAssoCommandExisting = false; - bool isFileExisting = PathFileExists(FullPathName) != FALSE; + bool isFileExisting = doesFileExist(FullPathName); if (isFileExisting) { @@ -1462,10 +1462,11 @@ HFONT createFont(const wchar_t* fontName, int fontSize, bool isBold, HWND hDestP bool removeReadOnlyFlagFromFileAttributes(const wchar_t* fileFullPath) { - if (!PathFileExists(fileFullPath)) + DWORD dwFileAttribs = ::GetFileAttributes(fileFullPath); + + if (dwFileAttribs == INVALID_FILE_ATTRIBUTES || (dwFileAttribs & FILE_ATTRIBUTE_DIRECTORY)) return false; - DWORD dwFileAttribs = ::GetFileAttributes(fileFullPath); dwFileAttribs &= ~FILE_ATTRIBUTE_READONLY; return (::SetFileAttributes(fileFullPath, dwFileAttribs) != FALSE); } @@ -1637,29 +1638,29 @@ Version::Version(const wstring& versionStr) void Version::setVersionFrom(const wstring& filePath) { - if (!filePath.empty() && ::PathFileExists(filePath.c_str())) + if (filePath.empty() || !doesFileExist(filePath.c_str())) + return; + + DWORD uselessArg = 0; // this variable is for passing the ignored argument to the functions + DWORD bufferSize = ::GetFileVersionInfoSize(filePath.c_str(), &uselessArg); + + if (bufferSize <= 0) + return; + + unsigned char* buffer = new unsigned char[bufferSize]; + ::GetFileVersionInfo(filePath.c_str(), 0, bufferSize, buffer); + + VS_FIXEDFILEINFO* lpFileInfo = nullptr; + UINT cbFileInfo = 0; + VerQueryValue(buffer, L"\\", reinterpret_cast(&lpFileInfo), &cbFileInfo); + if (cbFileInfo) { - DWORD uselessArg = 0; // this variable is for passing the ignored argument to the functions - DWORD bufferSize = ::GetFileVersionInfoSize(filePath.c_str(), &uselessArg); - - if (bufferSize <= 0) - return; - - unsigned char* buffer = new unsigned char[bufferSize]; - ::GetFileVersionInfo(filePath.c_str(), 0, bufferSize, buffer); - - VS_FIXEDFILEINFO* lpFileInfo = nullptr; - UINT cbFileInfo = 0; - VerQueryValue(buffer, L"\\", reinterpret_cast(&lpFileInfo), &cbFileInfo); - if (cbFileInfo) - { - _major = (lpFileInfo->dwFileVersionMS & 0xFFFF0000) >> 16; - _minor = lpFileInfo->dwFileVersionMS & 0x0000FFFF; - _patch = (lpFileInfo->dwFileVersionLS & 0xFFFF0000) >> 16; - _build = lpFileInfo->dwFileVersionLS & 0x0000FFFF; - } - delete[] buffer; + _major = (lpFileInfo->dwFileVersionMS & 0xFFFF0000) >> 16; + _minor = lpFileInfo->dwFileVersionMS & 0x0000FFFF; + _patch = (lpFileInfo->dwFileVersionLS & 0xFFFF0000) >> 16; + _build = lpFileInfo->dwFileVersionLS & 0x0000FFFF; } + delete[] buffer; } wstring Version::toString() @@ -1764,3 +1765,21 @@ bool Version::isCompatibleTo(const Version& from, const Version& to) const return false; } + +bool doesFileExist(const wchar_t* filePath) +{ + DWORD dwAttrib = ::GetFileAttributesW(filePath); + return (dwAttrib != INVALID_FILE_ATTRIBUTES && !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY)); +} + +bool doesDirectoryExist(const wchar_t* dirPath) +{ + DWORD dwAttrib = ::GetFileAttributesW(dirPath); + return (dwAttrib != INVALID_FILE_ATTRIBUTES && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY)); +} + +bool doesPathExist(const wchar_t* path) +{ + DWORD dwAttrib = ::GetFileAttributesW(path); + return (dwAttrib != INVALID_FILE_ATTRIBUTES); +} diff --git a/PowerEditor/src/MISC/Common/Common.h b/PowerEditor/src/MISC/Common/Common.h index 97f0c90d0..50468815d 100644 --- a/PowerEditor/src/MISC/Common/Common.h +++ b/PowerEditor/src/MISC/Common/Common.h @@ -13,6 +13,7 @@ // // You should have received a copy of the GNU General Public License // along with this program. If not, see . + #pragma once #include #include @@ -24,6 +25,8 @@ #include #include +#pragma deprecated(PathFileExists) // Use doesFileExist, doesDirectoryExist or doesPathExist (for file or directory) instead. + const bool dirUp = true; const bool dirDown = false; @@ -278,3 +281,7 @@ private: unsigned long _patch = 0; unsigned long _build = 0; }; + +bool doesFileExist(const wchar_t* filePath); +bool doesDirectoryExist(const wchar_t* dirPath); +bool doesPathExist(const wchar_t* path); \ No newline at end of file diff --git a/PowerEditor/src/MISC/Common/FileInterface.cpp b/PowerEditor/src/MISC/Common/FileInterface.cpp index 86a4ea4e1..b76c81709 100644 --- a/PowerEditor/src/MISC/Common/FileInterface.cpp +++ b/PowerEditor/src/MISC/Common/FileInterface.cpp @@ -32,8 +32,8 @@ Win32_IO_File::Win32_IO_File(const wchar_t *fname) WIN32_FILE_ATTRIBUTE_DATA attributes_original{}; DWORD dispParam = CREATE_ALWAYS; - BOOL doesFileExist = ::PathFileExistsW(fname); - if (doesFileExist) + bool fileExists = doesFileExist(fname); + if (fileExists) { // Store the file creation date & attributes for a possible use later... ::GetFileAttributesExW(fname, GetFileExInfoStandard, &attributes_original); @@ -59,7 +59,7 @@ Win32_IO_File::Win32_IO_File(const wchar_t *fname) _hFile = ::CreateFileW(fname, _accessParam, _shareParam, NULL, dispParam, _attribParam, NULL); } - if (doesFileExist && (dispParam == CREATE_ALWAYS) && (_hFile != INVALID_HANDLE_VALUE)) + if (fileExists && (dispParam == CREATE_ALWAYS) && (_hFile != INVALID_HANDLE_VALUE)) { // restore back the original creation date & attributes ::SetFileTime(_hFile, &(attributes_original.ftCreationTime), NULL, NULL); diff --git a/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp b/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp index 755b076f0..ca6f8b7d3 100644 --- a/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp +++ b/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp @@ -239,16 +239,16 @@ int PluginsManager::loadPluginFromPath(const wchar_t *pluginFilePath) PathRemoveExtension(xmlPath); PathAddExtension(xmlPath, L".xml"); - if (!PathFileExists(xmlPath)) + if (!doesFileExist(xmlPath)) { lstrcpyn(xmlPath, L"\0", MAX_PATH ); - wcscpy_s(xmlPath, nppParams.getAppDataNppDir() ); + wcscpy_s(xmlPath, nppParams.getAppDataNppDir()); PathAppend(xmlPath, L"plugins\\Config"); PathAppend(xmlPath, pi->_moduleName.c_str()); - PathRemoveExtension( xmlPath ); - PathAddExtension( xmlPath, L".xml" ); + PathRemoveExtension(xmlPath); + PathAddExtension(xmlPath, L".xml"); - if (! PathFileExists( xmlPath ) ) + if (!doesFileExist(xmlPath)) { throw wstring(wstring(xmlPath) + L" is missing."); } diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 0c662d93a..5e16f9339 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -598,7 +598,7 @@ LRESULT Notepad_plus::init(HWND hwnd) for (int i = 0; i < nbLRFile; ++i) { wstring * stdStr = nppParam.getLRFile(i); - if (!nppGUI._checkHistoryFiles || PathFileExists(stdStr->c_str())) + if (!nppGUI._checkHistoryFiles || doesFileExist(stdStr->c_str())) { _lastRecentFileList.add(stdStr->c_str()); } @@ -1876,7 +1876,7 @@ void Notepad_plus::getMatchedFileNames(const wchar_t *dir, size_t level, const v bool Notepad_plus::createFilelistForFiles(vector & fileNames) { const wchar_t *dir2Search = _findReplaceDlg.getDir2Search(); - if (!dir2Search[0] || !::PathFileExists(dir2Search)) + if (!dir2Search[0] || !doesDirectoryExist(dir2Search)) { return false; } @@ -2579,7 +2579,7 @@ void Notepad_plus::checkDocState() bool isCurrentDirty = curBuf->isDirty(); bool isSeveralDirty = isCurrentDirty; - bool isFileExisting = PathFileExists(curBuf->getFullPathName()) != FALSE; + bool isFileExisting = doesFileExist(curBuf->getFullPathName()); if (!isCurrentDirty) { for (size_t i = 0; i < MainFileManager.getNbBuffers(); ++i) @@ -6298,7 +6298,7 @@ void Notepad_plus::getCurrentOpenedFiles(Session & session, bool includUntitledD continue; if (!includUntitledDoc) - if (!PathFileExists(buf->getFullPathName())) + if (!doesFileExist(buf->getFullPathName())) continue; @@ -6947,7 +6947,7 @@ vector Notepad_plus::addNppComponents(const wchar_t *destDir, const wch wstring destDirName = (NppParameters::getInstance()).getNppPath(); pathAppend(destDirName, destDir); - if (!::PathFileExists(destDirName.c_str())) + if (!doesDirectoryExist(destDirName.c_str())) { ::CreateDirectory(destDirName.c_str(), NULL); } @@ -6957,7 +6957,7 @@ vector Notepad_plus::addNppComponents(const wchar_t *destDir, const wch size_t sz = fns.size(); for (size_t i = 0 ; i < sz ; ++i) { - if (::PathFileExists(fns.at(i).c_str())) + if (doesFileExist(fns.at(i).c_str())) { // copy to plugins directory wstring destName = destDirName; @@ -6983,7 +6983,7 @@ vector Notepad_plus::addNppPlugins(const wchar_t *extFilterName, const // Get plugins dir wstring destDirName = (NppParameters::getInstance()).getPluginRootDir(); - if (!::PathFileExists(destDirName.c_str())) + if (!doesDirectoryExist(destDirName.c_str())) { ::CreateDirectory(destDirName.c_str(), NULL); } @@ -6991,7 +6991,7 @@ vector Notepad_plus::addNppPlugins(const wchar_t *extFilterName, const size_t sz = fns.size(); for (size_t i = 0 ; i < sz ; ++i) { - if (::PathFileExists(fns.at(i).c_str())) + if (doesFileExist(fns.at(i).c_str())) { // copy to plugins directory wstring destName = destDirName; @@ -7003,7 +7003,7 @@ vector Notepad_plus::addNppPlugins(const wchar_t *extFilterName, const wstring name = nameExt.substr(0, pos); pathAppend(destName, name); - if (!::PathFileExists(destName.c_str())) + if (!doesDirectoryExist(destName.c_str())) { ::CreateDirectory(destName.c_str(), NULL); } @@ -8518,7 +8518,7 @@ void Notepad_plus::refreshDarkMode(bool resetStyle) pathAppend(themePath, xmlFileName); } - if (::PathFileExists(themePath.c_str()) == FALSE || themePath.empty()) + if (themePath.empty() || !doesFileExist(themePath.c_str())) { themePath = themeSwitcher.getThemeDirPath(); pathAppend(themePath, xmlFileName); @@ -8535,7 +8535,7 @@ void Notepad_plus::refreshDarkMode(bool resetStyle) themeName = themeSwitcher.getDefaultThemeLabel(); } - if (::PathFileExists(themePath.c_str()) == TRUE) + if (doesFileExist(themePath.c_str())) { nppParams.getNppGUI()._themeName = themePath; diff --git a/PowerEditor/src/Notepad_plus_Window.cpp b/PowerEditor/src/Notepad_plus_Window.cpp index 32538318a..79b2f5423 100644 --- a/PowerEditor/src/Notepad_plus_Window.cpp +++ b/PowerEditor/src/Notepad_plus_Window.cpp @@ -246,7 +246,7 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const wchar_t *cmdL { wstring appDataThemePath = appDataThemeDir; - if (!::PathFileExists(appDataThemePath.c_str())) + if (!doesDirectoryExist(appDataThemePath.c_str())) { ::CreateDirectory(appDataThemePath.c_str(), NULL); } @@ -271,7 +271,7 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const wchar_t *cmdL pathAppend(themePath, xmlFileName); } - if (::PathFileExists(themePath.c_str()) == FALSE || themePath.empty()) + if (themePath.empty() || !doesFileExist(themePath.c_str())) { themePath = themeSwitcher.getThemeDirPath(); pathAppend(themePath, xmlFileName); @@ -283,7 +283,7 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const wchar_t *cmdL themePath = themeInfo.second; } - if (::PathFileExists(themePath.c_str()) == TRUE) + if (doesFileExist(themePath.c_str())) { nppGUI._themeName.assign(themePath); nppParams.reloadStylers(themePath.c_str()); @@ -362,7 +362,7 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const wchar_t *cmdL } else if (cmdLineParams->_quoteType == 2) // content drom file { - if (::PathFileExists(cmdLineParams->_easterEggName.c_str())) + if (doesFileExist(cmdLineParams->_easterEggName.c_str())) { std::string content = getFileContent(cmdLineParams->_easterEggName.c_str()); WcharMbcsConvertor& wmc = WcharMbcsConvertor::getInstance(); diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index e73f5a910..5e0cdaee8 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -2168,11 +2168,11 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa // Then ReadDirectoryChanges does not detect the change. // Fortunately, notification is sent if right click or double click happens on that file // Let's leverage this as workaround to enhance npp file monitoring functionality. - // So calling "PathFileExists" is a workaround here. + // So calling "doesFileExist" is a workaround here. Buffer* currBuf = getCurrentBuffer(); if (currBuf && currBuf->isMonitoringOn()) - ::PathFileExists(currBuf->getFullPathName()); + doesFileExist(currBuf->getFullPathName()); const NppGUI & nppgui = nppParam.getNppGUI(); if (nppgui._fileAutoDetection != cdDisabled) @@ -2762,7 +2762,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa // saving session.xml into loaded session if a saved session is loaded and saveLoadedSessionOnExit option is enabled // wstring loadedSessionFilePath = nppParam.getLoadedSessionFilePath(); - if (!loadedSessionFilePath.empty() && PathFileExists(loadedSessionFilePath.c_str())) + if (!loadedSessionFilePath.empty() && doesFileExist(loadedSessionFilePath.c_str())) nppParam.writeSession(currentSession, loadedSessionFilePath.c_str()); } diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index 26da4ff4f..45890ea97 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -586,8 +586,8 @@ void Notepad_plus::command(int id) ::SendMessage(hwnd, NPPM_GETNPPFULLFILEPATH, CURRENTWORD_MAXLENGTH, reinterpret_cast(cmd2Exec)); } - // Full file path - if (::PathFileExists(curentWord)) + // Full file path: could be a folder or a file + if (doesPathExist(curentWord)) { wstring fullFilePath = id == IDM_EDIT_OPENINFOLDER ? L"/select," : L""; fullFilePath += L"\""; @@ -598,7 +598,7 @@ void Notepad_plus::command(int id) (id == IDM_EDIT_OPENASFILE && !::PathIsDirectory(curentWord))) ::ShellExecute(hwnd, L"open", cmd2Exec, fullFilePath.c_str(), L".", SW_SHOW); } - else // Full file path - need concatenate with current full file path + else // Relative file path - need concatenate with current full file path { wchar_t currentDir[CURRENTWORD_MAXLENGTH] = { '\0' }; ::SendMessage(hwnd, NPPM_GETCURRENTDIRECTORY, CURRENTWORD_MAXLENGTH, reinterpret_cast(currentDir)); @@ -609,8 +609,8 @@ void Notepad_plus::command(int id) fullFilePath += L"\\"; fullFilePath += curentWord; - if ((id == IDM_EDIT_OPENASFILE && - (!::PathFileExists(fullFilePath.c_str() + 1) || ::PathIsDirectory(fullFilePath.c_str() + 1)))) + if ((id == IDM_EDIT_OPENASFILE && + (!doesFileExist(fullFilePath.c_str() + 1)))) // + 1 for skipping the 1st char '"' { _nativeLangSpeaker.messageBox("FilePathNotFoundWarning", _pPublicInterface->getHSelf(), @@ -619,6 +619,8 @@ void Notepad_plus::command(int id) MB_OK | MB_APPLMODAL); return; } + // else id == IDM_EDIT_OPENINFOLDER - do it anyway. (even the last part does not exist, it doesn't matter) + fullFilePath += L"\""; ::ShellExecute(hwnd, L"open", cmd2Exec, fullFilePath.c_str(), L".", SW_SHOW); } @@ -2769,7 +2771,7 @@ void Notepad_plus::command(int id) else { const wchar_t *longFileName = curBuf->getFullPathName(); - if (::PathFileExists(longFileName)) + if (doesFileExist(longFileName)) { if (curBuf->isDirty()) { @@ -3577,7 +3579,7 @@ void Notepad_plus::command(int id) { wstring noEasterEggsPath((NppParameters::getInstance()).getNppPath()); noEasterEggsPath.append(L"\\noEasterEggs.xml"); - if (!::PathFileExists(noEasterEggsPath.c_str())) + if (!doesFileExist(noEasterEggsPath.c_str())) showAllQuotes(); return; } @@ -3585,7 +3587,7 @@ void Notepad_plus::command(int id) { wstring noEasterEggsPath((NppParameters::getInstance()).getNppPath()); noEasterEggsPath.append(L"\\noEasterEggs.xml"); - if (!::PathFileExists(noEasterEggsPath.c_str())) + if (!doesFileExist(noEasterEggsPath.c_str())) showQuoteFromIndex(iQuote); return; } diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index 019f17147..3bb3d3eda 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -255,8 +255,8 @@ BufferID Notepad_plus::doOpen(const wstring& fileName, bool isRecursive, bool is } } - bool isSnapshotMode = backupFileName != NULL && PathFileExists(backupFileName); - if (isSnapshotMode && !PathFileExists(longFileName)) // UNTITLED + bool isSnapshotMode = backupFileName != NULL && doesFileExist(backupFileName); + if (isSnapshotMode && !doesFileExist(longFileName)) // UNTITLED { wcscpy_s(longFileName, targetFileName.c_str()); } @@ -297,13 +297,13 @@ BufferID Notepad_plus::doOpen(const wstring& fileName, bool isRecursive, bool is return foundBufID; } - if (isFileSession(longFileName) && PathFileExists(longFileName)) + if (isFileSession(longFileName) && doesFileExist(longFileName)) { fileLoadSession(longFileName); return BUFFER_INVALID; } - if (isFileWorkspace(longFileName) && PathFileExists(longFileName)) + if (isFileWorkspace(longFileName) && doesFileExist(longFileName)) { nppParam.setWorkSpaceFilePath(0, longFileName); // This line switches to Project Panel 1 while starting up Npp @@ -313,7 +313,7 @@ BufferID Notepad_plus::doOpen(const wstring& fileName, bool isRecursive, bool is } bool isWow64Off = false; - if (!PathFileExists(longFileName)) + if (!doesFileExist(longFileName)) { nppParam.safeWow64EnableWow64FsRedirection(FALSE); isWow64Off = true; @@ -327,13 +327,13 @@ BufferID Notepad_plus::doOpen(const wstring& fileName, bool isRecursive, bool is if (!isSnapshotMode) // if not backup mode, or backupfile path is invalid { - if (!PathFileExists(longFileName) && !globbing) + if (!doesFileExist(longFileName) && !globbing) { wstring longFileDir(longFileName); PathRemoveFileSpec(longFileDir); bool isCreateFileSuccessful = false; - if (PathFileExists(longFileDir.c_str())) + if (doesDirectoryExist(longFileDir.c_str())) { int res = _nativeLangSpeaker.messageBox("CreateNewFileOrNot", _pPublicInterface->getHSelf(), @@ -414,7 +414,7 @@ BufferID Notepad_plus::doOpen(const wstring& fileName, bool isRecursive, bool is if (buffer != BUFFER_INVALID) { - isSnapshotMode = (backupFileName != NULL && ::PathFileExists(backupFileName)); + isSnapshotMode = (backupFileName != NULL && doesFileExist(backupFileName)); if (isSnapshotMode) { // To notify plugins that a snapshot dirty file is loaded on startup @@ -792,13 +792,13 @@ void Notepad_plus::doClose(BufferID id, int whichOne, bool doDeleteBackup) bool isWow64Off = false; NppParameters& nppParam = NppParameters::getInstance(); const wchar_t *fn = buf->getFullPathName(); - if (!PathFileExists(fn)) + if (!doesFileExist(fn)) { nppParam.safeWow64EnableWow64FsRedirection(FALSE); isWow64Off = true; } - if (PathFileExists(buf->getFullPathName())) + if (doesFileExist(buf->getFullPathName())) fileFullPath = buf->getFullPathName(); // We enable Wow64 system, if it was disabled @@ -1076,7 +1076,7 @@ bool Notepad_plus::fileCloseAll(bool doDeleteBackup, bool isSnapshotMode) { if (isSnapshotMode) { - if (buf->getBackupFileName() == L"" || !::PathFileExists(buf->getBackupFileName().c_str())) //backup file has been deleted from outside + if (buf->getBackupFileName() == L"" || !doesFileExist(buf->getBackupFileName().c_str())) //backup file has been deleted from outside { // warning user and save it if user want it. activateBuffer(id, MAIN_VIEW); @@ -1160,7 +1160,7 @@ bool Notepad_plus::fileCloseAll(bool doDeleteBackup, bool isSnapshotMode) { if (isSnapshotMode) { - if (buf->getBackupFileName() == L"" || !::PathFileExists(buf->getBackupFileName().c_str())) //backup file has been deleted from outside + if (buf->getBackupFileName() == L"" || !doesFileExist(buf->getBackupFileName().c_str())) //backup file has been deleted from outside { // warning user and save it if user want it. activateBuffer(id, SUB_VIEW); @@ -1628,7 +1628,7 @@ bool Notepad_plus::fileSave(BufferID id) fn_bak = fn_bak_expanded; // Make sure the directory exists - if (!::PathFileExists(fn_bak.c_str())) + if (!doesDirectoryExist(fn_bak.c_str())) { SHCreateDirectory(NULL, fn_bak.c_str()); } @@ -1895,7 +1895,7 @@ bool Notepad_plus::fileRename(BufferID id) scnN.nmhdr.idFrom = (uptr_t)bufferID; bool success = false; - bool isFileExisting = PathFileExists(buf->getFullPathName()) != FALSE; + bool isFileExisting = doesFileExist(buf->getFullPathName()); if (isFileExisting) { CustomFileDialog fDlg(_pPublicInterface->getHSelf()); @@ -1998,7 +1998,7 @@ bool Notepad_plus::fileRenameUntitled(BufferID id, const wchar_t* tabNewName) } Buffer* buf = MainFileManager.getBufferByID(bufferID); - bool isFileExisting = PathFileExists(buf->getFullPathName()) != FALSE; + bool isFileExisting = doesFileExist(buf->getFullPathName()); if (isFileExisting) return false; // We are just going to rename the tab nothing else @@ -2249,19 +2249,20 @@ bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode, const wch } bool isWow64Off = false; - if (!PathFileExists(pFn)) + if (!doesFileExist(pFn)) { nppParam.safeWow64EnableWow64FsRedirection(FALSE); isWow64Off = true; } - if (PathFileExists(pFn)) + + if (doesFileExist(pFn)) { if (isSnapshotMode && !session._mainViewFiles[i]._backupFilePath.empty()) lastOpened = doOpen(pFn, false, false, session._mainViewFiles[i]._encoding, session._mainViewFiles[i]._backupFilePath.c_str(), session._mainViewFiles[i]._originalFileLastModifTimestamp); else lastOpened = doOpen(pFn, false, false, session._mainViewFiles[i]._encoding); } - else if (isSnapshotMode && PathFileExists(session._mainViewFiles[i]._backupFilePath.c_str())) + else if (isSnapshotMode && doesFileExist(session._mainViewFiles[i]._backupFilePath.c_str())) { lastOpened = doOpen(pFn, false, false, session._mainViewFiles[i]._encoding, session._mainViewFiles[i]._backupFilePath.c_str(), session._mainViewFiles[i]._originalFileLastModifTimestamp); } @@ -2327,7 +2328,7 @@ bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode, const wch buf->setUserReadOnly(session._mainViewFiles[i]._isUserReadOnly); - if (isSnapshotMode && !session._mainViewFiles[i]._backupFilePath.empty() && PathFileExists(session._mainViewFiles[i]._backupFilePath.c_str())) + if (isSnapshotMode && !session._mainViewFiles[i]._backupFilePath.empty() && doesFileExist(session._mainViewFiles[i]._backupFilePath.c_str())) buf->setDirty(true); buf->setRTL(session._mainViewFiles[i]._isRTL); @@ -2378,13 +2379,13 @@ bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode, const wch } bool isWow64Off = false; - if (!PathFileExists(pFn)) + if (!doesFileExist(pFn)) { nppParam.safeWow64EnableWow64FsRedirection(FALSE); isWow64Off = true; } - if (PathFileExists(pFn)) + if (doesFileExist(pFn)) { //check if already open in main. If so, clone BufferID clonedBuf = _mainDocTab.findBufferByName(pFn); @@ -2401,7 +2402,7 @@ bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode, const wch lastOpened = doOpen(pFn, false, false, session._subViewFiles[k]._encoding); } } - else if (isSnapshotMode && PathFileExists(session._subViewFiles[k]._backupFilePath.c_str())) + else if (isSnapshotMode && doesFileExist(session._subViewFiles[k]._backupFilePath.c_str())) { lastOpened = doOpen(pFn, false, false, session._subViewFiles[k]._encoding, session._subViewFiles[k]._backupFilePath.c_str(), session._subViewFiles[k]._originalFileLastModifTimestamp); } @@ -2458,7 +2459,7 @@ bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode, const wch buf->setEncoding(session._subViewFiles[k]._encoding); buf->setUserReadOnly(session._subViewFiles[k]._isUserReadOnly); - if (isSnapshotMode && !session._subViewFiles[k]._backupFilePath.empty() && PathFileExists(session._subViewFiles[k]._backupFilePath.c_str())) + if (isSnapshotMode && !session._subViewFiles[k]._backupFilePath.empty() && doesFileExist(session._subViewFiles[k]._backupFilePath.c_str())) buf->setDirty(true); buf->setRTL(session._subViewFiles[k]._isRTL); @@ -2569,7 +2570,7 @@ bool Notepad_plus::fileLoadSession(const wchar_t *fn) } else { - if (PathFileExists(fn)) + if (doesFileExist(fn)) sessionFileName = fn; } @@ -2623,7 +2624,7 @@ const wchar_t * Notepad_plus::fileSaveSession(size_t nbFile, wchar_t ** fileName { for (size_t i = 0 ; i < nbFile ; ++i) { - if (PathFileExists(fileNames[i])) + if (doesFileExist(fileNames[i])) currentSession._mainViewFiles.push_back(wstring(fileNames[i])); } } diff --git a/PowerEditor/src/NppNotification.cpp b/PowerEditor/src/NppNotification.cpp index 2af2736f3..066a23c97 100644 --- a/PowerEditor/src/NppNotification.cpp +++ b/PowerEditor/src/NppNotification.cpp @@ -594,7 +594,7 @@ BOOL Notepad_plus::notify(SCNotification *notification) if (isInaccessible) _tabPopupMenu.enableItem(IDM_EDIT_CLEARREADONLY, false); - bool isFileExisting = PathFileExists(buf->getFullPathName()) != FALSE; + bool isFileExisting = doesFileExist(buf->getFullPathName()); _tabPopupMenu.enableItem(IDM_FILE_DELETE, isFileExisting); _tabPopupMenu.enableItem(IDM_FILE_RELOAD, isFileExisting); _tabPopupMenu.enableItem(IDM_FILE_OPEN_FOLDER, isFileExisting); diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index e73920c56..c69aef04a 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -1008,7 +1008,7 @@ NppParameters::NppParameters() std::wstring notepadStylePath(_nppPath); pathAppend(notepadStylePath, notepadStyleFile); - _asNotepadStyle = (PathFileExists(notepadStylePath.c_str()) == TRUE); + _asNotepadStyle = (doesFileExist(notepadStylePath.c_str()) == TRUE); //Load initial accelerator key definitions initMenuKeys(); @@ -1079,11 +1079,11 @@ bool NppParameters::reloadLang() std::wstring nativeLangPath(_localizationSwitcher._nativeLangPath); // if "nativeLang.xml" does not exist, use npp path - if (!PathFileExists(nativeLangPath.c_str())) + if (!doesFileExist(nativeLangPath.c_str())) { nativeLangPath = _nppPath; pathAppend(nativeLangPath, std::wstring(L"nativeLang.xml")); - if (!PathFileExists(nativeLangPath.c_str())) + if (!doesFileExist(nativeLangPath.c_str())) return false; } @@ -1142,7 +1142,7 @@ bool NppParameters::load() pathAppend(localConfPath, localConfFile); // Test if localConf.xml exist - _isLocal = (PathFileExists(localConfPath.c_str()) == TRUE); + _isLocal = (doesFileExist(localConfPath.c_str()) == TRUE); // Under vista and windows 7, the usage of doLocalConf.xml is not allowed // if Notepad++ is installed in "program files" directory, because of UAC @@ -1179,15 +1179,15 @@ bool NppParameters::load() _userPath = getSpecialFolderLocation(CSIDL_APPDATA); pathAppend(_userPath, L"Notepad++"); - if (!PathFileExists(_userPath.c_str())) + if (!doesDirectoryExist(_userPath.c_str())) ::CreateDirectory(_userPath.c_str(), NULL); _appdataNppDir = _userPluginConfDir = _userPath; pathAppend(_userPluginConfDir, L"plugins"); - if (!PathFileExists(_userPluginConfDir.c_str())) + if (!doesDirectoryExist(_userPluginConfDir.c_str())) ::CreateDirectory(_userPluginConfDir.c_str(), NULL); pathAppend(_userPluginConfDir, L"Config"); - if (!PathFileExists(_userPluginConfDir.c_str())) + if (!doesDirectoryExist(_userPluginConfDir.c_str())) ::CreateDirectory(_userPluginConfDir.c_str(), NULL); // For PluginAdmin to launch the wingup with UAC @@ -1197,9 +1197,9 @@ bool NppParameters::load() _pluginConfDir = _pluginRootDir; // for plugin list home pathAppend(_pluginConfDir, L"Config"); - if (!PathFileExists(nppPluginRootParent.c_str())) + if (!doesDirectoryExist(nppPluginRootParent.c_str())) ::CreateDirectory(nppPluginRootParent.c_str(), NULL); - if (!PathFileExists(_pluginRootDir.c_str())) + if (!doesDirectoryExist(_pluginRootDir.c_str())) ::CreateDirectory(_pluginRootDir.c_str(), NULL); _sessionPath = _userPath; // Session stock the absolute file path, it should never be on cloud @@ -1211,7 +1211,7 @@ bool NppParameters::load() // // the 2nd priority: cloud Choice Path // - _isCloud = (::PathFileExists(cloudChoicePath.c_str()) == TRUE); + _isCloud = doesFileExist(cloudChoicePath.c_str()); if (_isCloud) { // Read cloud choice @@ -1219,7 +1219,7 @@ bool NppParameters::load() WcharMbcsConvertor& wmc = WcharMbcsConvertor::getInstance(); std::wstring cloudChoiceStrW = wmc.char2wchar(cloudChoiceStr.c_str(), SC_CP_UTF8); - if (!cloudChoiceStrW.empty() && ::PathFileExists(cloudChoiceStrW.c_str())) + if (!cloudChoiceStrW.empty() && doesDirectoryExist(cloudChoiceStrW.c_str())) { _userPath = cloudChoiceStrW; _nppGUI._cloudPath = cloudChoiceStrW; @@ -1259,7 +1259,7 @@ bool NppParameters::load() pathAppend(langs_xml_path, L"langs.xml"); BOOL doRecover = FALSE; - if (::PathFileExists(langs_xml_path.c_str())) + if (doesFileExist(langs_xml_path.c_str())) { WIN32_FILE_ATTRIBUTE_DATA attributes{}; @@ -1327,7 +1327,7 @@ bool NppParameters::load() std::wstring srcConfigPath(_nppPath); pathAppend(srcConfigPath, L"config.model.xml"); - if (!::PathFileExists(configPath.c_str())) + if (!doesFileExist(configPath.c_str())) ::CopyFile(srcConfigPath.c_str(), configPath.c_str(), FALSE); _pXmlUserDoc = new TiXmlDocument(configPath); @@ -1350,7 +1350,7 @@ bool NppParameters::load() _stylerPath = _userPath; pathAppend(_stylerPath, L"stylers.xml"); - if (!PathFileExists(_stylerPath.c_str())) + if (!doesFileExist(_stylerPath.c_str())) { std::wstring srcStylersPath(_nppPath); pathAppend(srcStylersPath, L"stylers.model.xml"); @@ -1358,7 +1358,7 @@ bool NppParameters::load() ::CopyFile(srcStylersPath.c_str(), _stylerPath.c_str(), TRUE); } - if (_nppGUI._themeName.empty() || (!PathFileExists(_nppGUI._themeName.c_str()))) + if (_nppGUI._themeName.empty() || (!doesFileExist(_nppGUI._themeName.c_str()))) _nppGUI._themeName.assign(_stylerPath); _pXmlUserStylerDoc = new TiXmlDocument(_nppGUI._themeName.c_str()); @@ -1454,7 +1454,7 @@ bool NppParameters::load() } else // use %appdata% location, or (if absence then) npp installed location { - if (!PathFileExists(nativeLangPath.c_str())) + if (!doesFileExist(nativeLangPath.c_str())) { nativeLangPath = _nppPath; pathAppend(nativeLangPath, L"nativeLang.xml"); @@ -1495,7 +1495,7 @@ bool NppParameters::load() pathAppend(_shortcutsPath, SHORTCUTSXML_FILENAME); pathAppend(v852NoNeedShortcutsBackup, NONEEDSHORTCUTSXMLBACKUP_FILENAME); - if (!PathFileExists(_shortcutsPath.c_str())) + if (!doesFileExist(_shortcutsPath.c_str())) { std::wstring srcShortcutsPath(_nppPath); pathAppend(srcShortcutsPath, SHORTCUTSXML_FILENAME); @@ -1533,7 +1533,7 @@ bool NppParameters::load() _contextMenuPath = _userPath; pathAppend(_contextMenuPath, L"contextMenu.xml"); - if (!PathFileExists(_contextMenuPath.c_str())) + if (!doesFileExist(_contextMenuPath.c_str())) { std::wstring srcContextMenuPath(_nppPath); pathAppend(srcContextMenuPath, L"contextMenu.xml"); @@ -1586,10 +1586,10 @@ bool NppParameters::load() { wstring sessionInCaseOfCorruption_bak = _sessionPath; sessionInCaseOfCorruption_bak += SESSION_BACKUP_EXT; - if (::PathFileExists(sessionInCaseOfCorruption_bak.c_str())) + if (doesFileExist(sessionInCaseOfCorruption_bak.c_str())) { BOOL bFileSwapOk = false; - if (::PathFileExists(_sessionPath.c_str())) + if (doesFileExist(_sessionPath.c_str())) { // an invalid session.xml file exists bFileSwapOk = ::ReplaceFile(_sessionPath.c_str(), sessionInCaseOfCorruption_bak.c_str(), nullptr, @@ -1637,7 +1637,7 @@ bool NppParameters::load() std::wstring enableSelectFgColorPath = _userPath; pathAppend(enableSelectFgColorPath, L"enableSelectFgColor.xml"); - if (PathFileExists(enableSelectFgColorPath.c_str())) + if (doesFileExist(enableSelectFgColorPath.c_str())) { _isSelectFgColorEnabled = true; } @@ -1653,12 +1653,12 @@ bool NppParameters::load() issueFileName = nppLogNetworkDriveIssue; issueFileName += L".xml"; pathAppend(filePath, issueFileName); - _doNppLogNetworkDriveIssue = (PathFileExists(filePath.c_str()) == TRUE); + _doNppLogNetworkDriveIssue = doesFileExist(filePath.c_str()); if (!_doNppLogNetworkDriveIssue) { filePath2 = _userPath; pathAppend(filePath2, issueFileName); - _doNppLogNetworkDriveIssue = (PathFileExists(filePath2.c_str()) == TRUE); + _doNppLogNetworkDriveIssue = doesFileExist(filePath2.c_str()); } //-------------------------------------------------------------// @@ -1670,12 +1670,12 @@ bool NppParameters::load() issueFileName = nppLogNulContentCorruptionIssue; issueFileName += L".xml"; pathAppend(filePath, issueFileName); - _doNppLogNulContentCorruptionIssue = (PathFileExists(filePath.c_str()) == TRUE); + _doNppLogNulContentCorruptionIssue = doesFileExist(filePath.c_str()); if (!_doNppLogNulContentCorruptionIssue) { filePath2 = _userPath; pathAppend(filePath2, issueFileName); - _doNppLogNulContentCorruptionIssue = (PathFileExists(filePath2.c_str()) == TRUE); + _doNppLogNulContentCorruptionIssue = doesFileExist(filePath2.c_str()); } //-------------------------------------------------------------// @@ -1687,12 +1687,12 @@ bool NppParameters::load() filePath = _nppPath; std::wstring noRegForOSAppRestartTrigger = L"noRestartAutomatically.xml"; pathAppend(filePath, noRegForOSAppRestartTrigger); - _isRegForOSAppRestartDisabled = (::PathFileExists(filePath.c_str()) == TRUE); + _isRegForOSAppRestartDisabled = doesFileExist(filePath.c_str()); if (!_isRegForOSAppRestartDisabled) { filePath = _userPath; pathAppend(filePath, noRegForOSAppRestartTrigger); - _isRegForOSAppRestartDisabled = (::PathFileExists(filePath.c_str()) == TRUE); + _isRegForOSAppRestartDisabled = doesFileExist(filePath.c_str()); } return isAllLoaded; @@ -2285,7 +2285,7 @@ void NppParameters::setWorkingDir(const wchar_t * newPath) } else { - if (PathFileExists(_nppGUI._defaultDirExp)) + if (doesDirectoryExist(_nppGUI._defaultDirExp)) _currentDirectory = _nppGUI._defaultDirExp; else _currentDirectory = _nppPath.c_str(); @@ -3246,7 +3246,7 @@ void NppParameters::setCloudChoice(const wchar_t *pathChoice) std::wstring cloudChoicePath = getSettingsFolder(); cloudChoicePath += L"\\cloud\\"; - if (!PathFileExists(cloudChoicePath.c_str())) + if (!doesDirectoryExist(cloudChoicePath.c_str())) { ::CreateDirectory(cloudChoicePath.c_str(), NULL); } @@ -3263,7 +3263,7 @@ void NppParameters::removeCloudChoice() std::wstring cloudChoicePath = getSettingsFolder(); cloudChoicePath += L"\\cloud\\choice"; - if (PathFileExists(cloudChoicePath.c_str())) + if (doesFileExist(cloudChoicePath.c_str())) { ::DeleteFile(cloudChoicePath.c_str()); } @@ -3304,7 +3304,7 @@ bool NppParameters::writeSettingsFilesOnCloudForThe1stTime(const std::wstring & // config.xml std::wstring cloudConfigPath = cloudSettingsPath; pathAppend(cloudConfigPath, L"config.xml"); - if (!::PathFileExists(cloudConfigPath.c_str()) && _pXmlUserDoc) + if (!doesFileExist(cloudConfigPath.c_str()) && _pXmlUserDoc) { isOK = _pXmlUserDoc->SaveFile(cloudConfigPath.c_str()); if (!isOK) @@ -3314,7 +3314,7 @@ bool NppParameters::writeSettingsFilesOnCloudForThe1stTime(const std::wstring & // stylers.xml std::wstring cloudStylersPath = cloudSettingsPath; pathAppend(cloudStylersPath, L"stylers.xml"); - if (!::PathFileExists(cloudStylersPath.c_str()) && _pXmlUserStylerDoc) + if (!doesFileExist(cloudStylersPath.c_str()) && _pXmlUserStylerDoc) { isOK = _pXmlUserStylerDoc->SaveFile(cloudStylersPath.c_str()); if (!isOK) @@ -3324,7 +3324,7 @@ bool NppParameters::writeSettingsFilesOnCloudForThe1stTime(const std::wstring & // langs.xml std::wstring cloudLangsPath = cloudSettingsPath; pathAppend(cloudLangsPath, L"langs.xml"); - if (!::PathFileExists(cloudLangsPath.c_str()) && _pXmlUserDoc) + if (!doesFileExist(cloudLangsPath.c_str()) && _pXmlUserDoc) { isOK = _pXmlDoc->SaveFile(cloudLangsPath.c_str()); if (!isOK) @@ -3334,7 +3334,7 @@ bool NppParameters::writeSettingsFilesOnCloudForThe1stTime(const std::wstring & // userDefineLang.xml std::wstring cloudUserLangsPath = cloudSettingsPath; pathAppend(cloudUserLangsPath, L"userDefineLang.xml"); - if (!::PathFileExists(cloudUserLangsPath.c_str()) && _pXmlUserLangDoc) + if (!doesFileExist(cloudUserLangsPath.c_str()) && _pXmlUserLangDoc) { isOK = _pXmlUserLangDoc->SaveFile(cloudUserLangsPath.c_str()); if (!isOK) @@ -3344,7 +3344,7 @@ bool NppParameters::writeSettingsFilesOnCloudForThe1stTime(const std::wstring & // shortcuts.xml std::wstring cloudShortcutsPath = cloudSettingsPath; pathAppend(cloudShortcutsPath, SHORTCUTSXML_FILENAME); - if (!::PathFileExists(cloudShortcutsPath.c_str()) && _pXmlShortcutDocA) + if (!doesFileExist(cloudShortcutsPath.c_str()) && _pXmlShortcutDocA) { isOK = _pXmlShortcutDocA->SaveUnicodeFilePath(cloudShortcutsPath.c_str()); if (!isOK) @@ -3354,7 +3354,7 @@ bool NppParameters::writeSettingsFilesOnCloudForThe1stTime(const std::wstring & // contextMenu.xml std::wstring cloudContextMenuPath = cloudSettingsPath; pathAppend(cloudContextMenuPath, L"contextMenu.xml"); - if (!::PathFileExists(cloudContextMenuPath.c_str()) && _pXmlContextMenuDocA) + if (!doesFileExist(cloudContextMenuPath.c_str()) && _pXmlContextMenuDocA) { isOK = _pXmlContextMenuDocA->SaveUnicodeFilePath(cloudContextMenuPath.c_str()); if (!isOK) @@ -3364,7 +3364,7 @@ bool NppParameters::writeSettingsFilesOnCloudForThe1stTime(const std::wstring & // nativeLang.xml std::wstring cloudNativeLangPath = cloudSettingsPath; pathAppend(cloudNativeLangPath, L"nativeLang.xml"); - if (!::PathFileExists(cloudNativeLangPath.c_str()) && _pXmlNativeLangDocA) + if (!doesFileExist(cloudNativeLangPath.c_str()) && _pXmlNativeLangDocA) { isOK = _pXmlNativeLangDocA->SaveUnicodeFilePath(cloudNativeLangPath.c_str()); if (!isOK) @@ -3429,7 +3429,7 @@ void NppParameters::writeDefaultUDL() } else if (deleteAll) { - if (::PathFileExists(_userDefineLangPath.c_str())) + if (doesFileExist(_userDefineLangPath.c_str())) { ::DeleteFile(_userDefineLangPath.c_str()); } @@ -3447,7 +3447,7 @@ void NppParameters::writeNonDefaultUDL() { // no need to save, delete file const wchar_t* docFilePath = udl._udlXmlDoc->Value(); - if (docFilePath && ::PathFileExists(docFilePath)) + if (docFilePath && doesFileExist(docFilePath)) { ::DeleteFile(docFilePath); } @@ -3596,7 +3596,7 @@ void NppParameters::writeSession(const Session & session, const wchar_t *fileNam // wchar_t backupPathName[MAX_PATH]{}; BOOL doesBackupCopyExist = FALSE; - if (PathFileExists(sessionPathName)) + if (doesFileExist(sessionPathName)) { _tcscpy(backupPathName, sessionPathName); _tcscat(backupPathName, SESSION_BACKUP_EXT); @@ -3782,7 +3782,7 @@ void NppParameters::writeShortcuts() ::PathRemoveFileSpec(v852NoNeedShortcutsBackup); ::PathAppend(v852NoNeedShortcutsBackup, NONEEDSHORTCUTSXMLBACKUP_FILENAME); - if (!::PathFileExists(v852NoNeedShortcutsBackup)) + if (!doesFileExist(v852NoNeedShortcutsBackup)) { // Creat empty file v852NoNeedShortcutsBackup.xml for not giving warning, neither doing backup, in future use. HANDLE hFile = ::CreateFile(v852NoNeedShortcutsBackup, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); @@ -6321,7 +6321,7 @@ void NppParameters::feedGUIParameters(TiXmlNode *node) pathAppend(themePath, L"themes\\"); pathAppend(themePath, xmlFileName); - if (!isLocalOnly && ::PathFileExists(themePath.c_str()) == FALSE) + if (!isLocalOnly && !doesFileExist(themePath.c_str())) { themePath = _nppPath; pathAppend(themePath, L"themes\\"); @@ -6333,14 +6333,14 @@ void NppParameters::feedGUIParameters(TiXmlNode *node) themePath = isLocalOnly ? _nppPath : _userPath; pathAppend(themePath, L"stylers.xml"); - if (!isLocalOnly && ::PathFileExists(themePath.c_str()) == FALSE) + if (!isLocalOnly && !doesFileExist(themePath.c_str())) { themePath = _nppPath; pathAppend(themePath, L"stylers.xml"); } } - if (::PathFileExists(themePath.c_str()) == TRUE) + if (doesFileExist(themePath.c_str())) { _nppGUI._themeName.assign(themePath); } diff --git a/PowerEditor/src/ScintillaComponent/Buffer.cpp b/PowerEditor/src/ScintillaComponent/Buffer.cpp index c7448cd0b..e7185fffb 100644 --- a/PowerEditor/src/ScintillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScintillaComponent/Buffer.cpp @@ -262,14 +262,15 @@ bool Buffer::checkFileState() // returns true if the status has been changed (it bool isWow64Off = false; NppParameters& nppParam = NppParameters::getInstance(); - if (!PathFileExists(_fullPathName.c_str())) + bool fileExists = doesFileExist(_fullPathName.c_str()); + if (!fileExists) { nppParam.safeWow64EnableWow64FsRedirection(FALSE); isWow64Off = true; } bool isOK = false; - if (_currentStatus == DOC_INACCESSIBLE && !PathFileExists(_fullPathName.c_str())) //document is absent on its first load - we set readonly and not dirty, and make it be as document which has been deleted + if (_currentStatus == DOC_INACCESSIBLE && !fileExists) //document is absent on its first load - we set readonly and not dirty, and make it be as document which has been deleted { _currentStatus = DOC_DELETED;//DOC_INACCESSIBLE; _isInaccessible = true; @@ -279,7 +280,7 @@ bool Buffer::checkFileState() // returns true if the status has been changed (it doNotify(BufferChangeStatus | BufferChangeReadonly | BufferChangeTimestamp); isOK = true; } - else if (_currentStatus != DOC_DELETED && !PathFileExists(_fullPathName.c_str())) //document has been deleted + else if (_currentStatus != DOC_DELETED && !fileExists) //document has been deleted { _currentStatus = DOC_DELETED; _isFileReadOnly = false; @@ -288,7 +289,7 @@ bool Buffer::checkFileState() // returns true if the status has been changed (it doNotify(BufferChangeStatus | BufferChangeReadonly | BufferChangeTimestamp); isOK = true; } - else if (_currentStatus == DOC_DELETED && PathFileExists(_fullPathName.c_str())) + else if (_currentStatus == DOC_DELETED && fileExists) { //document has returned from its grave if (GetFileAttributesEx(_fullPathName.c_str(), GetFileExInfoStandard, &attributes) != 0) { @@ -326,7 +327,6 @@ bool Buffer::checkFileState() // returns true if the status has been changed (it { if (res == 1) { - NppParameters& nppParam = NppParameters::getInstance(); if (nppParam.doNppLogNetworkDriveIssue()) { wstring issueFn = nppLogNetworkDriveIssue; @@ -692,7 +692,7 @@ BufferID FileManager::loadFile(const wchar_t* filename, Document doc, int encodi //Get file size int64_t fileSize = -1; const wchar_t* pPath = filename; - if (!::PathFileExists(pPath)) + if (!doesFileExist(pPath)) { pPath = backupFileName; } @@ -750,8 +750,8 @@ BufferID FileManager::loadFile(const wchar_t* filename, Document doc, int encodi } } - bool isSnapshotMode = backupFileName != NULL && PathFileExists(backupFileName); - if (isSnapshotMode && !PathFileExists(fullpath)) // if backup mode and fullpath doesn't exist, we guess is UNTITLED + bool isSnapshotMode = backupFileName != NULL && doesFileExist(backupFileName); + if (isSnapshotMode && !doesFileExist(fullpath)) // if backup mode and fullpath doesn't exist, we guess is UNTITLED { wcscpy_s(fullpath, MAX_PATH, filename); // we restore fullpath with filename, in our case is "new #" } @@ -778,7 +778,7 @@ BufferID FileManager::loadFile(const wchar_t* filename, Document doc, int encodi if (backupFileName != NULL) { newBuf->_backupFileName = backupFileName; - if (!PathFileExists(fullpath)) + if (!doesFileExist(fullpath)) newBuf->_currentStatus = DOC_UNNAMED; } @@ -899,7 +899,7 @@ bool FileManager::deleteFile(BufferID id) // Make sure to form a string with double '\0' terminator. fileNamePath.append(1, '\0'); - if (!PathFileExists(fileNamePath.c_str())) + if (!doesFileExist(fileNamePath.c_str())) return false; SHFILEOPSTRUCT fileOpStruct = {}; @@ -1004,7 +1004,7 @@ bool FileManager::backupCurrentBuffer() backupFilePath += L"\\backup\\"; // if "backup" folder doesn't exist, create it. - if (!PathFileExists(backupFilePath.c_str())) + if (!doesFileExist(backupFilePath.c_str())) { ::CreateDirectory(backupFilePath.c_str(), NULL); } @@ -1079,7 +1079,7 @@ bool FileManager::backupCurrentBuffer() { if (buffer->isUntitled()) // "new #" file is saved successfully, then we replace its only physical existence by its temp { - if (::PathFileExists(fullpath)) + if (doesFileExist(fullpath)) ::ReplaceFile(fullpath, fullpathTemp.c_str(), nullptr, REPLACEFILE_IGNORE_MERGE_ERRORS | REPLACEFILE_IGNORE_ACL_ERRORS, 0, 0); else ::MoveFileEx(fullpathTemp.c_str(), fullpath, MOVEFILE_REPLACE_EXISTING); @@ -1183,7 +1183,7 @@ SavingStatus FileManager::saveBuffer(BufferID id, const wchar_t* filename, bool return SavingStatus::NotEnoughRoom; } - if (PathFileExists(fullpath)) + if (doesFileExist(fullpath)) { attrib = ::GetFileAttributes(fullpath); diff --git a/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp b/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp index e01f254fd..c2a5eae3f 100644 --- a/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp +++ b/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp @@ -504,9 +504,7 @@ void FileBrowser::openSelectFile() _selectedNodeFullPath = getNodePath(selectedNode); // test the path - if it's a file, open it, otherwise just fold or unfold it - if (!::PathFileExists(_selectedNodeFullPath.c_str())) - return; - if (::PathIsDirectory(_selectedNodeFullPath.c_str())) + if (!doesFileExist(_selectedNodeFullPath.c_str())) return; ::PostMessage(_hParent, NPPM_DOOPEN, 0, reinterpret_cast(_selectedNodeFullPath.c_str())); @@ -580,7 +578,7 @@ void FileBrowser::notified(LPNMHDR notification) // Check the validity of modified file path tvItem.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE; - if (::PathFileExists(filePath->c_str())) + if (doesPathExist(filePath->c_str())) { tvItem.iImage = INDEX_LEAF; tvItem.iSelectedImage = INDEX_LEAF; @@ -802,7 +800,7 @@ void FileBrowser::popupMenuCmd(int cmdID) if (!selectedNode) return; wstring path = getNodePath(selectedNode); - if (::PathFileExists(path.c_str())) + if (doesPathExist(path.c_str())) { wchar_t cmdStr[1024] = {}; if (getNodeType(selectedNode) == browserNodeType_file) @@ -823,7 +821,7 @@ void FileBrowser::popupMenuCmd(int cmdID) selectedNode = _treeView.getParent(selectedNode); wstring path = getNodePath(selectedNode); - if (::PathFileExists(path.c_str())) + if (doesPathExist(path.c_str())) { Command cmd(NppParameters::getInstance().getNppGUI()._commandLineInterpreter.c_str()); cmd.run(nullptr, path.c_str()); @@ -893,7 +891,7 @@ void FileBrowser::popupMenuCmd(int cmdID) if (!selectedNode) return; wstring path = getNodePath(selectedNode); - if (::PathFileExists(path.c_str())) + if (doesPathExist(path.c_str())) ::ShellExecute(NULL, L"open", path.c_str(), NULL, NULL, SW_SHOWNORMAL); } break; @@ -955,10 +953,7 @@ void FileBrowser::getDirectoryStructure(const wchar_t *dir, const std::vector& pl, wstring& verStr, const jso PluginUpdateInfo::PluginUpdateInfo(const wstring& fullFilePath, const wstring& filename) { - if (!::PathFileExists(fullFilePath.c_str())) + if (!doesFileExist(fullFilePath.c_str())) return; _fullFilePath = fullFilePath; @@ -644,12 +644,12 @@ bool PluginsAdminDlg::initFromJson() return false; } - if (!::PathFileExists(_pluginListFullPath.c_str())) + if (!doesFileExist(_pluginListFullPath.c_str())) { return false; } - if (!::PathFileExists(_updaterFullPath.c_str())) + if (!doesFileExist(_updaterFullPath.c_str())) { return false; } diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp index 1429157f2..d21cf91d1 100644 --- a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp +++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp @@ -5614,7 +5614,7 @@ intptr_t CALLBACK CloudAndLinkSubDlg::run_dlgProc(UINT message, WPARAM wParam, L if (withCloud) { // detect validation of path - if (!::PathFileExists(nppGUI._cloudPath.c_str())) + if (!doesDirectoryExist(nppGUI._cloudPath.c_str())) errMsg = L"Invalid path"; } @@ -5690,7 +5690,7 @@ intptr_t CALLBACK CloudAndLinkSubDlg::run_dlgProc(UINT message, WPARAM wParam, L ::SendDlgItemMessage(_hSelf, IDC_CLOUDPATH_EDIT, WM_GETTEXT, MAX_PATH, reinterpret_cast(inputDir)); ::ExpandEnvironmentStrings(inputDir, inputDirExpanded, MAX_PATH); NativeLangSpeaker* pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker(); - if (::PathFileExists(inputDirExpanded)) + if (doesDirectoryExist(inputDirExpanded)) { nppGUI._cloudPath = inputDirExpanded; nppParams.setCloudChoice(inputDirExpanded); diff --git a/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp b/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp index f78548075..18946f0cd 100644 --- a/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp +++ b/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp @@ -337,7 +337,7 @@ bool ProjectPanel::openWorkSpace(const wchar_t *projectFileName, bool force) return false; } - if (!::PathFileExists(projectFileName)) + if (!doesFileExist(projectFileName)) { delete pXmlDocProject; return false; @@ -538,7 +538,7 @@ bool ProjectPanel::buildTreeFrom(TiXmlNode *projectRoot, HTREEITEM hParentItem) const wchar_t *strValue = (childNode->ToElement())->Attribute(L"name"); wstring fullPath = getAbsoluteFilePath(strValue); wchar_t *strValueLabel = ::PathFindFileName(strValue); - int iImage = ::PathFileExists(fullPath.c_str())?INDEX_LEAF:INDEX_LEAF_INVALID; + int iImage = doesFileExist(fullPath.c_str()) ? INDEX_LEAF : INDEX_LEAF_INVALID; wstring* fullPathStr = new wstring(fullPath); fullPathStrs.push_back(fullPathStr); @@ -574,7 +574,7 @@ void ProjectPanel::openSelectFile() if (nType == nodeType_file && fn) { tvItem.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE; - if (::PathFileExists(fn->c_str())) + if (doesFileExist(fn->c_str())) { ::PostMessage(_hParent, NPPM_DOOPEN, 0, reinterpret_cast(fn->c_str())); tvItem.iImage = INDEX_LEAF; @@ -643,7 +643,7 @@ void ProjectPanel::notified(LPNMHDR notification) // Check the validity of modified file path tvItem.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE; - if (::PathFileExists(filePath->c_str())) + if (doesFileExist(filePath->c_str())) { tvItem.iImage = INDEX_LEAF; tvItem.iSelectedImage = INDEX_LEAF; @@ -1073,7 +1073,7 @@ void ProjectPanel::popupMenuCmd(int cmdID) } } - if (::PathFileExists(_workSpaceFilePath.c_str())) + if (doesFileExist(_workSpaceFilePath.c_str())) { openWorkSpace(_workSpaceFilePath.c_str(), forceOpen); } @@ -1179,7 +1179,7 @@ void ProjectPanel::popupMenuCmd(int cmdID) *fn = newValue; wchar_t *strValueLabel = ::PathFindFileName(fn->c_str()); wcscpy_s(textBuffer, strValueLabel); - int iImage = ::PathFileExists(fn->c_str())?INDEX_LEAF:INDEX_LEAF_INVALID; + int iImage = doesFileExist(fn->c_str()) ? INDEX_LEAF : INDEX_LEAF_INVALID; tvItem.iImage = tvItem.iSelectedImage = iImage; SendMessage(_treeView.getHSelf(), TVM_SETITEM, 0, reinterpret_cast(&tvItem)); setWorkSpaceDirty(true); diff --git a/PowerEditor/src/WinControls/ToolBar/ToolBar.cpp b/PowerEditor/src/WinControls/ToolBar/ToolBar.cpp index 9174ec054..7116be220 100644 --- a/PowerEditor/src/WinControls/ToolBar/ToolBar.cpp +++ b/PowerEditor/src/WinControls/ToolBar/ToolBar.cpp @@ -91,7 +91,7 @@ void ToolBar::initTheme(TiXmlDocument *toolIconsDocRoot) locator += L"\\"; locator += icoUnit._id; locator += ext; - if (::PathFileExists(locator.c_str())) + if (doesFileExist(locator.c_str())) { _customIconVect.push_back(iconLocator(HLIST_DEFAULT, i, locator)); _customIconVect.push_back(iconLocator(HLIST_DEFAULT2, i, locator)); @@ -106,7 +106,7 @@ void ToolBar::initTheme(TiXmlDocument *toolIconsDocRoot) locator_dis += icoUnit._id; locator_dis += disabled_suffix; locator_dis += ext; - if (::PathFileExists(locator_dis.c_str())) + if (doesFileExist(locator_dis.c_str())) { _customIconVect.push_back(iconLocator(HLIST_DISABLE, i, locator_dis)); _customIconVect.push_back(iconLocator(HLIST_DISABLE2, i, locator_dis)); diff --git a/PowerEditor/src/winmain.cpp b/PowerEditor/src/winmain.cpp index acd834062..77ae1cbe8 100644 --- a/PowerEditor/src/winmain.cpp +++ b/PowerEditor/src/winmain.cpp @@ -624,7 +624,7 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE /*hPrevInstance std::wstring updaterParams = L"-v"; updaterParams += VERSION_INTERNAL_VALUE; - bool isUpExist = nppGui._doesExistUpdater = (::PathFileExists(updaterFullPath.c_str()) == TRUE); + bool isUpExist = nppGui._doesExistUpdater = doesFileExist(updaterFullPath.c_str()); if (doUpdateNpp) // check more detail {