mirror of
				https://github.com/cmderdev/cmder.git
				synced 2025-10-31 17:32:27 +08:00 
			
		
		
		
	Get USER_PROFILE differently
USER_PROFILE is a known folder, so use that functionality to get it.
This commit is contained in:
		| @@ -3,6 +3,8 @@ | ||||
| #include <Shlwapi.h> | ||||
| #include "resource.h" | ||||
| #include <vector> | ||||
| #include <Shlobj.h> | ||||
|  | ||||
|  | ||||
| #pragma comment(lib, "Shlwapi.lib") | ||||
|  | ||||
| @@ -156,13 +158,18 @@ void StartCmder(std::wstring path, bool is_single_mode) | ||||
| 	SetEnvironmentVariable(L"CMDER_ROOT", exeDir); | ||||
| 	if (!streqi(path.c_str(), L"")) | ||||
| 	{ | ||||
| 		SetEnvironmentVariable(L"CMDER_START", path.c_str()); | ||||
| 		if (!SetEnvironmentVariable(L"CMDER_START", path.c_str())) { | ||||
| 			MessageBox(NULL, _T("Error trying to set CMDER_START to given path!"), _T("Error"), MB_OK); | ||||
| 		} | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		static wchar_t buff[MAX_PATH] = { 0 }; | ||||
| 		GetEnvironmentVariable(L"USER_PROFILE", buff, MAX_PATH); | ||||
| 		SetEnvironmentVariable(L"CMDER_START", buff); | ||||
| 		wchar_t* homeProfile = 0; | ||||
| 		SHGetKnownFolderPath(FOLDERID_Profile, 0, NULL, &homeProfile); | ||||
| 		if (!SetEnvironmentVariable(L"CMDER_START", homeProfile)) { | ||||
| 			MessageBox(NULL, _T("Error trying to set CMDER_START to USER_PROFILE!"), _T("Error"), MB_OK); | ||||
| 		} | ||||
| 		CoTaskMemFree(static_cast<void*>(homeProfile)); | ||||
| 	} | ||||
| 	 | ||||
| 	// Ensure EnvironmentVariables are propagated. | ||||
| @@ -177,8 +184,10 @@ void StartCmder(std::wstring path, bool is_single_mode) | ||||
| #endif | ||||
|  | ||||
| 	PROCESS_INFORMATION pi; | ||||
|  | ||||
| 	CreateProcess(conEmuPath, args, NULL, NULL, false, 0, NULL, NULL, &si, &pi); | ||||
| 	if (!CreateProcess(conEmuPath, args, NULL, NULL, false, 0, NULL, NULL, &si, &pi)) { | ||||
| 		MessageBox(NULL, _T("Unable to create the ConEmu Process!"), _T("Error"), MB_OK); | ||||
| 		return; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| bool IsUserOnly(std::wstring opt) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user