+ fix: Read-Only-Attribute cooperating with Exclusive-Write-Lock

This commit is contained in:
Rainer Kottenhoff 2021-03-24 13:51:31 +01:00
parent ee8c9f5498
commit 3ba128653d
2 changed files with 29 additions and 16 deletions

View File

@ -4709,7 +4709,8 @@ void SetWindowTitle(HWND hwnd, LPCWSTR lpszFile, int iFormat,
GetLngString(IDS_MUI_FILELOCKED, wchModeEx, COUNTOF(wchModeEx));
StringCchCat(szTitle, COUNTOF(szTitle), L" ");
StringCchCat(szTitle, COUNTOF(szTitle), wchModeEx);
} else if (bReadOnly) {
}
if (bReadOnly) {
GetLngString(IDS_MUI_READONLY, wchModeEx, COUNTOF(wchModeEx));
StringCchCat(szTitle, COUNTOF(szTitle), L" ");
StringCchCat(szTitle, COUNTOF(szTitle), wchModeEx);

View File

@ -11421,22 +11421,34 @@ void InstallFileWatching(const bool bInstall) {
assert(!IS_VALID_HANDLE(_hCurrFileHandle) && "CurrFileHandle not properly closed!");
_hCurrFileHandle = CreateFile(Paths.CurrentFile,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ, // 0 => NO FILE_SHARE_RW
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
Globals.dwLastError = GetLastError();
if (!IS_VALID_HANDLE(_hCurrFileHandle)) {
InfoBoxLng(MB_ICONERROR, NULL, IDS_MUI_FILELOCK_ERROR, PathFindFileName(Paths.CurrentFile));
// need to chose another mode
FILE_WATCHING_MODE const fwm = Settings.FileWatchingMode;
FileWatching.FileWatchingMode = (fwm != FWM_EXCLUSIVELOCK) ? fwm : FWM_MSGBOX;
InstallFileWatching(bInstall);
bool const bPrevReadOnlyAttrib = s_bFileReadOnly;
if (s_bFileReadOnly) {
SendWMCommand(Globals.hwndMain, IDM_FILE_READONLY); // try to gain access
}
if (!s_bFileReadOnly) {
_hCurrFileHandle = CreateFile(Paths.CurrentFile,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ, // 0 => NO FILE_SHARE_RW
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
Globals.dwLastError = GetLastError();
if (!IS_VALID_HANDLE(_hCurrFileHandle)) {
InfoBoxLng(MB_ICONERROR, NULL, IDS_MUI_FILELOCK_ERROR, PathFindFileName(Paths.CurrentFile));
// need to chose another mode
FILE_WATCHING_MODE const fwm = Settings.FileWatchingMode;
FileWatching.FileWatchingMode = (fwm != FWM_EXCLUSIVELOCK) ? fwm : FWM_MSGBOX;
InstallFileWatching(bInstall);
}
}
if (bPrevReadOnlyAttrib && !s_bFileReadOnly) {
SendWMCommand(Globals.hwndMain, IDM_FILE_READONLY); // try to reset
}
}
}
UpdateTitleBar(Globals.hwndMain);