+ fix: translatable error message format (msgbox)

+ chg: add filepath to message on file locking error
This commit is contained in:
Rainer Kottenhoff 2020-03-30 23:19:36 +02:00
parent 6d494ffb51
commit 1de35f8c6d
5 changed files with 69 additions and 33 deletions

View File

@ -80,6 +80,7 @@
#define IDS_MUI_WARN_LOAD_BIG_FILE 13015
#define IDS_MUI_ERR_FILE_TOO_LARGE 13016
#define IDS_MUI_WARN_UNKNOWN_EXT 13017
#define IDS_MUI_ERR_DLG_FORMAT 13018
// keep order (CRLF(0), CR(1), LF(2))
#define IDS_MUI_EOLMODENAME_CRLF 13020
#define IDS_MUI_EOLMODENAME_CR 13021

View File

@ -126,6 +126,7 @@ STRINGTABLE
BEGIN
IDS_MUI_ERR_LOADFILE "Error loading ""%s""."
IDS_MUI_ERR_SAVEFILE "Error saving ""%s""."
IDS_MUI_ERR_DLG_FORMAT "Error '%s', cause:\n%s(ID:%d)\n"
IDS_MUI_ERR_BROWSE "No file browser plugin was found.\nThe MiniPath file browser plugin can be downloaded from https://rizonesoft.com."
IDS_MUI_ERR_GREPWIN "No file search plugin was found.\nThe grepWinNP3 file search plugin can be downloaded from https://rizonesoft.com."
IDS_MUI_ERR_MRUDLG "No access to the selected file!\nWould you like to remove it from the list?"

View File

@ -102,11 +102,17 @@ HANDLE AcquireWriteFileLock(LPCWSTR lpIniFilePath, OVERLAPPED& rOvrLpd)
{
bLocked = LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK, 0, MAXDWORD, 0, &rOvrLpd); // wait for exclusive lock
if (!bLocked) {
MsgBoxLastError(L"AcquireWriteFileLock(): NO EXCLUSIVE LOCK ACQUIRED!", 0);
wchar_t msg[MAX_PATH + 128] = { 0 };
StringCchPrintf(msg, ARRAYSIZE(msg),
L"AcquireWriteFileLock(%s): NO EXCLUSIVE LOCK ACQUIRED!", lpIniFilePath);
MsgBoxLastError(msg, 0);
}
}
else {
MsgBoxLastError(L"AcquireWriteFileLock(): INVALID FILE HANDLE!", 0);
wchar_t msg[MAX_PATH + 128] = { 0 };
StringCchPrintf(msg, ARRAYSIZE(msg),
L"AcquireWriteFileLock(%s): INVALID FILE HANDLE!", lpIniFilePath);
MsgBoxLastError(msg, 0);
}
return (bLocked ? hFile : INVALID_HANDLE_VALUE);
}
@ -129,11 +135,17 @@ HANDLE AcquireReadFileLock(LPCWSTR lpIniFilePath, OVERLAPPED& rOvrLpd)
{
bLocked = LockFileEx(hFile, LOCKFILE_SHARED_LOCK, 0, MAXDWORD, 0, &rOvrLpd);
if (!bLocked) {
MsgBoxLastError(L"AcquireReadFileLock(): NO READER LOCK ACQUIRED!", 0);
wchar_t msg[MAX_PATH + 128] = { 0 };
StringCchPrintf(msg, ARRAYSIZE(msg),
L"AcquireReadFileLock(%s): NO READER LOCK ACQUIRED!", lpIniFilePath);
MsgBoxLastError(msg, 0);
}
}
else {
MsgBoxLastError(L"AcquireReadFileLock(): INVALID FILE HANDLE", 0);
wchar_t msg[MAX_PATH + 128] = { 0 };
StringCchPrintf(msg, ARRAYSIZE(msg),
L"AcquireReadFileLock(%s): INVALID FILE HANDLE!", lpIniFilePath);
MsgBoxLastError(msg, 0);
}
return (bLocked ? hFile : INVALID_HANDLE_VALUE);
}
@ -915,7 +927,10 @@ extern "C" bool CreateIniFile()
CloseHandle(hFile); // done
}
else {
MsgBoxLastError(L"CreateIniFile(): FAILD TO CREATE INITIAL INI FILE!", 0);
wchar_t msg[MAX_PATH + 128] = { 0 };
StringCchPrintf(msg, ARRAYSIZE(msg),
L"CreateIniFile(%s): FAILD TO CREATE INITIAL INI FILE!", Globals.IniFile);
MsgBoxLastError(msg, 0);
}
}
else {
@ -929,7 +944,10 @@ extern "C" bool CreateIniFile()
CloseHandle(hFile);
}
else {
MsgBoxLastError(L"CreateIniFile(): FAILED TO GET FILESIZE!", 0);
wchar_t msg[MAX_PATH + 128] = { 0 };
StringCchPrintf(msg, ARRAYSIZE(msg),
L"CreateIniFile(%s): FAILED TO GET FILESIZE!", Globals.IniFile);
MsgBoxLastError(msg, 0);
dwFileSize = INVALID_FILE_SIZE;
}
}

View File

@ -246,6 +246,7 @@
#include <list>
#include <algorithm>
#include <stdio.h>
#include <strsafe.h>
#ifdef SI_SUPPORT_IOSTREAMS
# include <iostream>
@ -1429,19 +1430,27 @@ CSimpleIniTempl<SI_CHAR, SI_STRLESS, SI_CONVERTER>::LoadFile(
const SI_WCHAR_T* a_pwszFile
)
{
HANDLE hFile = CreateFile(a_pwszFile,
GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
if (a_pwszFile && a_pwszFile[0])
{
HANDLE hFile = CreateFile(a_pwszFile,
GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
if (hFile == INVALID_HANDLE_VALUE) {
MsgBoxLastError(L"CSimpleIni::LoadFile(): INVALID_HANDLE_VALUE!", 0);
return SI_Error::SI_FILE;
if (hFile == INVALID_HANDLE_VALUE) {
wchar_t msg[MAX_PATH + 128] = { 0 };
StringCchPrintf(msg, ARRAYSIZE(msg),
L"CSimpleIni::LoadFile(%s): INVALID_HANDLE_VALUE!", a_pwszFile);
MsgBoxLastError(msg, 0);
return SI_Error::SI_FILE;
}
SI_Error rc = LoadFile(hFile);
CloseHandle(hFile);
return rc;
}
SI_Error rc = LoadFile(hFile);
CloseHandle(hFile);
return rc;
return SI_Error::SI_FILE;
}
#else
@ -2629,19 +2638,26 @@ CSimpleIniTempl<SI_CHAR, SI_STRLESS, SI_CONVERTER>::SaveFile(
bool a_bAddSignature
) const
{
HANDLE hFile = CreateFile(a_pwszFile,
GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
if (a_pwszFile && a_pwszFile[0])
{
HANDLE hFile = CreateFile(a_pwszFile,
GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
if (hFile == INVALID_HANDLE_VALUE) {
MsgBoxLastError(L"CSimpleIni::SaveFile(): INVALID_HANDLE_VALUE!", 0);
return SI_Error::SI_FILE;
if (hFile == INVALID_HANDLE_VALUE) {
wchar_t msg[MAX_PATH + 128] = { 0 };
StringCchPrintf(msg, ARRAYSIZE(msg),
L"CSimpleIni::SaveFile(%s): INVALID_HANDLE_VALUE!", a_pwszFile);
MsgBoxLastError(msg, 0);
return SI_Error::SI_FILE;
}
SI_Error rc = SaveFile(hFile, a_bAddSignature);
CloseHandle(hFile);
return rc;
}
SI_Error rc = SaveFile(hFile, a_bAddSignature);
CloseHandle(hFile);
return rc;
return SI_Error::SI_FILE;
}
#else

View File

@ -158,18 +158,18 @@ DWORD MsgBoxLastError(LPCWSTR lpszMessage, DWORD dwErrID)
NULL,
dwErrID,
Globals.iPrefLANGID,
(LPTSTR)&lpMsgBuf,
(LPWSTR)&lpMsgBuf,
0, NULL);
if (lpMsgBuf) {
// Display the error message and exit the process
size_t const len = StringCchLenW((LPCWSTR)lpMsgBuf, 0) + StringCchLenW(lpszMessage, 0) + 80;
size_t const len = StringCchLen((LPCWSTR)lpMsgBuf, 0) + StringCchLen(lpszMessage, 0) + 160;
LPWSTR lpDisplayBuf = (LPWSTR)AllocMem(len * sizeof(WCHAR), HEAP_ZERO_MEMORY);
if (lpDisplayBuf) {
StringCchPrintf(lpDisplayBuf, len, L"Error: '%s' failed with error id %d:\n%s.\n",
lpszMessage, dwErrID, (LPCWSTR)lpMsgBuf);
WCHAR msgFormat[128] = { L'\0' };
GetLngString(IDS_MUI_ERR_DLG_FORMAT, msgFormat, COUNTOF(msgFormat));
StringCchPrintf(lpDisplayBuf, len, msgFormat, lpszMessage, (LPCWSTR)lpMsgBuf, dwErrID);
// center message box to main
HWND focus = GetFocus();
HWND hwnd = focus ? focus : Globals.hwndMain;