Skip to content

Conversation

@lostindark
Copy link
Contributor

@lostindark lostindark commented Aug 20, 2025

With this change, notepad4 will use %LOCALAPPDATA%\notepad4 folder to store ini file if it is running from WinGet installation and keep the ini file in the exe folder unchanged. This will fix the WinGet upgrade issue.

@lostindark
Copy link
Contributor Author

lostindark commented Aug 20, 2025

Also I remove %USERPROFILE% and %APPDATA% support.
%USERPROFILE% is not supposed to used for storing app configurations. It is meant for user files.
%APPDATA% will roaming across machine, but notepad4.ini contains machine specific data (e.g. window location) so we should not store it there.

Update: restored USERPROFILE and APPDATA support since people may already depend on that.

@lostindark lostindark changed the title Update notepad4 to use %LOCALAPPDATA% for WinGet installation Use %LOCALAPPDATA% to store ini file for WinGet installation Aug 20, 2025
@zufuliu
Copy link
Owner

zufuliu commented Aug 20, 2025

Instead of checking _Microsoft.Winget.Source_, how about just check whether Notepad4.ini from Notepad4.exe folder is writeable?

@lostindark
Copy link
Contributor Author

lostindark commented Aug 20, 2025

Instead of checking _Microsoft.Winget.Source_, how about just check whether Notepad4.ini from Notepad4.exe folder is writeable?

Unfortunately Notepad4.ini is writable in WinGet installation folder, so we can't rely on that to check.

@lostindark
Copy link
Contributor Author

@zufuliu any other comments?

@Mapaler
Copy link

Mapaler commented Sep 17, 2025

Also I remove %USERPROFILE% and %APPDATA% support.我也删除了%USERPROFILE%和%APPDATA%支持。 %USERPROFILE% is not supposed to used for storing app configurations. It is meant for user files. %USERPROFILE%不应用于存储应用程序配置。它是用于用户文件的。 %APPDATA% will roaming across machine, but notepad4.ini contains machine specific data (e.g. window location) so we should not store it there. %APPDATA%将在机器上漫游,但 notepad4.ini 包含机器特定的数据(例如窗口位置),因此我们不应该将其存储在那里。

There are a lot of settings that I wish to roam, such as my configurations for some custom syntax highlighting.

Can we refer to the approach of Total Commander in this regard, using redirection to split the ini?

For example, the following excerpt

[Layout]
BreadCrumbBar=1
CmdLine=1
CurDir=1
DirectoryTabs=1
DriveBar1=1
DriveBar2=1
DriveBarFlat=1
DriveCombo=0
HistoryHotlistButtons=1
InterfaceFlat=1
KeyButtons=1
StatusBar=1
TabHeader=1
XPthemeBg=1
[Associations]
RedirectSection=%COMMANDER_PATH%\User\User.ini
[Command line history]
RedirectSection=%COMMANDER_PATH%\User\History.ini
[SplitPerFile]
RedirectSection=%COMMANDER_PATH%\User\History.ini
[SyncOptions]
RedirectSection=%COMMANDER_PATH%\User\User.ini
[USER]
RedirectSection=%COMMANDER_PATH%\User\User.ini

If there is a RedirectSection value encountered during the section, redirect to another ini file.

This method can also be used to set different configurations for different users on the same computer.

@lostindark
Copy link
Contributor Author

Also I remove %USERPROFILE% and %APPDATA% support.我也删除了%USERPROFILE%和%APPDATA%支持。 %USERPROFILE% is not supposed to used for storing app configurations. It is meant for user files. %USERPROFILE%不应用于存储应用程序配置。它是用于用户文件的。 %APPDATA% will roaming across machine, but notepad4.ini contains machine specific data (e.g. window location) so we should not store it there. %APPDATA%将在机器上漫游,但 notepad4.ini 包含机器特定的数据(例如窗口位置),因此我们不应该将其存储在那里。

There are a lot of settings that I wish to roam, such as my configurations for some custom syntax highlighting.

Can we refer to the approach of Total Commander in this regard, using redirection to split the ini?

For example, the following excerpt

[Layout]
BreadCrumbBar=1
CmdLine=1
CurDir=1
DirectoryTabs=1
DriveBar1=1
DriveBar2=1
DriveBarFlat=1
DriveCombo=0
HistoryHotlistButtons=1
InterfaceFlat=1
KeyButtons=1
StatusBar=1
TabHeader=1
XPthemeBg=1
[Associations]
RedirectSection=%COMMANDER_PATH%\User\User.ini
[Command line history]
RedirectSection=%COMMANDER_PATH%\User\History.ini
[SplitPerFile]
RedirectSection=%COMMANDER_PATH%\User\History.ini
[SyncOptions]
RedirectSection=%COMMANDER_PATH%\User\User.ini
[USER]
RedirectSection=%COMMANDER_PATH%\User\User.ini

If there is a RedirectSection value encountered during the section, redirect to another ini file.

This method can also be used to set different configurations for different users on the same computer.

This goes beyond the scope of this change. You should open a different issue to track it.

@lostindark
Copy link
Contributor Author

@zufuliu I updated the PR to restore support for PROFILE and APPDATA, please take another look.

@zufuliu
Copy link
Owner

zufuliu commented Sep 18, 2025

Before applying the change, I'm going to rewrite FindIniFile(), current code is bit complicate (e.g. CheckIniFile() been called 5 times, so likely the rfidList loop and your winget check code), also TestIniFile() and CreateIniFile() seems can be eliminated.

notepad4/src/Notepad4.cpp

Lines 546 to 548 in fd22083

FindIniFile();
TestIniFile();
CreateIniFile(szIniFile);

@zufuliu zufuliu added the ini label Sep 21, 2025
@zufuliu zufuliu removed the ⏸delayed label Jan 7, 2026
@zufuliu zufuliu added this to the v26.01 milestone Jan 7, 2026
@zufuliu
Copy link
Owner

zufuliu commented Jan 7, 2026

I'm going to integrate the change with some simplifications:

  1. Only check path contains magic string .Winget., I think this should be enough, if this cause problem, we can check a longer magic name. Maybe we could just check WinGet? web search shows installed packages path is %LOCALAPPDATA%\Microsoft\WinGet\Packages, C:\Program Files\WinGet\Packages or C:\Program Files (x86)\WinGet\Packages).
  2. CheckIniFile() will be adjusted to search program folder later for winget installation.

Also I remove %USERPROFILE% and %APPDATA% support.
%USERPROFILE% is not supposed to used for storing app configurations. It is meant for user files.
%APPDATA% will roaming across machine, but notepad4.ini contains machine specific data (e.g. window location) so we should not store it there.

Maybe these could be removed, and restored when people use these folders.

@lostindark
Copy link
Contributor Author

I'm going to integrate the change with some simplifications:

  1. Only check path contains magic string .Winget., I think this should be enough, if this cause problem, we can check a longer magic name. Maybe we could just check WinGet? web search shows installed packages path is %LOCALAPPDATA%\Microsoft\WinGet\Packages, C:\Program Files\WinGet\Packages or C:\Program Files (x86)\WinGet\Packages).
  2. CheckIniFile() will be adjusted to search program folder later for winget installation.

Also I remove %USERPROFILE% and %APPDATA% support.
%USERPROFILE% is not supposed to used for storing app configurations. It is meant for user files.
%APPDATA% will roaming across machine, but notepad4.ini contains machine specific data (e.g. window location) so we should not store it there.

Maybe these could be removed, and restored when people use these folders.

I think check the parent folder with .Winget. is enough. Notepad4 is a portable package, which should always be installed to %LOCALAPPDATA%\Microsoft\WinGet\Packages.

@zufuliu
Copy link
Owner

zufuliu commented Jan 8, 2026

Should we also copy Notepad4 DarkTheme.ini? unlike the empty Notepad4.ini file, it is regularly updated when a new scheme is added.

@zufuliu
Copy link
Owner

zufuliu commented Jan 8, 2026

The changes (changed to case sensitive search WinGet) were committed.

notepad4/src/Notepad4.cpp

Lines 6418 to 6422 in ae37bce

if (StrStr(tchModule, L"WinGet") != nullptr || StrStr(tchModule, L"Chocolatey") != nullptr) {
// %LOCALAPPDATA%\Microsoft\WinGet\Packages
// ChocolateyInstall
portable = false;
}

Notepad4 DarkTheme.ini is still not copied, I think it can be copied at three times:

  1. on first run inside FindIniFile():

    notepad4/src/Notepad4.cpp

    Lines 6502 to 6510 in ae37bce

    if (status == IniFindStatus::Program && !finder.portable && finder.appData != nullptr) {
    // copy ini to %LOCALAPPDATA%\Notepad4
    PathCombine(tchTmp, finder.appData, WC_NOTEPAD4);
    SHCreateDirectoryEx(nullptr, tchTmp, nullptr);
    PathAppend(tchTmp, &tchTest[finder.nameIndex]);
    CopyFile(tchTest, tchTmp, TRUE);
    // always use %LOCALAPPDATA% for non-portable installation
    pszFile = tchTmp;
    }
  2. on first use inside FindExtraIniFile():

    notepad4/src/Notepad4.cpp

    Lines 6548 to 6550 in ae37bce

    if (FindUserResourcePath(defaultName, lpszIniFile)) {
    return;
    }
  3. on first save inside Style_Save():

    notepad4/src/Styles.cpp

    Lines 898 to 903 in ae37bce

    if (np2StyleTheme != StyleTheme_Default) {
    if (!CreateIniFile(themePath)) {
    NP2HeapFree(pIniSectionBuf);
    MsgBoxLastError(MB_OK, IDS_CREATEINI_FAIL);
    return;
    }

in any cases, it will become out of sync when a new scheme is added.

@zufuliu
Copy link
Owner

zufuliu commented Jan 8, 2026

I think check the parent folder with .Winget. is enough. Notepad4 is a portable package, which should always be installed to %LOCALAPPDATA%\Microsoft\WinGet\Packages.

Instead of search path for magic strings, maybe we can add a registry (e.g. HKEY_CURRENT_USER\Software\Notepad4\portable) to indicate whether current installation is portable. menu "Settings -> Advanced Settings -> Use Portable Settings" can be added to toggle the registry and copy ini files between exe folder and %LOCALAPPDATA%\Notepad4.

@zufuliu zufuliu linked an issue Jan 9, 2026 that may be closed by this pull request
zufuliu added a commit that referenced this pull request Jan 9, 2026
@zufuliu
Copy link
Owner

zufuliu commented Jan 9, 2026

I think it can be copied at three times:

Just coped (commit 99498e4) on first run that requires less code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Updating through winget is not smooth

3 participants