Fix data loss issue due to no room on disk for saving
Fix #5664, fix #14089, close #14134pull/14148/head
parent
a511a575b7
commit
e30ee852d6
|
@ -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."/><!-- HowToReproduce: Close Notepad++, remove shortcuts.xml.v8.5.2.backup & v852ShortcutsCompatibilityWarning.xml if present, relaunch Notepad++, delete or modify a shortcuts via Shortcut Mapper, close Notepad++, then the message will show up -->
|
||||
<NotEnoughRoom4Saving title="Save failed" message="Failed to save file.
|
||||
It seems there's not enough space on disk to save file. Your file is not saved."/>
|
||||
</MessageBox>
|
||||
<ClipboardHistory>
|
||||
<PanelTitle name="Clipboard History"/>
|
||||
|
|
|
@ -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."/><!-- HowToReproduce: Close Notepad++, remove shortcuts.xml.v8.5.2.backup & v852ShortcutsCompatibilityWarning.xml if present, relaunch Notepad++, delete or modify a shortcuts via Shortcut Mapper, close Notepad++, then the message will show up -->
|
||||
<NotEnoughRoom4Saving title="Save failed" message="Failed to save file.
|
||||
It seems there's not enough space on disk to save file. Your file is not saved."/>
|
||||
|
||||
</MessageBox>
|
||||
<ClipboardHistory>
|
||||
<PanelTitle name="Clipboard History"/>
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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<std::mutex> 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))
|
||||
{
|
||||
|
|
|
@ -53,7 +53,8 @@ enum BufferStatusInfo {
|
|||
enum SavingStatus {
|
||||
SaveOK = 0,
|
||||
SaveOpenFailed = 1,
|
||||
SaveWritingFailed = 2
|
||||
SaveWritingFailed = 2,
|
||||
NotEnoughRoom = 3
|
||||
};
|
||||
|
||||
struct BufferViewInfo {
|
||||
|
|
Loading…
Reference in New Issue