You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.1 KiB

  1. #pragma once
  2. #ifdef _VERBOSE
  3. #pragma comment(lib, "ucrt.lib")
  4. #include <windows.h>
  5. #include <stdio.h>
  6. static HANDLE log_handle;
  7. static char buffer[8192];
  8. static wchar_t bufferW[8192];
  9. inline void init_logger()
  10. {
  11. log_handle = CreateFileA("doorstop.log", GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,
  12. NULL);
  13. }
  14. inline void free_logger()
  15. {
  16. CloseHandle(log_handle);
  17. }
  18. #define LOG(message, ...) \
  19. { \
  20. int len = _snprintf_s(buffer, sizeof(buffer)/sizeof(char), _TRUNCATE, message, __VA_ARGS__); \
  21. WriteFile(log_handle, buffer, len, NULL, NULL); \
  22. }
  23. #else
  24. inline void init_logger()
  25. {
  26. }
  27. inline void free_logger()
  28. {
  29. }
  30. #define LOG(message, ...)
  31. #endif
  32. #define ASSERT_F(test, message, ...) \
  33. if(!(test)) \
  34. { \
  35. _snwprintf_s(bufferW, sizeof(bufferW)/sizeof(wchar_t), _TRUNCATE, message, __VA_ARGS__); \
  36. MessageBoxW(NULL, bufferW, L"Doorstop: Fatal", MB_OK | MB_ICONERROR); \
  37. ExitProcess(EXIT_FAILURE); \
  38. }
  39. // A helper for cleaner error logging
  40. #define ASSERT(test, message) \
  41. if(!(test)) \
  42. { \
  43. MessageBoxW(NULL, message, L"Doorstop: Fatal", MB_OK | MB_ICONERROR); \
  44. ExitProcess(EXIT_FAILURE); \
  45. }
  46. #define ASSERT_SOFT(test, ...) \
  47. if(!(test)) \
  48. { \
  49. return __VA_ARGS__; \
  50. }