@@ -3048,6 +3048,8 @@ enum class IniFindStatus {
30483048 Found = 1 ,
30493049 Relative = 2 ,
30503050 Specified = 4 ,
3051+ Program = 8 ,
3052+ AppData = 16 ,
30513053};
30523054
30533055constexpr IniFindStatus operator |(IniFindStatus status, IniFindStatus value) noexcept {
@@ -3057,12 +3059,18 @@ constexpr IniFindStatus operator|(IniFindStatus status, IniFindStatus value) noe
30573059struct IniFinder {
30583060 LPCWSTR tchModule;
30593061 size_t nameIndex;
3062+ bool portable = true ;
30603063 LPWSTR folder[3 ]{};
30613064 const KNOWNFOLDERID* rfidList[3 ]{};
30623065
30633066 IniFinder () noexcept {
30643067 tchModule = szExeRealPath;
30653068 nameIndex = PathFindFileName (tchModule) - tchModule;
3069+ if (StrStrI (tchModule, L" WinGet" ) != nullptr || StrStrI (tchModule, L" Chocolatey" ) != nullptr ) {
3070+ // %LOCALAPPDATA%\Microsoft\WinGet\Packages
3071+ // ChocolateyInstall
3072+ portable = false ;
3073+ }
30663074 }
30673075 ~IniFinder () {
30683076 for (UINT i = 0 ; i < COUNTOF (folder); i++) {
@@ -3080,11 +3088,13 @@ IniFindStatus IniFinder::CheckIniFile(LPWSTR lpszFile) noexcept {
30803088 if (PathIsRelative (lpszFile)) {
30813089 WCHAR tchBuild[MAX_PATH];
30823090 // program directory
3083- lstrcpy (tchBuild, tchModule);
3084- lstrcpy (&tchBuild[nameIndex], lpszFile);
3085- if (PathIsFile (tchBuild)) {
3086- lstrcpy (lpszFile, tchBuild);
3087- return IniFindStatus::Found;
3091+ if (portable) {
3092+ lstrcpy (tchBuild, tchModule);
3093+ lstrcpy (&tchBuild[nameIndex], lpszFile);
3094+ if (PathIsFile (tchBuild)) {
3095+ lstrcpy (lpszFile, tchBuild);
3096+ return IniFindStatus::Found | IniFindStatus::Program;
3097+ }
30883098 }
30893099
30903100 if (rfidList[0 ] == nullptr ) {
@@ -3108,10 +3118,18 @@ IniFindStatus IniFinder::CheckIniFile(LPWSTR lpszFile) noexcept {
31083118 PathAppend (tchBuild, lpszFile);
31093119 if (PathIsFile (tchBuild)) {
31103120 lstrcpy (lpszFile, tchBuild);
3111- return IniFindStatus::Found;
3121+ return IniFindStatus::Found | IniFindStatus::AppData ;
31123122 }
31133123 }
31143124 }
3125+ if (!portable) {
3126+ lstrcpy (tchBuild, tchModule);
3127+ lstrcpy (&tchBuild[nameIndex], lpszFile);
3128+ if (PathIsFile (tchBuild)) {
3129+ lstrcpy (lpszFile, tchBuild);
3130+ return IniFindStatus::Found | IniFindStatus::Program;
3131+ }
3132+ }
31153133 return IniFindStatus::Relative;
31163134 }
31173135 if (PathIsFile (lpszFile)) {
@@ -3150,6 +3168,15 @@ void FindIniFile() noexcept {
31503168
31513169 if (FlagSet (status, IniFindStatus::Found)) {
31523170 WCHAR tchTmp[MAX_PATH];
3171+ if (FlagSet (status, IniFindStatus::Program) && !finder.portable && finder.folder [0 ] != nullptr ) {
3172+ // copy ini to %LOCALAPPDATA%\Notepad4
3173+ PathCombine (tchTmp, finder.folder [0 ], WC_NOTEPAD4);
3174+ SHCreateDirectoryEx (nullptr , tchTmp, nullptr );
3175+ PathAppend (tchTmp, &tchTest[finder.nameIndex ]);
3176+ CopyFile (tchTest, tchTmp, TRUE );
3177+ // always use %LOCALAPPDATA% for non-portable installation
3178+ lstrcpy (tchTest, tchTmp);
3179+ }
31533180 // check ini redirection
31543181 if (GetPrivateProfileString (INI_SECTION_NAME_MATEPATH, L" matepath.ini" , L" " , tchTmp, COUNTOF (tchTmp), tchTest)) {
31553182 if (!ExpandEnvironmentStringsEx (tchTmp, tchTest)) {
@@ -3171,8 +3198,13 @@ void FindIniFile() noexcept {
31713198 relative = FlagSet (status, IniFindStatus::Relative);
31723199 }
31733200 if (relative) {
3174- lstrcpy (tchTest, finder.tchModule );
3175- lstrcpy (&tchTest[finder.nameIndex ], pszFile);
3201+ if (!finder.portable && finder.folder [0 ] != nullptr ) {
3202+ PathCombine (tchTest, finder.folder [0 ], WC_NOTEPAD4);
3203+ PathAppend (tchTest, pszFile);
3204+ } else {
3205+ lstrcpy (tchTest, finder.tchModule );
3206+ lstrcpy (&tchTest[finder.nameIndex ], pszFile);
3207+ }
31763208 PathRenameExtension (tchTest, L" .ini" );
31773209 pszFile = tchTest;
31783210 if (PathIsFile (tchTest)) {
0 commit comments