mirror of
https://github.com/cmderdev/cmder.git
synced 2025-06-13 13:17:55 +08:00
## Rename user-profile.* user_profile.* to resolve #1806, #1675 * This is a backward compatible fix and will automatically and silently rename users '%cmder_root%/config/user-profile.\*' to '%cmder_root%/config/user_profile.\*' and '[user_specified_config_root]/user-profile.\*' to '[user_specified_config_root]/user_profile.\*' if the sources exist. * Cmder.exe does this for cmd.exe sessions. * The init scripts for bash and Powershell handles it for these shells
This commit is contained in:
committed by
Benjamin Staneck
parent
e4fb0d694b
commit
49da3745bc
@ -9,6 +9,7 @@
|
||||
#include <iostream>
|
||||
|
||||
#pragma comment(lib, "Shlwapi.lib")
|
||||
#pragma warning( disable : 4091 )
|
||||
|
||||
#ifndef UNICODE
|
||||
#error "Must be compiled with unicode support."
|
||||
@ -85,6 +86,8 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
|
||||
wchar_t userConfigDirPath[MAX_PATH] = { 0 };
|
||||
wchar_t userBinDirPath[MAX_PATH] = { 0 };
|
||||
wchar_t userProfiledDirPath[MAX_PATH] = { 0 };
|
||||
wchar_t userProfilePath[MAX_PATH] = { 0 };
|
||||
wchar_t legacyUserProfilePath[MAX_PATH] = { 0 };
|
||||
wchar_t args[MAX_PATH * 2 + 256] = { 0 };
|
||||
|
||||
std::wstring cmderStart = path;
|
||||
@ -104,6 +107,21 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
|
||||
PathCombine(icoPath, exeDir, L"icons\\cmder.ico");
|
||||
|
||||
PathCombine(configDirPath, exeDir, L"config");
|
||||
|
||||
PathCombine(legacyUserProfilePath, configDirPath, L"user-profile.cmd");
|
||||
if (PathFileExists(legacyUserProfilePath)) {
|
||||
PathCombine(userProfilePath, configDirPath, L"user_profile.cmd");
|
||||
|
||||
char *lPr = (char *)malloc(MAX_PATH);
|
||||
char *pR = (char *)malloc(MAX_PATH);
|
||||
size_t i;
|
||||
wcstombs_s(&i, lPr, (size_t)MAX_PATH,
|
||||
legacyUserProfilePath, (size_t)MAX_PATH);
|
||||
wcstombs_s(&i, pR, (size_t)MAX_PATH,
|
||||
userProfilePath, (size_t)MAX_PATH);
|
||||
rename(lPr, pR);
|
||||
}
|
||||
|
||||
if (wcscmp(userConfigDirPath, L"") == 0)
|
||||
{
|
||||
PathCombine(userConfigDirPath, exeDir, L"config");
|
||||
@ -118,6 +136,20 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
|
||||
|
||||
PathCombine(userProfiledDirPath, userConfigDirPath, L"profile.d");
|
||||
SHCreateDirectoryEx(0, userProfiledDirPath, 0);
|
||||
|
||||
PathCombine(legacyUserProfilePath, userConfigDirPath, L"user-profile.cmd");
|
||||
if (PathFileExists(legacyUserProfilePath)) {
|
||||
PathCombine(userProfilePath, userConfigDirPath, L"user_profile.cmd");
|
||||
|
||||
char *lPr = (char *)malloc(MAX_PATH);
|
||||
char *pR = (char *)malloc(MAX_PATH);
|
||||
size_t i;
|
||||
wcstombs_s(&i, lPr, (size_t)MAX_PATH,
|
||||
legacyUserProfilePath, (size_t)MAX_PATH);
|
||||
wcstombs_s(&i, pR, (size_t)MAX_PATH,
|
||||
userProfilePath, (size_t)MAX_PATH);
|
||||
rename(lPr, pR);
|
||||
}
|
||||
}
|
||||
|
||||
// Set path to vendored ConEmu config file
|
||||
@ -131,7 +163,6 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
|
||||
ExpandEnvironmentStrings(cpuCfgPath, cpuCfgPath, sizeof(cpuCfgPath) / sizeof(cpuCfgPath[0]));
|
||||
|
||||
PathCombine(userCfgPath, userConfigDirPath, L"user-ConEmu.xml");
|
||||
|
||||
if (PathFileExists(cpuCfgPath)) {
|
||||
if (PathFileExists(cfgPath)) {
|
||||
if (!CopyFile(cfgPath, cpuCfgPath, FALSE))
|
||||
|
Reference in New Issue
Block a user