diff --git a/PowerEditor/src/MISC/SysMsg/SysMsg.cpp b/PowerEditor/src/MISC/SysMsg/SysMsg.cpp index f33a75eed..d49188edb 100644 --- a/PowerEditor/src/MISC/SysMsg/SysMsg.cpp +++ b/PowerEditor/src/MISC/SysMsg/SysMsg.cpp @@ -55,6 +55,14 @@ void writeLog(const char *logFileName, const char *log2write) fclose(f); } +int filter(unsigned int code, struct _EXCEPTION_POINTERS *ep) +{ + if (code == EXCEPTION_ACCESS_VIOLATION) + return EXCEPTION_EXECUTE_HANDLER; + + return EXCEPTION_CONTINUE_SEARCH; +} + std::string purgeMenuItemString(const char * menuItemStr, bool keepAmpersand) { char cleanedName[64] = ""; diff --git a/PowerEditor/src/MISC/SysMsg/SysMsg.h b/PowerEditor/src/MISC/SysMsg/SysMsg.h index 80cc5ffb9..935385683 100644 --- a/PowerEditor/src/MISC/SysMsg/SysMsg.h +++ b/PowerEditor/src/MISC/SysMsg/SysMsg.h @@ -26,6 +26,8 @@ void systemMessage(const char *title); void printInt(int int2print); void printStr(const char *str2print); void writeLog(const char *logFileName, const char *log2write); +int filter(unsigned int code, struct _EXCEPTION_POINTERS *ep); + std::string purgeMenuItemString(const char * menuItemStr, bool keepAmpersand = false); #endif //M30_IDE_COMMUN_H diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index e23ae890f..13bcfc3c6 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -789,7 +789,7 @@ void Notepad_plus::doClose(BufferID id, int whichOne) { _pluginsManager.notify(&scnN); //add to recent files if its an existing file - if (!buf->isUntitled()) + if (!buf->isUntitled() && PathFileExists(buf->getFilePath())) { _lastRecentFileList.add(buf->getFilePath()); } diff --git a/PowerEditor/src/ScitillaComponent/Buffer.cpp b/PowerEditor/src/ScitillaComponent/Buffer.cpp index 1eaac3f8a..0aebb7499 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScitillaComponent/Buffer.cpp @@ -506,7 +506,6 @@ bool FileManager::saveBuffer(BufferID id, const char * filename, bool isCopy) { if (fp) { _pscratchTilla->execute(SCI_SETDOCPOINTER, 0, buffer->_doc); //generate new document - char data[blockSize + 1]; int lengthDoc = _pscratchTilla->getCurrentDocLen(); @@ -579,42 +578,48 @@ bool FileManager::loadFileData(Document doc, const char * filename, Utf8_16_Read const int blockSize = 128 * 1024; //128 kB char data[blockSize]; - FILE *fp = fopen(filename, "rb"); - if (!fp) + __try { + FILE *fp = fopen(filename, "rb"); + if (!fp) + return false; + + //Setup scratchtilla for new filedata + _pscratchTilla->execute(SCI_SETDOCPOINTER, 0, doc); + bool ro = _pscratchTilla->execute(SCI_GETREADONLY) != 0; + if (ro) { + _pscratchTilla->execute(SCI_SETREADONLY, false); + } + _pscratchTilla->execute(SCI_CLEARALL); + if (language < L_EXTERNAL) { + _pscratchTilla->execute(SCI_SETLEXER, ScintillaEditView::langNames[language].lexerID); + } else { + int id = language - L_EXTERNAL; + char * name = NppParameters::getInstance()->getELCFromIndex(id)._name; + _pscratchTilla->execute(SCI_SETLEXERLANGUAGE, 0, (LPARAM)name); + } + + size_t lenFile = 0; + size_t lenConvert = 0; //just in case conversion results in 0, but file not empty + do { + lenFile = fread(data, 1, blockSize, fp); + lenConvert = UnicodeConvertor->convert(data, lenFile); + _pscratchTilla->execute(SCI_APPENDTEXT, lenConvert, (LPARAM)(UnicodeConvertor->getNewBuf())); + } while (lenFile > 0); + + fclose(fp); + + _pscratchTilla->execute(SCI_EMPTYUNDOBUFFER); + _pscratchTilla->execute(SCI_SETSAVEPOINT); + if (ro) { + _pscratchTilla->execute(SCI_SETREADONLY, true); + } + _pscratchTilla->execute(SCI_SETDOCPOINTER, 0, _scratchDocDefault); + return true; + + }__except(filter(GetExceptionCode(), GetExceptionInformation())) { + printStr("File is too big to be opened by Notepad++"); return false; - - //Setup scratchtilla for new filedata - _pscratchTilla->execute(SCI_SETDOCPOINTER, 0, doc); - bool ro = _pscratchTilla->execute(SCI_GETREADONLY) != 0; - if (ro) { - _pscratchTilla->execute(SCI_SETREADONLY, false); - } - _pscratchTilla->execute(SCI_CLEARALL); - if (language < L_EXTERNAL) { - _pscratchTilla->execute(SCI_SETLEXER, ScintillaEditView::langNames[language].lexerID); - } else { - int id = language - L_EXTERNAL; - char * name = NppParameters::getInstance()->getELCFromIndex(id)._name; - _pscratchTilla->execute(SCI_SETLEXERLANGUAGE, 0, (LPARAM)name); - } - - size_t lenFile = 0; - size_t lenConvert = 0; //just in case conversion results in 0, but file not empty - do { - lenFile = fread(data, 1, blockSize, fp); - lenConvert = UnicodeConvertor->convert(data, lenFile); - _pscratchTilla->execute(SCI_APPENDTEXT, lenConvert, (LPARAM)(UnicodeConvertor->getNewBuf())); - } while (lenFile > 0); - - fclose(fp); - - _pscratchTilla->execute(SCI_EMPTYUNDOBUFFER); - _pscratchTilla->execute(SCI_SETSAVEPOINT); - if (ro) { - _pscratchTilla->execute(SCI_SETREADONLY, true); - } - _pscratchTilla->execute(SCI_SETDOCPOINTER, 0, _scratchDocDefault); - return true; + } } BufferID FileManager::getBufferFromName(const char * name) { char fullpath[MAX_PATH];