diff --git a/grepWinNP3/sktoolslib_mod/TextFile.cpp b/grepWinNP3/sktoolslib_mod/TextFile.cpp index 1a661df62..334138d71 100644 --- a/grepWinNP3/sktoolslib_mod/TextFile.cpp +++ b/grepWinNP3/sktoolslib_mod/TextFile.cpp @@ -58,9 +58,11 @@ bool CTextFile::Save(LPCWSTR path) DWORD byteswritten; if (!WriteFile(hFile, pFileBuf.get(), filelen, &byteswritten, NULL)) { + FlushFileBuffers(hFile); CloseHandle(hFile); return false; } + FlushFileBuffers(hFile); CloseHandle(hFile); return true; } diff --git a/src/Edit.c b/src/Edit.c index 4f5a93815..f9d7e33a7 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -1332,12 +1332,15 @@ bool EditSaveFile( bool bWriteSuccess = false; status->bCancelDataLoss = false; + ///~ (!) FILE_FLAG_NO_BUFFERING needs sector-size aligned buffer layout + DWORD const dwWriteAttributes = FILE_ATTRIBUTE_NORMAL | /*FILE_FLAG_NO_BUFFERING |*/ FILE_FLAG_WRITE_THROUGH; + HANDLE hFile = CreateFile(pszFile, GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, - FILE_ATTRIBUTE_NORMAL, + dwWriteAttributes, NULL); Globals.dwLastError = GetLastError(); @@ -1345,16 +1348,16 @@ bool EditSaveFile( // failure could be due to missing attributes (2k/XP) if (hFile == INVALID_HANDLE_VALUE) { - DWORD dwAttributes = GetFileAttributes(pszFile); - if (dwAttributes != INVALID_FILE_ATTRIBUTES) + DWORD dwSpecialAttributes = GetFileAttributes(pszFile); + if (dwSpecialAttributes != INVALID_FILE_ATTRIBUTES) { - dwAttributes = dwAttributes & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM); + dwSpecialAttributes &= (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM); hFile = CreateFile(pszFile, GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, - FILE_ATTRIBUTE_NORMAL | dwAttributes, + dwWriteAttributes | dwSpecialAttributes, NULL); Globals.dwLastError = GetLastError(); diff --git a/src/Helpers.c b/src/Helpers.c index 98099fa10..bf4c55574 100644 --- a/src/Helpers.c +++ b/src/Helpers.c @@ -766,7 +766,9 @@ bool WriteFileXL(HANDLE hFile, const char* const lpBuffer, const size_t nNumberO bytesLeft -= (size_t)dwWritten; } while (bWriteOk && ((dwWritten != 0) && (bytesLeft > 0))); - + + FlushFileBuffers(hFile); + *lpNumberOfBytesWritten = bytesWritten; return (bytesWritten == nNumberOfBytesToWrite); } diff --git a/src/Notepad3.c b/src/Notepad3.c index a92531b42..e2f9b9b26 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -10094,7 +10094,7 @@ bool FileLoad(bool bDontSave, bool bNew, bool bReload, HANDLE hFile = CreateFile(szFilePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL); + NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); Globals.dwLastError = GetLastError(); fSuccess = (hFile != INVALID_HANDLE_VALUE); if (fSuccess) {