diff --git a/language/common_res.h b/language/common_res.h index 83ecc1171..587065b16 100644 --- a/language/common_res.h +++ b/language/common_res.h @@ -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 diff --git a/language/np3_de_de/strings_de_de.rc b/language/np3_de_de/strings_de_de.rc index 4c0c10c0e..c87462861 100644 --- a/language/np3_de_de/strings_de_de.rc +++ b/language/np3_de_de/strings_de_de.rc @@ -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 diff --git a/language/np3_en_gb/strings_en_gb.rc b/language/np3_en_gb/strings_en_gb.rc index 48083f502..02b72b6a3 100644 --- a/language/np3_en_gb/strings_en_gb.rc +++ b/language/np3_en_gb/strings_en_gb.rc @@ -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 diff --git a/language/np3_en_us/strings_en_us.rc b/language/np3_en_us/strings_en_us.rc index 21a7c117c..3f79c2d54 100644 --- a/language/np3_en_us/strings_en_us.rc +++ b/language/np3_en_us/strings_en_us.rc @@ -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 diff --git a/src/Config/Config.cpp b/src/Config/Config.cpp index 8e6da9202..30afeb5de 100644 --- a/src/Config/Config.cpp +++ b/src/Config/Config.cpp @@ -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; + } +} + + //============================================================================= //============================================================================= diff --git a/src/Config/Config.h b/src/Config/Config.h index d71e449bc..0f07857cf 100644 --- a/src/Config/Config.h +++ b/src/Config/Config.h @@ -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); // ---------------------------------------------------------------------------- diff --git a/src/Notepad3.c b/src/Notepad3.c index 9ae9cddda..954723ea3 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -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;