SDLPal.cpp 1.4 KB

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