From b8d9a5bc93de36c3bc9481cf154ea981fb755b3c Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Mon, 10 Jun 2019 15:16:42 +0200 Subject: [PATCH] + fix: 1st bugfix session for new SimpleIni config reader. --- src/Config/Config.cpp | 1106 ++++++++++++++++++++++++++++++++++++++-- src/Config/Config.h | 11 +- src/Config/SimpleIni.h | 36 +- src/Dialogs.c | 4 +- src/Dialogs.h | 4 +- src/Helpers.c | 2 +- src/Notepad3.c | 1055 +++----------------------------------- src/Notepad3.h | 10 +- src/Styles.c | 2 +- src/TypeDefs.h | 2 +- 10 files changed, 1146 insertions(+), 1086 deletions(-) diff --git a/src/Config/Config.cpp b/src/Config/Config.cpp index 59a749fdd..2be01ce5d 100644 --- a/src/Config/Config.cpp +++ b/src/Config/Config.cpp @@ -13,38 +13,80 @@ *******************************************************************************/ #include +#include + +// ---------------------------------------------------------------------------- + +extern "C" { +#include "Version.h" +#include "Helpers.h" +#include "Styles.h" +#include "Dialogs.h" +#include "Encoding.h" +#include "Notepad3.h" +#include "resource.h" +} + +extern "C" const int g_FontQuality[4]; +extern "C" WININFO s_WinInfo; +extern "C" WININFO s_DefWinInfo; + +extern "C" const WCHAR* const TBBUTTON_DEFAULT_IDS_V1; +extern "C" const WCHAR* const TBBUTTON_DEFAULT_IDS_V2; + +extern "C" prefix_t s_mxSBPrefix[STATUS_SECTOR_COUNT]; +extern "C" prefix_t s_mxSBPostfix[STATUS_SECTOR_COUNT]; +extern "C" bool s_iStatusbarVisible[STATUS_SECTOR_COUNT]; +extern "C" int s_iStatusbarWidthSpec[STATUS_SECTOR_COUNT]; +extern "C" int s_vSBSOrder[STATUS_SECTOR_COUNT]; + +extern "C" WCHAR s_tchToolbarBitmap[MAX_PATH]; +extern "C" WCHAR s_tchToolbarBitmapHot[MAX_PATH]; +extern "C" WCHAR s_tchToolbarBitmapDisabled[MAX_PATH]; + +extern "C" bool s_bEnableSaveSettings; +extern "C" int s_iToolBarTheme; +extern "C" bool s_flagPosParam; +extern "C" int s_flagWindowPos; + +// ---------------------------------------------------------------------------- #include "SimpleIni.h" #include "Config.h" - -#define _PRIV_PROFILE_STRING_HANDLE_ - +// ============================================================================ static bool const s_bIsUTF8 = true; static bool const s_bUseMultiKey = false; static bool const s_bUseMultiLine = false; static bool const s_bSetSpaces = false; -static CSimpleIni s_INI(s_bIsUTF8, s_bUseMultiKey, s_bUseMultiLine); +// ---------------------------------------------------------------------------- +static int s_iStatusbarSections[STATUS_SECTOR_COUNT] = SBS_INIT_MINUS; + +// ---------------------------------------------------------------------------- + +#define SI_SUCCESS(RC) ((RC) >= SI_OK) // ============================================================================ +static CSimpleIni s_INI(s_bIsUTF8, s_bUseMultiKey, s_bUseMultiLine); + extern "C" bool LoadIniFile(LPCWSTR lpIniFilePath) { s_INI.Reset(); SI_Error const rc = s_INI.LoadFile(lpIniFilePath); - return (rc == SI_OK); + return SI_SUCCESS(rc); } -extern "C" bool SaveIniFile() +extern "C" bool SaveIniFile(LPCWSTR lpIniFilePath) { s_INI.SetSpaces(s_bSetSpaces); - SI_Error const rc = s_INI.SaveFile(Globals.IniFile, true); + SI_Error const rc = s_INI.SaveFile(lpIniFilePath, true); s_INI.Reset(); // done - return (rc == SI_OK); + return SI_SUCCESS(rc); } extern "C" void ReleaseIniFile() @@ -66,7 +108,7 @@ extern "C" size_t IniSectionGetString(LPCWSTR lpSectionName, LPCWSTR lpKeyName, bool bHasMultiple = false; StringCchCopyW(lpReturnedString, cchReturnedString, s_INI.GetValue(lpSectionName, lpKeyName, lpDefault, &bHasMultiple)); - assert(!bHasMultiple); + //assert(!bHasMultiple); return StringCchLenW(lpReturnedString, cchReturnedString); } // ============================================================================ @@ -76,7 +118,7 @@ extern "C" int IniSectionGetInt(LPCWSTR lpSectionName, LPCWSTR lpKeyName, int iD { bool bHasMultiple = false; int const iValue = (int)s_INI.GetLongValue(lpSectionName, lpKeyName, (long)iDefault, &bHasMultiple); - assert(!bHasMultiple); + //assert(!bHasMultiple); return iValue; } // ============================================================================ @@ -86,7 +128,7 @@ extern "C" double IniSectionGetDouble(LPCWSTR lpSectionName, LPCWSTR lpKeyName, { bool bHasMultiple = false; double const dValue = s_INI.GetDoubleValue(lpSectionName, lpKeyName, dDefault, &bHasMultiple); - assert(!bHasMultiple); + //assert(!bHasMultiple); return dValue; } // ============================================================================ @@ -96,7 +138,7 @@ extern "C" bool IniSectionGetBool(LPCWSTR lpSectionName, LPCWSTR lpKeyName, bool { bool bHasMultiple = false; bool const bValue = s_INI.GetBoolValue(lpSectionName, lpKeyName, bDefault, &bHasMultiple); - assert(!bHasMultiple); + //assert(!bHasMultiple); return bValue; } // ============================================================================ @@ -108,7 +150,7 @@ extern "C" bool IniSectionSetString(LPCWSTR lpSectionName, LPCWSTR lpKeyName, LP return s_INI.DeleteValue(lpSectionName, lpKeyName, NULL, false); } SI_Error const rc = s_INI.SetValue(lpSectionName, lpKeyName, lpString, nullptr, !s_bUseMultiKey); - return (rc == SI_OK); + return SI_SUCCESS(rc); } // ============================================================================ @@ -116,12 +158,12 @@ extern "C" bool IniSectionSetString(LPCWSTR lpSectionName, LPCWSTR lpKeyName, LP extern "C" bool IniSectionSetInt(LPCWSTR lpSectionName, LPCWSTR lpKeyName, int iValue) { SI_Error const rc = s_INI.SetLongValue(lpSectionName, lpKeyName, (long)iValue, nullptr, false, !s_bUseMultiKey); - return (rc == SI_OK); + return SI_SUCCESS(rc); } extern "C" bool IniSectionSetHex(LPCWSTR lpSectionName, LPCWSTR lpKeyName, int iValue) { SI_Error const rc = s_INI.SetLongValue(lpSectionName, lpKeyName, (long)iValue, nullptr, true, !s_bUseMultiKey); - return (rc == SI_OK); + return SI_SUCCESS(rc); } // ============================================================================ @@ -129,7 +171,7 @@ extern "C" bool IniSectionSetHex(LPCWSTR lpSectionName, LPCWSTR lpKeyName, int i extern "C" bool IniSectionSetDouble(LPCWSTR lpSectionName, LPCWSTR lpKeyName, double dValue) { SI_Error const rc = s_INI.SetDoubleValue(lpSectionName, lpKeyName, dValue, nullptr, !s_bUseMultiKey); - return (rc == SI_OK); + return SI_SUCCESS(rc); } // ============================================================================ @@ -137,7 +179,7 @@ extern "C" bool IniSectionSetDouble(LPCWSTR lpSectionName, LPCWSTR lpKeyName, do extern "C" bool IniSectionSetBool(LPCWSTR lpSectionName, LPCWSTR lpKeyName, bool bValue) { SI_Error const rc = s_INI.SetBoolValue(lpSectionName, lpKeyName, bValue, nullptr, !s_bUseMultiKey); - return (rc == SI_OK); + return SI_SUCCESS(rc); } // ============================================================================ @@ -155,15 +197,14 @@ extern "C" bool IniClearAllSections(LPCWSTR lpPrefix, bool bRemoveEmpty) CSimpleIni::TNamesDepend Sections; s_INI.GetAllSections(Sections); - bool ok = true; for (const auto& section : Sections) { if (StringCchCompareNI(section.pItem, len, lpPrefix, len) == 0) { - ok = ok && s_INI.Delete(section.pItem, nullptr, bRemoveEmpty); + s_INI.Delete(section.pItem, nullptr, bRemoveEmpty); } } - return ok; + return true; } // ============================================================================ @@ -177,10 +218,10 @@ extern "C" size_t IniFileGetString(LPCWSTR lpFilePath, LPCWSTR lpSectionName, LP { CSimpleIni Ini(s_bIsUTF8, s_bUseMultiKey, s_bUseMultiLine); SI_Error const rc = Ini.LoadFile(lpFilePath); - if (rc == SI_OK) { + if (SI_SUCCESS(rc)) { bool bHasMultiple = false; StringCchCopyW(lpReturnedString, cchReturnedString, Ini.GetValue(lpSectionName, lpKeyName, lpDefault, &bHasMultiple)); - assert(!bHasMultiple); + //assert(!bHasMultiple); } return StringCchLenW(lpReturnedString, cchReturnedString); } @@ -191,19 +232,20 @@ extern "C" bool IniFileSetString(LPCWSTR lpFilePath, LPCWSTR lpSectionName, LPCW { CSimpleIni Ini(s_bIsUTF8, s_bUseMultiKey, s_bUseMultiLine); SI_Error rc = Ini.LoadFile(lpFilePath); - if (rc == SI_OK) { + if (SI_SUCCESS(rc)) { if (lpString == NULL) { - rc = s_INI.DeleteValue(lpSectionName, lpKeyName, NULL, false) ? SI_OK : SI_FAIL; + Ini.DeleteValue(lpSectionName, lpKeyName, NULL, false); } else { - rc = Ini.SetValue(lpSectionName, lpKeyName, lpString, nullptr, !s_bUseMultiKey); + SI_Error const res = Ini.SetValue(lpSectionName, lpKeyName, lpString, nullptr, !s_bUseMultiKey); + rc = SI_SUCCESS(res) ? SI_OK : SI_FAIL; + } + if (SI_SUCCESS(rc)) { + Ini.SetSpaces(s_bSetSpaces); + rc = Ini.SaveFile(Globals.IniFile, true); } } - if (rc == SI_OK) { - Ini.SetSpaces(s_bSetSpaces); - rc = Ini.SaveFile(Globals.IniFile, true); - } - return (rc == SI_OK); + return SI_SUCCESS(rc); } // ============================================================================ @@ -212,10 +254,10 @@ extern "C" int IniFileGetInt(LPCWSTR lpFilePath, LPCWSTR lpSectionName, LPCWSTR { CSimpleIni Ini(s_bIsUTF8, s_bUseMultiKey, s_bUseMultiLine); SI_Error const rc = Ini.LoadFile(lpFilePath); - if (rc == SI_OK) { + if (SI_SUCCESS(rc)) { bool bHasMultiple = false; - int const iValue = s_INI.GetLongValue(lpSectionName, lpKeyName, (long)iDefault, &bHasMultiple); - assert(!bHasMultiple); + int const iValue = Ini.GetLongValue(lpSectionName, lpKeyName, (long)iDefault, &bHasMultiple); + //assert(!bHasMultiple); return iValue; } return iDefault; @@ -227,14 +269,12 @@ extern "C" bool IniFileSetInt(LPCWSTR lpFilePath, LPCWSTR lpSectionName, LPCWSTR { CSimpleIni Ini(s_bIsUTF8, s_bUseMultiKey, s_bUseMultiLine); SI_Error rc = Ini.LoadFile(lpFilePath); - if (rc == SI_OK) { - rc = s_INI.SetLongValue(lpSectionName, lpKeyName, (long)iValue, nullptr, false, !s_bUseMultiKey); - } - if (rc == SI_OK) { + if (SI_SUCCESS(rc)) { + Ini.SetLongValue(lpSectionName, lpKeyName, (long)iValue, nullptr, false, !s_bUseMultiKey); Ini.SetSpaces(s_bSetSpaces); rc = Ini.SaveFile(Globals.IniFile, true); } - return (rc == SI_OK); + return SI_SUCCESS(rc); } // ============================================================================ @@ -243,10 +283,10 @@ extern "C" bool IniFileGetBool(LPCWSTR lpFilePath, LPCWSTR lpSectionName, LPCWST { CSimpleIni Ini(s_bIsUTF8, s_bUseMultiKey, s_bUseMultiLine); SI_Error const rc = Ini.LoadFile(lpFilePath); - if (rc == SI_OK) { + if (SI_SUCCESS(rc)) { bool bHasMultiple = false; - bool const bValue = s_INI.GetBoolValue(lpSectionName, lpKeyName, bDefault, &bHasMultiple); - assert(!bHasMultiple); + bool const bValue = Ini.GetBoolValue(lpSectionName, lpKeyName, bDefault, &bHasMultiple); + //assert(!bHasMultiple); return bValue; } return bDefault; @@ -258,17 +298,991 @@ extern "C" bool IniFileSetBool(LPCWSTR lpFilePath, LPCWSTR lpSectionName, LPCWST { CSimpleIni Ini(s_bIsUTF8, s_bUseMultiKey, s_bUseMultiLine); SI_Error rc = Ini.LoadFile(lpFilePath); - if (rc == SI_OK) { - rc = s_INI.SetBoolValue(lpSectionName, lpKeyName, bValue, nullptr, !s_bUseMultiKey); - } - if (rc == SI_OK) { + if (SI_SUCCESS(rc)) { + Ini.SetBoolValue(lpSectionName, lpKeyName, bValue, nullptr, !s_bUseMultiKey); Ini.SetSpaces(s_bSetSpaces); rc = Ini.SaveFile(Globals.IniFile, true); } - return (rc == SI_OK); + return SI_SUCCESS(rc); } // ============================================================================ +//============================================================================= +// +// _CheckIniFile() +// +static bool _CheckIniFile(LPWSTR lpszFile, LPCWSTR lpszModule) +{ + WCHAR tchFileExpanded[MAX_PATH] = { L'\0' }; + ExpandEnvironmentStrings(lpszFile, tchFileExpanded, COUNTOF(tchFileExpanded)); + + if (PathIsRelative(tchFileExpanded)) + { + WCHAR tchBuild[MAX_PATH] = { L'\0' }; + // program directory + StringCchCopy(tchBuild, COUNTOF(tchBuild), lpszModule); + StringCchCopy(PathFindFileName(tchBuild), COUNTOF(tchBuild), tchFileExpanded); + if (PathFileExists(tchBuild)) { + StringCchCopy(lpszFile, MAX_PATH, tchBuild); + return true; + } + // sub directory (.\np3\) + StringCchCopy(tchBuild, COUNTOF(tchBuild), lpszModule); + PathCchRemoveFileSpec(tchBuild, COUNTOF(tchBuild)); + StringCchCat(tchBuild, COUNTOF(tchBuild), L"\\np3\\"); + StringCchCat(tchBuild, COUNTOF(tchBuild), tchFileExpanded); + if (PathFileExists(tchBuild)) { + StringCchCopy(lpszFile, MAX_PATH, tchBuild); + return true; + } + // Application Data (%APPDATA%) + if (GetKnownFolderPath(FOLDERID_RoamingAppData, tchBuild, COUNTOF(tchBuild))) { + PathCchAppend(tchBuild, COUNTOF(tchBuild), tchFileExpanded); + if (PathFileExists(tchBuild)) { + StringCchCopy(lpszFile, MAX_PATH, tchBuild); + return true; + } + } + // Home (%HOMEPATH%) user's profile dir + if (GetKnownFolderPath(FOLDERID_Profile, tchBuild, COUNTOF(tchBuild))) { + PathCchAppend(tchBuild, COUNTOF(tchBuild), tchFileExpanded); + if (PathFileExists(tchBuild)) { + StringCchCopy(lpszFile, MAX_PATH, tchBuild); + return true; + } + } + //~// in general search path + //~if (SearchPath(NULL,tchFileExpanded,L".ini",COUNTOF(tchBuild),tchBuild,NULL)) { + //~ StringCchCopy(lpszFile,MAX_PATH,tchBuild); + //~ return true; + //~} + } + else if (PathFileExists(tchFileExpanded)) { + StringCchCopy(lpszFile, MAX_PATH, tchFileExpanded); + return true; + } + return false; +} +// ============================================================================ + + +static bool _CheckIniFileRedirect(LPWSTR lpszAppName, LPWSTR lpszKeyName, LPWSTR lpszFile, LPCWSTR lpszModule) +{ + WCHAR tch[MAX_PATH] = { L'\0' }; + if (GetPrivateProfileString(lpszAppName, lpszKeyName, L"", tch, COUNTOF(tch), lpszFile)) { + if (_CheckIniFile(tch, lpszModule)) { + StringCchCopy(lpszFile, MAX_PATH, tch); + return true; + } + WCHAR tchFileExpanded[MAX_PATH] = { L'\0' }; + ExpandEnvironmentStrings(tch, tchFileExpanded, COUNTOF(tchFileExpanded)); + if (PathIsRelative(tchFileExpanded)) { + StringCchCopy(lpszFile, MAX_PATH, lpszModule); + StringCchCopy(PathFindFileName(lpszFile), MAX_PATH, tchFileExpanded); + return true; + } + StringCchCopy(lpszFile, MAX_PATH, tchFileExpanded); + return true; + } + return false; +} +// ============================================================================ + + +extern "C" bool FindIniFile() +{ + bool bFound = false; + WCHAR tchPath[MAX_PATH] = { L'\0' }; + WCHAR tchModule[MAX_PATH] = { L'\0' }; + + GetModuleFileName(NULL, tchModule, COUNTOF(tchModule)); + + // set env path to module dir + StringCchCopy(tchPath, COUNTOF(tchPath), tchModule); + PathCchRemoveFileSpec(tchPath, COUNTOF(tchPath)); + SetEnvironmentVariable(NOTEPAD3_MODULE_DIR_ENV_VAR, tchPath); + + if (StrIsNotEmpty(Globals.IniFile)) { + if (StringCchCompareXI(Globals.IniFile, L"*?") == 0) { + return bFound; + } + if (!_CheckIniFile(Globals.IniFile, tchModule)) { + ExpandEnvironmentStringsEx(Globals.IniFile, COUNTOF(Globals.IniFile)); + if (PathIsRelative(Globals.IniFile)) { + StringCchCopy(tchPath, COUNTOF(tchPath), tchModule); + PathCchRemoveFileSpec(tchPath, COUNTOF(tchPath)); + PathCchAppend(tchPath, COUNTOF(tchPath), Globals.IniFile); + StringCchCopy(Globals.IniFile, COUNTOF(Globals.IniFile), tchPath); + } + } + } + else { + StringCchCopy(tchPath, COUNTOF(tchPath), PathFindFileName(tchModule)); + PathCchRenameExtension(tchPath, COUNTOF(tchPath), L".ini"); + + bFound = _CheckIniFile(tchPath, tchModule); + + if (!bFound) { + StringCchCopy(tchPath, COUNTOF(tchPath), L"Notepad3.ini"); + bFound = _CheckIniFile(tchPath, tchModule); + } + + if (bFound) + { + // allow two redirections: administrator -> user -> custom + if (_CheckIniFileRedirect(_W(SAPPNAME), _W(SAPPNAME) L".ini", tchPath, tchModule)) + { + _CheckIniFileRedirect(_W(SAPPNAME), _W(SAPPNAME) L".ini", tchPath, tchModule); + } + StringCchCopy(Globals.IniFile, COUNTOF(Globals.IniFile), tchPath); + } + else { + StringCchCopy(Globals.IniFile, COUNTOF(Globals.IniFile), tchModule); + PathCchRenameExtension(Globals.IniFile, COUNTOF(Globals.IniFile), L".ini"); + } + } + + NormalizePathEx(Globals.IniFile, COUNTOF(Globals.IniFile), true, false); + + return bFound; +} +//============================================================================= + + +extern "C" int TestIniFile() { + + if (StringCchCompareXI(Globals.IniFile, L"*?") == 0) { + StringCchCopy(Globals.IniFileDefault, COUNTOF(Globals.IniFileDefault), L""); + StringCchCopy(Globals.IniFile, COUNTOF(Globals.IniFile), L""); + return(0); + } + + if (PathIsDirectory(Globals.IniFile) || *CharPrev(Globals.IniFile, StrEnd(Globals.IniFile, COUNTOF(Globals.IniFile))) == L'\\') { + WCHAR wchModule[MAX_PATH] = { L'\0' }; + GetModuleFileName(NULL, wchModule, COUNTOF(wchModule)); + PathCchAppend(Globals.IniFile, COUNTOF(Globals.IniFile), PathFindFileName(wchModule)); + PathCchRenameExtension(Globals.IniFile, COUNTOF(Globals.IniFile), L".ini"); + if (!PathFileExists(Globals.IniFile)) { + StringCchCopy(PathFindFileName(Globals.IniFile), COUNTOF(Globals.IniFile), L"Notepad3.ini"); + if (!PathFileExists(Globals.IniFile)) { + StringCchCopy(PathFindFileName(Globals.IniFile), COUNTOF(Globals.IniFile), PathFindFileName(wchModule)); + PathCchRenameExtension(Globals.IniFile, COUNTOF(Globals.IniFile), L".ini"); + } + } + } + + NormalizePathEx(Globals.IniFile, COUNTOF(Globals.IniFile), true, false); + + if (!PathFileExists(Globals.IniFile) || PathIsDirectory(Globals.IniFile)) { + StringCchCopy(Globals.IniFileDefault, COUNTOF(Globals.IniFileDefault), Globals.IniFile); + StringCchCopy(Globals.IniFile, COUNTOF(Globals.IniFile), L""); + return(0); + } + return(1); +} +//============================================================================= + + +extern "C" bool CreateIniFile() +{ + return(CreateIniFileEx(Globals.IniFile)); +} +//============================================================================= + +extern "C" bool CreateIniFileEx(LPCWSTR lpszIniFile) +{ + if (StrIsNotEmpty(lpszIniFile)) + { + WCHAR* pwchTail = StrRChrW(lpszIniFile, NULL, L'\\'); + if (pwchTail) { + *pwchTail = 0; + SHCreateDirectoryEx(NULL, lpszIniFile, NULL); + *pwchTail = L'\\'; + } + + HANDLE hFile = CreateFile(lpszIniFile, + GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + Globals.dwLastError = GetLastError(); + if (hFile != INVALID_HANDLE_VALUE) { + if (GetFileSize(hFile, NULL) == 0) { + DWORD dw; + //WriteFile(hFile,(LPCVOID)L"\xFE\xFF[Notepad3]\r\n",26,&dw,NULL); // UTF-16LE + WriteFile(hFile, (LPCVOID)L"\xEF\xBB\xBF[Notepad3]\r\n", 26, &dw, NULL); // UTF-8 SIG + Globals.bIniFileFromScratch = true; + } + CloseHandle(hFile); + Style_SetIniFile(lpszIniFile); + return true; + } + } + return false; +} +//============================================================================= + + + +//============================================================================= +// +// LoadSettings() +// +// +static int s_iSettingsVersion = CFG_VER_CURRENT; + +void LoadSettings() +{ + int const _ver = StrIsEmpty(Globals.IniFile) ? CFG_VER_CURRENT : CFG_VER_NONE; + + LoadIniFile(Globals.IniFile); + { + bool bDirtyFlag = false; // do we have to save the file on done + // prerequisites + s_iSettingsVersion = IniSectionGetInt(L"Settings", L"SettingsVersion", _ver); + + Defaults.SaveSettings = StrIsNotEmpty(Globals.IniFile); + Settings.SaveSettings = IniSectionGetBool(L"Settings", L"SaveSettings", Defaults.SaveSettings); + + // -------------------------------------------------------------------------- + // first set "hard coded" .ini-Settings + // -------------------------------------------------------------------------- + const WCHAR* const Settings2_Section = L"Settings2"; + + Defaults2.PreferredLanguageLocaleName[0] = L'\0'; + IniSectionGetString(Settings2_Section, L"PreferredLanguageLocaleName", Defaults2.PreferredLanguageLocaleName, + Settings2.PreferredLanguageLocaleName, COUNTOF(Settings2.PreferredLanguageLocaleName)); + + StringCchCopyW(Defaults2.DefaultExtension, COUNTOF(Defaults2.DefaultExtension), L"txt"); + IniSectionGetString(Settings2_Section, L"DefaultExtension", Defaults2.DefaultExtension, + Settings2.DefaultExtension, COUNTOF(Settings2.DefaultExtension)); + StrTrim(Settings2.DefaultExtension, L" \t.\""); + + Defaults2.DefaultDirectory[0] = L'\0'; + IniSectionGetString(Settings2_Section, L"DefaultDirectory", Defaults2.DefaultDirectory, + Settings2.DefaultDirectory, COUNTOF(Settings2.DefaultDirectory)); + + Defaults2.FileDlgFilters[0] = L'\0'; + IniSectionGetString(Settings2_Section, L"FileDlgFilters", Defaults2.FileDlgFilters, + Settings2.FileDlgFilters, COUNTOF(Settings2.FileDlgFilters) - 2); + + Defaults2.FileCheckInverval = 2000UL; + Settings2.FileCheckInverval = clampul(IniSectionGetInt(Settings2_Section, L"FileCheckInverval", + Defaults2.FileCheckInverval), 250UL, 300000UL); + FileWatching.FileCheckInverval = Settings2.FileCheckInverval; + + Defaults2.AutoReloadTimeout = 2000UL; + Settings2.AutoReloadTimeout = clampul(IniSectionGetInt(Settings2_Section, L"AutoReloadTimeout", + Defaults2.AutoReloadTimeout), 250UL, 300000UL); + FileWatching.AutoReloadTimeout = Settings2.AutoReloadTimeout; + + // deprecated + Defaults.RenderingTechnology = IniSectionGetInt(Settings2_Section, L"SciDirectWriteTech", -111); + if ((Defaults.RenderingTechnology != -111) && Settings.SaveSettings) { + // cleanup + IniSectionSetString(Settings2_Section, L"SciDirectWriteTech", NULL); + bDirtyFlag = true; + } + Defaults.RenderingTechnology = clampi(Defaults.RenderingTechnology, 0, 3); + + // Settings2 deprecated + Defaults.Bidirectional = IniSectionGetInt(Settings2_Section, L"EnableBidirectionalSupport", -111); + if ((Defaults.Bidirectional != -111) && Settings.SaveSettings) { + // cleanup + IniSectionSetString(Settings2_Section, L"EnableBidirectionalSupport", NULL); + bDirtyFlag = true; + } + Defaults.Bidirectional = (clampi(Defaults.Bidirectional, SC_BIDIRECTIONAL_DISABLED, SC_BIDIRECTIONAL_R2L) > 0) ? SC_BIDIRECTIONAL_R2L : 0; + + Defaults2.IMEInteraction = -1; + Settings2.IMEInteraction = clampi(IniSectionGetInt(Settings2_Section, L"IMEInteraction", Defaults2.IMEInteraction), -1, SC_IME_INLINE); + // Korean IME use inline mode by default + if (Settings2.IMEInteraction == -1) { // auto detection once + // ScintillaWin::KoreanIME() + int const codePage = Scintilla_InputCodePage(); + Settings2.IMEInteraction = ((codePage == 949 || codePage == 1361) ? SC_IME_INLINE : SC_IME_WINDOWED); + } + + Defaults2.SciFontQuality = g_FontQuality[3]; + Settings2.SciFontQuality = clampi(IniSectionGetInt(Settings2_Section, L"SciFontQuality", Defaults2.SciFontQuality), 0, 3); + + Defaults2.MarkOccurrencesMaxCount = 2000; + Settings2.MarkOccurrencesMaxCount = IniSectionGetInt(Settings2_Section, L"MarkOccurrencesMaxCount", Defaults2.MarkOccurrencesMaxCount); + if (Settings2.MarkOccurrencesMaxCount <= 0) { Settings2.MarkOccurrencesMaxCount = INT_MAX; } + + Defaults2.UpdateDelayMarkAllOccurrences = 50; + Settings2.UpdateDelayMarkAllOccurrences = clampi(IniSectionGetInt(Settings2_Section, L"UpdateDelayMarkAllOccurrences", + Defaults2.UpdateDelayMarkAllOccurrences), USER_TIMER_MINIMUM, 10000); + Defaults2.DenyVirtualSpaceAccess = false; + Settings2.DenyVirtualSpaceAccess = IniSectionGetBool(Settings2_Section, L"DenyVirtualSpaceAccess", Defaults2.DenyVirtualSpaceAccess); + + Defaults2.UseOldStyleBraceMatching = false; + Settings2.UseOldStyleBraceMatching = IniSectionGetBool(Settings2_Section, L"UseOldStyleBraceMatching", Defaults2.UseOldStyleBraceMatching); + + Defaults2.CurrentLineHorizontalSlop = 40; + Settings2.CurrentLineHorizontalSlop = clampi(IniSectionGetInt(Settings2_Section, L"CurrentLineHorizontalSlop", Defaults2.CurrentLineHorizontalSlop), 0, 240); + + Defaults2.CurrentLineVerticalSlop = 5; + Settings2.CurrentLineVerticalSlop = clampi(IniSectionGetInt(Settings2_Section, L"CurrentLineVerticalSlop", Defaults2.CurrentLineVerticalSlop), 0, 25); + + + int const iARCLdef = 67; + Defaults2.AnalyzeReliableConfidenceLevel = (float)iARCLdef / 100.0f; + int const iARCLset = clampi(IniSectionGetInt(Settings2_Section, L"AnalyzeReliableConfidenceLevel", iARCLdef), 0, 100); + Settings2.AnalyzeReliableConfidenceLevel = (float)iARCLset / 100.0f; + + /* ~~~ + int const iRCEDCMdef = 85; + Defaults2.ReliableCEDConfidenceMapping = (float)iRCEDCMdef / 100.0f; + int const iRCEDCMset = clampi(IniSectionGetInt(Settings2_Section, L"ReliableCEDConfidenceMapping", iRCEDCMdef), 0, 100); + Settings2.ReliableCEDConfidenceMapping = (float)iRCEDCMset / 100.0f; + + int const iURCEDCMdef = 20; + Defaults2.UnReliableCEDConfidenceMapping = (float)iURCEDCMdef / 100.0f; + int const iURCEDCMset = clampi(IniSectionGetInt(Settings2_Section, L"UnReliableCEDConfidenceMapping", iURCEDCMdef), 0, iRCEDCMset); + Settings2.UnReliableCEDConfidenceMapping = (float)iURCEDCMset / 100.0f; + ~~~ */ + + Defaults2.AdministrationTool[0] = L'\0'; + IniSectionGetString(Settings2_Section, L"AdministrationTool.exe", Defaults2.AdministrationTool, + Settings2.AdministrationTool, COUNTOF(Settings2.AdministrationTool)); + + Defaults2.DefaultWindowPosition[0] = L'\0'; + IniSectionGetString(Settings2_Section, L"DefaultWindowPosition", Defaults2.DefaultWindowPosition, + Settings2.DefaultWindowPosition, COUNTOF(Settings2.DefaultWindowPosition)); + bool const bExplicitDefaultWinPos = (StringCchLenW(Settings2.DefaultWindowPosition, 0) != 0); + + Defaults2.FileLoadWarningMB = 1; + Settings2.FileLoadWarningMB = clampi(IniSectionGetInt(Settings2_Section, L"FileLoadWarningMB", Defaults2.FileLoadWarningMB), 0, 2048); + + Defaults2.OpacityLevel = 75; + Settings2.OpacityLevel = clampi(IniSectionGetInt(Settings2_Section, L"OpacityLevel", Defaults2.OpacityLevel), 10, 100); + + Defaults2.FindReplaceOpacityLevel = 50; + Settings2.FindReplaceOpacityLevel = clampi(IniSectionGetInt(Settings2_Section, L"FindReplaceOpacityLevel", Defaults2.FindReplaceOpacityLevel), 10, 100); + + Defaults2.FileBrowserPath[0] = L'\0'; + IniSectionGetString(Settings2_Section, L"filebrowser.exe", Defaults2.FileBrowserPath, Settings2.FileBrowserPath, COUNTOF(Settings2.FileBrowserPath)); + + StringCchCopyW(Defaults2.AppUserModelID, COUNTOF(Defaults2.AppUserModelID), _W(SAPPNAME)); + IniSectionGetString(Settings2_Section, L"ShellAppUserModelID", Defaults2.AppUserModelID, Settings2.AppUserModelID, COUNTOF(Settings2.AppUserModelID)); + + Defaults2.ExtendedWhiteSpaceChars[0] = L'\0'; + IniSectionGetString(Settings2_Section, L"ExtendedWhiteSpaceChars", Defaults2.ExtendedWhiteSpaceChars, + Settings2.ExtendedWhiteSpaceChars, COUNTOF(Settings2.ExtendedWhiteSpaceChars)); + + Defaults2.AutoCompleteWordCharSet[0] = L'\0'; + IniSectionGetString(Settings2_Section, L"AutoCompleteWordCharSet", Defaults2.AutoCompleteWordCharSet, + Settings2.AutoCompleteWordCharSet, COUNTOF(Settings2.AutoCompleteWordCharSet)); + + StringCchCopyW(Defaults2.TimeStamp, COUNTOF(Defaults2.TimeStamp), L"\\$Date:[^\\$]+\\$ | $Date: %Y/%m/%d %H:%M:%S $"); + IniSectionGetString(Settings2_Section, L"TimeStamp", Defaults2.TimeStamp, Settings2.TimeStamp, COUNTOF(Settings2.TimeStamp)); + + Defaults2.DateTimeShort[0] = L'\0'; + IniSectionGetString(Settings2_Section, L"DateTimeShort", Defaults2.DateTimeShort, Settings2.DateTimeShort, COUNTOF(Settings2.DateTimeShort)); + + Defaults2.DateTimeLong[0] = L'\0'; + IniSectionGetString(Settings2_Section, L"DateTimeLong", Defaults2.DateTimeLong, Settings2.DateTimeLong, COUNTOF(Settings2.DateTimeLong)); + + StringCchCopyW(Defaults2.WebTemplate1, COUNTOF(Defaults2.WebTemplate1), L"https://google.com/search?q=%s"); + IniSectionGetString(Settings2_Section, L"WebTemplate1", Defaults2.WebTemplate1, Settings2.WebTemplate1, COUNTOF(Settings2.WebTemplate1)); + + StringCchCopyW(Defaults2.WebTemplate2, COUNTOF(Defaults2.WebTemplate2), L"https://en.wikipedia.org/w/index.php?search=%s"); + IniSectionGetString(Settings2_Section, L"WebTemplate2", Defaults2.WebTemplate2, Settings2.WebTemplate2, COUNTOF(Settings2.WebTemplate2)); + + + // -------------------------------------------------------------------------- + const WCHAR* const Settings_Section = L"Settings"; + // -------------------------------------------------------------------------- + +#define GET_BOOL_VALUE_FROM_INISECTION(VARNAME,DEFAULT) \ + Defaults.VARNAME = DEFAULT; \ + Settings.VARNAME = IniSectionGetBool(Settings_Section, _W(_STRG(VARNAME)), Defaults.VARNAME) + +#define GET_INT_VALUE_FROM_INISECTION(VARNAME,DEFAULT,MIN,MAX) \ + Defaults.VARNAME = DEFAULT; \ + Settings.VARNAME = clampi(IniSectionGetInt(Settings_Section, _W(_STRG(VARNAME)), Defaults.VARNAME),MIN,MAX) + +#define GET_CAST_INT_VALUE_FROM_INISECTION(CAST,VARNAME,DEFAULT,MIN,MAX) \ + Defaults.VARNAME = static_cast(DEFAULT); \ + Settings.VARNAME = static_cast(clampi(IniSectionGetInt(Settings_Section, _W(_STRG(VARNAME)), Defaults.VARNAME),MIN,MAX)) + +#define GET_ENC_VALUE_FROM_INISECTION(VARNAME,DEFAULT,MIN,MAX) \ + Defaults.VARNAME = (cpi_enc_t)DEFAULT; \ + Settings.VARNAME = (cpi_enc_t)clampi(IniSectionGetInt(Settings_Section, _W(_STRG(VARNAME)), (int)Defaults.VARNAME),(int)MIN,(int)MAX) + + GET_BOOL_VALUE_FROM_INISECTION(SaveRecentFiles, true); + GET_BOOL_VALUE_FROM_INISECTION(PreserveCaretPos, false); + GET_BOOL_VALUE_FROM_INISECTION(SaveFindReplace, false); + + Defaults.EFR_Data.bFindClose = false; + Settings.EFR_Data.bFindClose = IniSectionGetBool(Settings_Section, L"CloseFind", Defaults.EFR_Data.bFindClose); + Defaults.EFR_Data.bReplaceClose = false; + Settings.EFR_Data.bReplaceClose = IniSectionGetBool(Settings_Section, L"CloseReplace", Defaults.EFR_Data.bReplaceClose); + Defaults.EFR_Data.bNoFindWrap = false; + Settings.EFR_Data.bNoFindWrap = IniSectionGetBool(Settings_Section, L"NoFindWrap", Defaults.EFR_Data.bNoFindWrap); + Defaults.EFR_Data.bTransformBS = false; + Settings.EFR_Data.bTransformBS = IniSectionGetBool(Settings_Section, L"FindTransformBS", Defaults.EFR_Data.bTransformBS); + Defaults.EFR_Data.bWildcardSearch = false; + Settings.EFR_Data.bWildcardSearch = IniSectionGetBool(Settings_Section, L"WildcardSearch", Defaults.EFR_Data.bWildcardSearch); + Defaults.EFR_Data.bMarkOccurences = true; + Settings.EFR_Data.bMarkOccurences = IniSectionGetBool(Settings_Section, L"FindMarkAllOccurrences", Defaults.EFR_Data.bMarkOccurences); + Defaults.EFR_Data.bHideNonMatchedLines = false; + Settings.EFR_Data.bHideNonMatchedLines = IniSectionGetBool(Settings_Section, L"HideNonMatchedLines", Defaults.EFR_Data.bHideNonMatchedLines); + Defaults.EFR_Data.bDotMatchAll = false; + Settings.EFR_Data.bDotMatchAll = IniSectionGetBool(Settings_Section, L"RegexDotMatchesAll", Defaults.EFR_Data.bDotMatchAll); + Defaults.EFR_Data.fuFlags = 0; + Settings.EFR_Data.fuFlags = (UINT)IniSectionGetInt(Settings_Section, L"efrData_fuFlags", (int)Defaults.EFR_Data.fuFlags); + + Defaults.OpenWithDir[0] = L'\0'; + if (!IniSectionGetString(Settings_Section, L"OpenWithDir", Defaults.OpenWithDir, Settings.OpenWithDir, COUNTOF(Settings.OpenWithDir))) { + GetKnownFolderPath(FOLDERID_Desktop, Settings.OpenWithDir, COUNTOF(Settings.OpenWithDir)); + } + else { + PathAbsoluteFromApp(Settings.OpenWithDir, NULL, COUNTOF(Settings.OpenWithDir), true); + } + + Defaults.FavoritesDir[0] = L'\0'; + //StringCchCopyW(Defaults.FavoritesDir, COUNTOF(Defaults.FavoritesDir), L"%USERPROFILE%"); + if (!IniSectionGetString(Settings_Section, L"Favorites", Defaults.FavoritesDir, Settings.FavoritesDir, COUNTOF(Settings.FavoritesDir))) { + GetKnownFolderPath(FOLDERID_Favorites, Settings.FavoritesDir, COUNTOF(Settings.FavoritesDir)); + } + else { + PathAbsoluteFromApp(Settings.FavoritesDir, NULL, COUNTOF(Settings.FavoritesDir), true); + } + + GET_INT_VALUE_FROM_INISECTION(PathNameFormat, 1, 0, 2); + GET_INT_VALUE_FROM_INISECTION(WordWrapMode, 0, 0, 1); + GET_INT_VALUE_FROM_INISECTION(WordWrapIndent, 2, 0, 6); + + GET_BOOL_VALUE_FROM_INISECTION(WordWrap, false); Globals.fvBackup.bWordWrap = Settings.WordWrap; + GET_BOOL_VALUE_FROM_INISECTION(TabsAsSpaces, false); Globals.fvBackup.bTabsAsSpaces = Settings.TabsAsSpaces; + GET_BOOL_VALUE_FROM_INISECTION(TabIndents, true); Globals.fvBackup.bTabIndents = Settings.TabIndents; + GET_INT_VALUE_FROM_INISECTION(TabWidth, 4, 1, 1024); Globals.fvBackup.iTabWidth = Settings.TabWidth; + GET_INT_VALUE_FROM_INISECTION(IndentWidth, 4, 0, 1024); Globals.fvBackup.iIndentWidth = Settings.IndentWidth; + GET_INT_VALUE_FROM_INISECTION(LongLinesLimit, 80, 0, LONG_LINES_MARKER_LIMIT); Globals.fvBackup.iLongLinesLimit = Settings.LongLinesLimit; + Globals.iWrapCol = Settings.LongLinesLimit; + + Defaults.WordWrapSymbols = 22; + int const iWS = IniSectionGetInt(Settings_Section, L"WordWrapSymbols", Defaults.WordWrapSymbols); + Settings.WordWrapSymbols = clampi(iWS % 10, 0, 2) + clampi((iWS % 100 - iWS % 10) / 10, 0, 2) * 10; + + GET_BOOL_VALUE_FROM_INISECTION(ShowWordWrapSymbols, true); + GET_BOOL_VALUE_FROM_INISECTION(MatchBraces, true); + GET_BOOL_VALUE_FROM_INISECTION(AutoCloseTags, false); + GET_INT_VALUE_FROM_INISECTION(HighlightCurrentLine, 1, 0, 2); + GET_BOOL_VALUE_FROM_INISECTION(HyperlinkHotspot, true); + GET_BOOL_VALUE_FROM_INISECTION(ScrollPastEOF, false); + GET_BOOL_VALUE_FROM_INISECTION(ShowHypLnkToolTip, true); + + GET_BOOL_VALUE_FROM_INISECTION(AutoIndent, true); + GET_BOOL_VALUE_FROM_INISECTION(AutoCompleteWords, false); + GET_BOOL_VALUE_FROM_INISECTION(AutoCLexerKeyWords, false); + GET_BOOL_VALUE_FROM_INISECTION(AccelWordNavigation, false); + GET_BOOL_VALUE_FROM_INISECTION(ShowIndentGuides, false); + GET_BOOL_VALUE_FROM_INISECTION(BackspaceUnindents, false); + GET_BOOL_VALUE_FROM_INISECTION(WarnInconsistentIndents, false); + GET_BOOL_VALUE_FROM_INISECTION(AutoDetectIndentSettings, false); + GET_BOOL_VALUE_FROM_INISECTION(MarkLongLines, (s_iSettingsVersion < CFG_VER_0002)); Defaults.MarkLongLines = false; // new default + GET_INT_VALUE_FROM_INISECTION(LongLineMode, EDGE_LINE, EDGE_LINE, EDGE_BACKGROUND); + GET_BOOL_VALUE_FROM_INISECTION(ShowSelectionMargin, true); + GET_BOOL_VALUE_FROM_INISECTION(ShowLineNumbers, true); + GET_BOOL_VALUE_FROM_INISECTION(ShowCodeFolding, true); FocusedView.ShowCodeFolding = Settings.ShowCodeFolding; + GET_BOOL_VALUE_FROM_INISECTION(MarkOccurrences, true); + GET_BOOL_VALUE_FROM_INISECTION(MarkOccurrencesMatchVisible, false); + GET_BOOL_VALUE_FROM_INISECTION(MarkOccurrencesMatchCase, false); + GET_BOOL_VALUE_FROM_INISECTION(MarkOccurrencesMatchWholeWords, true); + + Defaults.MarkOccurrencesCurrentWord = !Defaults.MarkOccurrencesMatchWholeWords; + Settings.MarkOccurrencesCurrentWord = IniSectionGetBool(Settings_Section, L"MarkOccurrencesCurrentWord", Defaults.MarkOccurrencesCurrentWord); + Settings.MarkOccurrencesCurrentWord = Settings.MarkOccurrencesCurrentWord && !Settings.MarkOccurrencesMatchWholeWords; + + GET_BOOL_VALUE_FROM_INISECTION(ViewWhiteSpace, false); + GET_BOOL_VALUE_FROM_INISECTION(ViewEOLs, false); + + cpi_enc_t const iPrefEncIniSetting = (cpi_enc_t)Encoding_MapIniSetting(false, (int)CPI_UTF8); + GET_ENC_VALUE_FROM_INISECTION(DefaultEncoding, iPrefEncIniSetting, CPI_NONE, INT_MAX); + Settings.DefaultEncoding = ((Settings.DefaultEncoding == CPI_NONE) ? CPI_UTF8 : (cpi_enc_t)Encoding_MapIniSetting(true, (int)Settings.DefaultEncoding)); + GET_BOOL_VALUE_FROM_INISECTION(UseDefaultForFileEncoding, false); + GET_BOOL_VALUE_FROM_INISECTION(LoadASCIIasUTF8, true); + GET_BOOL_VALUE_FROM_INISECTION(UseReliableCEDonly, true); + GET_BOOL_VALUE_FROM_INISECTION(LoadNFOasOEM, true); + GET_BOOL_VALUE_FROM_INISECTION(NoEncodingTags, false); + GET_BOOL_VALUE_FROM_INISECTION(SkipUnicodeDetection, false); + GET_BOOL_VALUE_FROM_INISECTION(SkipANSICodePageDetection, false); + GET_INT_VALUE_FROM_INISECTION(DefaultEOLMode, SC_EOL_CRLF, SC_EOL_CRLF, SC_EOL_LF); + GET_BOOL_VALUE_FROM_INISECTION(WarnInconsistEOLs, true); + GET_BOOL_VALUE_FROM_INISECTION(FixLineEndings, false); + GET_BOOL_VALUE_FROM_INISECTION(FixTrailingBlanks, false); + GET_INT_VALUE_FROM_INISECTION(PrintHeader, 1, 0, 3); + GET_INT_VALUE_FROM_INISECTION(PrintFooter, 0, 0, 1); + GET_INT_VALUE_FROM_INISECTION(PrintColorMode, 3, 0, 4); + + int const zoomScale = float2int(1000.0f / GetBaseFontSize(Globals.hwndMain)); + Defaults.PrintZoom = (s_iSettingsVersion < CFG_VER_0001) ? (zoomScale / 10) : zoomScale; + int iPrintZoom = clampi(IniSectionGetInt(Settings_Section, L"PrintZoom", Defaults.PrintZoom), 0, SC_MAX_ZOOM_LEVEL); + if (s_iSettingsVersion < CFG_VER_0001) { iPrintZoom = 100 + (iPrintZoom - 10) * 10; } + Settings.PrintZoom = clampi(iPrintZoom, SC_MIN_ZOOM_LEVEL, SC_MAX_ZOOM_LEVEL); + + WCHAR localeInfo[3]; + GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, LOCALE_IMEASURE, localeInfo, 3); + LONG const _margin = (localeInfo[0] == L'0') ? 2000L : 1000L; // Metric system. L'1' is US System + Defaults.PrintMargin.left = _margin; + Settings.PrintMargin.left = clampi(IniSectionGetInt(Settings_Section, L"PrintMarginLeft", Defaults.PrintMargin.left), 0, 40000); + Defaults.PrintMargin.top = _margin; + Settings.PrintMargin.top = clampi(IniSectionGetInt(Settings_Section, L"PrintMarginTop", Defaults.PrintMargin.top), 0, 40000); + Defaults.PrintMargin.right = _margin; + Settings.PrintMargin.right = clampi(IniSectionGetInt(Settings_Section, L"PrintMarginRight", Defaults.PrintMargin.right), 0, 40000); + Defaults.PrintMargin.bottom = _margin; + Settings.PrintMargin.bottom = clampi(IniSectionGetInt(Settings_Section, L"PrintMarginBottom", Defaults.PrintMargin.bottom), 0, 40000); + + GET_BOOL_VALUE_FROM_INISECTION(SaveBeforeRunningTools, false); + GET_CAST_INT_VALUE_FROM_INISECTION(FILE_WATCHING_MODE, FileWatchingMode, FWM_NONE, FWM_NONE, FWM_AUTORELOAD); FileWatching.FileWatchingMode = Settings.FileWatchingMode; + GET_BOOL_VALUE_FROM_INISECTION(ResetFileWatching, true); FileWatching.ResetFileWatching = Settings.ResetFileWatching; + GET_INT_VALUE_FROM_INISECTION(EscFunction, 0, 0, 2); + GET_BOOL_VALUE_FROM_INISECTION(AlwaysOnTop, false); + GET_BOOL_VALUE_FROM_INISECTION(MinimizeToTray, false); + GET_BOOL_VALUE_FROM_INISECTION(TransparentMode, false); + GET_BOOL_VALUE_FROM_INISECTION(FindReplaceTransparentMode, true); + GET_INT_VALUE_FROM_INISECTION(RenderingTechnology, Defaults.RenderingTechnology, 0, 3); // set before + GET_INT_VALUE_FROM_INISECTION(Bidirectional, Defaults.Bidirectional, 0, 2); // set before + GET_BOOL_VALUE_FROM_INISECTION(MuteMessageBeep, false); + + ///~Settings2.IMEInteraction = clampi(IniSectionGetInt(Settings_Section, L"IMEInteraction", Settings2.IMEInteraction), SC_IME_WINDOWED, SC_IME_INLINE); + + // see TBBUTTON s_tbbMainWnd[] for initial/reset set of buttons + StringCchCopyW(Defaults.ToolbarButtons, COUNTOF(Defaults.ToolbarButtons), (s_iSettingsVersion < CFG_VER_0002) ? TBBUTTON_DEFAULT_IDS_V1 : TBBUTTON_DEFAULT_IDS_V2); + IniSectionGetString(Settings_Section, L"ToolbarButtons", Defaults.ToolbarButtons, Settings.ToolbarButtons, COUNTOF(Settings.ToolbarButtons)); + + GET_BOOL_VALUE_FROM_INISECTION(ShowToolbar, true); + GET_BOOL_VALUE_FROM_INISECTION(ShowStatusbar, true); + + GET_INT_VALUE_FROM_INISECTION(EncodingDlgSizeX, 340, INT_MIN, INT_MAX); + GET_INT_VALUE_FROM_INISECTION(EncodingDlgSizeY, 292, INT_MIN, INT_MAX); + GET_INT_VALUE_FROM_INISECTION(RecodeDlgSizeX, 340, INT_MIN, INT_MAX); + GET_INT_VALUE_FROM_INISECTION(RecodeDlgSizeY, 292, INT_MIN, INT_MAX); + GET_INT_VALUE_FROM_INISECTION(FileMRUDlgSizeX, 487, INT_MIN, INT_MAX); + GET_INT_VALUE_FROM_INISECTION(FileMRUDlgSizeY, 339, INT_MIN, INT_MAX); + GET_INT_VALUE_FROM_INISECTION(OpenWithDlgSizeX, 305, INT_MIN, INT_MAX); + GET_INT_VALUE_FROM_INISECTION(OpenWithDlgSizeY, 281, INT_MIN, INT_MAX); + GET_INT_VALUE_FROM_INISECTION(FavoritesDlgSizeX, 305, INT_MIN, INT_MAX); + GET_INT_VALUE_FROM_INISECTION(FavoritesDlgSizeY, 281, INT_MIN, INT_MAX); + GET_INT_VALUE_FROM_INISECTION(AddToFavDlgSizeX, 317, INT_MIN, INT_MAX); + + GET_INT_VALUE_FROM_INISECTION(FindReplaceDlgSizeX, 494, INT_MIN, INT_MAX); + GET_INT_VALUE_FROM_INISECTION(FindReplaceDlgPosX, CW_USEDEFAULT, INT_MIN, INT_MAX); + GET_INT_VALUE_FROM_INISECTION(FindReplaceDlgPosY, CW_USEDEFAULT, INT_MIN, INT_MAX); + + GET_INT_VALUE_FROM_INISECTION(CustomSchemesDlgSizeX, 833, INT_MIN, INT_MAX); + GET_INT_VALUE_FROM_INISECTION(CustomSchemesDlgSizeY, 515, INT_MIN, INT_MAX); + GET_INT_VALUE_FROM_INISECTION(CustomSchemesDlgPosX, CW_USEDEFAULT, INT_MIN, INT_MAX); + GET_INT_VALUE_FROM_INISECTION(CustomSchemesDlgPosY, CW_USEDEFAULT, INT_MIN, INT_MAX); + + // -------------------------------------------------------------------------- + const WCHAR* const StatusBar_Section = L"Statusbar Settings"; + // -------------------------------------------------------------------------- + + WCHAR tchStatusBar[MIDSZ_BUFFER] = { L'\0' }; + + IniSectionGetString(StatusBar_Section, L"SectionPrefixes", STATUSBAR_SECTION_PREFIXES, tchStatusBar, COUNTOF(tchStatusBar)); + ReadStrgsFromCSV(tchStatusBar, s_mxSBPrefix, STATUS_SECTOR_COUNT, MICRO_BUFFER, L"_PRFX_"); + + IniSectionGetString(StatusBar_Section, L"SectionPostfixes", STATUSBAR_SECTION_POSTFIXES, tchStatusBar, COUNTOF(tchStatusBar)); + ReadStrgsFromCSV(tchStatusBar, s_mxSBPostfix, STATUS_SECTOR_COUNT, MICRO_BUFFER, L"_POFX_"); + + IniSectionGetString(StatusBar_Section, L"VisibleSections", STATUSBAR_DEFAULT_IDS, tchStatusBar, COUNTOF(tchStatusBar)); + ReadVectorFromString(tchStatusBar, s_iStatusbarSections, STATUS_SECTOR_COUNT, 0, (STATUS_SECTOR_COUNT - 1), -1); + + for (int i = 0; i < STATUS_SECTOR_COUNT; ++i) { + s_iStatusbarVisible[i] = false; + } + int cnt = 0; + for (int i = 0; i < STATUS_SECTOR_COUNT; ++i) { + s_vSBSOrder[i] = -1; + int const id = s_iStatusbarSections[i]; + if (id >= 0) { + s_vSBSOrder[cnt++] = id; + s_iStatusbarVisible[id] = true; + } + } + + IniSectionGetString(StatusBar_Section, L"SectionWidthSpecs", STATUSBAR_SECTION_WIDTH_SPECS, tchStatusBar, COUNTOF(tchStatusBar)); + ReadVectorFromString(tchStatusBar, s_iStatusbarWidthSpec, STATUS_SECTOR_COUNT, -4096, 4096, 0); + + Globals.bZeroBasedColumnIndex = IniSectionGetBool(StatusBar_Section, L"ZeroBasedColumnIndex", false); + Globals.bZeroBasedCharacterCount = IniSectionGetBool(StatusBar_Section, L"ZeroBasedCharacterCount", false); + + + // -------------------------------------------------------------------------- + const WCHAR* const ToolbarImg_Section = L"Toolbar Images"; + // -------------------------------------------------------------------------- + + IniSectionGetString(ToolbarImg_Section, L"BitmapDefault", L"", + s_tchToolbarBitmap, COUNTOF(s_tchToolbarBitmap)); + IniSectionGetString(ToolbarImg_Section, L"BitmapHot", L"", + s_tchToolbarBitmapHot, COUNTOF(s_tchToolbarBitmap)); + IniSectionGetString(ToolbarImg_Section, L"BitmapDisabled", L"", + s_tchToolbarBitmapDisabled, COUNTOF(s_tchToolbarBitmap)); + + + // -------------------------------------------------------------------------- + const WCHAR* const Window_Section = L"Window"; + // -------------------------------------------------------------------------- + + int ResX, ResY; + GetCurrentMonitorResolution(Globals.hwndMain, &ResX, &ResY); + + WCHAR tchHighDpiToolBar[32] = { L'\0' }; + StringCchPrintf(tchHighDpiToolBar, COUNTOF(tchHighDpiToolBar), L"%ix%i HighDpiToolBar", ResX, ResY); + s_iToolBarTheme = IniSectionGetInt(Window_Section, tchHighDpiToolBar, -1); + s_iToolBarTheme = clampi(s_iToolBarTheme, -1, StrIsEmpty(s_tchToolbarBitmap) ? 1 : 2); + if (s_iToolBarTheme < 0) { // undefined: determine high DPI (higher than Full-HD) + s_iToolBarTheme = IsFullHDOrHigher(Globals.hwndMain, ResX, ResY) ? 1 : 0; + } + + // -------------------------------------------------------------- + // startup window (ignore window position if /p was specified) + // -------------------------------------------------------------- + + // 1st set default window position + + s_DefWinInfo = InitDefaultWndPos(2); // std. default position + + if (bExplicitDefaultWinPos) { + int bMaxi = 0; + int const itok = swscanf_s(Settings2.DefaultWindowPosition, L"%i,%i,%i,%i,%i", + &s_DefWinInfo.x, &s_DefWinInfo.y, &s_DefWinInfo.cx, &s_DefWinInfo.cy, &bMaxi); + if (itok == 4 || itok == 5) { // scan successful + if (s_DefWinInfo.cx < 1) s_DefWinInfo.cx = CW_USEDEFAULT; + if (s_DefWinInfo.cy < 1) s_DefWinInfo.cy = CW_USEDEFAULT; + if (bMaxi) s_DefWinInfo.max = true; + if (itok == 4) s_DefWinInfo.max = false; + InitWindowPosition(&s_DefWinInfo, 0); + } + else { + // overwrite bad defined default position + StringCchPrintf(Settings2.DefaultWindowPosition, COUNTOF(Settings2.DefaultWindowPosition), + L"%i,%i,%i,%i,%i", s_DefWinInfo.x, s_DefWinInfo.y, s_DefWinInfo.cx, s_DefWinInfo.cy, s_DefWinInfo.max); + IniFileSetString(Globals.IniFile, L"Settings2", L"DefaultWindowPosition", Settings2.DefaultWindowPosition); + } + } + + // 2nd set initial window position + + s_WinInfo = s_DefWinInfo; + + if (!s_flagPosParam /*|| g_bStickyWinPos*/) { + + WCHAR tchPosX[32], tchPosY[32], tchSizeX[32], tchSizeY[32], tchMaximized[32], tchZoom[32]; + + StringCchPrintf(tchPosX, COUNTOF(tchPosX), L"%ix%i PosX", ResX, ResY); + StringCchPrintf(tchPosY, COUNTOF(tchPosY), L"%ix%i PosY", ResX, ResY); + StringCchPrintf(tchSizeX, COUNTOF(tchSizeX), L"%ix%i SizeX", ResX, ResY); + StringCchPrintf(tchSizeY, COUNTOF(tchSizeY), L"%ix%i SizeY", ResX, ResY); + StringCchPrintf(tchMaximized, COUNTOF(tchMaximized), L"%ix%i Maximized", ResX, ResY); + StringCchPrintf(tchZoom, COUNTOF(tchZoom), L"%ix%i Zoom", ResX, ResY); + + s_WinInfo.x = IniSectionGetInt(Window_Section, tchPosX, CW_USEDEFAULT); + s_WinInfo.y = IniSectionGetInt(Window_Section, tchPosY, CW_USEDEFAULT); + s_WinInfo.cx = IniSectionGetInt(Window_Section, tchSizeX, CW_USEDEFAULT); + s_WinInfo.cy = IniSectionGetInt(Window_Section, tchSizeY, CW_USEDEFAULT); + s_WinInfo.max = IniSectionGetBool(Window_Section, tchMaximized, false); + s_WinInfo.max = clampi(s_WinInfo.max, 0, 1); + s_WinInfo.zoom = IniSectionGetInt(Window_Section, tchZoom, (s_iSettingsVersion < CFG_VER_0001) ? 0 : 100); + if (s_iSettingsVersion < CFG_VER_0001) { s_WinInfo.zoom = (s_WinInfo.zoom + 10) * 10; } + s_WinInfo.zoom = clampi(s_WinInfo.zoom, SC_MIN_ZOOM_LEVEL, SC_MAX_ZOOM_LEVEL); + + if ((s_WinInfo.x == CW_USEDEFAULT) || (s_WinInfo.y == CW_USEDEFAULT) || + (s_WinInfo.cx == CW_USEDEFAULT) || (s_WinInfo.cy == CW_USEDEFAULT)) + { + s_flagWindowPos = 2; // std. default position (CmdLn: /pd) + } + else + s_flagWindowPos = 0; // init to g_WinInfo + } + + // ------------------------------------------------------------------------ + + // --- override by resolution specific settings --- + WCHAR tchSciDirectWriteTech[64]; + StringCchPrintf(tchSciDirectWriteTech, COUNTOF(tchSciDirectWriteTech), L"%ix%i RenderingTechnology", ResX, ResY); + Settings.RenderingTechnology = clampi(IniSectionGetInt(Window_Section, tchSciDirectWriteTech, Settings.RenderingTechnology), 0, 3); + + WCHAR tchSciFontQuality[64]; + StringCchPrintf(tchSciFontQuality, COUNTOF(tchSciFontQuality), L"%ix%i SciFontQuality", ResX, ResY); + Settings2.SciFontQuality = clampi(IniSectionGetInt(Window_Section, tchSciFontQuality, Settings2.SciFontQuality), 0, 3); + + if (bDirtyFlag) { + SaveIniFile(Globals.IniFile); + } + ReleaseIniFile(); + } + + // define scintilla internal codepage + const int iSciDefaultCodePage = SC_CP_UTF8; // default UTF8 + + // remove internal support for Chinese, Japan, Korean DBCS use UTF-8 instead + /* + if (Settings.DefaultEncoding == CPI_ANSI_DEFAULT) + { + // check for Chinese, Japan, Korean DBCS code pages and switch accordingly + int acp = (int)GetACP(); + if (acp == 932 || acp == 936 || acp == 949 || acp == 950) { + iSciDefaultCodePage = acp; + } + Settings.DefaultEncoding = Encoding_GetByCodePage(iSciDefaultCodePage); + } + */ + + // set flag for encoding default + Encoding_SetDefaultFlag(Settings.DefaultEncoding); + + // define default charset + Globals.iDefaultCharSet = (int)CharSetFromCodePage((UINT)iSciDefaultCodePage); + + // Scintilla Styles + Style_Load(); +} +//============================================================================= + + + +//============================================================================= +// +// SaveSettings() +// + +#define SAVE_VALUE_IF_NOT_EQ_DEFAULT(TYPE, VARNAME) \ + if (Settings.VARNAME != Defaults.VARNAME) { \ + IniSectionSet##TYPE(Settings_Section, _W(_STRG(VARNAME)), Settings.VARNAME); \ + } \ + else { \ + IniSectionSetString(Settings_Section, _W(_STRG(VARNAME)), NULL); \ + } + +// ---------------------------------------------------------------------------- + + +void SaveSettings(bool bSaveSettingsNow) +{ + if (StrIsEmpty(Globals.IniFile) || !s_bEnableSaveSettings) { return; } + + CreateIniFile(); + LoadIniFile(Globals.IniFile); + + const WCHAR* const Settings_Section = L"Settings"; + + if (!(Settings.SaveSettings || bSaveSettingsNow)) { + IniSectionSetInt(Settings_Section, L"SettingsVersion", CFG_VER_CURRENT); + if (Settings.SaveSettings != Defaults.SaveSettings) { + IniSectionSetBool(Settings_Section, L"SaveSettings", Settings.SaveSettings); + } + SaveIniFile(Globals.IniFile); + return; + } + + // update window placement + s_WinInfo = GetMyWindowPlacement(Globals.hwndMain, NULL); + + { + IniSectionSetInt(Settings_Section, L"SettingsVersion", CFG_VER_CURRENT); + + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, SaveSettings); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, SaveRecentFiles); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, PreserveCaretPos); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, SaveFindReplace); + + if (Settings.EFR_Data.bFindClose != Defaults.EFR_Data.bFindClose) { + IniSectionSetBool(Settings_Section, L"CloseFind", Settings.EFR_Data.bFindClose); + } + if (Settings.EFR_Data.bReplaceClose != Defaults.EFR_Data.bReplaceClose) { + IniSectionSetBool(Settings_Section, L"CloseReplace", Settings.EFR_Data.bReplaceClose); + } + if (Settings.EFR_Data.bNoFindWrap != Defaults.EFR_Data.bNoFindWrap) { + IniSectionSetBool(Settings_Section, L"NoFindWrap", Settings.EFR_Data.bNoFindWrap); + } + if (Settings.EFR_Data.bTransformBS != Defaults.EFR_Data.bTransformBS) { + IniSectionSetBool(Settings_Section, L"FindTransformBS", Settings.EFR_Data.bTransformBS); + } + if (Settings.EFR_Data.bWildcardSearch != Defaults.EFR_Data.bWildcardSearch) { + IniSectionSetBool(Settings_Section, L"WildcardSearch", Settings.EFR_Data.bWildcardSearch); + } + if (Settings.EFR_Data.bMarkOccurences != Defaults.EFR_Data.bMarkOccurences) { + IniSectionSetBool(Settings_Section, L"FindMarkAllOccurrences", Settings.EFR_Data.bMarkOccurences); + } + if (Settings.EFR_Data.bHideNonMatchedLines != Defaults.EFR_Data.bHideNonMatchedLines) { + IniSectionSetBool(Settings_Section, L"HideNonMatchedLines", Settings.EFR_Data.bHideNonMatchedLines); + } + if (Settings.EFR_Data.bDotMatchAll != Defaults.EFR_Data.bDotMatchAll) { + IniSectionSetBool(Settings_Section, L"RegexDotMatchesAll", Settings.EFR_Data.bDotMatchAll); + } + if (Settings.EFR_Data.fuFlags != Defaults.EFR_Data.fuFlags) { + IniSectionSetInt(Settings_Section, L"efrData_fuFlags", Settings.EFR_Data.fuFlags); + } + + WCHAR wchTmp[MAX_PATH] = { L'\0' }; + if (StringCchCompareXIW(Settings.OpenWithDir, Defaults.OpenWithDir) != 0) { + PathRelativeToApp(Settings.OpenWithDir, wchTmp, COUNTOF(wchTmp), false, true, Flags.PortableMyDocs); + IniSectionSetString(Settings_Section, L"OpenWithDir", wchTmp); + } + if (StringCchCompareXIW(Settings.FavoritesDir, Defaults.FavoritesDir) != 0) { + PathRelativeToApp(Settings.FavoritesDir, wchTmp, COUNTOF(wchTmp), false, true, Flags.PortableMyDocs); + IniSectionSetString(Settings_Section, L"Favorites", wchTmp); + } + + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, PathNameFormat); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, WordWrap); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, TabsAsSpaces); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, TabIndents); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, TabWidth); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, IndentWidth); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, LongLinesLimit); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, BackspaceUnindents); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, WordWrapMode); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, WordWrapIndent); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, WordWrapSymbols); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, ShowWordWrapSymbols); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, MatchBraces); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, AutoCloseTags); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, HighlightCurrentLine); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, HyperlinkHotspot); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, ScrollPastEOF); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, ShowHypLnkToolTip); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, AutoIndent); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, AutoCompleteWords); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, AutoCLexerKeyWords); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, AccelWordNavigation); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, ShowIndentGuides); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, WarnInconsistentIndents); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, AutoDetectIndentSettings); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, MarkLongLines); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, LongLineMode); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, ShowSelectionMargin); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, ShowLineNumbers); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, ShowCodeFolding); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, MarkOccurrences); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, MarkOccurrencesMatchVisible); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, MarkOccurrencesMatchCase); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, MarkOccurrencesMatchWholeWords); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, MarkOccurrencesCurrentWord); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, ViewWhiteSpace); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, ViewEOLs); + + Settings.DefaultEncoding = (cpi_enc_t)Encoding_MapIniSetting(false, (int)Settings.DefaultEncoding); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, DefaultEncoding); + Settings.DefaultEncoding = (cpi_enc_t)Encoding_MapIniSetting(true, (int)Settings.DefaultEncoding); + + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, UseDefaultForFileEncoding); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, LoadASCIIasUTF8); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, UseReliableCEDonly); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, LoadNFOasOEM); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, NoEncodingTags); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, SkipUnicodeDetection); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, SkipANSICodePageDetection); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, DefaultEOLMode); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, WarnInconsistEOLs); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, FixLineEndings); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, FixTrailingBlanks); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, PrintHeader); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, PrintFooter); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, PrintColorMode); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, PrintZoom); + + if (Settings.PrintMargin.left != Defaults.PrintMargin.left) { + IniSectionSetInt(Settings_Section, L"PrintMarginLeft", Settings.PrintMargin.left); + } + if (Settings.PrintMargin.top != Defaults.PrintMargin.top) { + IniSectionSetInt(Settings_Section, L"PrintMarginTop", Settings.PrintMargin.top); + } + if (Settings.PrintMargin.right != Defaults.PrintMargin.right) { + IniSectionSetInt(Settings_Section, L"PrintMarginRight", Settings.PrintMargin.right); + } + if (Settings.PrintMargin.bottom != Defaults.PrintMargin.bottom) { + IniSectionSetInt(Settings_Section, L"PrintMarginBottom", Settings.PrintMargin.bottom); + } + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, SaveBeforeRunningTools); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, FileWatchingMode); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, ResetFileWatching); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, EscFunction); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, AlwaysOnTop); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, MinimizeToTray); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, TransparentMode); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, FindReplaceTransparentMode); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, RenderingTechnology); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, Bidirectional); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, MuteMessageBeep); + + ///~IniSectionSetInt(Settings_Section, L"IMEInteraction", Settings2.IMEInteraction); + + Toolbar_GetButtons(Globals.hwndToolbar, IDT_FILE_NEW, Settings.ToolbarButtons, COUNTOF(Settings.ToolbarButtons)); + if (StringCchCompareX(Settings.ToolbarButtons, Defaults.ToolbarButtons) == 0) { + IniSectionSetString(Settings_Section, L"ToolbarButtons", NULL); + } + else { + IniSectionSetString(Settings_Section, L"ToolbarButtons", Settings.ToolbarButtons); + } + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, ShowToolbar); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, ShowStatusbar); + + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, EncodingDlgSizeX); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, EncodingDlgSizeY); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, RecodeDlgSizeX); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, RecodeDlgSizeY); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, FileMRUDlgSizeX); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, FileMRUDlgSizeY); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, OpenWithDlgSizeX); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, OpenWithDlgSizeY); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, FavoritesDlgSizeX); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, FavoritesDlgSizeY); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, AddToFavDlgSizeX); + + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, FindReplaceDlgSizeX); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, FindReplaceDlgPosX); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, FindReplaceDlgPosY); + + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, CustomSchemesDlgSizeX); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, CustomSchemesDlgSizeY); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, CustomSchemesDlgPosX); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, CustomSchemesDlgPosY); + } + + int ResX, ResY; + GetCurrentMonitorResolution(Globals.hwndMain, &ResX, &ResY); + + const WCHAR* const Window_Section = L"Window"; + + WCHAR tchHighDpiToolBar[32]; + StringCchPrintf(tchHighDpiToolBar, COUNTOF(tchHighDpiToolBar), L"%ix%i HighDpiToolBar", ResX, ResY); + IniSectionSetInt(Window_Section, tchHighDpiToolBar, s_iToolBarTheme); + + if (!Flags.bStickyWindowPosition) { + + WCHAR tchPosX[32], tchPosY[32], tchSizeX[32], tchSizeY[32], tchMaximized[32], tchZoom[32]; + + StringCchPrintf(tchPosX, COUNTOF(tchPosX), L"%ix%i PosX", ResX, ResY); + StringCchPrintf(tchPosY, COUNTOF(tchPosY), L"%ix%i PosY", ResX, ResY); + StringCchPrintf(tchSizeX, COUNTOF(tchSizeX), L"%ix%i SizeX", ResX, ResY); + StringCchPrintf(tchSizeY, COUNTOF(tchSizeY), L"%ix%i SizeY", ResX, ResY); + StringCchPrintf(tchMaximized, COUNTOF(tchMaximized), L"%ix%i Maximized", ResX, ResY); + StringCchPrintf(tchZoom, COUNTOF(tchMaximized), L"%ix%i Zoom", ResX, ResY); + + IniSectionSetInt(Window_Section, tchPosX, s_WinInfo.x); + IniSectionSetInt(Window_Section, tchPosY, s_WinInfo.y); + IniSectionSetInt(Window_Section, tchSizeX, s_WinInfo.cx); + IniSectionSetInt(Window_Section, tchSizeY, s_WinInfo.cy); + IniSectionSetBool(Window_Section, tchMaximized, s_WinInfo.max); + IniSectionSetInt(Window_Section, tchZoom, s_WinInfo.zoom); + } + + SaveIniFile(Globals.IniFile); + + Style_Save(); // Scintilla Styles + +} +//============================================================================= + + + + + //============================================================================= diff --git a/src/Config/Config.h b/src/Config/Config.h index bcf5521c2..62cd0316c 100644 --- a/src/Config/Config.h +++ b/src/Config/Config.h @@ -25,8 +25,17 @@ extern "C" { //==== Ini-File Handling ============================================= +bool FindIniFile(); +int TestIniFile(); +bool CreateIniFile(); +bool CreateIniFileEx(LPCWSTR lpszIniFile); +void LoadSettings(); +void SaveSettings(bool); + +// ---------------------------------------------------------------------------- + bool LoadIniFile(LPCWSTR lpIniFilePath); -bool SaveIniFile(); +bool SaveIniFile(LPCWSTR lpIniFilePath); void ReleaseIniFile(); size_t IniSectionGetString(LPCWSTR lpSectionName, LPCWSTR lpKeyName, LPCWSTR lpDefault, diff --git a/src/Config/SimpleIni.h b/src/Config/SimpleIni.h index f0bda3bff..de830f129 100644 --- a/src/Config/SimpleIni.h +++ b/src/Config/SimpleIni.h @@ -1272,14 +1272,6 @@ private: */ size_t m_uDataLen; - /** File path for this data */ - char m_FilePathA[MAX_PATH]; - -#ifdef SI_HAS_WIDE_FILE - SI_WCHAR_T m_FilePathW[MAX_PATH]; -#endif - - /** File comment for this data, if one exists. */ const SI_CHAR * m_pFileComment; @@ -1344,10 +1336,6 @@ CSimpleIniTempl::Reset() delete[] m_pData; m_pData = NULL; m_uDataLen = 0; - m_FilePathA[0] = '\0'; -#ifdef SI_HAS_WIDE_FILE - m_FilePathW[0] = L'\0'; -#endif m_pFileComment = NULL; if (!m_data.empty()) { m_data.erase(m_data.begin(), m_data.end()); @@ -1392,7 +1380,6 @@ CSimpleIniTempl::LoadFile( ) { #ifdef _WIN32 - wcscpy_s(m_FilePathW, _countof(m_FilePathW), a_pwszFile); FILE * fp = NULL; #if __STDC_WANT_SECURE_LIB__ && !_WIN32_WCE _wfopen_s(&fp, a_pwszFile, L"rb"); @@ -1565,16 +1552,6 @@ CSimpleIniTempl::LoadData( m_pData = pData; m_uDataLen = uLen+1; } - - // Notepad3: change .ini-file encoding to UTF-8 - if (pDataUTF16toUTF8) { -#ifdef SI_HAS_WIDE_FILE - SaveFile(m_FilePathW, true); -#else - SaveFile(m_FilePathA, true); -#endif - } - return SI_OK; } @@ -2529,17 +2506,17 @@ CSimpleIniTempl::Save( if (iSection->pComment) { if (bNeedNewLine) { a_oOutput.Write(SI_NEWLINE_A); - a_oOutput.Write(SI_NEWLINE_A); + //§§§a_oOutput.Write(SI_NEWLINE_A); + bNeedNewLine = false; } if (!OutputMultiLineText(a_oOutput, convert, iSection->pComment)) { return SI_FAIL; } - bNeedNewLine = false; } if (bNeedNewLine) { a_oOutput.Write(SI_NEWLINE_A); - a_oOutput.Write(SI_NEWLINE_A); + //§§§a_oOutput.Write(SI_NEWLINE_A); bNeedNewLine = false; } @@ -2548,10 +2525,12 @@ CSimpleIniTempl::Save( if (!convert.ConvertToStore(iSection->pItem)) { return SI_FAIL; } + //a_oOutput.Write(SI_NEWLINE_A); // before new section a_oOutput.Write("["); a_oOutput.Write(convert.Data()); a_oOutput.Write("]"); a_oOutput.Write(SI_NEWLINE_A); + bNeedNewLine = false; } // get all of the keys sorted in load order @@ -2577,6 +2556,7 @@ CSimpleIniTempl::Save( // write out the comment if there is one if (iValue->pComment) { a_oOutput.Write(SI_NEWLINE_A); + bNeedNewLine = false; if (!OutputMultiLineText(a_oOutput, convert, iValue->pComment)) { return SI_FAIL; } @@ -2597,6 +2577,7 @@ CSimpleIniTempl::Save( // multi-line data needs to be processed specially to ensure // that we use the correct newline format for the current system a_oOutput.Write("<<pItem)) { return SI_FAIL; } @@ -2606,9 +2587,10 @@ CSimpleIniTempl::Save( a_oOutput.Write(convert.Data()); } a_oOutput.Write(SI_NEWLINE_A); + bNeedNewLine = false; } } - bNeedNewLine = true; + //§§§bNeedNewLine = true; } return SI_OK; diff --git a/src/Dialogs.c b/src/Dialogs.c index 93d76476a..f4ed1a1a7 100644 --- a/src/Dialogs.c +++ b/src/Dialogs.c @@ -3968,7 +3968,7 @@ bool StatusSetTextID(HWND hwnd, UINT nPart, UINT uID) // // Toolbar_Get/SetButtons() // -int Toolbar_GetButtons(HWND hwnd, int cmdBase, LPWSTR lpszButtons, int cchButtons) +int Toolbar_GetButtons(HANDLE hwnd, int cmdBase, LPWSTR lpszButtons, int cchButtons) { WCHAR tchButtons[512] = { L'\0' }; WCHAR tchItem[32] = { L'\0' }; @@ -3988,7 +3988,7 @@ int Toolbar_GetButtons(HWND hwnd, int cmdBase, LPWSTR lpszButtons, int cchButton return(c); } -int Toolbar_SetButtons(HWND hwnd, int cmdBase, LPCWSTR lpszButtons, LPCTBBUTTON ptbb, int ctbb) +int Toolbar_SetButtons(HANDLE hwnd, int cmdBase, LPCWSTR lpszButtons, LPCTBBUTTON ptbb, int ctbb) { WCHAR tchButtons[MIDSZ_BUFFER]; diff --git a/src/Dialogs.h b/src/Dialogs.h index 1360d55d1..a6b77040a 100644 --- a/src/Dialogs.h +++ b/src/Dialogs.h @@ -99,8 +99,8 @@ void DeleteBitmapButton(HWND hwnd, int nCtlId); void StatusSetText(HWND hwnd, UINT nPart, LPCWSTR lpszText); bool StatusSetTextID(HWND hwnd, UINT nPart, UINT uID); -int Toolbar_GetButtons(HWND hwnd, int cmdBase, LPWSTR lpszButtons, int cchButtons); -int Toolbar_SetButtons(HWND, int, LPCWSTR, void*, int); +int Toolbar_GetButtons(HANDLE hwnd, int cmdBase, LPWSTR lpszButtons, int cchButtons); +int Toolbar_SetButtons(HANDLE, int, LPCWSTR, void*, int); LRESULT SendWMSize(HWND hwnd, RECT* rc); diff --git a/src/Helpers.c b/src/Helpers.c index 15fad7fec..c6002d7b6 100644 --- a/src/Helpers.c +++ b/src/Helpers.c @@ -1605,7 +1605,7 @@ bool MRU_Save(LPMRULIST pmru) } } - SaveIniFile(); + SaveIniFile(Globals.IniFile); return true; } return false; diff --git a/src/Notepad3.c b/src/Notepad3.c index 95b9d4229..217ae2daf 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -57,11 +57,30 @@ GLOBALS_T Globals; SETTINGS_T Settings; SETTINGS_T Defaults; SETTINGS2_T Settings2; -static SETTINGS2_T Defaults2; +SETTINGS2_T Defaults2; FOCUSEDVIEW_T FocusedView; FILEWATCHING_T FileWatching; +WININFO s_WinInfo = INIT_WININFO; +WININFO s_DefWinInfo = INIT_WININFO; + +prefix_t s_mxSBPrefix[STATUS_SECTOR_COUNT]; +prefix_t s_mxSBPostfix[STATUS_SECTOR_COUNT]; + +bool s_iStatusbarVisible[STATUS_SECTOR_COUNT] = SBS_INIT_ZERO; +int s_iStatusbarWidthSpec[STATUS_SECTOR_COUNT] = SBS_INIT_ZERO; +int s_vSBSOrder[STATUS_SECTOR_COUNT] = SBS_INIT_MINUS; + +WCHAR s_tchToolbarBitmap[MAX_PATH] = { L'\0' }; +WCHAR s_tchToolbarBitmapHot[MAX_PATH] = { L'\0' }; +WCHAR s_tchToolbarBitmapDisabled[MAX_PATH] = { L'\0' }; + +bool s_bEnableSaveSettings = true; +int s_iToolBarTheme = -1; +bool s_flagPosParam = false; +int s_flagWindowPos = 0; + // ------------------------------------ static WCHAR s_wchWndClass[16] = _W(SAPPNAME); @@ -72,29 +91,11 @@ static HWND s_hwndReBar = NULL; static WCHAR s_wchTmpFilePath[MAX_PATH] = { L'\0' }; -static int s_iSettingsVersion = CFG_VER_CURRENT; -static bool s_bEnableSaveSettings = true; - -static prefix_t s_mxSBPrefix[STATUS_SECTOR_COUNT]; -static prefix_t s_mxSBPostfix[STATUS_SECTOR_COUNT]; - -static int s_iStatusbarSections[STATUS_SECTOR_COUNT] = SBS_INIT_MINUS; -static bool s_iStatusbarVisible[STATUS_SECTOR_COUNT] = SBS_INIT_ZERO; -static int s_vSBSOrder[STATUS_SECTOR_COUNT] = SBS_INIT_MINUS; - -static int s_iStatusbarWidthSpec[STATUS_SECTOR_COUNT] = SBS_INIT_ZERO; - -static WCHAR s_tchToolbarBitmap[MAX_PATH] = { L'\0' }; -static WCHAR s_tchToolbarBitmapHot[MAX_PATH] = { L'\0' }; -static WCHAR s_tchToolbarBitmapDisabled[MAX_PATH] = { L'\0' }; - static WCHAR s_wchPrefixSelection[256] = { L'\0' }; static WCHAR s_wchAppendSelection[256] = { L'\0' }; static WCHAR s_wchPrefixLines[256] = { L'\0' }; static WCHAR s_wchAppendLines[256] = { L'\0' }; -static WININFO s_WinInfo = INIT_WININFO; -static WININFO s_DefWinInfo = INIT_WININFO; static int s_WinCurrentWidth = 0; #define FILE_LIST_SIZE 32 @@ -112,7 +113,6 @@ static bool s_bRunningWatch = false; static bool s_bFileReadOnly = false; static bool s_bIsElevated = false; -static int s_iToolBarTheme = -1; static int s_iSortOptions = 0; static int s_iAlignMode = 0; static bool s_bIsAppThemed = true; @@ -190,8 +190,8 @@ static const int NUMTOOLBITMAPS = 29; // ---------------------------------------------------------------------------- -static const WCHAR* const TBBUTTON_DEFAULT_IDS_V1 = L"1 2 4 3 28 0 5 6 0 7 8 9 0 10 11 0 12 0 24 26 0 22 23 0 13 14 0 27 0 15 0 25 0 17"; -static const WCHAR* const TBBUTTON_DEFAULT_IDS_V2 = L"1 2 4 3 28 0 5 6 0 7 8 9 0 10 11 0 12 0 24 26 0 22 23 0 13 14 0 15 0 25 0 29 0 17"; +const WCHAR* const TBBUTTON_DEFAULT_IDS_V1 = L"1 2 4 3 28 0 5 6 0 7 8 9 0 10 11 0 12 0 24 26 0 22 23 0 13 14 0 27 0 15 0 25 0 17"; +const WCHAR* const TBBUTTON_DEFAULT_IDS_V2 = L"1 2 4 3 28 0 5 6 0 7 8 9 0 10 11 0 12 0 24 26 0 22 23 0 13 14 0 15 0 25 0 29 0 17"; //============================================================================= @@ -534,8 +534,6 @@ static int s_flagReuseWindow = 0; static int s_flagSingleFileInstance = 0; static bool s_flagStartAsTrayIcon = false; static int s_flagAlwaysOnTop = 0; -static bool s_flagPosParam = false; -static int s_flagWindowPos = 0; static bool s_flagKeepTitleExcerpt = false; static bool s_flagNewFromClipboard = false; static bool s_flagPasteBoard = false; @@ -1017,10 +1015,10 @@ void EndWaitCursor() //============================================================================= // -// _InitWindowPosition() +// InitDefaultWndPos() // // -static WININFO _InitDefaultWndPos(const int flagsPos) +WININFO InitDefaultWndPos(const int flagsPos) { RECT rc; GetWindowRect(GetDesktopWindow(), &rc); @@ -1037,7 +1035,13 @@ static WININFO _InitDefaultWndPos(const int flagsPos) } // ---------------------------------------------------------------------------- -static void _InitWindowPosition(WININFO* pWinInfo, const int flagsPos) + +//============================================================================= +// +// InitWindowPosition() +// +// +void InitWindowPosition(WININFO* pWinInfo, const int flagsPos) { WININFO winfo = *pWinInfo; @@ -1052,7 +1056,7 @@ static void _InitWindowPosition(WININFO* pWinInfo, const int flagsPos) } else if (flagsPos == 3) { - winfo = _InitDefaultWndPos(flagsPos); + winfo = InitDefaultWndPos(flagsPos); } else if (flagsPos >= 4) { @@ -1144,7 +1148,7 @@ HWND InitInstance(HINSTANCE hInstance,LPCWSTR pszCmdLine,int nCmdShow) { UNUSED(pszCmdLine); - _InitWindowPosition(&s_WinInfo, s_flagWindowPos); + InitWindowPosition(&s_WinInfo, s_flagWindowPos); s_WinCurrentWidth = s_WinInfo.cx; // get monitor coordinates from g_WinInfo @@ -1565,6 +1569,21 @@ LRESULT CALLBACK MainWndProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) } +//============================================================================= +// +// SaveAllSettings() +// +void SaveAllSettings(bool bSaveSettingsNow) +{ + WCHAR tchMsg[80]; + GetLngString(IDS_MUI_SAVINGSETTINGS, tchMsg, COUNTOF(tchMsg)); + BeginWaitCursor(tchMsg); + + SaveSettings(bSaveSettingsNow); + + EndWaitCursor(); +} + //============================================================================= // @@ -2339,7 +2358,7 @@ void CreateBars(HWND hwnd, HINSTANCE hInstance) s_cyReBarFrame = s_bIsAppThemed ? 0 : 2; if (bDirtyFlag) { - SaveIniFile(); + SaveIniFile(Globals.IniFile); } } @@ -2382,7 +2401,7 @@ LRESULT MsgEndSession(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) } // call SaveSettings() when Globals.hwndToolbar is still valid - SaveSettings(false); + SaveAllSettings(false); if (StrIsNotEmpty(Globals.IniFile)) { @@ -3492,7 +3511,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) case IDM_FILE_NEWWINDOW: case IDM_FILE_NEWWINDOW2: - //~SaveSettings(false); + //~SaveAllSettings(false); DialogNewWindow(hwnd, Settings.SaveBeforeRunningTools, (iLoWParam != IDM_FILE_NEWWINDOW2)); break; @@ -5390,7 +5409,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) else IniSectionSetString(L"Settings2", L"StickyWindowPosition", NULL); - SaveIniFile(); + SaveIniFile(Globals.IniFile); } } break; @@ -5553,7 +5572,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) if (!bCreateFailure) { if (WritePrivateProfileString(L"Settings", L"WriteTest", L"ok", Globals.IniFile)) { - SaveSettings(true); + SaveAllSettings(true); InfoBoxLng(MB_ICONINFORMATION, NULL, IDS_MUI_SAVEDSETTINGS); } else { @@ -6111,13 +6130,13 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) break; case CMD_CLEARSAVEDWINPOS: - s_DefWinInfo = _InitDefaultWndPos(2); + s_DefWinInfo = InitDefaultWndPos(2); IniFileSetString(Globals.IniFile, L"Settings2", L"DefaultWindowPosition", NULL); break; case CMD_OPENINIFILE: if (StrIsNotEmpty(Globals.IniFile)) { - SaveSettings(false); + SaveAllSettings(false); FileLoad(false,false,false,false,true,true,Globals.IniFile); } break; @@ -7275,759 +7294,6 @@ void GetFindPatternMB(LPSTR chFindPattern, size_t bufferSize) } -//============================================================================= -// -// LoadSettings() -// -// -void LoadSettings() -{ - int const _ver = StrIsEmpty(Globals.IniFile) ? CFG_VER_CURRENT : CFG_VER_NONE; - - LoadIniFile(Globals.IniFile); - { - bool bDirtyFlag = false; // do we have to save the file on done - // prerequisites - s_iSettingsVersion = IniSectionGetInt(L"Settings", L"SettingsVersion", _ver); - - Defaults.SaveSettings = StrIsNotEmpty(Globals.IniFile); - Settings.SaveSettings = IniSectionGetBool(L"Settings", L"SaveSettings", Defaults.SaveSettings); - - // -------------------------------------------------------------------------- - // first set "hard coded" .ini-Settings - // -------------------------------------------------------------------------- - const WCHAR* const Settings2_Section = L"Settings2"; - - Defaults2.PreferredLanguageLocaleName[0] = L'\0'; - IniSectionGetString(Settings2_Section, L"PreferredLanguageLocaleName", Defaults2.PreferredLanguageLocaleName, - Settings2.PreferredLanguageLocaleName, COUNTOF(Settings2.PreferredLanguageLocaleName)); - - StringCchCopyW(Defaults2.DefaultExtension, COUNTOF(Defaults2.DefaultExtension), L"txt"); - IniSectionGetString(Settings2_Section, L"DefaultExtension", Defaults2.DefaultExtension, - Settings2.DefaultExtension, COUNTOF(Settings2.DefaultExtension)); - StrTrim(Settings2.DefaultExtension, L" \t.\""); - - Defaults2.DefaultDirectory[0] = L'\0'; - IniSectionGetString(Settings2_Section, L"DefaultDirectory", Defaults2.DefaultDirectory, - Settings2.DefaultDirectory, COUNTOF(Settings2.DefaultDirectory)); - - Defaults2.FileDlgFilters[0] = L'\0'; - IniSectionGetString(Settings2_Section, L"FileDlgFilters", Defaults2.FileDlgFilters, - Settings2.FileDlgFilters, COUNTOF(Settings2.FileDlgFilters) - 2); - - Defaults2.FileCheckInverval = 2000UL; - Settings2.FileCheckInverval = clampul(IniSectionGetInt(Settings2_Section, L"FileCheckInverval", - Defaults2.FileCheckInverval), 250UL, 300000UL); - FileWatching.FileCheckInverval = Settings2.FileCheckInverval; - - Defaults2.AutoReloadTimeout = 2000UL; - Settings2.AutoReloadTimeout = clampul(IniSectionGetInt(Settings2_Section, L"AutoReloadTimeout", - Defaults2.AutoReloadTimeout), 250UL, 300000UL); - FileWatching.AutoReloadTimeout = Settings2.AutoReloadTimeout; - - // deprecated - Defaults.RenderingTechnology = IniSectionGetInt(Settings2_Section, L"SciDirectWriteTech", -111); - if ((Defaults.RenderingTechnology != -111) && Settings.SaveSettings) { - // cleanup - IniSectionSetString(Settings2_Section, L"SciDirectWriteTech", NULL); - bDirtyFlag = true; - } - Defaults.RenderingTechnology = clampi(Defaults.RenderingTechnology, 0, 3); - - // Settings2 deprecated - Defaults.Bidirectional = IniSectionGetInt(Settings2_Section, L"EnableBidirectionalSupport", -111); - if ((Defaults.Bidirectional != -111) && Settings.SaveSettings) { - // cleanup - IniSectionSetString(Settings2_Section, L"EnableBidirectionalSupport", NULL); - bDirtyFlag = true; - } - Defaults.Bidirectional = (clampi(Defaults.Bidirectional, SC_BIDIRECTIONAL_DISABLED, SC_BIDIRECTIONAL_R2L) > 0) ? SC_BIDIRECTIONAL_R2L : 0; - - Defaults2.IMEInteraction = -1; - Settings2.IMEInteraction = clampi(IniSectionGetInt(Settings2_Section, L"IMEInteraction", Defaults2.IMEInteraction), -1, SC_IME_INLINE); - // Korean IME use inline mode by default - if (Settings2.IMEInteraction == -1) { // auto detection once - // ScintillaWin::KoreanIME() - int const codePage = Scintilla_InputCodePage(); - Settings2.IMEInteraction = ((codePage == 949 || codePage == 1361) ? SC_IME_INLINE : SC_IME_WINDOWED); - } - - Defaults2.SciFontQuality = g_FontQuality[3]; - Settings2.SciFontQuality = clampi(IniSectionGetInt(Settings2_Section, L"SciFontQuality", Defaults2.SciFontQuality), 0, 3); - - Defaults2.MarkOccurrencesMaxCount = 2000; - Settings2.MarkOccurrencesMaxCount = IniSectionGetInt(Settings2_Section, L"MarkOccurrencesMaxCount", Defaults2.MarkOccurrencesMaxCount); - if (Settings2.MarkOccurrencesMaxCount <= 0) { Settings2.MarkOccurrencesMaxCount = INT_MAX; } - - Defaults2.UpdateDelayMarkAllOccurrences = 50; - Settings2.UpdateDelayMarkAllOccurrences = clampi(IniSectionGetInt(Settings2_Section, L"UpdateDelayMarkAllOccurrences", - Defaults2.UpdateDelayMarkAllOccurrences), USER_TIMER_MINIMUM, 10000); - Defaults2.DenyVirtualSpaceAccess = false; - Settings2.DenyVirtualSpaceAccess = IniSectionGetBool(Settings2_Section, L"DenyVirtualSpaceAccess", Defaults2.DenyVirtualSpaceAccess); - - Defaults2.UseOldStyleBraceMatching = false; - Settings2.UseOldStyleBraceMatching = IniSectionGetBool(Settings2_Section, L"UseOldStyleBraceMatching", Defaults2.UseOldStyleBraceMatching); - - Defaults2.CurrentLineHorizontalSlop = 40; - Settings2.CurrentLineHorizontalSlop = clampi(IniSectionGetInt(Settings2_Section, L"CurrentLineHorizontalSlop", Defaults2.CurrentLineHorizontalSlop), 0, 240); - - Defaults2.CurrentLineVerticalSlop = 5; - Settings2.CurrentLineVerticalSlop = clampi(IniSectionGetInt(Settings2_Section, L"CurrentLineVerticalSlop", Defaults2.CurrentLineVerticalSlop), 0, 25); - - - int const iARCLdef = 67; - Defaults2.AnalyzeReliableConfidenceLevel = (float)iARCLdef / 100.0f; - int const iARCLset = clampi(IniSectionGetInt(Settings2_Section, L"AnalyzeReliableConfidenceLevel", iARCLdef), 0, 100); - Settings2.AnalyzeReliableConfidenceLevel = (float)iARCLset / 100.0f; - - /* ~~~ - int const iRCEDCMdef = 85; - Defaults2.ReliableCEDConfidenceMapping = (float)iRCEDCMdef / 100.0f; - int const iRCEDCMset = clampi(IniSectionGetInt(Settings2_Section, L"ReliableCEDConfidenceMapping", iRCEDCMdef), 0, 100); - Settings2.ReliableCEDConfidenceMapping = (float)iRCEDCMset / 100.0f; - - int const iURCEDCMdef = 20; - Defaults2.UnReliableCEDConfidenceMapping = (float)iURCEDCMdef / 100.0f; - int const iURCEDCMset = clampi(IniSectionGetInt(Settings2_Section, L"UnReliableCEDConfidenceMapping", iURCEDCMdef), 0, iRCEDCMset); - Settings2.UnReliableCEDConfidenceMapping = (float)iURCEDCMset / 100.0f; - ~~~ */ - - Defaults2.AdministrationTool[0] = L'\0'; - IniSectionGetString(Settings2_Section, L"AdministrationTool.exe", Defaults2.AdministrationTool, - Settings2.AdministrationTool, COUNTOF(Settings2.AdministrationTool)); - - Defaults2.DefaultWindowPosition[0] = L'\0'; - IniSectionGetString(Settings2_Section, L"DefaultWindowPosition", Defaults2.DefaultWindowPosition, - Settings2.DefaultWindowPosition, COUNTOF(Settings2.DefaultWindowPosition)); - bool const bExplicitDefaultWinPos = (StringCchLenW(Settings2.DefaultWindowPosition, 0) != 0); - - Defaults2.FileLoadWarningMB = 1; - Settings2.FileLoadWarningMB = clampi(IniSectionGetInt(Settings2_Section, L"FileLoadWarningMB", Defaults2.FileLoadWarningMB), 0, 2048); - - Defaults2.OpacityLevel = 75; - Settings2.OpacityLevel = clampi(IniSectionGetInt(Settings2_Section, L"OpacityLevel", Defaults2.OpacityLevel), 10, 100); - - Defaults2.FindReplaceOpacityLevel = 50; - Settings2.FindReplaceOpacityLevel = clampi(IniSectionGetInt(Settings2_Section, L"FindReplaceOpacityLevel", Defaults2.FindReplaceOpacityLevel), 10, 100); - - Defaults2.FileBrowserPath[0] = L'\0'; - IniSectionGetString(Settings2_Section, L"filebrowser.exe", Defaults2.FileBrowserPath, Settings2.FileBrowserPath, COUNTOF(Settings2.FileBrowserPath)); - - StringCchCopyW(Defaults2.AppUserModelID, COUNTOF(Defaults2.AppUserModelID), _W(SAPPNAME)); - IniSectionGetString(Settings2_Section, L"ShellAppUserModelID", Defaults2.AppUserModelID, Settings2.AppUserModelID, COUNTOF(Settings2.AppUserModelID)); - - Defaults2.ExtendedWhiteSpaceChars[0] = L'\0'; - IniSectionGetString(Settings2_Section, L"ExtendedWhiteSpaceChars", Defaults2.ExtendedWhiteSpaceChars, - Settings2.ExtendedWhiteSpaceChars, COUNTOF(Settings2.ExtendedWhiteSpaceChars)); - - Defaults2.AutoCompleteWordCharSet[0] = L'\0'; - IniSectionGetString(Settings2_Section, L"AutoCompleteWordCharSet", Defaults2.AutoCompleteWordCharSet, - Settings2.AutoCompleteWordCharSet, COUNTOF(Settings2.AutoCompleteWordCharSet)); - - StringCchCopyW(Defaults2.TimeStamp, COUNTOF(Defaults2.TimeStamp), L"\\$Date:[^\\$]+\\$ | $Date: %Y/%m/%d %H:%M:%S $"); - IniSectionGetString(Settings2_Section, L"TimeStamp", Defaults2.TimeStamp, Settings2.TimeStamp, COUNTOF(Settings2.TimeStamp)); - - Defaults2.DateTimeShort[0] = L'\0'; - IniSectionGetString(Settings2_Section, L"DateTimeShort", Defaults2.DateTimeShort, Settings2.DateTimeShort, COUNTOF(Settings2.DateTimeShort)); - - Defaults2.DateTimeLong[0] = L'\0'; - IniSectionGetString(Settings2_Section, L"DateTimeLong", Defaults2.DateTimeLong, Settings2.DateTimeLong, COUNTOF(Settings2.DateTimeLong)); - - StringCchCopyW(Defaults2.WebTemplate1, COUNTOF(Defaults2.WebTemplate1), L"https://google.com/search?q=%s"); - IniSectionGetString(Settings2_Section, L"WebTemplate1", Defaults2.WebTemplate1, Settings2.WebTemplate1, COUNTOF(Settings2.WebTemplate1)); - - StringCchCopyW(Defaults2.WebTemplate2, COUNTOF(Defaults2.WebTemplate2), L"https://en.wikipedia.org/w/index.php?search=%s"); - IniSectionGetString(Settings2_Section, L"WebTemplate2", Defaults2.WebTemplate2, Settings2.WebTemplate2, COUNTOF(Settings2.WebTemplate2)); - - - // -------------------------------------------------------------------------- - const WCHAR* const Settings_Section = L"Settings"; - // -------------------------------------------------------------------------- - -#define GET_BOOL_VALUE_FROM_INISECTION(VARNAME,DEFAULT) \ - Defaults.VARNAME = DEFAULT; \ - Settings.VARNAME = IniSectionGetBool(Settings_Section, _W(_STRG(VARNAME)), Defaults.VARNAME) - -#define GET_INT_VALUE_FROM_INISECTION(VARNAME,DEFAULT,MIN,MAX) \ - Defaults.VARNAME = DEFAULT; \ - Settings.VARNAME = clampi(IniSectionGetInt(Settings_Section, _W(_STRG(VARNAME)), Defaults.VARNAME),MIN,MAX) - -#define GET_ENC_VALUE_FROM_INISECTION(VARNAME,DEFAULT,MIN,MAX) \ - Defaults.VARNAME = (cpi_enc_t)DEFAULT; \ - Settings.VARNAME = (cpi_enc_t)clampi(IniSectionGetInt(Settings_Section, _W(_STRG(VARNAME)), (int)Defaults.VARNAME),(int)MIN,(int)MAX) - - GET_BOOL_VALUE_FROM_INISECTION(SaveRecentFiles, true); - GET_BOOL_VALUE_FROM_INISECTION(PreserveCaretPos, false); - GET_BOOL_VALUE_FROM_INISECTION(SaveFindReplace, false); - - Defaults.EFR_Data.bFindClose = false; - Settings.EFR_Data.bFindClose = IniSectionGetBool(Settings_Section, L"CloseFind", Defaults.EFR_Data.bFindClose); - Defaults.EFR_Data.bReplaceClose = false; - Settings.EFR_Data.bReplaceClose = IniSectionGetBool(Settings_Section, L"CloseReplace", Defaults.EFR_Data.bReplaceClose); - Defaults.EFR_Data.bNoFindWrap = false; - Settings.EFR_Data.bNoFindWrap = IniSectionGetBool(Settings_Section, L"NoFindWrap", Defaults.EFR_Data.bNoFindWrap); - Defaults.EFR_Data.bTransformBS = false; - Settings.EFR_Data.bTransformBS = IniSectionGetBool(Settings_Section, L"FindTransformBS", Defaults.EFR_Data.bTransformBS); - Defaults.EFR_Data.bWildcardSearch = false; - Settings.EFR_Data.bWildcardSearch = IniSectionGetBool(Settings_Section, L"WildcardSearch", Defaults.EFR_Data.bWildcardSearch); - Defaults.EFR_Data.bMarkOccurences = true; - Settings.EFR_Data.bMarkOccurences = IniSectionGetBool(Settings_Section, L"FindMarkAllOccurrences", Defaults.EFR_Data.bMarkOccurences); - Defaults.EFR_Data.bHideNonMatchedLines = false; - Settings.EFR_Data.bHideNonMatchedLines = IniSectionGetBool(Settings_Section, L"HideNonMatchedLines", Defaults.EFR_Data.bHideNonMatchedLines); - Defaults.EFR_Data.bDotMatchAll = false; - Settings.EFR_Data.bDotMatchAll = IniSectionGetBool(Settings_Section, L"RegexDotMatchesAll", Defaults.EFR_Data.bDotMatchAll); - Defaults.EFR_Data.fuFlags = 0; - Settings.EFR_Data.fuFlags = (UINT)IniSectionGetInt(Settings_Section, L"efrData_fuFlags", (int)Defaults.EFR_Data.fuFlags); - - Defaults.OpenWithDir[0] = L'\0'; - if (!IniSectionGetString(Settings_Section, L"OpenWithDir", Defaults.OpenWithDir, Settings.OpenWithDir, COUNTOF(Settings.OpenWithDir))) { - GetKnownFolderPath(&FOLDERID_Desktop, Settings.OpenWithDir, COUNTOF(Settings.OpenWithDir)); - } - else { - PathAbsoluteFromApp(Settings.OpenWithDir, NULL, COUNTOF(Settings.OpenWithDir), true); - } - - Defaults.FavoritesDir[0] = L'\0'; - //StringCchCopyW(Defaults.FavoritesDir, COUNTOF(Defaults.FavoritesDir), L"%USERPROFILE%"); - if (!IniSectionGetString(Settings_Section, L"Favorites", Defaults.FavoritesDir, Settings.FavoritesDir, COUNTOF(Settings.FavoritesDir))) { - GetKnownFolderPath(&FOLDERID_Favorites, Settings.FavoritesDir, COUNTOF(Settings.FavoritesDir)); - } - else { - PathAbsoluteFromApp(Settings.FavoritesDir, NULL, COUNTOF(Settings.FavoritesDir), true); - } - - GET_INT_VALUE_FROM_INISECTION(PathNameFormat, 1, 0, 2); - GET_INT_VALUE_FROM_INISECTION(WordWrapMode, 0, 0, 1); - GET_INT_VALUE_FROM_INISECTION(WordWrapIndent, 2, 0, 6); - - GET_BOOL_VALUE_FROM_INISECTION(WordWrap, false); Globals.fvBackup.bWordWrap = Settings.WordWrap; - GET_BOOL_VALUE_FROM_INISECTION(TabsAsSpaces, false); Globals.fvBackup.bTabsAsSpaces = Settings.TabsAsSpaces; - GET_BOOL_VALUE_FROM_INISECTION(TabIndents, true); Globals.fvBackup.bTabIndents = Settings.TabIndents; - GET_INT_VALUE_FROM_INISECTION(TabWidth, 4, 1, 1024); Globals.fvBackup.iTabWidth = Settings.TabWidth; - GET_INT_VALUE_FROM_INISECTION(IndentWidth, 4, 0, 1024); Globals.fvBackup.iIndentWidth = Settings.IndentWidth; - GET_INT_VALUE_FROM_INISECTION(LongLinesLimit, 80, 0, LONG_LINES_MARKER_LIMIT); Globals.fvBackup.iLongLinesLimit = Settings.LongLinesLimit; - Globals.iWrapCol = Settings.LongLinesLimit; - - Defaults.WordWrapSymbols = 22; - int const iWS = IniSectionGetInt(Settings_Section, L"WordWrapSymbols", Defaults.WordWrapSymbols); - Settings.WordWrapSymbols = clampi(iWS % 10, 0, 2) + clampi((iWS % 100 - iWS % 10) / 10, 0, 2) * 10; - - GET_BOOL_VALUE_FROM_INISECTION(ShowWordWrapSymbols, true); - GET_BOOL_VALUE_FROM_INISECTION(MatchBraces, true); - GET_BOOL_VALUE_FROM_INISECTION(AutoCloseTags, false); - GET_INT_VALUE_FROM_INISECTION(HighlightCurrentLine, 1, 0, 2); - GET_BOOL_VALUE_FROM_INISECTION(HyperlinkHotspot, true); - GET_BOOL_VALUE_FROM_INISECTION(ScrollPastEOF, false); - GET_BOOL_VALUE_FROM_INISECTION(ShowHypLnkToolTip, true); - - GET_BOOL_VALUE_FROM_INISECTION(AutoIndent, true); - GET_BOOL_VALUE_FROM_INISECTION(AutoCompleteWords, false); - GET_BOOL_VALUE_FROM_INISECTION(AutoCLexerKeyWords, false); - GET_BOOL_VALUE_FROM_INISECTION(AccelWordNavigation, false); - GET_BOOL_VALUE_FROM_INISECTION(ShowIndentGuides, false); - GET_BOOL_VALUE_FROM_INISECTION(BackspaceUnindents, false); - GET_BOOL_VALUE_FROM_INISECTION(WarnInconsistentIndents, false); - GET_BOOL_VALUE_FROM_INISECTION(AutoDetectIndentSettings, false); - GET_BOOL_VALUE_FROM_INISECTION(MarkLongLines, (s_iSettingsVersion < CFG_VER_0002)); Defaults.MarkLongLines = false; // new default - GET_INT_VALUE_FROM_INISECTION(LongLineMode, EDGE_LINE, EDGE_LINE, EDGE_BACKGROUND); - GET_BOOL_VALUE_FROM_INISECTION(ShowSelectionMargin, true); - GET_BOOL_VALUE_FROM_INISECTION(ShowLineNumbers, true); - GET_BOOL_VALUE_FROM_INISECTION(ShowCodeFolding, true); FocusedView.ShowCodeFolding = Settings.ShowCodeFolding; - GET_BOOL_VALUE_FROM_INISECTION(MarkOccurrences, true); - GET_BOOL_VALUE_FROM_INISECTION(MarkOccurrencesMatchVisible, false); - GET_BOOL_VALUE_FROM_INISECTION(MarkOccurrencesMatchCase, false); - GET_BOOL_VALUE_FROM_INISECTION(MarkOccurrencesMatchWholeWords, true); - - Defaults.MarkOccurrencesCurrentWord = !Defaults.MarkOccurrencesMatchWholeWords; - Settings.MarkOccurrencesCurrentWord = IniSectionGetBool(Settings_Section, L"MarkOccurrencesCurrentWord", Defaults.MarkOccurrencesCurrentWord); - Settings.MarkOccurrencesCurrentWord = Settings.MarkOccurrencesCurrentWord && !Settings.MarkOccurrencesMatchWholeWords; - - GET_BOOL_VALUE_FROM_INISECTION(ViewWhiteSpace, false); - GET_BOOL_VALUE_FROM_INISECTION(ViewEOLs, false); - - cpi_enc_t const iPrefEncIniSetting = (cpi_enc_t)Encoding_MapIniSetting(false, (int)CPI_UTF8); - GET_ENC_VALUE_FROM_INISECTION(DefaultEncoding, iPrefEncIniSetting, CPI_NONE, INT_MAX); - Settings.DefaultEncoding = ((Settings.DefaultEncoding == CPI_NONE) ? CPI_UTF8 : (cpi_enc_t)Encoding_MapIniSetting(true, (int)Settings.DefaultEncoding)); - GET_BOOL_VALUE_FROM_INISECTION(UseDefaultForFileEncoding, false); - GET_BOOL_VALUE_FROM_INISECTION(LoadASCIIasUTF8, true); - GET_BOOL_VALUE_FROM_INISECTION(UseReliableCEDonly, true); - GET_BOOL_VALUE_FROM_INISECTION(LoadNFOasOEM, true); - GET_BOOL_VALUE_FROM_INISECTION(NoEncodingTags, false); - GET_BOOL_VALUE_FROM_INISECTION(SkipUnicodeDetection, false); - GET_BOOL_VALUE_FROM_INISECTION(SkipANSICodePageDetection, false); - GET_INT_VALUE_FROM_INISECTION(DefaultEOLMode, SC_EOL_CRLF, SC_EOL_CRLF, SC_EOL_LF); - GET_BOOL_VALUE_FROM_INISECTION(WarnInconsistEOLs, true); - GET_BOOL_VALUE_FROM_INISECTION(FixLineEndings, false); - GET_BOOL_VALUE_FROM_INISECTION(FixTrailingBlanks, false); - GET_INT_VALUE_FROM_INISECTION(PrintHeader, 1, 0, 3); - GET_INT_VALUE_FROM_INISECTION(PrintFooter, 0, 0, 1); - GET_INT_VALUE_FROM_INISECTION(PrintColorMode, 3, 0, 4); - - int const zoomScale = float2int(1000.0f / GetBaseFontSize(Globals.hwndMain)); - Defaults.PrintZoom = (s_iSettingsVersion < CFG_VER_0001) ? (zoomScale / 10) : zoomScale; - int iPrintZoom = clampi(IniSectionGetInt(Settings_Section, L"PrintZoom", Defaults.PrintZoom), 0, SC_MAX_ZOOM_LEVEL); - if (s_iSettingsVersion < CFG_VER_0001) { iPrintZoom = 100 + (iPrintZoom - 10) * 10; } - Settings.PrintZoom = clampi(iPrintZoom, SC_MIN_ZOOM_LEVEL, SC_MAX_ZOOM_LEVEL); - - WCHAR localeInfo[3]; - GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, LOCALE_IMEASURE, localeInfo, 3); - LONG const _margin = (localeInfo[0] == L'0') ? 2000L : 1000L; // Metric system. L'1' is US System - Defaults.PrintMargin.left = _margin; - Settings.PrintMargin.left = clampi(IniSectionGetInt(Settings_Section, L"PrintMarginLeft", Defaults.PrintMargin.left), 0, 40000); - Defaults.PrintMargin.top = _margin; - Settings.PrintMargin.top = clampi(IniSectionGetInt(Settings_Section, L"PrintMarginTop", Defaults.PrintMargin.top), 0, 40000); - Defaults.PrintMargin.right = _margin; - Settings.PrintMargin.right = clampi(IniSectionGetInt(Settings_Section, L"PrintMarginRight", Defaults.PrintMargin.right), 0, 40000); - Defaults.PrintMargin.bottom = _margin; - Settings.PrintMargin.bottom = clampi(IniSectionGetInt(Settings_Section, L"PrintMarginBottom", Defaults.PrintMargin.bottom), 0, 40000); - - GET_BOOL_VALUE_FROM_INISECTION(SaveBeforeRunningTools, false); - GET_INT_VALUE_FROM_INISECTION(FileWatchingMode, FWM_NONE, FWM_NONE, FWM_AUTORELOAD); FileWatching.FileWatchingMode = Settings.FileWatchingMode; - GET_BOOL_VALUE_FROM_INISECTION(ResetFileWatching, true); FileWatching.ResetFileWatching = Settings.ResetFileWatching; - GET_INT_VALUE_FROM_INISECTION(EscFunction, 0, 0, 2); - GET_BOOL_VALUE_FROM_INISECTION(AlwaysOnTop, false); - GET_BOOL_VALUE_FROM_INISECTION(MinimizeToTray, false); - GET_BOOL_VALUE_FROM_INISECTION(TransparentMode, false); - GET_BOOL_VALUE_FROM_INISECTION(FindReplaceTransparentMode, true); - GET_INT_VALUE_FROM_INISECTION(RenderingTechnology, Defaults.RenderingTechnology, 0, 3); // set before - GET_INT_VALUE_FROM_INISECTION(Bidirectional, Defaults.Bidirectional, 0, 2); // set before - GET_BOOL_VALUE_FROM_INISECTION(MuteMessageBeep, false); - - ///~Settings2.IMEInteraction = clampi(IniSectionGetInt(Settings_Section, L"IMEInteraction", Settings2.IMEInteraction), SC_IME_WINDOWED, SC_IME_INLINE); - - // see TBBUTTON s_tbbMainWnd[] for initial/reset set of buttons - StringCchCopyW(Defaults.ToolbarButtons, COUNTOF(Defaults.ToolbarButtons), (s_iSettingsVersion < CFG_VER_0002) ? TBBUTTON_DEFAULT_IDS_V1 : TBBUTTON_DEFAULT_IDS_V2); - IniSectionGetString(Settings_Section, L"ToolbarButtons", Defaults.ToolbarButtons, Settings.ToolbarButtons, COUNTOF(Settings.ToolbarButtons)); - - GET_BOOL_VALUE_FROM_INISECTION(ShowToolbar, true); - GET_BOOL_VALUE_FROM_INISECTION(ShowStatusbar, true); - - GET_INT_VALUE_FROM_INISECTION(EncodingDlgSizeX, 340, INT_MIN, INT_MAX); - GET_INT_VALUE_FROM_INISECTION(EncodingDlgSizeY, 292, INT_MIN, INT_MAX); - GET_INT_VALUE_FROM_INISECTION(RecodeDlgSizeX, 340, INT_MIN, INT_MAX); - GET_INT_VALUE_FROM_INISECTION(RecodeDlgSizeY, 292, INT_MIN, INT_MAX); - GET_INT_VALUE_FROM_INISECTION(FileMRUDlgSizeX, 487, INT_MIN, INT_MAX); - GET_INT_VALUE_FROM_INISECTION(FileMRUDlgSizeY, 339, INT_MIN, INT_MAX); - GET_INT_VALUE_FROM_INISECTION(OpenWithDlgSizeX, 305, INT_MIN, INT_MAX); - GET_INT_VALUE_FROM_INISECTION(OpenWithDlgSizeY, 281, INT_MIN, INT_MAX); - GET_INT_VALUE_FROM_INISECTION(FavoritesDlgSizeX, 305, INT_MIN, INT_MAX); - GET_INT_VALUE_FROM_INISECTION(FavoritesDlgSizeY, 281, INT_MIN, INT_MAX); - GET_INT_VALUE_FROM_INISECTION(AddToFavDlgSizeX, 317, INT_MIN, INT_MAX); - - GET_INT_VALUE_FROM_INISECTION(FindReplaceDlgSizeX, 494, INT_MIN, INT_MAX); - GET_INT_VALUE_FROM_INISECTION(FindReplaceDlgPosX, CW_USEDEFAULT, INT_MIN, INT_MAX); - GET_INT_VALUE_FROM_INISECTION(FindReplaceDlgPosY, CW_USEDEFAULT, INT_MIN, INT_MAX); - - GET_INT_VALUE_FROM_INISECTION(CustomSchemesDlgSizeX, 833, INT_MIN, INT_MAX); - GET_INT_VALUE_FROM_INISECTION(CustomSchemesDlgSizeY, 515, INT_MIN, INT_MAX); - GET_INT_VALUE_FROM_INISECTION(CustomSchemesDlgPosX, CW_USEDEFAULT, INT_MIN, INT_MAX); - GET_INT_VALUE_FROM_INISECTION(CustomSchemesDlgPosY, CW_USEDEFAULT, INT_MIN, INT_MAX); - - // -------------------------------------------------------------------------- - const WCHAR* const StatusBar_Section = L"Statusbar Settings"; - // -------------------------------------------------------------------------- - - WCHAR tchStatusBar[MIDSZ_BUFFER] = { L'\0' }; - - IniSectionGetString(StatusBar_Section, L"SectionPrefixes", STATUSBAR_SECTION_PREFIXES, tchStatusBar, COUNTOF(tchStatusBar)); - ReadStrgsFromCSV(tchStatusBar, s_mxSBPrefix, STATUS_SECTOR_COUNT, MICRO_BUFFER, L"_PRFX_"); - - IniSectionGetString(StatusBar_Section, L"SectionPostfixes", STATUSBAR_SECTION_POSTFIXES, tchStatusBar, COUNTOF(tchStatusBar)); - ReadStrgsFromCSV(tchStatusBar, s_mxSBPostfix, STATUS_SECTOR_COUNT, MICRO_BUFFER, L"_POFX_"); - - IniSectionGetString(StatusBar_Section, L"VisibleSections", STATUSBAR_DEFAULT_IDS, tchStatusBar, COUNTOF(tchStatusBar)); - ReadVectorFromString(tchStatusBar, s_iStatusbarSections, STATUS_SECTOR_COUNT, 0, (STATUS_SECTOR_COUNT - 1), -1); - - for (int i = 0; i < STATUS_SECTOR_COUNT; ++i) { - s_iStatusbarVisible[i] = false; - } - int cnt = 0; - for (int i = 0; i < STATUS_SECTOR_COUNT; ++i) { - s_vSBSOrder[i] = -1; - int const id = s_iStatusbarSections[i]; - if (id >= 0) { - s_vSBSOrder[cnt++] = id; - s_iStatusbarVisible[id] = true; - } - } - - IniSectionGetString(StatusBar_Section, L"SectionWidthSpecs", STATUSBAR_SECTION_WIDTH_SPECS, tchStatusBar, COUNTOF(tchStatusBar)); - ReadVectorFromString(tchStatusBar, s_iStatusbarWidthSpec, STATUS_SECTOR_COUNT, -4096, 4096, 0); - - Globals.bZeroBasedColumnIndex = IniSectionGetBool(StatusBar_Section, L"ZeroBasedColumnIndex", false); - Globals.bZeroBasedCharacterCount = IniSectionGetBool(StatusBar_Section, L"ZeroBasedCharacterCount", false); - - - // -------------------------------------------------------------------------- - const WCHAR* const ToolbarImg_Section = L"Toolbar Images"; - // -------------------------------------------------------------------------- - - IniSectionGetString(ToolbarImg_Section, L"BitmapDefault", L"", - s_tchToolbarBitmap, COUNTOF(s_tchToolbarBitmap)); - IniSectionGetString(ToolbarImg_Section, L"BitmapHot", L"", - s_tchToolbarBitmapHot, COUNTOF(s_tchToolbarBitmap)); - IniSectionGetString(ToolbarImg_Section, L"BitmapDisabled", L"", - s_tchToolbarBitmapDisabled, COUNTOF(s_tchToolbarBitmap)); - - - // -------------------------------------------------------------------------- - const WCHAR* const Window_Section = L"Window"; - // -------------------------------------------------------------------------- - - int ResX, ResY; - GetCurrentMonitorResolution(Globals.hwndMain, &ResX, &ResY); - - WCHAR tchHighDpiToolBar[32] = { L'\0' }; - StringCchPrintf(tchHighDpiToolBar, COUNTOF(tchHighDpiToolBar), L"%ix%i HighDpiToolBar", ResX, ResY); - s_iToolBarTheme = IniSectionGetInt(Window_Section, tchHighDpiToolBar, -1); - s_iToolBarTheme = clampi(s_iToolBarTheme, -1, StrIsEmpty(s_tchToolbarBitmap) ? 1 : 2); - if (s_iToolBarTheme < 0) { // undefined: determine high DPI (higher than Full-HD) - s_iToolBarTheme = IsFullHDOrHigher(Globals.hwndMain, ResX, ResY) ? 1 : 0; - } - - // -------------------------------------------------------------- - // startup window (ignore window position if /p was specified) - // -------------------------------------------------------------- - - // 1st set default window position - - s_DefWinInfo = _InitDefaultWndPos(2); // std. default position - - if (bExplicitDefaultWinPos) { - int bMaxi = 0; - int const itok = swscanf_s(Settings2.DefaultWindowPosition, L"%i,%i,%i,%i,%i", - &s_DefWinInfo.x, &s_DefWinInfo.y, &s_DefWinInfo.cx, &s_DefWinInfo.cy, &bMaxi); - if (itok == 4 || itok == 5) { // scan successful - if (s_DefWinInfo.cx < 1) s_DefWinInfo.cx = CW_USEDEFAULT; - if (s_DefWinInfo.cy < 1) s_DefWinInfo.cy = CW_USEDEFAULT; - if (bMaxi) s_DefWinInfo.max = true; - if (itok == 4) s_DefWinInfo.max = false; - _InitWindowPosition(&s_DefWinInfo, 0); - } - else { - // overwrite bad defined default position - StringCchPrintf(Settings2.DefaultWindowPosition, COUNTOF(Settings2.DefaultWindowPosition), - L"%i,%i,%i,%i,%i", s_DefWinInfo.x, s_DefWinInfo.y, s_DefWinInfo.cx, s_DefWinInfo.cy, s_DefWinInfo.max); - IniFileSetString(Globals.IniFile, L"Settings2", L"DefaultWindowPosition", Settings2.DefaultWindowPosition); - } - } - - // 2nd set initial window position - - s_WinInfo = s_DefWinInfo; - - if (!s_flagPosParam /*|| g_bStickyWinPos*/) { - - WCHAR tchPosX[32], tchPosY[32], tchSizeX[32], tchSizeY[32], tchMaximized[32], tchZoom[32]; - - StringCchPrintf(tchPosX, COUNTOF(tchPosX), L"%ix%i PosX", ResX, ResY); - StringCchPrintf(tchPosY, COUNTOF(tchPosY), L"%ix%i PosY", ResX, ResY); - StringCchPrintf(tchSizeX, COUNTOF(tchSizeX), L"%ix%i SizeX", ResX, ResY); - StringCchPrintf(tchSizeY, COUNTOF(tchSizeY), L"%ix%i SizeY", ResX, ResY); - StringCchPrintf(tchMaximized, COUNTOF(tchMaximized), L"%ix%i Maximized", ResX, ResY); - StringCchPrintf(tchZoom, COUNTOF(tchZoom), L"%ix%i Zoom", ResX, ResY); - - s_WinInfo.x = IniSectionGetInt(Window_Section, tchPosX, CW_USEDEFAULT); - s_WinInfo.y = IniSectionGetInt(Window_Section, tchPosY, CW_USEDEFAULT); - s_WinInfo.cx = IniSectionGetInt(Window_Section, tchSizeX, CW_USEDEFAULT); - s_WinInfo.cy = IniSectionGetInt(Window_Section, tchSizeY, CW_USEDEFAULT); - s_WinInfo.max = IniSectionGetBool(Window_Section, tchMaximized, false); - s_WinInfo.max = clampi(s_WinInfo.max, 0, 1); - s_WinInfo.zoom = IniSectionGetInt(Window_Section, tchZoom, (s_iSettingsVersion < CFG_VER_0001) ? 0 : 100); - if (s_iSettingsVersion < CFG_VER_0001) { s_WinInfo.zoom = (s_WinInfo.zoom + 10) * 10; } - s_WinInfo.zoom = clampi(s_WinInfo.zoom, SC_MIN_ZOOM_LEVEL, SC_MAX_ZOOM_LEVEL); - - if ((s_WinInfo.x == CW_USEDEFAULT) || (s_WinInfo.y == CW_USEDEFAULT) || - (s_WinInfo.cx == CW_USEDEFAULT) || (s_WinInfo.cy == CW_USEDEFAULT)) - { - s_flagWindowPos = 2; // std. default position (CmdLn: /pd) - } - else - s_flagWindowPos = 0; // init to g_WinInfo - } - - // ------------------------------------------------------------------------ - - // --- override by resolution specific settings --- - WCHAR tchSciDirectWriteTech[64]; - StringCchPrintf(tchSciDirectWriteTech, COUNTOF(tchSciDirectWriteTech), L"%ix%i RenderingTechnology", ResX, ResY); - Settings.RenderingTechnology = clampi(IniSectionGetInt(Window_Section, tchSciDirectWriteTech, Settings.RenderingTechnology), 0, 3); - - WCHAR tchSciFontQuality[64]; - StringCchPrintf(tchSciFontQuality, COUNTOF(tchSciFontQuality), L"%ix%i SciFontQuality", ResX, ResY); - Settings2.SciFontQuality = clampi(IniSectionGetInt(Window_Section, tchSciFontQuality, Settings2.SciFontQuality), 0, 3); - - if (bDirtyFlag) { - SaveIniFile(); - } - ReleaseIniFile(); - } - - // define scintilla internal codepage - const int iSciDefaultCodePage = SC_CP_UTF8; // default UTF8 - - // remove internal support for Chinese, Japan, Korean DBCS use UTF-8 instead - /* - if (Settings.DefaultEncoding == CPI_ANSI_DEFAULT) - { - // check for Chinese, Japan, Korean DBCS code pages and switch accordingly - int acp = (int)GetACP(); - if (acp == 932 || acp == 936 || acp == 949 || acp == 950) { - iSciDefaultCodePage = acp; - } - Settings.DefaultEncoding = Encoding_GetByCodePage(iSciDefaultCodePage); - } - */ - - // set flag for encoding default - Encoding_SetDefaultFlag(Settings.DefaultEncoding); - - // define default charset - Globals.iDefaultCharSet = (int)CharSetFromCodePage((UINT)iSciDefaultCodePage); - - // Scintilla Styles - Style_Load(); -} - - -//============================================================================= -// -// SaveSettings() -// - -#define SAVE_VALUE_IF_NOT_EQ_DEFAULT(TYPE, VARNAME) \ - if (Settings.VARNAME != Defaults.VARNAME) { \ - IniSectionSet##TYPE(Settings_Section, _W(_STRG(VARNAME)), Settings.VARNAME); \ - } \ - else { \ - IniSectionSetString(Settings_Section, _W(_STRG(VARNAME)), NULL); \ - } - -// ---------------------------------------------------------------------------- - - -void SaveSettings(bool bSaveSettingsNow) -{ - if (StrIsEmpty(Globals.IniFile) || !s_bEnableSaveSettings) { return; } - - CreateIniFile(); - LoadIniFile(Globals.IniFile); - - const WCHAR* const Settings_Section = L"Settings"; - - if (!(Settings.SaveSettings || bSaveSettingsNow)) { - IniSectionSetInt(Settings_Section, L"SettingsVersion", CFG_VER_CURRENT); - if (Settings.SaveSettings != Defaults.SaveSettings) { - IniSectionSetBool(Settings_Section, L"SaveSettings", Settings.SaveSettings); - } - SaveIniFile(); - return; - } - - // update window placement - s_WinInfo = GetMyWindowPlacement(Globals.hwndMain, NULL); - - WCHAR tchMsg[80]; - GetLngString(IDS_MUI_SAVINGSETTINGS, tchMsg, COUNTOF(tchMsg)); - BeginWaitCursor(tchMsg); - - { - IniSectionSetInt(Settings_Section, L"SettingsVersion", CFG_VER_CURRENT); - - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, SaveSettings); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, SaveRecentFiles); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, PreserveCaretPos); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, SaveFindReplace); - - if (Settings.EFR_Data.bFindClose != Defaults.EFR_Data.bFindClose) { - IniSectionSetBool(Settings_Section, L"CloseFind", Settings.EFR_Data.bFindClose); - } - if (Settings.EFR_Data.bReplaceClose != Defaults.EFR_Data.bReplaceClose) { - IniSectionSetBool(Settings_Section, L"CloseReplace", Settings.EFR_Data.bReplaceClose); - } - if (Settings.EFR_Data.bNoFindWrap != Defaults.EFR_Data.bNoFindWrap) { - IniSectionSetBool(Settings_Section, L"NoFindWrap", Settings.EFR_Data.bNoFindWrap); - } - if (Settings.EFR_Data.bTransformBS != Defaults.EFR_Data.bTransformBS) { - IniSectionSetBool(Settings_Section, L"FindTransformBS", Settings.EFR_Data.bTransformBS); - } - if (Settings.EFR_Data.bWildcardSearch != Defaults.EFR_Data.bWildcardSearch) { - IniSectionSetBool(Settings_Section, L"WildcardSearch", Settings.EFR_Data.bWildcardSearch); - } - if (Settings.EFR_Data.bMarkOccurences != Defaults.EFR_Data.bMarkOccurences) { - IniSectionSetBool(Settings_Section, L"FindMarkAllOccurrences", Settings.EFR_Data.bMarkOccurences); - } - if (Settings.EFR_Data.bHideNonMatchedLines != Defaults.EFR_Data.bHideNonMatchedLines) { - IniSectionSetBool(Settings_Section, L"HideNonMatchedLines", Settings.EFR_Data.bHideNonMatchedLines); - } - if (Settings.EFR_Data.bDotMatchAll != Defaults.EFR_Data.bDotMatchAll) { - IniSectionSetBool(Settings_Section, L"RegexDotMatchesAll", Settings.EFR_Data.bDotMatchAll); - } - if (Settings.EFR_Data.fuFlags != Defaults.EFR_Data.fuFlags) { - IniSectionSetInt(Settings_Section, L"efrData_fuFlags", Settings.EFR_Data.fuFlags); - } - - WCHAR wchTmp[MAX_PATH] = { L'\0' }; - if (StringCchCompareXIW(Settings.OpenWithDir, Defaults.OpenWithDir) != 0) { - PathRelativeToApp(Settings.OpenWithDir, wchTmp, COUNTOF(wchTmp), false, true, Flags.PortableMyDocs); - IniSectionSetString(Settings_Section, L"OpenWithDir", wchTmp); - } - if (StringCchCompareXIW(Settings.FavoritesDir, Defaults.FavoritesDir) != 0) { - PathRelativeToApp(Settings.FavoritesDir, wchTmp, COUNTOF(wchTmp), false, true, Flags.PortableMyDocs); - IniSectionSetString(Settings_Section, L"Favorites", wchTmp); - } - - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, PathNameFormat); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, WordWrap); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, TabsAsSpaces); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, TabIndents); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, TabWidth); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, IndentWidth); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, LongLinesLimit); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, BackspaceUnindents); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, WordWrapMode); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, WordWrapIndent); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, WordWrapSymbols); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, ShowWordWrapSymbols); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, MatchBraces); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, AutoCloseTags); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, HighlightCurrentLine); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, HyperlinkHotspot); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, ScrollPastEOF); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, ShowHypLnkToolTip); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, AutoIndent); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, AutoCompleteWords); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, AutoCLexerKeyWords); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, AccelWordNavigation); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, ShowIndentGuides); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, WarnInconsistentIndents); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, AutoDetectIndentSettings); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, MarkLongLines); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, LongLineMode); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, ShowSelectionMargin); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, ShowLineNumbers); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, ShowCodeFolding); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, MarkOccurrences); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, MarkOccurrencesMatchVisible); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, MarkOccurrencesMatchCase); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, MarkOccurrencesMatchWholeWords); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, MarkOccurrencesCurrentWord); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, ViewWhiteSpace); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, ViewEOLs); - - Settings.DefaultEncoding = (cpi_enc_t)Encoding_MapIniSetting(false, (int)Settings.DefaultEncoding); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, DefaultEncoding); - Settings.DefaultEncoding = (cpi_enc_t)Encoding_MapIniSetting(true, (int)Settings.DefaultEncoding); - - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, UseDefaultForFileEncoding); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, LoadASCIIasUTF8); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, UseReliableCEDonly); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, LoadNFOasOEM); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, NoEncodingTags); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, SkipUnicodeDetection); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, SkipANSICodePageDetection); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, DefaultEOLMode); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, WarnInconsistEOLs); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, FixLineEndings); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, FixTrailingBlanks); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, PrintHeader); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, PrintFooter); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, PrintColorMode); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, PrintZoom); - - if (Settings.PrintMargin.left != Defaults.PrintMargin.left) { - IniSectionSetInt(Settings_Section, L"PrintMarginLeft", Settings.PrintMargin.left); - } - if (Settings.PrintMargin.top != Defaults.PrintMargin.top) { - IniSectionSetInt(Settings_Section, L"PrintMarginTop", Settings.PrintMargin.top); - } - if (Settings.PrintMargin.right != Defaults.PrintMargin.right) { - IniSectionSetInt(Settings_Section, L"PrintMarginRight", Settings.PrintMargin.right); - } - if (Settings.PrintMargin.bottom != Defaults.PrintMargin.bottom) { - IniSectionSetInt(Settings_Section, L"PrintMarginBottom", Settings.PrintMargin.bottom); - } - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, SaveBeforeRunningTools); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, FileWatchingMode); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, ResetFileWatching); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, EscFunction); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, AlwaysOnTop); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, MinimizeToTray); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, TransparentMode); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, FindReplaceTransparentMode); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, RenderingTechnology); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, Bidirectional); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, MuteMessageBeep); - - ///~IniSectionSetInt(Settings_Section, L"IMEInteraction", Settings2.IMEInteraction); - - Toolbar_GetButtons(Globals.hwndToolbar, IDT_FILE_NEW, Settings.ToolbarButtons, COUNTOF(Settings.ToolbarButtons)); - if (StringCchCompareX(Settings.ToolbarButtons, Defaults.ToolbarButtons) == 0) { - IniSectionSetString(Settings_Section, L"ToolbarButtons", NULL); - } else { - IniSectionSetString(Settings_Section, L"ToolbarButtons", Settings.ToolbarButtons); - } - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, ShowToolbar); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, ShowStatusbar); - - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, EncodingDlgSizeX); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, EncodingDlgSizeY); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, RecodeDlgSizeX); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, RecodeDlgSizeY); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, FileMRUDlgSizeX); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, FileMRUDlgSizeY); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, OpenWithDlgSizeX); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, OpenWithDlgSizeY); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, FavoritesDlgSizeX); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, FavoritesDlgSizeY); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, AddToFavDlgSizeX); - - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, FindReplaceDlgSizeX); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, FindReplaceDlgPosX); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, FindReplaceDlgPosY); - - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, CustomSchemesDlgSizeX); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, CustomSchemesDlgSizeY); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, CustomSchemesDlgPosX); - SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, CustomSchemesDlgPosY); - } - - int ResX, ResY; - GetCurrentMonitorResolution(Globals.hwndMain, &ResX, &ResY); - - const WCHAR* const Window_Section = L"Window"; - - WCHAR tchHighDpiToolBar[32]; - StringCchPrintf(tchHighDpiToolBar,COUNTOF(tchHighDpiToolBar),L"%ix%i HighDpiToolBar", ResX, ResY); - IniSectionSetInt(Window_Section, tchHighDpiToolBar, s_iToolBarTheme); - - if (!Flags.bStickyWindowPosition) { - - WCHAR tchPosX[32], tchPosY[32], tchSizeX[32], tchSizeY[32], tchMaximized[32], tchZoom[32]; - - StringCchPrintf(tchPosX,COUNTOF(tchPosX),L"%ix%i PosX",ResX,ResY); - StringCchPrintf(tchPosY,COUNTOF(tchPosY),L"%ix%i PosY",ResX,ResY); - StringCchPrintf(tchSizeX,COUNTOF(tchSizeX),L"%ix%i SizeX",ResX,ResY); - StringCchPrintf(tchSizeY,COUNTOF(tchSizeY),L"%ix%i SizeY",ResX,ResY); - StringCchPrintf(tchMaximized,COUNTOF(tchMaximized),L"%ix%i Maximized",ResX,ResY); - StringCchPrintf(tchZoom, COUNTOF(tchMaximized), L"%ix%i Zoom", ResX, ResY); - - IniSectionSetInt(Window_Section,tchPosX,s_WinInfo.x); - IniSectionSetInt(Window_Section,tchPosY,s_WinInfo.y); - IniSectionSetInt(Window_Section,tchSizeX,s_WinInfo.cx); - IniSectionSetInt(Window_Section,tchSizeY,s_WinInfo.cy); - IniSectionSetBool(Window_Section,tchMaximized,s_WinInfo.max); - IniSectionSetInt(Window_Section,tchZoom, s_WinInfo.zoom); - } - - SaveIniFile(); - - Style_Save(); // Scintilla Styles - - EndWaitCursor(); -} - - //============================================================================= // // ParseCommandLine() @@ -8500,215 +7766,6 @@ void LoadFlags() } -//============================================================================= -// -// _CheckIniFile() -// -static bool _CheckIniFile(LPWSTR lpszFile,LPCWSTR lpszModule) -{ - WCHAR tchFileExpanded[MAX_PATH] = { L'\0' }; - ExpandEnvironmentStrings(lpszFile,tchFileExpanded,COUNTOF(tchFileExpanded)); - - if (PathIsRelative(tchFileExpanded)) - { - WCHAR tchBuild[MAX_PATH] = { L'\0' }; - // program directory - StringCchCopy(tchBuild,COUNTOF(tchBuild),lpszModule); - StringCchCopy(PathFindFileName(tchBuild),COUNTOF(tchBuild),tchFileExpanded); - if (PathFileExists(tchBuild)) { - StringCchCopy(lpszFile,MAX_PATH,tchBuild); - return true; - } - // sub directory (.\np3\) - StringCchCopy(tchBuild, COUNTOF(tchBuild), lpszModule); - PathCchRemoveFileSpec(tchBuild, COUNTOF(tchBuild)); - StringCchCat(tchBuild,COUNTOF(tchBuild),L"\\np3\\"); - StringCchCat(tchBuild,COUNTOF(tchBuild),tchFileExpanded); - if (PathFileExists(tchBuild)) { - StringCchCopy(lpszFile, MAX_PATH, tchBuild); - return true; - } - // Application Data (%APPDATA%) - if (GetKnownFolderPath(&FOLDERID_RoamingAppData, tchBuild, COUNTOF(tchBuild))) { - PathCchAppend(tchBuild,COUNTOF(tchBuild),tchFileExpanded); - if (PathFileExists(tchBuild)) { - StringCchCopy(lpszFile,MAX_PATH,tchBuild); - return true; - } - } - // Home (%HOMEPATH%) user's profile dir - if (GetKnownFolderPath(&FOLDERID_Profile, tchBuild, COUNTOF(tchBuild))) { - PathCchAppend(tchBuild, COUNTOF(tchBuild), tchFileExpanded); - if (PathFileExists(tchBuild)) { - StringCchCopy(lpszFile, MAX_PATH, tchBuild); - return true; - } - } - //~// in general search path - //~if (SearchPath(NULL,tchFileExpanded,L".ini",COUNTOF(tchBuild),tchBuild,NULL)) { - //~ StringCchCopy(lpszFile,MAX_PATH,tchBuild); - //~ return true; - //~} - } - else if (PathFileExists(tchFileExpanded)) { - StringCchCopy(lpszFile,MAX_PATH,tchFileExpanded); - return true; - } - return false; -} - - -static bool _CheckIniFileRedirect(LPWSTR lpszAppName, LPWSTR lpszKeyName, LPWSTR lpszFile,LPCWSTR lpszModule) -{ - WCHAR tch[MAX_PATH] = { L'\0' }; - if (GetPrivateProfileString(lpszAppName, lpszKeyName, L"", tch, COUNTOF(tch), lpszFile)) { - if (_CheckIniFile(tch,lpszModule)) { - StringCchCopy(lpszFile,MAX_PATH,tch); - return true; - } - WCHAR tchFileExpanded[MAX_PATH] = { L'\0' }; - ExpandEnvironmentStrings(tch,tchFileExpanded,COUNTOF(tchFileExpanded)); - if (PathIsRelative(tchFileExpanded)) { - StringCchCopy(lpszFile,MAX_PATH,lpszModule); - StringCchCopy(PathFindFileName(lpszFile),MAX_PATH,tchFileExpanded); - return true; - } - StringCchCopy(lpszFile,MAX_PATH,tchFileExpanded); - return true; - } - return false; -} - - -bool FindIniFile() -{ - bool bFound = false; - WCHAR tchPath[MAX_PATH] = { L'\0' }; - WCHAR tchModule[MAX_PATH] = { L'\0' }; - - GetModuleFileName(NULL,tchModule,COUNTOF(tchModule)); - - // set env path to module dir - StringCchCopy(tchPath, COUNTOF(tchPath), tchModule); - PathCchRemoveFileSpec(tchPath, COUNTOF(tchPath)); - SetEnvironmentVariable(NOTEPAD3_MODULE_DIR_ENV_VAR, tchPath); - - if (StrIsNotEmpty(Globals.IniFile)) { - if (StringCchCompareXI(Globals.IniFile, L"*?") == 0) { - return bFound; - } - if (!_CheckIniFile(Globals.IniFile,tchModule)) { - ExpandEnvironmentStringsEx(Globals.IniFile,COUNTOF(Globals.IniFile)); - if (PathIsRelative(Globals.IniFile)) { - StringCchCopy(tchPath,COUNTOF(tchPath),tchModule); - PathCchRemoveFileSpec(tchPath, COUNTOF(tchPath)); - PathCchAppend(tchPath,COUNTOF(tchPath),Globals.IniFile); - StringCchCopy(Globals.IniFile,COUNTOF(Globals.IniFile),tchPath); - } - } - } - else { - StringCchCopy(tchPath,COUNTOF(tchPath),PathFindFileName(tchModule)); - PathCchRenameExtension(tchPath,COUNTOF(tchPath),L".ini"); - - bFound = _CheckIniFile(tchPath,tchModule); - - if (!bFound) { - StringCchCopy(tchPath,COUNTOF(tchPath),L"Notepad3.ini"); - bFound = _CheckIniFile(tchPath,tchModule); - } - - if (bFound) - { - // allow two redirections: administrator -> user -> custom - if (_CheckIniFileRedirect(_W(SAPPNAME), _W(SAPPNAME) L".ini", tchPath, tchModule)) - { - _CheckIniFileRedirect(_W(SAPPNAME), _W(SAPPNAME) L".ini", tchPath, tchModule); - } - StringCchCopy(Globals.IniFile,COUNTOF(Globals.IniFile),tchPath); - } - else { - StringCchCopy(Globals.IniFile,COUNTOF(Globals.IniFile),tchModule); - PathCchRenameExtension(Globals.IniFile,COUNTOF(Globals.IniFile),L".ini"); - } - } - - NormalizePathEx(Globals.IniFile,COUNTOF(Globals.IniFile), true, false); - - return bFound; -} - - -int TestIniFile() { - - if (StringCchCompareXI(Globals.IniFile,L"*?") == 0) { - StringCchCopy(Globals.IniFileDefault,COUNTOF(Globals.IniFileDefault),L""); - StringCchCopy(Globals.IniFile,COUNTOF(Globals.IniFile),L""); - return(0); - } - - if (PathIsDirectory(Globals.IniFile) || *CharPrev(Globals.IniFile,StrEnd(Globals.IniFile, COUNTOF(Globals.IniFile))) == L'\\') { - WCHAR wchModule[MAX_PATH] = { L'\0' }; - GetModuleFileName(NULL,wchModule,COUNTOF(wchModule)); - PathCchAppend(Globals.IniFile,COUNTOF(Globals.IniFile),PathFindFileName(wchModule)); - PathCchRenameExtension(Globals.IniFile,COUNTOF(Globals.IniFile),L".ini"); - if (!PathFileExists(Globals.IniFile)) { - StringCchCopy(PathFindFileName(Globals.IniFile),COUNTOF(Globals.IniFile),L"Notepad3.ini"); - if (!PathFileExists(Globals.IniFile)) { - StringCchCopy(PathFindFileName(Globals.IniFile),COUNTOF(Globals.IniFile),PathFindFileName(wchModule)); - PathCchRenameExtension(Globals.IniFile,COUNTOF(Globals.IniFile),L".ini"); - } - } - } - - NormalizePathEx(Globals.IniFile,COUNTOF(Globals.IniFile), true, false); - - if (!PathFileExists(Globals.IniFile) || PathIsDirectory(Globals.IniFile)) { - StringCchCopy(Globals.IniFileDefault,COUNTOF(Globals.IniFileDefault),Globals.IniFile); - StringCchCopy(Globals.IniFile,COUNTOF(Globals.IniFile),L""); - return(0); - } - return(1); -} - - -bool CreateIniFile() -{ - return(CreateIniFileEx(Globals.IniFile)); -} - -bool CreateIniFileEx(LPCWSTR lpszIniFile) -{ - if (StrIsNotEmpty(lpszIniFile)) - { - WCHAR *pwchTail = StrRChrW(lpszIniFile, NULL, L'\\'); - if (pwchTail) { - *pwchTail = 0; - SHCreateDirectoryEx(NULL,lpszIniFile,NULL); - *pwchTail = L'\\'; - } - - HANDLE hFile = CreateFile(lpszIniFile, - GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE, - NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL); - Globals.dwLastError = GetLastError(); - if (hFile != INVALID_HANDLE_VALUE) { - if (GetFileSize(hFile,NULL) == 0) { - DWORD dw; - //WriteFile(hFile,(LPCVOID)L"\xFE\xFF[Notepad3]\r\n",26,&dw,NULL); // UTF-16LE - WriteFile(hFile,(LPCVOID)L"\xEF\xBB\xBF[Notepad3]\r\n",26,&dw,NULL); // UTF-8 SIG - Globals.bIniFileFromScratch = true; - } - CloseHandle(hFile); - Style_SetIniFile(lpszIniFile); - return true; - } - } - return false; -} - - - //============================================================================= // // _DelayUpdateStatusbar() @@ -8785,6 +7842,8 @@ void UpdateToolbar() _DelayUpdateToolbar(40); } + + //============================================================================= static void _UpdateToolbarDelayed() diff --git a/src/Notepad3.h b/src/Notepad3.h index c2c755b0d..61bb61fff 100644 --- a/src/Notepad3.h +++ b/src/Notepad3.h @@ -117,6 +117,8 @@ typedef enum { //==== Function Declarations ================================================== bool InitApplication(HINSTANCE hInstance); HWND InitInstance(HINSTANCE hInstance, LPCWSTR pszCmdLine, int nCmdShow); +WININFO InitDefaultWndPos(const int flagsPos); +void InitWindowPosition(WININFO* pWinInfo, const int flagsPos); void BeginWaitCursor(LPCWSTR text); void EndWaitCursor(); bool ActivatePrevInst(); @@ -130,15 +132,9 @@ void InstallFileWatching(LPCWSTR lpszFile); void CALLBACK WatchTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime); void CALLBACK PasteBoardTimer(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime); - -void LoadSettings(); -void SaveSettings(bool); void ParseCommandLine(); void LoadFlags(); -bool FindIniFile(); -int TestIniFile(); -bool CreateIniFile(); -bool CreateIniFileEx(LPCWSTR lpszIniFile); +void SaveAllSettings(bool bSaveSettingsNow); void ShowZoomCallTip(); void CancelCallTip(); diff --git a/src/Styles.c b/src/Styles.c index 5f6d33c35..c2f48720c 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -769,7 +769,7 @@ bool Style_ExportToFile(const WCHAR* szFile, bool bForceAll) } } - SaveIniFile(); + SaveIniFile(szFile); } return ok; } diff --git a/src/TypeDefs.h b/src/TypeDefs.h index 2f918e400..1fff083b8 100644 --- a/src/TypeDefs.h +++ b/src/TypeDefs.h @@ -507,7 +507,7 @@ typedef struct _settings2_t } SETTINGS2_T, *PSETTINGS2_T; extern SETTINGS2_T Settings2; -//extern SETTINGS2_T Defaults2; +extern SETTINGS2_T Defaults2; //=============================================================================