SDLPal.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "pch.h"
  2. #include <wrl.h>
  3. #include <windows.h>
  4. #include "../SDLPal.Common/AsyncHelper.h"
  5. #include "../../global.h"
  6. #include "../../palcfg.h"
  7. #include "App.xaml.h"
  8. HANDLE g_eventHandle = CreateEventEx(NULL, NULL, 0, EVENT_ALL_ACCESS);
  9. int CALLBACK WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
  10. {
  11. if (FAILED(Windows::Foundation::Initialize(RO_INIT_MULTITHREADED))) {
  12. return 1;
  13. }
  14. PAL_LoadConfig(TRUE);
  15. bool last_crashed = false;
  16. try
  17. {
  18. // Check the 'running' file to determine whether the program is abnormally terminated last time.
  19. // If so, force to launch the setting page.
  20. auto file = AWait(Windows::Storage::ApplicationData::Current->LocalFolder->GetFileAsync("running"), g_eventHandle);
  21. // When there is a debugger, ignore the last crash state, as it can be recovered by the debugger.
  22. if (!IsDebuggerPresent())
  23. {
  24. gConfig.fLaunchSetting = TRUE;
  25. last_crashed = true;
  26. }
  27. AWait(file->DeleteAsync(), g_eventHandle);
  28. }
  29. catch(Platform::Exception^)
  30. { }
  31. if (gConfig.fLaunchSetting || last_crashed)
  32. {
  33. Windows::UI::Xaml::Application::Start(
  34. ref new Windows::UI::Xaml::ApplicationInitializationCallback(
  35. [last_crashed](Windows::UI::Xaml::ApplicationInitializationCallbackParams^ p) {
  36. auto app = ref new SDLPal::App();
  37. app->LastCrashed = last_crashed;
  38. }
  39. )
  40. );
  41. }
  42. else
  43. SDL_WinRTRunApp(SDL_main, NULL);
  44. return 0;
  45. }