Modify the configuration redirection mode
The extension of https://github.com/zufuliu/notepad4/pull/1069#issuecomment-3301947767
Can we refer to the approach of Total Commander in this regard, using redirection to split the ini?
This allows for the separation of roaming configuration and local configuration.
It can also be used to control which configurations remain consistent and which ones differ in a multi-user environment.
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.
Some pseudocode
function ReadIni(filePath, section, key) {
let redirectPath = Win32ApiGetIni(filePath, section, "RedirectSection");
if (redirectPath) {
// recursion
return ReadIni(ResolvePath(redirectPath), section, key);
} else {
return Win32ApiGetIni(filePath, section, key);
}
}
function Win32ApiGetIni(filePath, section, key) {
let retVal = "";
GetPrivateProfileString(filePath, section, "", retVal, 0xFF, key);
return retVal;
}
function ResolvePath(filePath) {
let resolveedPath = filePath;
resolveedPath = resolveedPath.replace("%COMMANDER_PATH%", thisApp.exePath);
resolveedPath = Win32ApiGetFullPathName(resolveedPath);
return filePath;
}
The initial INI file can be redirected according to the following priority:
- If
.\Notepad4.iniexists, the application runs directly in portable mode. - Per-user configuration (customizable by the individual user):
[HKEY_CURRENT_USER\SOFTWARE\zufuliu\Notepad4]
IniFileName=%AppData%\zufuliu\Notepad4\Notepad4.ini
- System-wide default configuration (set by the administrator):
[HKEY_LOCAL_MACHINE\SOFTWARE\zufuliu\Notepad4]
IniFileName= %ProgramData%\zufuliu\Notepad4\Notepad4.ini
I thought that if I redirect the ini address to %OneDrive%, I would be able to sync software settings across different devices.
Redirection is already supported: https://github.com/zufuliu/notepad4/blob/7b31ae4bef0a84338e24f4fc1b08a718abd7d4e2/doc/Notepad4.ini#L1-L4