mirror of
https://github.com/notepad-plus-plus/notepad-plus-plus.git
synced 2025-07-08 14:34:44 +02:00
parent
cd45afc020
commit
0ca0348e7f
@ -22,11 +22,10 @@
|
|||||||
#include <locale>
|
#include <locale>
|
||||||
#include "StaticDialog.h"
|
#include "StaticDialog.h"
|
||||||
#include "CustomFileDialog.h"
|
#include "CustomFileDialog.h"
|
||||||
|
|
||||||
#include "FileInterface.h"
|
#include "FileInterface.h"
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "Utf8.h"
|
#include "Utf8.h"
|
||||||
#include <Parameters.h>
|
#include "Parameters.h"
|
||||||
#include "Buffer.h"
|
#include "Buffer.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@ -2002,3 +2001,5 @@ HANDLE createFileWaitSec(const wchar_t* filePath, DWORD accessParam, DWORD share
|
|||||||
|
|
||||||
return data._hFile;
|
return data._hFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -843,12 +843,22 @@ bool FileManager::reloadBuffer(BufferID id)
|
|||||||
// Set _isLoadedDirty false before calling "_pscratchTilla->execute(SCI_CLEARALL);" in loadFileData() to avoid setDirty in SCN_SAVEPOINTREACHED / SCN_SAVEPOINTLEFT
|
// Set _isLoadedDirty false before calling "_pscratchTilla->execute(SCI_CLEARALL);" in loadFileData() to avoid setDirty in SCN_SAVEPOINTREACHED / SCN_SAVEPOINTLEFT
|
||||||
|
|
||||||
//Get file size
|
//Get file size
|
||||||
FILE* fp = _wfopen(buf->getFullPathName(), L"rb");
|
int64_t fileSize = 0;
|
||||||
if (!fp)
|
WIN32_FILE_ATTRIBUTE_DATA attributes{};
|
||||||
|
getFileAttributesExWaitSec(buf->getFullPathName(), &attributes);
|
||||||
|
if (attributes.dwFileAttributes == INVALID_FILE_ATTRIBUTES)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
_fseeki64(fp, 0, SEEK_END);
|
}
|
||||||
int64_t fileSize = _ftelli64(fp);
|
else
|
||||||
fclose(fp);
|
{
|
||||||
|
LARGE_INTEGER size{};
|
||||||
|
size.LowPart = attributes.nFileSizeLow;
|
||||||
|
size.HighPart = attributes.nFileSizeHigh;
|
||||||
|
|
||||||
|
fileSize = size.QuadPart;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
char* data = new char[blockSize + 8]; // +8 for incomplete multibyte char
|
char* data = new char[blockSize + 8]; // +8 for incomplete multibyte char
|
||||||
|
|
||||||
@ -1561,10 +1571,7 @@ LangType FileManager::detectLanguageFromTextBegining(const unsigned char *data,
|
|||||||
|
|
||||||
bool FileManager::loadFileData(Document doc, int64_t fileSize, const wchar_t * filename, char* data, Utf8_16_Read * unicodeConvertor, LoadedFileFormat& fileFormat)
|
bool FileManager::loadFileData(Document doc, int64_t fileSize, const wchar_t * filename, char* data, Utf8_16_Read * unicodeConvertor, LoadedFileFormat& fileFormat)
|
||||||
{
|
{
|
||||||
FILE *fp = _wfopen(filename, L"rb");
|
// Check file size firstly
|
||||||
if (!fp)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// size/6 is the normal room Scintilla keeps for editing, but here we limit it to 1MiB when loading (maybe we want to load big files without editing them too much)
|
// size/6 is the normal room Scintilla keeps for editing, but here we limit it to 1MiB when loading (maybe we want to load big files without editing them too much)
|
||||||
int64_t bufferSizeRequested = fileSize + std::min<int64_t>(1LL << 20, fileSize / 6);
|
int64_t bufferSizeRequested = fileSize + std::min<int64_t>(1LL << 20, fileSize / 6);
|
||||||
|
|
||||||
@ -1582,7 +1589,6 @@ bool FileManager::loadFileData(Document doc, int64_t fileSize, const wchar_t * f
|
|||||||
L"File size problem",
|
L"File size problem",
|
||||||
MB_OK | MB_APPLMODAL);
|
MB_OK | MB_APPLMODAL);
|
||||||
|
|
||||||
fclose(fp);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else // x64
|
else // x64
|
||||||
@ -1602,13 +1608,17 @@ bool FileManager::loadFileData(Document doc, int64_t fileSize, const wchar_t * f
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fclose(fp);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FILE* fp = _wfopen(filename, L"rb");
|
||||||
|
|
||||||
|
if (!fp)
|
||||||
|
return false;
|
||||||
|
|
||||||
//Setup scratchtilla for new filedata
|
//Setup scratchtilla for new filedata
|
||||||
_pscratchTilla->execute(SCI_SETSTATUS, SC_STATUS_OK); // reset error status
|
_pscratchTilla->execute(SCI_SETSTATUS, SC_STATUS_OK); // reset error status
|
||||||
_pscratchTilla->execute(SCI_SETDOCPOINTER, 0, doc);
|
_pscratchTilla->execute(SCI_SETDOCPOINTER, 0, doc);
|
||||||
@ -1641,7 +1651,7 @@ bool FileManager::loadFileData(Document doc, int64_t fileSize, const wchar_t * f
|
|||||||
bool success = true;
|
bool success = true;
|
||||||
EolType format = EolType::unknown;
|
EolType format = EolType::unknown;
|
||||||
int sciStatus = SC_STATUS_OK;
|
int sciStatus = SC_STATUS_OK;
|
||||||
wchar_t szException[64] = { '\0' };
|
wchar_t szException[64] = {'\0'};
|
||||||
__try
|
__try
|
||||||
{
|
{
|
||||||
// First allocate enough memory for the whole file (this will reduce memory copy during loading)
|
// First allocate enough memory for the whole file (this will reduce memory copy during loading)
|
||||||
@ -1730,7 +1740,7 @@ bool FileManager::loadFileData(Document doc, int64_t fileSize, const wchar_t * f
|
|||||||
}
|
}
|
||||||
while (lenFile > 0);
|
while (lenFile > 0);
|
||||||
}
|
}
|
||||||
__except(EXCEPTION_EXECUTE_HANDLER)
|
__except (EXCEPTION_EXECUTE_HANDLER)
|
||||||
{
|
{
|
||||||
switch (sciStatus)
|
switch (sciStatus)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user