| 1055 | } |
| 1056 | |
| 1057 | bool CConEmuMain::SetConfigFile(LPCWSTR asFilePath, bool abWriteReq /*= false*/, bool abSpecialPath /*= false*/) |
| 1058 | { |
| 1059 | LPCWSTR pszExt = asFilePath ? PointToExt(asFilePath) : nullptr; |
| 1060 | int nLen = asFilePath ? lstrlen(asFilePath) : 0; |
| 1061 | |
| 1062 | if (!asFilePath || !*asFilePath) |
| 1063 | { |
| 1064 | DisplayLastError(L"Empty file path specified in CConEmuMain::SetConfigFile", -1); |
| 1065 | return false; |
| 1066 | } |
| 1067 | |
| 1068 | if (!asFilePath || !*asFilePath || !pszExt || !*pszExt || (nLen > MAX_PATH)) |
| 1069 | { |
| 1070 | CEStr lsMsg( |
| 1071 | L"Invalid file path specified in CConEmuMain::SetConfigFile", |
| 1072 | L"\n", L"asFilePath=`", asFilePath, L"`", |
| 1073 | L"\n", L"Only *.xml files are allowed"); |
| 1074 | DisplayLastError(lsMsg, -1); |
| 1075 | return false; |
| 1076 | } |
| 1077 | |
| 1078 | CEStr szPath; |
| 1079 | int nFileType = 0; |
| 1080 | |
| 1081 | if (lstrcmpi(pszExt, L".ini") == 0) |
| 1082 | { |
| 1083 | nFileType = 1; |
| 1084 | } |
| 1085 | else if (lstrcmpi(pszExt, L".xml") == 0) |
| 1086 | { |
| 1087 | nFileType = 0; |
| 1088 | } |
| 1089 | else |
| 1090 | { |
| 1091 | DisplayLastError(L"Unsupported file extension specified in CConEmuMain::SetConfigFile", -1); |
| 1092 | return false; |
| 1093 | } |
| 1094 | |
| 1095 | |
| 1096 | //The path must be already in full form, call apiGetFullPathName just for ensure (but it may return wrong path) |
| 1097 | _ASSERTE((asFilePath[1]==L':' && asFilePath[2]==L'\\') || (asFilePath[0]==L'\\' && asFilePath[1]==L'\\')); |
| 1098 | nLen = apiGetFullPathName(asFilePath, szPath); |
| 1099 | if (!nLen || (nLen >= MAX_PATH)) |
| 1100 | { |
| 1101 | DisplayLastError(L"Failed to expand specified file path in CConEmuMain::SetConfigFile"); |
| 1102 | return false; |
| 1103 | } |
| 1104 | |
| 1105 | LPCWSTR pszFilePath = PointToName(szPath); |
| 1106 | if (!pszFilePath || (pszFilePath == szPath.ms_Val)) |
| 1107 | { |
| 1108 | DisplayLastError(L"Invalid file path specified in CConEmuMain::SetConfigFile (backslash not found)", -1); |
| 1109 | return false; |
| 1110 | } |
| 1111 | |
| 1112 | |
| 1113 | // Create the folder if it's absent |
| 1114 | // Function accepts paths with trailing file names |
no test coverage detected