SDLPal.cpp 1.2 KB

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