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. #pragma comment(lib, "ucrt.lib")
  3. #include <windows.h>
  4. #include <stdio.h>
  5. #ifdef _VERBOSE
  6. static HANDLE log_handle;
  7. static char buffer[8192];
  8. inline void init_logger()
  9. {
  10. log_handle = CreateFileA("doorstop.log", GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,
  11. NULL);
  12. }
  13. inline void free_logger()
  14. {
  15. CloseHandle(log_handle);
  16. }
  17. #define LOG(message, ...) \
  18. { \
  19. int len = _snprintf_s(buffer, sizeof(buffer)/sizeof(char), _TRUNCATE, message, __VA_ARGS__); \
  20. WriteFile(log_handle, buffer, len, NULL, NULL); \
  21. }
  22. #else
  23. inline void init_logger()
  24. {
  25. }
  26. inline void free_logger()
  27. {
  28. }
  29. #define LOG(message, ...)
  30. #endif
  31. static wchar_t bufferW[8192];
  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. }