diff --git a/PowerEditor/installer/nativeLang/english.xml b/PowerEditor/installer/nativeLang/english.xml index e6303fa33..e405e615f 100644 --- a/PowerEditor/installer/nativeLang/english.xml +++ b/PowerEditor/installer/nativeLang/english.xml @@ -1490,6 +1490,8 @@ Please test those commands and, if needed, re-edit them. Alternatively, you can downgrade to Notepad++ v8.5.2 and restore your previous data. Notepad++ will backup your old "shortcuts.xml" and save it as "shortcuts.xml.v8.5.2.backup". Renaming "shortcuts.xml.v8.5.2.backup" -> "shortcuts.xml", your commands should be restored and work properly."/> + diff --git a/PowerEditor/installer/nativeLang/english_customizable.xml b/PowerEditor/installer/nativeLang/english_customizable.xml index 8d82e688f..05f3ebaf0 100644 --- a/PowerEditor/installer/nativeLang/english_customizable.xml +++ b/PowerEditor/installer/nativeLang/english_customizable.xml @@ -1491,6 +1491,9 @@ Please test those commands and, if needed, re-edit them. Alternatively, you can downgrade to Notepad++ v8.5.2 and restore your previous data. Notepad++ will backup your old "shortcuts.xml" and save it as "shortcuts.xml.v8.5.2.backup". Renaming "shortcuts.xml.v8.5.2.backup" -> "shortcuts.xml", your commands should be restored and work properly."/> + + diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index 47bf93f3f..66ac69a41 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -628,14 +628,19 @@ bool Notepad_plus::doSave(BufferID id, const TCHAR * filename, bool isCopy) _pluginsManager.notify(&scnN); } - if (res == SavingStatus::SaveWritingFailed) + if (res == SavingStatus::NotEnoughRoom) { _nativeLangSpeaker.messageBox("NotEnoughRoom4Saving", _pPublicInterface->getHSelf(), - TEXT("Failed to save file.\nIt seems there's not enough space on disk to save file."), + TEXT("Failed to save file.\nIt seems there's not enough space on disk to save file. Your file is not saved."), TEXT("Save failed"), MB_OK); } + else if (res == SavingStatus::SaveWritingFailed) + { + wstring errorMessage = GetLastErrorAsString(GetLastError()); + ::MessageBox(_pPublicInterface->getHSelf(), errorMessage.c_str(), TEXT("Save failed"), MB_OK | MB_ICONWARNING); + } else if (res == SavingStatus::SaveOpenFailed) { if (_isAdministrator) diff --git a/PowerEditor/src/ScintillaComponent/Buffer.cpp b/PowerEditor/src/ScintillaComponent/Buffer.cpp index 9eba0f8f3..703c82067 100644 --- a/PowerEditor/src/ScintillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScintillaComponent/Buffer.cpp @@ -1114,7 +1114,7 @@ bool FileManager::deleteBufferBackup(BufferID id) std::mutex save_mutex; -SavingStatus FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool isCopy) +SavingStatus FileManager::saveBuffer(BufferID id, const TCHAR* filename, bool isCopy) { std::lock_guard lock(save_mutex); @@ -1136,6 +1136,28 @@ SavingStatus FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool i ::GetLongPathName(fullpath, fullpath, MAX_PATH); } } + + wchar_t dirDest[MAX_PATH]; + wcscpy_s(dirDest, MAX_PATH, fullpath); + ::PathRemoveFileSpecW(dirDest); + + const wchar_t* currentBufFilePath = buffer->getFullPathName(); + ULARGE_INTEGER freeBytesForUser; + + BOOL getFreeSpaceRes = ::GetDiskFreeSpaceExW(dirDest, &freeBytesForUser, nullptr, nullptr); + if (getFreeSpaceRes != FALSE) + { + int64_t fileSize = buffer->getFileLength(); + if (fileSize >= 0 && lstrcmp(fullpath, currentBufFilePath) == 0) // if file to save does exist, and it's an operation "Save" but not "Save As" + { + // if file exists and the operation "Save" but not "Save As", its current length should be considered as part of free room space since the file itself will be overrrided + freeBytesForUser.QuadPart += fileSize; + } + + // determinate if free space is enough + if (freeBytesForUser.QuadPart < buffer->docLength()) + return SavingStatus::NotEnoughRoom; + } if (PathFileExists(fullpath)) { diff --git a/PowerEditor/src/ScintillaComponent/Buffer.h b/PowerEditor/src/ScintillaComponent/Buffer.h index 3f4a8a791..697094a1c 100644 --- a/PowerEditor/src/ScintillaComponent/Buffer.h +++ b/PowerEditor/src/ScintillaComponent/Buffer.h @@ -53,7 +53,8 @@ enum BufferStatusInfo { enum SavingStatus { SaveOK = 0, SaveOpenFailed = 1, - SaveWritingFailed = 2 + SaveWritingFailed = 2, + NotEnoughRoom = 3 }; struct BufferViewInfo {