| 1224 | CloseConsole(); |
| 1225 | } |
| 1226 | int OutputHandler::print(int type, const wchar_t* fmt, ...) |
| 1227 | { |
| 1228 | int ret = 0; |
| 1229 | |
| 1230 | va_list args; |
| 1231 | |
| 1232 | va_start(args, fmt); |
| 1233 | |
| 1234 | auto len = _vscwprintf(fmt, args) + 1; // _vscprintf doesn't count terminating null |
| 1235 | |
| 1236 | if (len >= 0) { |
| 1237 | |
| 1238 | if (len > static_cast<int>(m_buf.size())) { |
| 1239 | len = max(len, 1024); |
| 1240 | auto new_size = max(static_cast<int>(m_buf.size()) * 2, len); |
| 1241 | m_buf.resize(new_size); |
| 1242 | } |
| 1243 | |
| 1244 | ret = vswprintf_s(&m_buf[0], m_buf.size(), fmt, args); |
| 1245 | |
| 1246 | } else { |
| 1247 | ret = len; |
| 1248 | } |
| 1249 | |
| 1250 | va_end(args); |
| 1251 | |
| 1252 | if (ret < 1) { |
| 1253 | return ret; |
| 1254 | } |
| 1255 | |
| 1256 | wstring str; |
| 1257 | |
| 1258 | if (!m_have_console) { |
| 1259 | if (m_output_str.length() == 0) { |
| 1260 | if (type == CMD_PIPE_SUCCESS) { |
| 1261 | str = CMD_PIPE_SUCCESS_STR; |
| 1262 | } else { |
| 1263 | str = CMD_PIPE_ERROR_STR; |
| 1264 | } |
| 1265 | } |
| 1266 | } |
| 1267 | |
| 1268 | str += &m_buf[0]; |
| 1269 | |
| 1270 | if (!m_have_console) { |
| 1271 | |
| 1272 | m_output_str += str; |
| 1273 | |
| 1274 | } else { |
| 1275 | if (type == CMD_PIPE_SUCCESS) { |
| 1276 | fwprintf(stdout, L"%s", str.c_str()); |
| 1277 | } else { |
| 1278 | fwprintf(stderr, L"%s", str.c_str()); |
| 1279 | } |
| 1280 | } |
| 1281 | |
| 1282 | return ret; |
| 1283 | } |
no test coverage detected