mirror of
https://github.com/rizonesoft/Notepad3.git
synced 2026-06-14 21:09:05 +08:00
+ fix: Ask before overriding read-only protected configuration file.
This commit is contained in:
parent
7285c1fdc4
commit
33811e9ecd
@ -110,6 +110,7 @@
|
||||
#define IDS_MUI_DROP_NO_FILE 14018
|
||||
#define IDS_MUI_SELMULTI 14019
|
||||
#define IDS_MUI_SELRECTORMULTI 14020
|
||||
#define IDS_MUI_INIFILE_READONLY 14021
|
||||
|
||||
#define IDS_MUI_ASK_SAVE 15000
|
||||
#define IDS_MUI_ASK_REVERT 15001
|
||||
|
||||
@ -180,6 +180,8 @@ BEGIN
|
||||
IDS_MUI_SAVEDSETTINGS "Die aktuellen Notepad3 Einstellungen wurden gespeichert."
|
||||
IDS_MUI_CREATEINI_FAIL "Fehler bei der Erzeugung einer Konfigurationsdatei."
|
||||
IDS_MUI_WRITEINI_FAIL "Fehler beim schreiben der Einstellungen in die Konfigurationsdatei."
|
||||
IDS_MUI_INIFILE_READONLY
|
||||
"Die Konfigurationsdatei ist schreibgeschützt - ignorieren und Konfiguration überschreiben?"
|
||||
IDS_MUI_SETTINGSNOTSAVED
|
||||
"Es wurde keine Konfigurationsdatei gefunden.\nUm die Veränderungen der Stilanpassungen zu behalten, sollten die Einstellungen gespeichert werden (F7) oder über die Schematakonfiguration (Ctrl+F12) exportiert werden."
|
||||
END
|
||||
|
||||
@ -180,6 +180,8 @@ BEGIN
|
||||
IDS_MUI_SAVEDSETTINGS "The current program settings have been saved."
|
||||
IDS_MUI_CREATEINI_FAIL "Error creating configuration file."
|
||||
IDS_MUI_WRITEINI_FAIL "Error writing settings to configuration file."
|
||||
IDS_MUI_INIFILE_READONLY
|
||||
"Configuration file is readonly - ignore and override settings?"
|
||||
IDS_MUI_SETTINGSNOTSAVED
|
||||
"No existing configuration file was found.\nTo keep your style modifications, save settings now (F7) or go back to scheme configuration (Ctrl+F12) and export your styles."
|
||||
END
|
||||
|
||||
@ -180,6 +180,8 @@ BEGIN
|
||||
IDS_MUI_SAVEDSETTINGS "The current program settings have been saved."
|
||||
IDS_MUI_CREATEINI_FAIL "Error creating configuration file."
|
||||
IDS_MUI_WRITEINI_FAIL "Error writing settings to configuration file."
|
||||
IDS_MUI_INIFILE_READONLY
|
||||
"Configuration file is readonly - ignore and override settings?"
|
||||
IDS_MUI_SETTINGSNOTSAVED
|
||||
"No existing configuration file was found.\nTo keep your style modifications, save settings now (F7) or go back to scheme configuration (Ctrl+F12) and export your styles."
|
||||
END
|
||||
|
||||
@ -2099,6 +2099,70 @@ __try {
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// CmdSaveSettingsNow()
|
||||
//
|
||||
void CmdSaveSettingsNow()
|
||||
{
|
||||
bool bCreateFailure = false;
|
||||
if (StrIsEmpty(Globals.IniFile)) {
|
||||
if (StrIsNotEmpty(Globals.IniFileDefault)) {
|
||||
StringCchCopy(Globals.IniFile, COUNTOF(Globals.IniFile), Globals.IniFileDefault);
|
||||
DWORD dwFileSize = 0UL;
|
||||
Globals.bCanSaveIniFile = CreateIniFile(Globals.IniFile, &dwFileSize);
|
||||
if (Globals.bCanSaveIniFile) {
|
||||
Globals.bIniFileFromScratch = (dwFileSize == 0UL);
|
||||
StringCchCopy(Globals.IniFileDefault, COUNTOF(Globals.IniFileDefault), L"");
|
||||
}
|
||||
else {
|
||||
StringCchCopy(Globals.IniFile, COUNTOF(Globals.IniFile), L"");
|
||||
Globals.bCanSaveIniFile = false;
|
||||
bCreateFailure = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (bCreateFailure) {
|
||||
InfoBoxLng(MB_ICONWARNING, NULL, IDS_MUI_CREATEINI_FAIL);
|
||||
return;
|
||||
}
|
||||
DWORD dwFileAttributes = 0;
|
||||
if (!Globals.bCanSaveIniFile) {
|
||||
dwFileAttributes = GetFileAttributes(Globals.IniFile);
|
||||
if (dwFileAttributes == INVALID_FILE_ATTRIBUTES) {
|
||||
InfoBoxLng(MB_ICONWARNING, NULL, IDS_MUI_CREATEINI_FAIL);
|
||||
return;
|
||||
}
|
||||
if (dwFileAttributes & FILE_ATTRIBUTE_READONLY) {
|
||||
INT_PTR const answer = InfoBoxLng(MB_YESNO | MB_ICONWARNING, NULL, IDS_MUI_INIFILE_READONLY);
|
||||
if ((IDOK == answer) || (IDYES == answer)) {
|
||||
SetFileAttributes(Globals.IniFile, FILE_ATTRIBUTE_NORMAL); // override read-only attrib
|
||||
Globals.bCanSaveIniFile = CanAccessPath(Globals.IniFile, GENERIC_WRITE);
|
||||
}
|
||||
}
|
||||
else {
|
||||
dwFileAttributes = 0; // no need to change the file attributes
|
||||
}
|
||||
}
|
||||
if (Globals.bCanSaveIniFile && SaveAllSettings(true)) {
|
||||
InfoBoxLng(MB_ICONINFORMATION, L"MsgSaveSettingsInfo", IDS_MUI_SAVEDSETTINGS);
|
||||
if (dwFileAttributes != 0) {
|
||||
SetFileAttributes(Globals.IniFile, dwFileAttributes); // reset
|
||||
Globals.bCanSaveIniFile = CanAccessPath(Globals.IniFile, GENERIC_WRITE);
|
||||
}
|
||||
}
|
||||
else {
|
||||
Globals.dwLastError = GetLastError();
|
||||
InfoBoxLng(MB_ICONWARNING, NULL, IDS_MUI_WRITEINI_FAIL);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//=============================================================================
|
||||
|
||||
|
||||
@ -33,8 +33,9 @@ bool CreateIniFile(LPCWSTR pszIniFilePath, DWORD* pdwFileSize_out);
|
||||
void LoadSettings();
|
||||
bool SaveWindowPositionSettings(bool bClearSettings);
|
||||
bool SaveAllSettings(bool bForceSaveSettings);
|
||||
void CmdSaveSettingsNow();
|
||||
|
||||
bool OpenSettingsFile(bool* keepCached);
|
||||
bool OpenSettingsFile(bool* keepCached);
|
||||
bool CloseSettingsFile(bool bSaveChanges, bool keepCached);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
@ -5542,43 +5542,9 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
|
||||
case IDM_VIEW_SAVESETTINGSNOW:
|
||||
if (IsCmdEnabled(hwnd, IDM_VIEW_SAVESETTINGSNOW)) {
|
||||
|
||||
bool bCreateFailure = false;
|
||||
if (StrIsEmpty(Globals.IniFile)) {
|
||||
if (StrIsNotEmpty(Globals.IniFileDefault)) {
|
||||
StringCchCopy(Globals.IniFile, COUNTOF(Globals.IniFile), Globals.IniFileDefault);
|
||||
DWORD dwFileSize = 0UL;
|
||||
Globals.bCanSaveIniFile = CreateIniFile(Globals.IniFile, &dwFileSize);
|
||||
if (Globals.bCanSaveIniFile) {
|
||||
Globals.bIniFileFromScratch = (dwFileSize == 0UL);
|
||||
StringCchCopy(Globals.IniFileDefault, COUNTOF(Globals.IniFileDefault), L"");
|
||||
}
|
||||
else {
|
||||
StringCchCopy(Globals.IniFile, COUNTOF(Globals.IniFile), L"");
|
||||
Globals.bCanSaveIniFile = false;
|
||||
bCreateFailure = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (!bCreateFailure)
|
||||
{
|
||||
SetFileAttributes(Globals.IniFile, FILE_ATTRIBUTE_NORMAL); // override read-only attrib
|
||||
|
||||
if (SaveAllSettings(true)) {
|
||||
InfoBoxLng(MB_ICONINFORMATION, L"MsgSaveSettingsInfo", IDS_MUI_SAVEDSETTINGS);
|
||||
}
|
||||
else {
|
||||
Globals.dwLastError = GetLastError();
|
||||
InfoBoxLng(MB_ICONWARNING, NULL, IDS_MUI_WRITEINI_FAIL);
|
||||
}
|
||||
}
|
||||
else {
|
||||
InfoBoxLng(MB_ICONWARNING, NULL, IDS_MUI_CREATEINI_FAIL);
|
||||
}
|
||||
if (IsCmdEnabled(hwnd, IDM_VIEW_SAVESETTINGSNOW))
|
||||
{
|
||||
CmdSaveSettingsNow();
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user