mirror of
https://github.com/rizonesoft/Notepad3.git
synced 2026-06-11 21:03:05 +08:00
+ fix: Load files larger than 2GB (64-bit) - Limit to 4GB (Scintilla problems)
This commit is contained in:
parent
cc874fe716
commit
3771340dcd
@ -37,18 +37,25 @@ see ecryption-doc.txt for details
|
||||
#define WKEY_LEN 256
|
||||
#define KEY_LEN 512
|
||||
|
||||
bool useFileKey = false; // file should be encrypted
|
||||
char fileKey[KEY_LEN] = { 0 }; // ascii passphrase for the file key
|
||||
WCHAR unicodeFileKey[WKEY_LEN] = { 0 }; // unicode file passphrase
|
||||
bool useMasterKey = false; // file should have a master key
|
||||
char masterKey[KEY_LEN] = { 0 }; // ascii passphrase for the master key
|
||||
WCHAR unicodeMasterKey[WKEY_LEN] = { 0 }; // unicode master passphrase
|
||||
BYTE binFileKey[KEY_BYTES]; // the encryption key in for the file
|
||||
bool hasBinFileKey = false;
|
||||
BYTE masterFileKey[KEY_BYTES]; // file key encrypted with the master key
|
||||
BYTE masterFileIV[AES_MAX_IV_SIZE]; // the iv for the master key
|
||||
bool hasMasterFileKey = false;
|
||||
bool masterKeyAvailable = false; // information for the passphrase dialog box
|
||||
static bool useFileKey = false; // file should be encrypted
|
||||
static char fileKey[KEY_LEN] = { 0 }; // ascii passphrase for the file key
|
||||
static WCHAR unicodeFileKey[WKEY_LEN] = { 0 }; // unicode file passphrase
|
||||
static bool useMasterKey = false; // file should have a master key
|
||||
static char masterKey[KEY_LEN] = { 0 }; // ascii passphrase for the master key
|
||||
static WCHAR unicodeMasterKey[WKEY_LEN] = { 0 }; // unicode master passphrase
|
||||
static BYTE binFileKey[KEY_BYTES]; // the encryption key in for the file
|
||||
static bool hasBinFileKey = false;
|
||||
static BYTE masterFileKey[KEY_BYTES]; // file key encrypted with the master key
|
||||
static BYTE masterFileIV[AES_MAX_IV_SIZE]; // the iv for the master key
|
||||
static bool hasMasterFileKey = false;
|
||||
static bool masterKeyAvailable = false; // information for the passphrase dialog box
|
||||
|
||||
|
||||
bool IsEncryptionRequired()
|
||||
{
|
||||
return (useFileKey || hasMasterFileKey);
|
||||
}
|
||||
|
||||
|
||||
void ResetEncryption()
|
||||
{
|
||||
@ -325,31 +332,30 @@ bool ReadFileKey(HWND hwnd, bool master)
|
||||
// read the file data, decrypt if necessary,
|
||||
// return the result as a new allocation
|
||||
//
|
||||
int ReadAndDecryptFile(HWND hwnd, HANDLE hFile, size_t size, void** result, size_t *resultlen)
|
||||
int ReadAndDecryptFile(HWND hwnd, HANDLE hFile, size_t fileSize, void** result, size_t *resultlen)
|
||||
{
|
||||
HANDLE rawhandle = *result;
|
||||
BYTE* rawdata = (BYTE*)GlobalLock(rawhandle);
|
||||
|
||||
int returnFlag = DECRYPT_SUCCESS;
|
||||
bool usedEncryption = false;
|
||||
DWORD readsize = 0;
|
||||
bool bRetryPassPhrase = true;
|
||||
size_t bytesRead = 0ULL;
|
||||
|
||||
while (bRetryPassPhrase) {
|
||||
|
||||
SetFilePointer(hFile, 0L, NULL, FILE_BEGIN);
|
||||
returnFlag = DECRYPT_SUCCESS;
|
||||
usedEncryption = false;
|
||||
readsize = 0;
|
||||
bRetryPassPhrase = false;
|
||||
|
||||
// TODO: size_t -> (DWORD) cast: Huge Files conversion problem
|
||||
bool bReadSuccess = ReadFile(hFile, rawdata, (DWORD)size, &readsize, NULL);
|
||||
returnFlag = bReadSuccess ? DECRYPT_SUCCESS : DECRYPT_FREAD_FAILED;
|
||||
bool const bReadOk = ReadFileXL(hFile, rawdata, fileSize, &bytesRead);
|
||||
|
||||
returnFlag = bReadOk ? DECRYPT_SUCCESS : DECRYPT_FREAD_FAILED;
|
||||
|
||||
// we read the file, check if it looks like our encryption format
|
||||
|
||||
if (bReadSuccess && (readsize > (PREAMBLE_SIZE + AES_MAX_IV_SIZE))) {
|
||||
if (bReadOk && (bytesRead > (PREAMBLE_SIZE + AES_MAX_IV_SIZE))) {
|
||||
|
||||
long *ldata = (long*)rawdata;
|
||||
|
||||
@ -410,11 +416,11 @@ int ReadAndDecryptFile(HWND hwnd, HANDLE hFile, size_t size, void** result, size
|
||||
{ // finally, decrypt the actual data
|
||||
ptrdiff_t nbb = BAD_CIPHER_STATE;
|
||||
ptrdiff_t nbp = BAD_CIPHER_STATE;
|
||||
if ((readsize - code_offset) >= PAD_SLOP) {
|
||||
nbb = AES_blockDecrypt(&fileCypher, &fileDecode, &rawdata[code_offset], readsize - code_offset - PAD_SLOP, rawdata);
|
||||
if ((bytesRead - code_offset) >= PAD_SLOP) {
|
||||
nbb = AES_blockDecrypt(&fileCypher, &fileDecode, &rawdata[code_offset], bytesRead - code_offset - PAD_SLOP, rawdata);
|
||||
}
|
||||
if (nbb >= 0) {
|
||||
nbp = AES_padDecrypt(&fileCypher, &fileDecode, &rawdata[code_offset + nbb], readsize - code_offset - nbb, rawdata + nbb);
|
||||
nbp = AES_padDecrypt(&fileCypher, &fileDecode, &rawdata[code_offset + nbb], bytesRead - code_offset - nbb, rawdata + nbb);
|
||||
}
|
||||
if (nbp >= 0) {
|
||||
size_t const nb = nbb + nbp;
|
||||
@ -426,7 +432,7 @@ int ReadAndDecryptFile(HWND hwnd, HANDLE hFile, size_t size, void** result, size
|
||||
bRetryPassPhrase = (InfoBoxLng(MB_RETRYCANCEL | MB_ICONWARNING, NULL, IDS_MUI_PASS_FAILURE) == IDRETRY);
|
||||
if (!bRetryPassPhrase) {
|
||||
// enable raw encryption read
|
||||
*resultlen = readsize;
|
||||
*resultlen = bytesRead;
|
||||
returnFlag |= DECRYPT_WRONG_PASS;
|
||||
}
|
||||
}
|
||||
@ -450,7 +456,7 @@ int ReadAndDecryptFile(HWND hwnd, HANDLE hFile, size_t size, void** result, size
|
||||
|
||||
if (!usedEncryption) { // here, the file is believed to be a straight text file
|
||||
ResetEncryption();
|
||||
*resultlen = readsize;
|
||||
*resultlen = bytesRead;
|
||||
returnFlag |= DECRYPT_NO_ENCRYPTION;
|
||||
}
|
||||
|
||||
@ -463,7 +469,7 @@ bool EncryptAndWriteFile(HWND hwnd, HANDLE hFile, BYTE *data, size_t size, size_
|
||||
{
|
||||
UNUSED(hwnd);
|
||||
|
||||
if (useFileKey || hasMasterFileKey) {
|
||||
if (IsEncryptionRequired()) {
|
||||
AES_keyInstance fileEncode; // encryption key for the file
|
||||
AES_cipherInstance fileCypher; // cypher for the file, including the IV
|
||||
DWORD PREAMBLE_written = 0;
|
||||
@ -538,35 +544,30 @@ bool EncryptAndWriteFile(HWND hwnd, HANDLE hFile, BYTE *data, size_t size, size_
|
||||
|
||||
// now encrypt the main file
|
||||
{
|
||||
DWORD enclen_written = 0;
|
||||
size_t enclen = 0;
|
||||
bool bWriteRes = false;
|
||||
|
||||
|
||||
BYTE* encdata = (BYTE*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size + PAD_SLOP); // add slop to the end for padding
|
||||
|
||||
if (!encdata) {
|
||||
return bWriteRes;
|
||||
}
|
||||
|
||||
size_t enclen = 0;
|
||||
if (size > PAD_SLOP) { enclen += AES_blockEncrypt(&fileCypher, &fileEncode, data, size - PAD_SLOP, encdata); }
|
||||
|
||||
enclen += AES_padEncrypt(&fileCypher, &fileEncode, data + enclen, size - enclen, encdata + enclen);
|
||||
|
||||
// TODO: huge file size size_t vs. DWORD
|
||||
bWriteRes = WriteFile(hFile, encdata, (DWORD)enclen, &enclen_written, NULL);
|
||||
size_t enclen_written = 0;
|
||||
bWriteRes = WriteFileXL(hFile, encdata, enclen, &enclen_written);
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, encdata); // clean-up
|
||||
|
||||
*written = PREAMBLE_written + enclen_written; // return the file size written
|
||||
return(bWriteRes); // and the file ok status
|
||||
*written = (size_t)PREAMBLE_written + enclen_written; // return the file size written
|
||||
return bWriteRes; // and the file ok status
|
||||
}
|
||||
}
|
||||
else {
|
||||
// not an encrypted file, write normally
|
||||
// TODO: huge file size size_t vs. DWORD
|
||||
DWORD dwWritten;
|
||||
bool bWriteSuccess = WriteFile(hFile, data, (DWORD)size, &dwWritten, NULL);
|
||||
*written = dwWritten;
|
||||
return(bWriteSuccess);
|
||||
return WriteFileXL(hFile, data, size, written);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -27,6 +27,8 @@
|
||||
#define DECRYPT_CANCELED_NO_PASS 0x08
|
||||
#define DECRYPT_FATAL_ERROR 0x10
|
||||
|
||||
bool IsEncryptionRequired();
|
||||
|
||||
int ReadAndDecryptFile(HWND hwnd, HANDLE hFile, size_t size, void** result, size_t *resultlen);
|
||||
bool EncryptAndWriteFile(HWND hwnd, HANDLE hFile, BYTE *data, size_t size, size_t*written);
|
||||
|
||||
|
||||
@ -146,9 +146,9 @@ BEGIN
|
||||
"Die lêer %s kan nie gestoor word nie en kan beskermd wees.\n\nWil jy begin %s as 'n 'Verhoogde' toepassing?"
|
||||
IDS_MUI_ERR_ADMINEXE "Kon geen administrasie uitvoerbaar vind nie. \nGaan na https://www.rizonesoft.com vir meer?"
|
||||
IDS_MUI_WARN_LOAD_BIG_FILE
|
||||
"Is jy seker jy wil hierdie groot lêer oopmaak?\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
"Is jy seker jy wil hierdie groot lêer oopmaak?\n\t(Grootte: %s >= %s)!\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
IDS_MUI_ERR_FILE_TOO_LARGE
|
||||
"Kan nie daardie groot lêer hanteer nie (Grootte: %lli MB)!"
|
||||
"Kan nie daardie groot lêer hanteer nie (Grootte: %s)!"
|
||||
IDS_MUI_WARN_UNKNOWN_EXT
|
||||
"Onbekende lêernaam uitbreiding (%s)!\nLaai data in elk geval?"
|
||||
IDS_MUI_INDENT_CONSISTENT "Die lêer het 'n konsekwente indentasie!"
|
||||
|
||||
@ -146,9 +146,9 @@ BEGIN
|
||||
"Файл «%s» нельга захаваць з прычыны абароны ад змянення.\n\nЖадаеце запусціць %s з павышанымі правамі?"
|
||||
IDS_MUI_ERR_ADMINEXE "Не знойдены інструмент адміністратара\nНаведаць сайт https://rizonesoft.com?"
|
||||
IDS_MUI_WARN_LOAD_BIG_FILE
|
||||
"Вы ўпэўнены, што хочаце адкрыць гэты вялікі файл?\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
"Вы ўпэўнены, што хочаце адкрыць гэты вялікі файл?\n\t(памер: %s >= %s)!\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
IDS_MUI_ERR_FILE_TOO_LARGE
|
||||
"Немагчыма апрацаваць гэты вялікі файл (памер: %lli МБ)!"
|
||||
"Немагчыма апрацаваць гэты вялікі файл (памер: %s)!"
|
||||
IDS_MUI_WARN_UNKNOWN_EXT
|
||||
"Невядомае пашырэнне файла (%s)!\nПрацягнуць ладаванне даных?"
|
||||
IDS_MUI_INDENT_CONSISTENT "Файл мае аднолькавага выгляду водступы!"
|
||||
|
||||
@ -146,9 +146,9 @@ BEGIN
|
||||
"Die Datei ""%s"" kann nicht gespeichert werden und ist evtl. geschützt.\n\nMöchtest Du %s mit erhöhten Rechten starten?"
|
||||
IDS_MUI_ERR_ADMINEXE "Kein Verwaltungswerkzeug gefunden.\nBitte auf der Website https://rizonesoft.com prüfen."
|
||||
IDS_MUI_WARN_LOAD_BIG_FILE
|
||||
"Bist Du sicher, dass Du diese sehr große Datei öffnen möchtest?\n(Styling und Syntax Highlighting wird nicht durchgeführt!)"
|
||||
"Bist Du sicher, dass Du diese sehr große Datei öffnen möchtest?\n\t(Größe: %s >= %s)!\n(Styling und Syntax Highlighting wird nicht durchgeführt!)"
|
||||
IDS_MUI_ERR_FILE_TOO_LARGE
|
||||
"Notepad3 kann so große Dateien nicht laden (Größe: %lli MB)!"
|
||||
"Notepad3 kann so große Dateien nicht laden (Größe: %s)!"
|
||||
IDS_MUI_WARN_UNKNOWN_EXT
|
||||
"Unbekannte Dateierweiterung (%s)!\nSollen die Daten trotzdem geladen werden?"
|
||||
IDS_MUI_INDENT_CONSISTENT "Die Datei hat einheitliche Einrückungen!"
|
||||
|
||||
@ -146,9 +146,9 @@ BEGIN
|
||||
"The file ""%s"" cannot be saved and may be protected.\n\nDo you want to launch %s as 'Elevated' application?"
|
||||
IDS_MUI_ERR_ADMINEXE "No administration executable found.\nCheck website https://rizonesoft.com?"
|
||||
IDS_MUI_WARN_LOAD_BIG_FILE
|
||||
"Are you sure you want to open this large file?\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
"Are you sure you want to open this large file?\n\t(size: %s >= %s)!\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
IDS_MUI_ERR_FILE_TOO_LARGE
|
||||
"Can't handle that huge file (size: %lli MB)!"
|
||||
"Can't handle that huge file (size: %s)!"
|
||||
IDS_MUI_WARN_UNKNOWN_EXT
|
||||
"Unknown file name extension (%s)!\nLoading data anyway?"
|
||||
IDS_MUI_INDENT_CONSISTENT "The file has a consistent indentation!"
|
||||
|
||||
@ -146,9 +146,9 @@ BEGIN
|
||||
"The file ""%s"" cannot be saved and may be protected.\n\nDo you want to launch %s as 'Elevated' application?"
|
||||
IDS_MUI_ERR_ADMINEXE "No administration executable found.\nCheck website https://rizonesoft.com?"
|
||||
IDS_MUI_WARN_LOAD_BIG_FILE
|
||||
"Are you sure you want to open this large file?\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
"Are you sure you want to open this large file?\n\t(size: %s >= %s)!\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
IDS_MUI_ERR_FILE_TOO_LARGE
|
||||
"Can't handle that huge file (size: %lli MB)!"
|
||||
"Can't handle that huge file (size: %s)!"
|
||||
IDS_MUI_WARN_UNKNOWN_EXT
|
||||
"Unknown file name extension (%s)!\nLoading data anyway?"
|
||||
IDS_MUI_INDENT_CONSISTENT "The file has a consistent indentation!"
|
||||
|
||||
@ -146,9 +146,9 @@ BEGIN
|
||||
"El archivo ""%s"" no se puede guardar y puede estar protegido.\n\n¿Quiere lanzar %s como aplicación elevada?"
|
||||
IDS_MUI_ERR_ADMINEXE "No se ha encontrado administración ejecutable.\n¿Consultar website https://rizonesoft.com?"
|
||||
IDS_MUI_WARN_LOAD_BIG_FILE
|
||||
"¿Seguro que quiere abrir este archivo tan grande?\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
"¿Seguro que quiere abrir este archivo tan grande?\n\t(tamaño: %s >= %s)!\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
IDS_MUI_ERR_FILE_TOO_LARGE
|
||||
"No puedo manejar ese archivo enorme (tamaño: %lli MB)!"
|
||||
"No puedo manejar ese archivo enorme (tamaño: %s)!"
|
||||
IDS_MUI_WARN_UNKNOWN_EXT
|
||||
"¡Extensión de nombre de archivo desconocido (%s)!\n¿Cargar de todos modos?"
|
||||
IDS_MUI_INDENT_CONSISTENT "¡El archivo tiene una sangría consistente!"
|
||||
|
||||
@ -146,9 +146,9 @@ BEGIN
|
||||
"Le fichier ""% s "" ne peut pas être sauvegardé et est peut-être protégé.\n\nVoulez-vous lancer %s en tant qu'application élevée?"
|
||||
IDS_MUI_ERR_ADMINEXE "Aucun fichier exécutable d'administration trouvé.\nCheck website https://rizonesoft.com?"
|
||||
IDS_MUI_WARN_LOAD_BIG_FILE
|
||||
"Etes-vous sûr de vouloir ouvrir ce gros fichier?\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
"Etes-vous sûr de vouloir ouvrir ce gros fichier?\n\t(taille: %s >= %s)!\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
IDS_MUI_ERR_FILE_TOO_LARGE
|
||||
"Ne peut pas gérer cet énorme fichier (taille: %lli MB)!"
|
||||
"Ne peut pas gérer cet énorme fichier (taille: %s)!"
|
||||
IDS_MUI_WARN_UNKNOWN_EXT
|
||||
"Extension de nom de fichier inconnue (%s)!\nChargement des données quand même?"
|
||||
IDS_MUI_INDENT_CONSISTENT "Le fichier a un retrait cohérent!"
|
||||
|
||||
@ -146,9 +146,9 @@ BEGIN
|
||||
"A következő fájlt: ""%s"" nem lehet menteni, lehet, hogy védett.\n\nElindítsuk a %s alkalmazást adminisztrátorként?"
|
||||
IDS_MUI_ERR_ADMINEXE "Adminisztrátor végrehajtható nem található.\nFelkeressük ezt a weboldalt: https://rizonesoft.com?"
|
||||
IDS_MUI_WARN_LOAD_BIG_FILE
|
||||
"Biztosan meg szeretné nyitni ezt a nagy fájlt?\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
"Biztosan meg szeretné nyitni ezt a nagy fájlt?\n\t(méret: %s >= %s)!\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
IDS_MUI_ERR_FILE_TOO_LARGE
|
||||
"Nem tudok ilyen nagy fájlt kezelni (méret: %lli MB)!"
|
||||
"Nem tudok ilyen nagy fájlt kezelni (méret: %s)!"
|
||||
IDS_MUI_WARN_UNKNOWN_EXT
|
||||
"Ismeretlen fájlkiterjesztés (%s)!\nMindenképpen betöltsem?"
|
||||
IDS_MUI_INDENT_CONSISTENT "A fájlnak konzisztens behúzásai vannak!"
|
||||
|
||||
@ -146,9 +146,9 @@ BEGIN
|
||||
"Il file ""%s"" non può essere salvato e potrebbe essere protetto.\n\nVuoi aprire %s con diritti amministrativi?"
|
||||
IDS_MUI_ERR_ADMINEXE "Nessun eseguibile di administration trovato.\nControllare https://rizonesoft.com?"
|
||||
IDS_MUI_WARN_LOAD_BIG_FILE
|
||||
"Sei sicuro di voler aprire questo file grande?\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
"Sei sicuro di voler aprire questo file grande?\n\t(dimensione: %s >= %s)!\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
IDS_MUI_ERR_FILE_TOO_LARGE
|
||||
"Impossibile gestire un file così grande (dimensione: %lli MB)!"
|
||||
"Impossibile gestire un file così grande (dimensione: %s)!"
|
||||
IDS_MUI_WARN_UNKNOWN_EXT
|
||||
"Estensione sconosciuta (%s)!\nProseguire con il caricamento?"
|
||||
IDS_MUI_INDENT_CONSISTENT "Il file ha una indentazione consistente!"
|
||||
|
||||
@ -146,9 +146,9 @@ BEGIN
|
||||
"「%s」を保存できませんでした。保護されている可能性があります。\n\n権限を昇格して %s を起動しますか?"
|
||||
IDS_MUI_ERR_ADMINEXE "管理ツールが見つかりません。\nNotepad3 の公式サイトを開きますか? https://rizonesoft.com"
|
||||
IDS_MUI_WARN_LOAD_BIG_FILE
|
||||
"大容量のファイルです。このファイルを開きますか?\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
"大容量のファイルです。このファイルを開きますか?\n\t(サイズ: %s >= %s)!\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
IDS_MUI_ERR_FILE_TOO_LARGE
|
||||
"大容量すぎて処理できません! (サイズ: %lli MB)"
|
||||
"大容量すぎて処理できません! (サイズ: %s)"
|
||||
IDS_MUI_WARN_UNKNOWN_EXT
|
||||
"%s は設定のない拡張子です。\n読み込みますか?"
|
||||
IDS_MUI_INDENT_CONSISTENT "インデントは一貫しています。"
|
||||
|
||||
@ -146,9 +146,9 @@ BEGIN
|
||||
"""%s"" 파일을 저장할 수 없으며 보호되어 있을 수 있습니다.\n\nDo you want to launch %s as 'Elevated' application?"
|
||||
IDS_MUI_ERR_ADMINEXE "사용 가능한 관리 도구를 찾을 수 없습니다. https://rizonesoft.com 에서 확인 하시겠습니까?"
|
||||
IDS_MUI_WARN_LOAD_BIG_FILE
|
||||
"이 대용량 파일을 열겠습니까?\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
"이 대용량 파일을 열겠습니까?\n\t(size: %s >= %s)!\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
IDS_MUI_ERR_FILE_TOO_LARGE
|
||||
"Can't handle that huge file (size: %lli MB)!"
|
||||
"Can't handle that huge file (size: %s)!"
|
||||
IDS_MUI_WARN_UNKNOWN_EXT
|
||||
"알 수 없는 확장자 (%s)!\n데이터를 로딩 하시겠습니까?"
|
||||
IDS_MUI_INDENT_CONSISTENT "들여쓰기가 일관적입니다!"
|
||||
|
||||
@ -146,9 +146,9 @@ BEGIN
|
||||
"Het bestand ""%s"" kan niet worden opgeslagen en kan worden beveiligd.\n\nWilt u %s als verhoogde applicatie starten?"
|
||||
IDS_MUI_ERR_ADMINEXE "Geen administratief uitvoerbaar bestand gevonden.\nControleer website https://rizonesoft.com?"
|
||||
IDS_MUI_WARN_LOAD_BIG_FILE
|
||||
"Weet je zeker dat je dit grote bestand wilt openen?\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
"Weet je zeker dat je dit grote bestand wilt openen?\n\t(grootte: %s >= %s)!\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
IDS_MUI_ERR_FILE_TOO_LARGE
|
||||
"Kan dat enorme bestand niet aan (grootte: %lli MB)!"
|
||||
"Kan dat enorme bestand niet aan (grootte: %s)!"
|
||||
IDS_MUI_WARN_UNKNOWN_EXT
|
||||
"Onbekende bestandsnaamextensie (%s)!\nGegevens toch laden?"
|
||||
IDS_MUI_INDENT_CONSISTENT "Het bestand heeft een consistente inspringing!"
|
||||
|
||||
@ -146,9 +146,9 @@ BEGIN
|
||||
"Plik ""%s"" nie może zostać zapisany i może być zabezpieczony.\n\nDo you want to launch %s as 'Elevated' application?"
|
||||
IDS_MUI_ERR_ADMINEXE "Nie znaleziono narzędzia administracyjnego.\nSprawdź stronę https://rizonesoft.com?"
|
||||
IDS_MUI_WARN_LOAD_BIG_FILE
|
||||
"Czy na pewno chcesz otworzyć ten duży plik?\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
"Czy na pewno chcesz otworzyć ten duży plik?\n\t(size: %s >= %s)!\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
IDS_MUI_ERR_FILE_TOO_LARGE
|
||||
"Can't handle that huge file (size: %lli MB)!"
|
||||
"Can't handle that huge file (size: %s)!"
|
||||
IDS_MUI_WARN_UNKNOWN_EXT
|
||||
"Nieznane rozszerzenie nazwy pliku (%s)!\nCzy mimo to załadować?"
|
||||
IDS_MUI_INDENT_CONSISTENT "Ten plik posiada jednolite wcięcie!"
|
||||
|
||||
@ -146,9 +146,9 @@ BEGIN
|
||||
"The file ""%s"" cannot be saved and may be protected.\n\nDo you want to launch %s as 'Elevated' application??"
|
||||
IDS_MUI_ERR_ADMINEXE "No administration executable found.\nCheck website https://rizonesoft.com?"
|
||||
IDS_MUI_WARN_LOAD_BIG_FILE
|
||||
"Are you sure you want to open this large file?\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
"Are you sure you want to open this large file?\n\t(size: %s >= %s)!\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
IDS_MUI_ERR_FILE_TOO_LARGE
|
||||
"Can't handle that huge file (size: %lli MB)!"
|
||||
"Can't handle that huge file (size: %s)!"
|
||||
IDS_MUI_WARN_UNKNOWN_EXT
|
||||
"Unknown file name extension (%s)!\nLoading data anyway?"
|
||||
IDS_MUI_INDENT_CONSISTENT "The file has a consistent indentation!"
|
||||
|
||||
@ -146,9 +146,9 @@ BEGIN
|
||||
"Файл «%s» не может быть сохранен и может быть защищен.\n\nХотите запустить %s с повышенными правами?"
|
||||
IDS_MUI_ERR_ADMINEXE "Не найден инструмент администратора\nПосетить сайт https://rizonesoft.com?"
|
||||
IDS_MUI_WARN_LOAD_BIG_FILE
|
||||
"Вы уверены, что хотите открыть этот очень большой файл?\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
"Вы уверены, что хотите открыть этот очень большой файл?\n\t(размер: %s >= %s)!\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
IDS_MUI_ERR_FILE_TOO_LARGE
|
||||
"Невозможно обработать этот большой файл (размер: %lli МБ)!"
|
||||
"Невозможно обработать этот большой файл (размер: %s)!"
|
||||
IDS_MUI_WARN_UNKNOWN_EXT
|
||||
"Неизвестное расширения файла (%s)!\nПродолжить загрузку данных?"
|
||||
IDS_MUI_INDENT_CONSISTENT "Файл имеет одинакового вида отступы!"
|
||||
|
||||
@ -146,9 +146,9 @@ BEGIN
|
||||
"The file ""%s"" cannot be saved and may be protected.\n\nDo you want to launch %s as 'Elevated' application??"
|
||||
IDS_MUI_ERR_ADMINEXE "No administration executable found.\nCheck website https://rizonesoft.com?"
|
||||
IDS_MUI_WARN_LOAD_BIG_FILE
|
||||
"Are you sure you want to open this large file?\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
"Are you sure you want to open this large file?\n\t(size: %s >= %s)!\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
IDS_MUI_ERR_FILE_TOO_LARGE
|
||||
"Can't handle that huge file (size: %lli MB)!"
|
||||
"Can't handle that huge file (size: %s)!"
|
||||
IDS_MUI_WARN_UNKNOWN_EXT
|
||||
"Unknown file name extension (%s)!\nLoading data anyway?"
|
||||
IDS_MUI_INDENT_CONSISTENT "The file has a consistent indentation!"
|
||||
|
||||
@ -146,9 +146,9 @@ BEGIN
|
||||
"Filen ""%s"" kan inte sparas och kan vara skyddad.\n\nVill du köra %s med utökade privilegier?"
|
||||
IDS_MUI_ERR_ADMINEXE "Ingen exekverbar fil för administratör kan hittas.\nGå till websidan https://rizonesoft.com?"
|
||||
IDS_MUI_WARN_LOAD_BIG_FILE
|
||||
"Vill du öppna denna stora fil?\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
"Vill du öppna denna stora fil?\n\t(storlek: %s >= %s)!\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
IDS_MUI_ERR_FILE_TOO_LARGE
|
||||
"Kan inte hantera så stor fil (storlek: %lli MB)!"
|
||||
"Kan inte hantera så stor fil (storlek: %s)!"
|
||||
IDS_MUI_WARN_UNKNOWN_EXT
|
||||
"Okändt filnamnstillägg (%s)!\nVill du fortsätta ändå?"
|
||||
IDS_MUI_INDENT_CONSISTENT "Filen har konsistent indrag!"
|
||||
|
||||
@ -146,9 +146,9 @@ BEGIN
|
||||
"The file ""%s"" cannot be saved and may be protected.\n\nDo you want to launch %s as 'Elevated' application??"
|
||||
IDS_MUI_ERR_ADMINEXE "No administration executable found.\nCheck website https://rizonesoft.com?"
|
||||
IDS_MUI_WARN_LOAD_BIG_FILE
|
||||
"Are you sure you want to open this large file?\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
"Are you sure you want to open this large file?\n\t(size: %s >= %s)!\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
IDS_MUI_ERR_FILE_TOO_LARGE
|
||||
"Can't handle that huge file (size: %lli MB)!"
|
||||
"Can't handle that huge file (size: %s)!"
|
||||
IDS_MUI_WARN_UNKNOWN_EXT
|
||||
"Unknown file name extension (%s)!\nLoading data anyway?"
|
||||
IDS_MUI_INDENT_CONSISTENT "The file has a consistent indentation!"
|
||||
|
||||
@ -146,9 +146,9 @@ BEGIN
|
||||
"文件“%s”不能被保存,它可能是受保护的。\n\n是否希望提升 %s 的权限?"
|
||||
IDS_MUI_ERR_ADMINEXE "无管理工具可用。\n\n访问 https://rizonesoft.com/ 看看?"
|
||||
IDS_MUI_WARN_LOAD_BIG_FILE
|
||||
"是否确实要打开一个如此庞大的文件?\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
"是否确实要打开一个如此庞大的文件?\n\t(大小 %s >= %s)!\n(Styling and Syntax Highlighting will not be applied!)"
|
||||
IDS_MUI_ERR_FILE_TOO_LARGE
|
||||
"无法处理如此庞大的文件(大小 %lli MB)!"
|
||||
"无法处理如此庞大的文件(大小 %s)!"
|
||||
IDS_MUI_WARN_UNKNOWN_EXT
|
||||
"扩展名“%s”不是已知的文本文件。仍然要尝试打开吗?"
|
||||
IDS_MUI_INDENT_CONSISTENT "该文件的缩进全部一致。"
|
||||
|
||||
168
src/Edit.c
168
src/Edit.c
@ -1044,33 +1044,52 @@ bool EditLoadFile(
|
||||
return false;
|
||||
}
|
||||
|
||||
// calculate buffer limit
|
||||
// calculate buffer size and limits
|
||||
|
||||
LARGE_INTEGER liFileSize = { 0, 0 };
|
||||
bool const okay = GetFileSizeEx(hFile, &liFileSize);
|
||||
bool const bLargerThan2GB = okay && (liFileSize.LowPart >= ((DWORD)INT32_MAX));
|
||||
//DWORD const fileSizeMB = (DWORD)liFileSize.HighPart * (DWORD_MAX >> 20) + (liFileSize.LowPart >> 20);
|
||||
|
||||
bool const bLargerThan2GB = okay && ((liFileSize.HighPart > 0) || (liFileSize.LowPart >= (DWORD)INT32_MAX));
|
||||
|
||||
//if (!okay || (liFileSize.HighPart != 0) || (liFileSize.LowPart > (DWORD_MAX - 8))) {
|
||||
if (!okay || (liFileSize.HighPart != 0) || bLargerThan2GB) {
|
||||
if (!okay || bLargerThan2GB) {
|
||||
if (!okay) {
|
||||
Globals.dwLastError = GetLastError();
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
// refuse to handle file
|
||||
InfoBoxLng(MB_ICONERROR, NULL, IDS_MUI_ERR_FILE_TOO_LARGE, (liFileSize.QuadPart / 1024LL / 1024LL));
|
||||
CloseHandle(hFile);
|
||||
Encoding_Forced(CPI_NONE);
|
||||
Flags.bLargeFileLoaded = true;
|
||||
#ifdef _WIN64
|
||||
// can only handle ASCII/UTF-8 of this size
|
||||
Encoding_Forced(CPI_UTF8);
|
||||
// @@@ TODO: Scintilla can't handle files larger than 4GB :-( yet (2020-02-25)
|
||||
bool const bFileTooBig = (liFileSize.HighPart > 0); // > DWORD_MAX
|
||||
#else
|
||||
bool const bFileTooBig = true; // _WIN32: file size < 2GB only
|
||||
#endif
|
||||
if (bFileTooBig) {
|
||||
// refuse to handle file in 32-bit
|
||||
WCHAR sizeStr[64] = { L'\0' };
|
||||
StrFormatByteSize((LONGLONG)liFileSize.QuadPart, sizeStr, COUNTOF(sizeStr));
|
||||
InfoBoxLng(MB_ICONERROR, NULL, IDS_MUI_ERR_FILE_TOO_LARGE, sizeStr);
|
||||
CloseHandle(hFile);
|
||||
Encoding_Forced(CPI_NONE);
|
||||
Flags.bLargeFileLoaded = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
DWORD const dwFileSize = liFileSize.LowPart;
|
||||
DWORD const dwBufferSize = dwFileSize + 8;
|
||||
size_t const fileSize = (size_t)liFileSize.QuadPart;
|
||||
|
||||
// Check if a warning message should be displayed for large files
|
||||
DWORD const dwFileSizeLimit = (DWORD)Settings2.FileLoadWarningMB;
|
||||
if ((dwFileSizeLimit != 0LL) && ((dwFileSizeLimit * 1024LL * 1024LL) < dwFileSize)) {
|
||||
if (InfoBoxLng(MB_YESNO, L"MsgFileSizeWarning", IDS_MUI_WARN_LOAD_BIG_FILE) != IDYES) {
|
||||
size_t const fileSizeWarning = (size_t)Settings2.FileLoadWarningMB << 20;
|
||||
if ((fileSizeWarning != 0ULL) && (fileSizeWarning <= fileSize))
|
||||
{
|
||||
WCHAR sizeStr[64] = { L'\0' };
|
||||
StrFormatByteSize((LONGLONG)liFileSize.QuadPart, sizeStr, COUNTOF(sizeStr));
|
||||
WCHAR sizeWarnStr[64] = { L'\0' };
|
||||
StrFormatByteSize((LONGLONG)fileSizeWarning, sizeWarnStr, COUNTOF(sizeWarnStr));
|
||||
if (InfoBoxLng(MB_YESNO, L"MsgFileSizeWarning", IDS_MUI_WARN_LOAD_BIG_FILE, sizeStr, sizeWarnStr) != IDYES) {
|
||||
CloseHandle(hFile);
|
||||
Encoding_Forced(CPI_NONE);
|
||||
return false;
|
||||
@ -1091,7 +1110,7 @@ bool EditLoadFile(
|
||||
}
|
||||
|
||||
// new document text buffer
|
||||
char* lpData = AllocMem(dwBufferSize, HEAP_ZERO_MEMORY);
|
||||
char* lpData = AllocMem(fileSize + 2ULL, HEAP_ZERO_MEMORY);
|
||||
if (!lpData)
|
||||
{
|
||||
Globals.dwLastError = GetLastError();
|
||||
@ -1102,7 +1121,7 @@ bool EditLoadFile(
|
||||
}
|
||||
|
||||
size_t cbData = 0LL;
|
||||
int const readFlag = ReadAndDecryptFile(hwnd, hFile, dwBufferSize, (void**)&lpData, &cbData);
|
||||
int const readFlag = ReadAndDecryptFile(hwnd, hFile, fileSize, (void**)&lpData, &cbData);
|
||||
Globals.dwLastError = GetLastError();
|
||||
CloseHandle(hFile);
|
||||
|
||||
@ -1137,6 +1156,31 @@ bool EditLoadFile(
|
||||
return false;
|
||||
}
|
||||
|
||||
// force very large file to be ASCII/UTF-8 (!) - Scintilla can't handle it otherwise
|
||||
if (bLargerThan2GB)
|
||||
{
|
||||
bool const bIsUTF8Sig = IsUTF8Signature(lpData);
|
||||
Encoding_Forced(bIsUTF8Sig ? CPI_UTF8SIGN : CPI_UTF8);
|
||||
|
||||
FileVars_Init(NULL, 0, &Globals.fvCurFile);
|
||||
status->iEncoding = Encoding_Forced(CPI_GET);
|
||||
status->iEOLMode = Settings.DefaultEOLMode;
|
||||
|
||||
if (bIsUTF8Sig) {
|
||||
EditSetNewText(hwnd, UTF8StringStart(lpData), cbData - 3, bClearUndoHistory);
|
||||
}
|
||||
else {
|
||||
EditSetNewText(hwnd, lpData, cbData, bClearUndoHistory);
|
||||
}
|
||||
|
||||
SciCall_SetEOLMode(Settings.DefaultEOLMode);
|
||||
|
||||
FreeMem(lpData);
|
||||
return true;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
ENC_DET_T encDetection = Encoding_DetectEncoding(pszFile, lpData, cbData, iEncFallback,
|
||||
bSkipUTFDetection, bSkipANSICPDetection, bForceEncDetection);
|
||||
|
||||
@ -1301,10 +1345,10 @@ bool EditSaveFile(
|
||||
{
|
||||
|
||||
HANDLE hFile;
|
||||
bool bWriteSuccess;
|
||||
bool bWriteSuccess = false;
|
||||
|
||||
char* lpData;
|
||||
size_t dwBytesWritten;
|
||||
size_t bytesWritten;
|
||||
|
||||
status->bCancelDataLoss = false;
|
||||
|
||||
@ -1359,17 +1403,58 @@ bool EditSaveFile(
|
||||
// get text
|
||||
DocPos cbData = SciCall_GetTextLength();
|
||||
|
||||
if (cbData <= 0) {
|
||||
bWriteSuccess = SetEndOfFile(hFile);
|
||||
// files larger than 2GB will be forced stored as ASCII/UTF-8
|
||||
if (cbData >= (DocPos)INT32_MAX) {
|
||||
Encoding_Current(CPI_UTF8);
|
||||
Encoding_Forced(CPI_UTF8);
|
||||
status->iEncoding = Encoding_Forced(CPI_GET);
|
||||
}
|
||||
|
||||
if ((cbData <= 0) || (cbData >= DWORD_MAX)) {
|
||||
bWriteSuccess = SetEndOfFile(hFile) && (cbData < DWORD_MAX);
|
||||
Globals.dwLastError = GetLastError();
|
||||
}
|
||||
else {
|
||||
|
||||
lpData = AllocMem(cbData + 4, HEAP_ZERO_MEMORY); //fix: +bom
|
||||
cbData = SciCall_GetText((cbData+1), lpData);
|
||||
|
||||
if (Encoding_IsUNICODE(status->iEncoding)) // UTF-16LE/BE_(BOM)
|
||||
if (Encoding_IsUTF8(status->iEncoding))
|
||||
{
|
||||
const char* bom = NULL;
|
||||
DocPos bomoffset = 0;
|
||||
|
||||
if (Encoding_IsUTF8_SIGN(status->iEncoding)) {
|
||||
bom = "\xEF\xBB\xBF";
|
||||
bomoffset = 3;
|
||||
}
|
||||
|
||||
SetEndOfFile(hFile);
|
||||
|
||||
if (IsEncryptionRequired() && (cbData < ((DocPos)INT32_MAX - 4)))
|
||||
{
|
||||
lpData = AllocMem(cbData + 4, HEAP_ZERO_MEMORY); //fix: +bom
|
||||
cbData = SciCall_GetText((cbData + 1), lpData);
|
||||
if (bom) {
|
||||
MoveMemory(&lpData[bomoffset], lpData, cbData);
|
||||
CopyMemory(lpData, bom, bomoffset);
|
||||
}
|
||||
bWriteSuccess = EncryptAndWriteFile(hwnd, hFile, (BYTE*)lpData, (size_t)(cbData + bomoffset), &bytesWritten);
|
||||
Globals.dwLastError = GetLastError();
|
||||
FreeMem(lpData);
|
||||
}
|
||||
else { // raw data handling of UTF-8 or >2GB file size
|
||||
DWORD dwBytesWritten = 0;
|
||||
if (bom) {
|
||||
WriteFile(hFile, bom, (DWORD)bomoffset, &dwBytesWritten, NULL);
|
||||
}
|
||||
bWriteSuccess = WriteFile(hFile, SciCall_GetCharacterPointer(), (DWORD)cbData, &dwBytesWritten, NULL);
|
||||
bytesWritten = (size_t)dwBytesWritten + bomoffset;
|
||||
}
|
||||
}
|
||||
|
||||
else if (Encoding_IsUNICODE(status->iEncoding)) // UTF-16LE/BE_(BOM)
|
||||
{
|
||||
lpData = AllocMem(cbData + 4, HEAP_ZERO_MEMORY); //fix: +bom
|
||||
cbData = SciCall_GetText((cbData + 1), lpData);
|
||||
|
||||
SetEndOfFile(hFile);
|
||||
|
||||
LPWSTR lpDataWide = AllocMem((cbData+1) * 2 + 2, HEAP_ZERO_MEMORY);
|
||||
@ -1385,33 +1470,18 @@ bool EditSaveFile(
|
||||
if (Encoding_IsUNICODE_REVERSE(status->iEncoding)) {
|
||||
SwabEx((char*)lpDataWide, (char*)lpDataWide, cbDataWide * sizeof(WCHAR));
|
||||
}
|
||||
bWriteSuccess = EncryptAndWriteFile(hwnd, hFile, (BYTE*)lpDataWide, cbDataWide * sizeof(WCHAR), &dwBytesWritten);
|
||||
bWriteSuccess = EncryptAndWriteFile(hwnd, hFile, (BYTE*)lpDataWide, cbDataWide * sizeof(WCHAR), &bytesWritten);
|
||||
Globals.dwLastError = GetLastError();
|
||||
|
||||
FreeMem(lpDataWide);
|
||||
FreeMem(lpData);
|
||||
}
|
||||
|
||||
else if (Encoding_IsUTF8(status->iEncoding))
|
||||
{
|
||||
SetEndOfFile(hFile);
|
||||
|
||||
DocPos bomoffset = 0;
|
||||
if (Encoding_IsUTF8_SIGN(status->iEncoding)) {
|
||||
const char* bom = "\xEF\xBB\xBF";
|
||||
bomoffset = 3;
|
||||
MoveMemory(&lpData[bomoffset], lpData, cbData);
|
||||
CopyMemory(lpData, bom, bomoffset);
|
||||
}
|
||||
//bWriteSuccess = WriteFile(hFile,lpData,cbData,&dwBytesWritten,NULL);
|
||||
bWriteSuccess = EncryptAndWriteFile(hwnd, hFile, (BYTE*)lpData, (DWORD)(cbData + bomoffset), &dwBytesWritten);
|
||||
Globals.dwLastError = GetLastError();
|
||||
|
||||
FreeMem(lpData);
|
||||
}
|
||||
|
||||
else if (Encoding_IsEXTERNAL_8BIT(status->iEncoding)) {
|
||||
|
||||
lpData = AllocMem(cbData + 4, HEAP_ZERO_MEMORY); //fix: +bom
|
||||
cbData = SciCall_GetText((cbData + 1), lpData);
|
||||
|
||||
BOOL bCancelDataLoss = FALSE;
|
||||
UINT uCodePage = Encoding_GetCodePage(status->iEncoding);
|
||||
|
||||
@ -1440,7 +1510,7 @@ bool EditSaveFile(
|
||||
|
||||
if (!bCancelDataLoss || InfoBoxLng(MB_OKCANCEL,L"MsgConv3",IDS_MUI_ERR_UNICODE2) == IDOK) {
|
||||
SetEndOfFile(hFile);
|
||||
bWriteSuccess = EncryptAndWriteFile(hwnd, hFile, (BYTE*)lpData, cbDataNew, &dwBytesWritten);
|
||||
bWriteSuccess = EncryptAndWriteFile(hwnd, hFile, (BYTE*)lpData, cbDataNew, &bytesWritten);
|
||||
Globals.dwLastError = GetLastError();
|
||||
}
|
||||
else {
|
||||
@ -1450,9 +1520,13 @@ bool EditSaveFile(
|
||||
FreeMem(lpData);
|
||||
}
|
||||
|
||||
else {
|
||||
else
|
||||
{
|
||||
lpData = AllocMem(cbData + 4, HEAP_ZERO_MEMORY); //fix: +bom
|
||||
cbData = SciCall_GetText((cbData + 1), lpData);
|
||||
|
||||
SetEndOfFile(hFile);
|
||||
bWriteSuccess = EncryptAndWriteFile(hwnd, hFile, (BYTE*)lpData, (DWORD)cbData, &dwBytesWritten);
|
||||
bWriteSuccess = EncryptAndWriteFile(hwnd, hFile, (BYTE*)lpData, (DWORD)cbData, &bytesWritten);
|
||||
Globals.dwLastError = GetLastError();
|
||||
FreeMem(lpData);
|
||||
}
|
||||
|
||||
@ -910,6 +910,53 @@ bool IsCmdEnabled(HWND hwnd,UINT uId)
|
||||
return (!(ustate & (MF_GRAYED|MF_DISABLED)));
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// ReadFileXL()
|
||||
//
|
||||
bool ReadFileXL(HANDLE hFile, BYTE* const lpBuffer, size_t nNumberOfBytesToRead, size_t* lpNumberOfBytesRead)
|
||||
{
|
||||
DWORD dwRead = 0;
|
||||
size_t bytesRead = 0ULL;
|
||||
size_t bytesLeft = nNumberOfBytesToRead;
|
||||
bool bReadOk = false;
|
||||
do {
|
||||
DWORD const chunk_size = (bytesLeft < (size_t)DWORD_MAX) ? (DWORD)bytesLeft : DWORD_MAX - 1UL;
|
||||
bReadOk = ReadFile(hFile, &lpBuffer[bytesRead], chunk_size, &dwRead, NULL);
|
||||
bytesRead += (size_t)dwRead;
|
||||
bytesLeft -= (size_t)dwRead;
|
||||
}
|
||||
while (bReadOk && ((dwRead != 0) && (bytesLeft > 0)));
|
||||
|
||||
*lpNumberOfBytesRead = bytesRead;
|
||||
return (bytesRead == nNumberOfBytesToRead);
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// WriteFileXL()
|
||||
//
|
||||
bool WriteFileXL(HANDLE hFile, const BYTE* const lpBuffer, size_t nNumberOfBytesToWrite, size_t* lpNumberOfBytesWritten)
|
||||
{
|
||||
DWORD dwWritten = 0;
|
||||
size_t bytesWritten = 0ULL;
|
||||
size_t bytesLeft = nNumberOfBytesToWrite;
|
||||
bool bWriteOk = false;
|
||||
do {
|
||||
DWORD const chunk_size = (bytesLeft < (size_t)DWORD_MAX) ? (DWORD)bytesLeft : DWORD_MAX - 1UL;
|
||||
|
||||
bWriteOk = WriteFile(hFile, &lpBuffer[bytesWritten], chunk_size, &dwWritten, NULL);
|
||||
bytesWritten += (size_t)dwWritten;
|
||||
bytesLeft -= (size_t)dwWritten;
|
||||
}
|
||||
while (bWriteOk && ((dwWritten != 0) && (bytesLeft > 0)));
|
||||
|
||||
*lpNumberOfBytesWritten = bytesWritten;
|
||||
return (bytesWritten == nNumberOfBytesToWrite);
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// GetKnownFolderPath()
|
||||
|
||||
@ -292,7 +292,8 @@ inline bool IsButtonUnchecked(HWND hwnd, int iButtonID) { return (IsDlgButtonChe
|
||||
#define CheckCmdPos(hmenu,pos,b) CheckMenuItem((hmenu),(pos),(b)?MF_BYPOSITION|MF_CHECKED:MF_BYPOSITION|MF_UNCHECKED)
|
||||
|
||||
|
||||
|
||||
bool ReadFileXL(HANDLE hFile, BYTE* const lpBuffer, size_t nNumberOfBytesToRead, size_t* lpNumberOfBytesRead);
|
||||
bool WriteFileXL(HANDLE hFile, const BYTE* const lpBuffer, size_t nNumberOfBytesToWrite, size_t* lpNumberOfBytesWritten);
|
||||
bool GetKnownFolderPath(REFKNOWNFOLDERID, LPWSTR lpOutPath, size_t cchCount);
|
||||
void PathRelativeToApp(LPWSTR lpszSrc,LPWSTR lpszDest,int cchDest,bool,bool,bool);
|
||||
void PathAbsoluteFromApp(LPWSTR lpszSrc,LPWSTR lpszDest,int cchDest,bool);
|
||||
|
||||
@ -1394,7 +1394,7 @@ HWND InitInstance(HINSTANCE hInstance,LPCWSTR pszCmdLine,int nCmdShow)
|
||||
// Match Text
|
||||
if (s_flagMatchText && StrIsNotEmpty(s_lpMatchArg))
|
||||
{
|
||||
if (SciCall_GetTextLength() > 0) {
|
||||
if (!Sci_IsDocEmpty()) {
|
||||
|
||||
WideCharToMultiByteEx(Encoding_SciCP,0,s_lpMatchArg,-1,Settings.EFR_Data.szFind,COUNTOF(Settings.EFR_Data.szFind),NULL,NULL);
|
||||
|
||||
@ -3910,7 +3910,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
|
||||
_IGNORE_NOTIFY_CHANGE_;
|
||||
if (EditSetNewEncoding(Globals.hwndEdit, iNewEncoding, (s_flagSetEncoding != CPI_NONE))) {
|
||||
|
||||
if (SciCall_GetTextLength() <= 0) {
|
||||
if (Sci_IsDocEmpty()) {
|
||||
Encoding_Current(iNewEncoding);
|
||||
Encoding_HasChanged(iNewEncoding);
|
||||
}
|
||||
@ -4929,7 +4929,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
|
||||
case IDM_EDIT_SELTONEXT:
|
||||
case IDM_EDIT_SELTOPREV:
|
||||
|
||||
if (SciCall_GetTextLength() <= 0) { break; }
|
||||
if (Sci_IsDocEmpty()) { break; }
|
||||
|
||||
if (Sci_IsMultiSelection()) {
|
||||
switch (iLoWParam) {
|
||||
@ -8207,7 +8207,7 @@ static void _UpdateToolbarDelayed()
|
||||
CheckTool(Globals.hwndToolbar, IDT_VIEW_PIN_ON_TOP, Settings.AlwaysOnTop);
|
||||
|
||||
bool b1 = SciCall_IsSelectionEmpty();
|
||||
bool b2 = (bool)(SciCall_GetTextLength() > 0);
|
||||
bool b2 = !Sci_IsDocEmpty();
|
||||
bool ro = SciCall_GetReadOnly();
|
||||
bool tv = FocusedView.HideNonMatchedLines;
|
||||
|
||||
|
||||
@ -647,7 +647,7 @@ inline int Sci_GetCurrentEOL_W(LPWCH eol) {
|
||||
inline DocPos Sci_GetSelectionStartEx() {
|
||||
if (!Sci_IsMultiSelection()) { return SciCall_GetSelectionStart(); }
|
||||
DocPosU const nsel = SciCall_GetSelections();
|
||||
DocPos selStart = SciCall_GetTextLength() + 1;
|
||||
DocPos selStart = Sci_GetDocEndPosition() + 1;
|
||||
for (DocPosU i = 0; i < nsel; ++i) {
|
||||
DocPos const iStart = SciCall_GetSelectionNStart(i);
|
||||
if (iStart < selStart) { selStart = iStart; }
|
||||
|
||||
Loading…
Reference in New Issue
Block a user