|
42 | 42 | #include <iostream> |
43 | 43 | #include <thread> |
44 | 44 |
|
| 45 | +#ifdef _WIN32 |
| 46 | +#include <dbghelp.h> |
| 47 | +#include <shellapi.h> |
| 48 | +#include <shlobj.h> |
| 49 | +#include <Strsafe.h> |
| 50 | +#endif |
| 51 | + |
45 | 52 | #include <primitives/log.h> |
46 | 53 | DECLARE_STATIC_LOGGER(logger, "main"); |
47 | 54 |
|
|
324 | 331 | std::cout << c.getDefaultProject().print_cpp(); |
325 | 332 | return 0; |
326 | 333 | } |
| 334 | + if (options().count("print-cpp2")) |
| 335 | + { |
| 336 | + auto pkg = extractFromString(options["print-cpp2"].as<String>()); |
| 337 | + Config c(pkg.getDirSrc()); |
| 338 | + c.getDefaultProject().pkg = pkg; |
| 339 | + std::cout << c.getDefaultProject().print_cpp2(); |
| 340 | + return 0; |
| 341 | + } |
327 | 342 |
|
328 | 343 | Settings::get_user_settings().force_server_query = options()[SERVER_QUERY].as<bool>(); |
329 | 344 |
|
|
382 | 397 | Config c; |
383 | 398 | c.load_current_config(); |
384 | 399 | Projects &projects = c.getProjects(); |
385 | | - const auto cwd = fs::current_path(); |
| 400 | + const auto cwd = ::current_path(); |
386 | 401 | for (auto &ps : projects) |
387 | 402 | { |
388 | 403 | auto &project = ps.second; |
|
392 | 407 | { |
393 | 408 | p = t / fs::unique_path(); |
394 | 409 | fs::create_directories(p); |
395 | | - fs::current_path(p); |
| 410 | + ::current_path(p); |
396 | 411 |
|
397 | 412 | if (!isValidSourceUrl(project.source)) |
398 | 413 | throw std::runtime_error("Source is empty"); |
|
404 | 419 | { |
405 | 420 | if (par) |
406 | 421 | { |
407 | | - fs::current_path(cwd); |
| 422 | + ::current_path(cwd); |
408 | 423 | remove_all_from_dir(p); |
409 | 424 | } |
410 | 425 | }; |
@@ -433,16 +448,65 @@ catch (...) |
433 | 448 | return 1; |
434 | 449 | } |
435 | 450 |
|
| 451 | +#ifdef _WIN32 |
| 452 | +int GenerateDump(EXCEPTION_POINTERS* pExceptionPointers) |
| 453 | +{ |
| 454 | + BOOL bMiniDumpSuccessful; |
| 455 | + WCHAR szPath[MAX_PATH]; |
| 456 | + WCHAR szFileName[MAX_PATH]; |
| 457 | + WCHAR* szAppName = L"cppan\\dump"; |
| 458 | + DWORD dwBufferSize = MAX_PATH; |
| 459 | + HANDLE hDumpFile; |
| 460 | + SYSTEMTIME stLocalTime; |
| 461 | + MINIDUMP_EXCEPTION_INFORMATION ExpParam; |
| 462 | + |
| 463 | + GetLocalTime(&stLocalTime); |
| 464 | + GetTempPath(dwBufferSize, szPath); |
| 465 | + |
| 466 | + StringCchPrintf(szFileName, MAX_PATH, L"%s%s", szPath, szAppName); |
| 467 | + CreateDirectory(szFileName, NULL); |
| 468 | + |
| 469 | + StringCchPrintf(szFileName, MAX_PATH, L"%s%s\\%d.%d.%d-%04d%02d%02d-%02d%02d%02d-%ld-%ld.dmp", |
| 470 | + szPath, szAppName, VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, |
| 471 | + stLocalTime.wYear, stLocalTime.wMonth, stLocalTime.wDay, |
| 472 | + stLocalTime.wHour, stLocalTime.wMinute, stLocalTime.wSecond, |
| 473 | + GetCurrentProcessId(), GetCurrentThreadId()); |
| 474 | + hDumpFile = CreateFile(szFileName, GENERIC_READ | GENERIC_WRITE, |
| 475 | + FILE_SHARE_WRITE | FILE_SHARE_READ, 0, CREATE_ALWAYS, 0, 0); |
| 476 | + |
| 477 | + ExpParam.ThreadId = GetCurrentThreadId(); |
| 478 | + ExpParam.ExceptionPointers = pExceptionPointers; |
| 479 | + ExpParam.ClientPointers = TRUE; |
| 480 | + |
| 481 | + bMiniDumpSuccessful = MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), |
| 482 | + hDumpFile, MiniDumpWithDataSegs, &ExpParam, NULL, NULL); |
| 483 | + |
| 484 | + return EXCEPTION_EXECUTE_HANDLER; |
| 485 | +} |
| 486 | +#endif |
| 487 | + |
436 | 488 | int main(int argc, char *argv[]) |
437 | 489 | { |
438 | | - auto r = main1(argc, argv); |
439 | | - return r; |
| 490 | +#ifndef _WIN32 |
| 491 | + auto r = main1(argc, argv); |
| 492 | + return r; |
| 493 | +#else |
| 494 | + __try |
| 495 | + { |
| 496 | + auto r = main1(argc, argv); |
| 497 | + return r; |
| 498 | + } |
| 499 | + __except (GenerateDump(GetExceptionInformation())) |
| 500 | + { |
| 501 | + return 1; |
| 502 | + } |
| 503 | +#endif |
440 | 504 | } |
441 | 505 |
|
442 | 506 | void check_spec_file() |
443 | 507 | { |
444 | 508 | // no config - cannot do anything more |
445 | | - if (!fs::exists(CPPAN_FILENAME)) |
| 509 | + if (!fs::exists(::current_path() / CPPAN_FILENAME)) |
446 | 510 | throw std::runtime_error("No spec file found"); |
447 | 511 | } |
448 | 512 |
|
|
0 commit comments