From ca2129b66b5a4ab8dc6c83486805316f07d3c214 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Thu, 10 May 2018 13:12:30 +0200 Subject: [PATCH 1/5] + fix: broken Hyperlink Hotspot handling --- src/Edit.c | 10 ++++------ src/Notepad3.c | 25 +++++++++++-------------- src/SciCall.h | 7 ++++--- src/Styles.c | 33 ++++++++++++++++++++------------- 4 files changed, 39 insertions(+), 36 deletions(-) diff --git a/src/Edit.c b/src/Edit.c index 7d192d340..a8cad01ef 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -6559,7 +6559,6 @@ void EditUpdateUrlHotspots(HWND hwnd, DocPos startPos, DocPos endPos, bool bActi DocPos start = startPos; DocPos end = endPos; - int const iStyle = Style_GetHotspotStyleID(); do { DocPos iPos = _FindInTarget(hwnd, pszUrlRegEx, iRegExLen, SCFIND_NP3_REGEX, &start, &end, false, FRMOD_IGNORE); @@ -6574,7 +6573,7 @@ void EditUpdateUrlHotspots(HWND hwnd, DocPos startPos, DocPos endPos, bool bActi // mark this match SciCall_StartStyling(iPos); if (bActiveHotspot) - SciCall_SetStyling((DocPosCR)mlen, iStyle); + SciCall_SetStyling((DocPosCR)mlen, (char)Style_GetHotspotStyleID()); else EditFinalizeStyling(hwnd, endPos); @@ -6631,8 +6630,7 @@ void EditHideNotMarkedLineRange(HWND hwnd, DocPos iStartPos, DocPos iEndPos, boo SciCall_SetFoldFlags(0); //SciCall_SetFoldFlags(SC_FOLDFLAG_LEVELNUMBERS | SC_FOLDFLAG_LINESTATE); // Debug - // hide lines without indicator - const int iStyleHideID = Style_GetInvisibleStyleID(); + // --- hide lines without indicator --- const DocLn iStartLine = SciCall_LineFromPosition(iStartPos); const DocLn iEndLine = SciCall_LineFromPosition(iEndPos); @@ -6651,7 +6649,7 @@ void EditHideNotMarkedLineRange(HWND hwnd, DocPos iStartPos, DocPos iEndPos, boo const DocPos begPos = SciCall_PositionFromLine(iStartLine); const DocPos lnLen = SciCall_LineLength(iStartLine); SciCall_StartStyling(begPos); - SciCall_SetStyling((DocPosCR)lnLen, iStyleHideID); + SciCall_SetStyling((DocPosCR)lnLen, (char)Style_GetInvisibleStyleID()); } int level = baseLevel; @@ -6667,7 +6665,7 @@ void EditHideNotMarkedLineRange(HWND hwnd, DocPos iStartPos, DocPos iEndPos, boo const DocPos begPos = SciCall_PositionFromLine(iLine); const DocPos lnLen = SciCall_LineLength(iLine); SciCall_StartStyling(begPos); - SciCall_SetStyling((DocPosCR)lnLen, iStyleHideID); + SciCall_SetStyling((DocPosCR)lnLen, (char)Style_GetInvisibleStyleID()); if (level == baseLevel) { SciCall_SetFoldLevel(iLine - 1, SC_FOLDLEVELHEADERFLAG | level++); diff --git a/src/Notepad3.c b/src/Notepad3.c index 2287d4b7a..3910cf790 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -2747,9 +2747,9 @@ void MsgInitMenu(HWND hwnd,WPARAM wParam,LPARAM lParam) EnableCmd(hmenu,IDM_VIEW_SAVESETTINGSNOW,g_bEnableSaveSettings && i); bool bIsHLink = false; - if ((bool)SendMessage(g_hwndEdit, SCI_STYLEGETHOTSPOT, Style_GetHotspotStyleID(), 0)) + if ((bool)SendMessage(g_hwndEdit, SCI_STYLEGETHOTSPOT, Style_GetHotspotStyleID(), 0)) { - bIsHLink = (Style_GetHotspotStyleID() == (int)SendMessage(g_hwndEdit, SCI_GETSTYLEAT, SciCall_GetCurrentPos(), 0)); + bIsHLink = (SciCall_GetStyleAt(SciCall_GetCurrentPos()) == (char)Style_GetHotspotStyleID()); } EnableCmd(hmenu, CMD_OPEN_HYPERLINK, bIsHLink); @@ -5610,28 +5610,25 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam) // void OpenHotSpotURL(DocPos position, bool bForceBrowser) { - int iStyle = (int)SendMessage(g_hwndEdit, SCI_GETSTYLEAT, position, 0); + char const cStyle = SciCall_GetStyleAt(position); - if (Style_GetHotspotStyleID() != iStyle) - return; - - if (!(bool)SendMessage(g_hwndEdit, SCI_STYLEGETHOTSPOT, Style_GetHotspotStyleID(), 0)) - return; + if (cStyle != (char)Style_GetHotspotStyleID()) { return; } + if (!(bool)SendMessage(g_hwndEdit, SCI_STYLEGETHOTSPOT, Style_GetHotspotStyleID(), 0)) { return; } // get left most position of style DocPos pos = position; - int iNewStyle = iStyle; - while ((iNewStyle == iStyle) && (--pos > 0)) { - iNewStyle = (int)SendMessage(g_hwndEdit, SCI_GETSTYLEAT, pos, 0); + char cNewStyle = cStyle; + while ((cNewStyle == cStyle) && (--pos > 0)) { + cNewStyle = SciCall_GetStyleAt(pos); } DocPos firstPos = (pos != 0) ? (pos + 1) : 0; // get right most position of style pos = position; - iNewStyle = iStyle; + cNewStyle = cStyle; DocPos posTextLength = SciCall_GetTextLength(); - while ((iNewStyle == iStyle) && (++pos < posTextLength)) { - iNewStyle = (int)SendMessage(g_hwndEdit, SCI_GETSTYLEAT, pos, 0); + while ((cNewStyle == cStyle) && (++pos < posTextLength)) { + cNewStyle = SciCall_GetStyleAt(pos); } DocPos lastPos = pos; DocPos length = (lastPos - firstPos); diff --git a/src/SciCall.h b/src/SciCall.h index 1de016e14..470239e2d 100644 --- a/src/SciCall.h +++ b/src/SciCall.h @@ -265,9 +265,10 @@ DeclareSciCallR1(DocLineFromVisible, DOCLINEFROMVISIBLE, DocLn, DocLn, line) // // Style definition // -DeclareSciCallR1(StyleGetFore, STYLEGETFORE, COLORREF, int, styleNumber) -DeclareSciCallR1(StyleGetBack, STYLEGETBACK, COLORREF, int, styleNumber) -DeclareSciCallV2(SetStyling, SETSTYLING, DocPosCR, length, int, style) +DeclareSciCallR1(StyleGetFore, STYLEGETFORE, COLORREF, char, style) +DeclareSciCallR1(StyleGetBack, STYLEGETBACK, COLORREF, char, style) +DeclareSciCallR1(GetStyleAt, GETSTYLEAT, char, DocPos, position) +DeclareSciCallV2(SetStyling, SETSTYLING, DocPosCR, length, char, style) DeclareSciCallV1(StartStyling, STARTSTYLING, DocPos, position) DeclareSciCallR0(GetEndStyled, GETENDSTYLED, DocPos) diff --git a/src/Styles.c b/src/Styles.c index 04a911da8..407fa2910 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -111,7 +111,8 @@ EDITLEXER lexStandard2nd = { SCLEX_NULL, 63266, L"2nd Default Text", L"txt; text { -1, 00000, L"", L"", L"" } } }; -enum LexDefaultStyles { + +typedef enum { STY_DEFAULT = 0, STY_MARGIN = 1, STY_BRACE_OK = 2, @@ -129,7 +130,13 @@ enum LexDefaultStyles { STY_URL_HOTSPOT = 14, STY_INVISIBLE = 15, STY_READONLY = 16 -}; + + // MAX = 127 +} +LexDefaultStyles; + + +// ---------------------------------------------------------------------------- @@ -3855,6 +3862,7 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) } + //============================================================================= // // Style_GetHotspotStyleID() @@ -3871,18 +3879,17 @@ int Style_GetHotspotStyleID() // void Style_SetUrlHotSpot(HWND hwnd, bool bHotSpot) { - // Hot Spot settings - const int iStyleHotSpot = Style_GetHotspotStyleID(); + int const cHotSpotStyleID = Style_GetHotspotStyleID(); if (bHotSpot) { const WCHAR* const lpszStyleHotSpot = GetCurrentStdLexer()->Styles[STY_URL_HOTSPOT].szValue; - SendMessage(hwnd, SCI_STYLESETHOTSPOT, iStyleHotSpot, (LPARAM)true); + SendMessage(hwnd, SCI_STYLESETHOTSPOT, cHotSpotStyleID, (LPARAM)true); SendMessage(hwnd, SCI_SETHOTSPOTSINGLELINE, false, 0); // Font - Style_SetStyles(hwnd, iStyleHotSpot, lpszStyleHotSpot, false); + Style_SetStyles(hwnd, cHotSpotStyleID, lpszStyleHotSpot, false); //if (StrStrI(lpszStyleHotSpot, L"underline") != NULL) // SendMessage(hwnd, SCI_SETHOTSPOTACTIVEUNDERLINE, true, 0); @@ -3894,19 +3901,19 @@ void Style_SetUrlHotSpot(HWND hwnd, bool bHotSpot) // Fore if (Style_StrGetColor(true, lpszStyleHotSpot, &rgb)) { COLORREF inactiveFG = (COLORREF)((rgb * 75 + 50) / 100); - SendMessage(hwnd, SCI_STYLESETFORE, iStyleHotSpot, (LPARAM)inactiveFG); + SendMessage(hwnd, SCI_STYLESETFORE, cHotSpotStyleID, (LPARAM)inactiveFG); SendMessage(hwnd, SCI_SETHOTSPOTACTIVEFORE, true, (LPARAM)rgb); } // Back if (Style_StrGetColor(false, lpszStyleHotSpot, &rgb)) { - SendMessage(hwnd, SCI_STYLESETBACK, iStyleHotSpot, (LPARAM)rgb); + SendMessage(hwnd, SCI_STYLESETBACK, cHotSpotStyleID, (LPARAM)rgb); SendMessage(hwnd, SCI_SETHOTSPOTACTIVEBACK, true, (LPARAM)rgb); } } else { const WCHAR* const lpszStyleHotSpot = g_pLexCurrent->Styles[STY_DEFAULT].szValue; - Style_SetStyles(hwnd, iStyleHotSpot, lpszStyleHotSpot, false); - SendMessage(hwnd, SCI_STYLESETHOTSPOT, iStyleHotSpot, (LPARAM)false); + Style_SetStyles(hwnd, cHotSpotStyleID, lpszStyleHotSpot, false); + SendMessage(hwnd, SCI_STYLESETHOTSPOT, cHotSpotStyleID, (LPARAM)false); } } @@ -3932,7 +3939,7 @@ void Style_SetInvisible(HWND hwnd, bool bInvisible) //SendMessage(hwnd, SCI_FOLDDISPLAYTEXTSETSTYLE, (WPARAM)SC_FOLDDISPLAYTEXT_BOXED, 0); //SciCall_MarkerDefine(MARKER_NP3_OCCUR_LINE, SC_MARK_EMPTY); // occurrences marker if (bInvisible) { - SendMessage(hwnd, SCI_STYLESETVISIBLE, Style_GetInvisibleStyleID(), (LPARAM)!bInvisible); + SendMessage(hwnd, SCI_STYLESETVISIBLE, (WPARAM)Style_GetInvisibleStyleID(), (LPARAM)!bInvisible); } } @@ -3944,7 +3951,7 @@ void Style_SetInvisible(HWND hwnd, bool bInvisible) // int Style_GetReadonlyStyleID() { - return (STYLE_LASTPREDEFINED + STY_READONLY); + return (STYLE_MAX - STY_READONLY); } @@ -3954,7 +3961,7 @@ int Style_GetReadonlyStyleID() // void Style_SetReadonly(HWND hwnd, bool bReadonly) { - SendMessage(hwnd, SCI_STYLESETCHANGEABLE, Style_GetReadonlyStyleID(), (LPARAM)!bReadonly); + SendMessage(hwnd, SCI_STYLESETCHANGEABLE, (WPARAM)Style_GetReadonlyStyleID(), (LPARAM)!bReadonly); } From 185e09cde87f994c35bed10cca5763138eb2ed7f Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Thu, 10 May 2018 14:02:57 +0200 Subject: [PATCH 2/5] + enh: handling of default/standard lexer styles --- src/Notepad3.c | 34 +++++++++++++++++++++------------- src/Styles.c | 19 +++++++++++++++++-- src/Styles.h | 1 + 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/Notepad3.c b/src/Notepad3.c index 3910cf790..12697474c 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -6123,7 +6123,9 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam) return true; case STATUS_2ND_DEF: - PostMessage(hwnd, WM_COMMAND, MAKELONG(IDM_VIEW_USE2NDDEFAULT, 1), 0); + if (!Style_IsCurLexerStandard()) { + PostMessage(hwnd, WM_COMMAND, MAKELONG(IDM_VIEW_USE2NDDEFAULT, 1), 0); + } return true; case STATUS_LEXER: @@ -7946,17 +7948,25 @@ static void __fastcall _UpdateStatusbarDelayed(bool bForceRedraw) } // ------------------------------------------------------ - static bool s_bUse2ndDefault = -1; - bool bUse2ndDefault = Style_GetUse2ndDefault(); - if (s_bUse2ndDefault != bUse2ndDefault) { - if (bUse2ndDefault) - { - StringCchPrintf(tchStatusBar[STATUS_2ND_DEF], txtWidth, L"%s2ND", g_mxStatusBarPrefix[STATUS_2ND_DEF]); - } - else { + static int s_iUse2ndDefault = -1; + int iUse2ndDefault = Style_IsCurLexerStandard() ? 0 : (Style_GetUse2ndDefault() ? 2 : 1); + + if (s_iUse2ndDefault != iUse2ndDefault) { + switch (iUse2ndDefault) { + case 0: + StringCchPrintf(tchStatusBar[STATUS_2ND_DEF], txtWidth, L"%s", g_mxStatusBarPrefix[STATUS_2ND_DEF]); + break; + case 1: StringCchPrintf(tchStatusBar[STATUS_2ND_DEF], txtWidth, L"%sSTD", g_mxStatusBarPrefix[STATUS_2ND_DEF]); + break; + case 2: + StringCchPrintf(tchStatusBar[STATUS_2ND_DEF], txtWidth, L"%s2ND", g_mxStatusBarPrefix[STATUS_2ND_DEF]); + break; + default: + StringCchPrintf(tchStatusBar[STATUS_2ND_DEF], txtWidth, L"%sXXX", g_mxStatusBarPrefix[STATUS_2ND_DEF]); + break; } - s_bUse2ndDefault = bUse2ndDefault; + s_iUse2ndDefault = iUse2ndDefault; bIsUpdateNeeded = true; } // ------------------------------------------------------ @@ -7964,13 +7974,11 @@ static void __fastcall _UpdateStatusbarDelayed(bool bForceRedraw) static WCHAR tchLexerName[MINI_BUFFER]; static int s_iCurLexer = -1; - static bool s_bIs2ndDefault = -1; int const iCurLexer = Style_GetCurrentLexerRID(); - if ((s_iCurLexer != iCurLexer) || (s_bIs2ndDefault != bUse2ndDefault)) { + if (s_iCurLexer != iCurLexer) { Style_GetCurrentLexerName(tchLexerName, MINI_BUFFER); StringCchPrintf(tchStatusBar[STATUS_LEXER], txtWidth, L"%s%s", g_mxStatusBarPrefix[STATUS_LEXER], tchLexerName); s_iCurLexer = iCurLexer; - s_bIs2ndDefault = bUse2ndDefault; bIsUpdateNeeded = true; } // ------------------------------------------------------ diff --git a/src/Styles.c b/src/Styles.c index 407fa2910..4839b45da 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -3043,6 +3043,17 @@ PEDITLEXER __fastcall GetDefaultLexer() } + +//============================================================================= +// +// IsLexerStandard() +// +bool Style_IsCurLexerStandard() +{ + return IsLexerStandard(g_pLexCurrent); +} + + //============================================================================= // // _SetBaseFontSize(), _GetBaseFontSize() @@ -3358,10 +3369,14 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) const WCHAR* const wchNewLexerStyleStrg = pLexNew->Styles[STY_DEFAULT].szValue; // first set standard lexer's default values - if (IsLexerStandard(pLexNew)) + if (IsLexerStandard(pLexNew)) { g_pLexCurrent = pLexNew; - else + EnableCmd(GetMenu(g_hwndMain), IDM_VIEW_USE2NDDEFAULT, false); + } + else { g_pLexCurrent = GetCurrentStdLexer(); + EnableCmd(GetMenu(g_hwndMain), IDM_VIEW_USE2NDDEFAULT, true); + } const WCHAR* const wchStandardStyleStrg = g_pLexCurrent->Styles[STY_DEFAULT].szValue; diff --git a/src/Styles.h b/src/Styles.h index b0f576683..92b220e8f 100644 --- a/src/Styles.h +++ b/src/Styles.h @@ -105,6 +105,7 @@ void Style_CopyStyles_IfNotDefined(LPWSTR,LPWSTR,int,bool,bool); bool Style_SelectFont(HWND,LPWSTR,int,LPCWSTR,LPCWSTR,bool,bool,bool,bool); bool Style_SelectColor(HWND,bool,LPWSTR,int,bool); void Style_SetStyles(HWND,int,LPCWSTR,bool); +bool Style_IsCurLexerStandard(); int Style_GetCurrentLexerRID(); void Style_GetCurrentLexerName(LPWSTR,int); int Style_GetLexerIconId(PEDITLEXER); From cf63c7c628c3726be37b73e501c42afa200827e2 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Thu, 10 May 2018 16:09:46 +0200 Subject: [PATCH 3/5] + fix: Brace matching for Batch Lexer --- scintilla/lexers/LexBatch.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scintilla/lexers/LexBatch.cxx b/scintilla/lexers/LexBatch.cxx index 9004484f1..b641fc86d 100644 --- a/scintilla/lexers/LexBatch.cxx +++ b/scintilla/lexers/LexBatch.cxx @@ -41,7 +41,8 @@ static inline bool AtEOL(Accessor &styler, Sci_PositionU i) { // Tests for BATCH Operators static bool IsBOperator(char ch) { return (ch == '=') || (ch == '+') || (ch == '>') || (ch == '<') || - (ch == '|') || (ch == '?') || (ch == '*'); + (ch == '|') || (ch == '?') || (ch == '*') || + (ch == '(') || (ch == ')') || (ch == '[') || (ch == ']'); } // Tests for BATCH Separators From 04e19da814298a4ca8c745f7ba2a2ad956c2e436 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Thu, 10 May 2018 21:18:33 +0200 Subject: [PATCH 4/5] + chg: default ini for Notepad3Portable --- .../App/DefaultData/settings/Notepad3.ini | Bin 5798 -> 5398 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/np3portableapp/Notepad3Portable/App/DefaultData/settings/Notepad3.ini b/np3portableapp/Notepad3Portable/App/DefaultData/settings/Notepad3.ini index 6f86c07b9ebc21b48194755bb4d115095d236d3e..5ab183cb9018afd3b930658fe6b7f4218a4e068b 100644 GIT binary patch delta 112 zcmZ3cJ56hXg?K1KFoP>Y5JLbE`!l#Pcry3^`KlAo%TKJjG0Y8Gf z1pF>eeho*@d!Zt9c<Ex_rB_3B&_)Lh-j~pqAA5xobPUi#lR^g;Y)1Oh z{njtwBE}s>7i0KnVS}KLb>NYDQjBrlo0|LGwU%_4VUeAb{F^}+PWch+G_)FJLiRn!71qx%r;*KA_)oh^kV}4Y zJ8GQ^^|^u(?F8v&Hw-a From 29b1b2009a7f7ed027e312583d2cbad0ebb9ccc8 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Fri, 11 May 2018 08:03:01 +0200 Subject: [PATCH 5/5] + enh: notepad3.ini redirection to avoid overriding settings by unzip distribution package --- Build/Notepad3_redirector.ini | Bin 0 -> 120 bytes .../App/Notepad3/{ => np3}/Notepad3.ini | Bin .../App/Notepad3/x64/{ => np3}/Notepad3.ini | Bin src/Notepad3.c | 56 +++++++++++------- src/Notepad3.h | 2 - 5 files changed, 35 insertions(+), 23 deletions(-) create mode 100644 Build/Notepad3_redirector.ini rename np3portableapp/Notepad3Portable/App/Notepad3/{ => np3}/Notepad3.ini (100%) rename np3portableapp/Notepad3Portable/App/Notepad3/x64/{ => np3}/Notepad3.ini (100%) diff --git a/Build/Notepad3_redirector.ini b/Build/Notepad3_redirector.ini new file mode 100644 index 0000000000000000000000000000000000000000..3635bc8efee3434f18a1f83fc0eab1d99fde88e9 GIT binary patch literal 120 zcmezWFPg!RA)ldyA(f$kA(0`4!I&YIftP^`LsX9;lOYd?Z5dR7a{de<46Y0T42}#g cKpnn7z6(PrgAY*5g~5{{2&g6orwJg_0cVL6fB*mh literal 0 HcmV?d00001 diff --git a/np3portableapp/Notepad3Portable/App/Notepad3/Notepad3.ini b/np3portableapp/Notepad3Portable/App/Notepad3/np3/Notepad3.ini similarity index 100% rename from np3portableapp/Notepad3Portable/App/Notepad3/Notepad3.ini rename to np3portableapp/Notepad3Portable/App/Notepad3/np3/Notepad3.ini diff --git a/np3portableapp/Notepad3Portable/App/Notepad3/x64/Notepad3.ini b/np3portableapp/Notepad3Portable/App/Notepad3/x64/np3/Notepad3.ini similarity index 100% rename from np3portableapp/Notepad3Portable/App/Notepad3/x64/Notepad3.ini rename to np3portableapp/Notepad3Portable/App/Notepad3/x64/np3/Notepad3.ini diff --git a/src/Notepad3.c b/src/Notepad3.c index 12697474c..6f7a84c59 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -7268,7 +7268,7 @@ void LoadFlags() // FindIniFile() // // -bool CheckIniFile(LPWSTR lpszFile,LPCWSTR lpszModule) +static bool __fastcall _CheckIniFile(LPWSTR lpszFile,LPCWSTR lpszModule) { WCHAR tchFileExpanded[MAX_PATH] = { L'\0' }; WCHAR tchBuild[MAX_PATH] = { L'\0' }; @@ -7278,12 +7278,20 @@ bool CheckIniFile(LPWSTR lpszFile,LPCWSTR lpszModule) // program directory StringCchCopy(tchBuild,COUNTOF(tchBuild),lpszModule); StringCchCopy(PathFindFileName(tchBuild),COUNTOF(tchBuild),tchFileExpanded); - if (PathFileExists(tchBuild)) { StringCchCopy(lpszFile,MAX_PATH,tchBuild); return true; } - // %appdata% + // sub directory (.\np3\) + StringCchCopy(tchBuild, COUNTOF(tchBuild), lpszModule); + PathRemoveFileSpec(tchBuild); + StringCchCat(tchBuild,COUNTOF(tchBuild),L"\\np3\\"); + StringCchCat(tchBuild,COUNTOF(tchBuild),tchFileExpanded); + if (PathFileExists(tchBuild)) { + StringCchCopy(lpszFile, MAX_PATH, tchBuild); + return true; + } + // %APPDATA% //if (S_OK == SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, tchBuild)) { if (GetKnownFolderPath(&FOLDERID_RoamingAppData, tchBuild, COUNTOF(tchBuild))) { PathCchAppend(tchBuild,COUNTOF(tchBuild),tchFileExpanded); @@ -7298,20 +7306,19 @@ bool CheckIniFile(LPWSTR lpszFile,LPCWSTR lpszModule) return true; } } - else if (PathFileExists(tchFileExpanded)) { StringCchCopy(lpszFile,MAX_PATH,tchFileExpanded); return true; } - return false; } -bool CheckIniFileRedirect(LPWSTR lpszFile,LPCWSTR lpszModule) + +static bool __fastcall _CheckIniFileRedirect(LPWSTR lpszFile,LPCWSTR lpszModule) { WCHAR tch[MAX_PATH] = { L'\0' }; if (GetPrivateProfileString(L"Notepad3",L"Notepad3.ini",L"",tch,COUNTOF(tch),lpszFile)) { - if (CheckIniFile(tch,lpszModule)) { + if (_CheckIniFile(tch,lpszModule)) { StringCchCopy(lpszFile,MAX_PATH,tch); return true; } @@ -7332,44 +7339,51 @@ bool CheckIniFileRedirect(LPWSTR lpszFile,LPCWSTR lpszModule) return false; } + int FindIniFile() { - WCHAR tchTest[MAX_PATH] = { L'\0' }; + 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); + PathRemoveFileSpec(tchPath); + SetEnvironmentVariable(L"NOTEPAD3MODULEDIR", tchPath); + if (StringCchLenW(g_wchIniFile,COUNTOF(g_wchIniFile))) { if (StringCchCompareIX(g_wchIniFile,L"*?") == 0) return(0); else { - if (!CheckIniFile(g_wchIniFile,tchModule)) { + if (!_CheckIniFile(g_wchIniFile,tchModule)) { ExpandEnvironmentStringsEx(g_wchIniFile,COUNTOF(g_wchIniFile)); if (PathIsRelative(g_wchIniFile)) { - StringCchCopy(tchTest,COUNTOF(tchTest),tchModule); - PathRemoveFileSpec(tchTest); - PathCchAppend(tchTest,COUNTOF(tchTest),g_wchIniFile); - StringCchCopy(g_wchIniFile,COUNTOF(g_wchIniFile),tchTest); + StringCchCopy(tchPath,COUNTOF(tchPath),tchModule); + PathRemoveFileSpec(tchPath); + PathCchAppend(tchPath,COUNTOF(tchPath),g_wchIniFile); + StringCchCopy(g_wchIniFile,COUNTOF(g_wchIniFile),tchPath); } } } } else { - StringCchCopy(tchTest,COUNTOF(tchTest),PathFindFileName(tchModule)); - PathCchRenameExtension(tchTest,COUNTOF(tchTest),L".ini"); - bool bFound = CheckIniFile(tchTest,tchModule); + StringCchCopy(tchPath,COUNTOF(tchPath),PathFindFileName(tchModule)); + PathCchRenameExtension(tchPath,COUNTOF(tchPath),L".ini"); + bool bFound = _CheckIniFile(tchPath,tchModule); if (!bFound) { - StringCchCopy(tchTest,COUNTOF(tchTest),L"Notepad3.ini"); - bFound = CheckIniFile(tchTest,tchModule); + StringCchCopy(tchPath,COUNTOF(tchPath),L"Notepad3.ini"); + bFound = _CheckIniFile(tchPath,tchModule); } if (bFound) { // allow two redirections: administrator -> user -> custom - if (CheckIniFileRedirect(tchTest,tchModule)) - CheckIniFileRedirect(tchTest,tchModule); + if (_CheckIniFileRedirect(tchPath,tchModule)) + _CheckIniFileRedirect(tchPath,tchModule); - StringCchCopy(g_wchIniFile,COUNTOF(g_wchIniFile),tchTest); + StringCchCopy(g_wchIniFile,COUNTOF(g_wchIniFile),tchPath); } else { StringCchCopy(g_wchIniFile,COUNTOF(g_wchIniFile),tchModule); diff --git a/src/Notepad3.h b/src/Notepad3.h index 1fa2df8d3..1780c40e6 100644 --- a/src/Notepad3.h +++ b/src/Notepad3.h @@ -130,8 +130,6 @@ void LoadSettings(); void SaveSettings(bool); void ParseCommandLine(); void LoadFlags(); -bool CheckIniFile(LPWSTR,LPCWSTR); -bool CheckIniFileRedirect(LPWSTR,LPCWSTR); int FindIniFile(); int TestIniFile(); int CreateIniFile();