diff --git a/App.xaml.cpp b/App.xaml.cpp index 714dc9e..2594d0e 100644 --- a/App.xaml.cpp +++ b/App.xaml.cpp @@ -58,32 +58,36 @@ void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEvent Windows::Foundation::Size minsize = { 320.0f, 320.0f }; Windows::UI::ViewManagement::ApplicationView::GetForCurrentView()->SetPreferredMinSize(minsize); - if (m_directXPage == nullptr) - { - m_directXPage = ref new DirectXPage(); - } + App::ROMDB->Initialize().then([this, e] { + if (m_directXPage == nullptr) + { + m_directXPage = ref new DirectXPage(); + } - // Create a AppShell to act as the navigation context and navigate to the first page - //auto shell = ref new AppShell(); + // Create a AppShell to act as the navigation context and navigate to the first page + //auto shell = ref new AppShell(); - //if (shell->AppFrame->Content == nullptr) - //{ - // // When the navigation stack isn't restored navigate to the first page, - // // suppressing the initial entrance animation and configuring the new - // // page by passing required information as a navigation parameter - // //shell->AppFrame->Navigate(TypeName(Views::LandingPage::typeid), e->Arguments, ref new Windows::UI::Xaml::Media::Animation::SuppressNavigationTransitionInfo()); - //} + //if (shell->AppFrame->Content == nullptr) + //{ + // // When the navigation stack isn't restored navigate to the first page, + // // suppressing the initial entrance animation and configuring the new + // // page by passing required information as a navigation parameter + // //shell->AppFrame->Navigate(TypeName(Views::LandingPage::typeid), e->Arguments, ref new Windows::UI::Xaml::Media::Animation::SuppressNavigationTransitionInfo()); + //} - if (e->PreviousExecutionState == ApplicationExecutionState::Terminated) - { - m_directXPage->LoadInternalState(ApplicationData::Current->LocalSettings->Values); - } + if (e->PreviousExecutionState == ApplicationExecutionState::Terminated) + { + m_directXPage->LoadInternalState(ApplicationData::Current->LocalSettings->Values); + } - // Place the page in the current window and ensure that it is active. - Window::Current->Content = m_directXPage; - Window::Current->Activate(); + // Place the page in the current window and ensure that it is active. + + Window::Current->Content = m_directXPage; + Window::Current->Activate(); + }); + } /// diff --git a/DirectXPage.xaml.cpp b/DirectXPage.xaml.cpp index 1b35555..b69e137 100644 --- a/DirectXPage.xaml.cpp +++ b/DirectXPage.xaml.cpp @@ -187,40 +187,33 @@ DirectXPage::DirectXPage(): //DL: modified to not do it autmatically //m_main->StartRenderLoop(); - //open the database - App::ROMDB->Initialize().then([this, settings] - { - if (!settings->HasKey("FIRSTSTART")) - { - settings->Insert("FIRSTSTART", dynamic_cast(PropertyValue::CreateBoolean(false))); - - //copy DEMO ROm then open menu - return CopyDemoROM(); - } - else - return create_task([] {}); - //}).then([this] - //{ - //test insert ROM - //ROMDBEntry^ entry = ref new ROMDBEntry(0, "Test game", "testgame.gba", "D:\\ROM"); - //return App::ROMDB->Add(entry); - //test obtain ROM - //auto entry = App::ROMDB->AllROMDBEntries->GetAt(1); - - - - }).then([this] + // create_task([this] {return CopyDemoROMAsync();}).then([this] //NOTE: this will make CopyDemoROM to run on background thread + //and cause exception at entry->Snapshot->SetSourceAsync(stream); + + CopyDemoROMAsync().then([this] //NOTE: this let CopyDemonROM to run on UI thread { - //open menu - RootSplitView->IsPaneOpen = true; + //open menu, need dispatcher to move it to UI thread, otherwise exception + this->Dispatcher->RunAsync(CoreDispatcherPriority::Normal, ref new DispatchedHandler([this]() + { + RootSplitView->IsPaneOpen = true; + })); + }); } -task DirectXPage::CopyDemoROM(void) +task DirectXPage::CopyDemoROMAsync(void) { + auto settings = ApplicationData::Current->LocalSettings->Values; + + if (settings->HasKey("FIRSTSTART")) + return create_task([] {}); + + + + settings->Insert("FIRSTSTART", dynamic_cast(PropertyValue::CreateBoolean(false))); StorageFolder ^installDir = Windows::ApplicationModel::Package::Current->InstalledLocation; return create_task(installDir->GetFolderAsync("Assets/")) diff --git a/DirectXPage.xaml.h b/DirectXPage.xaml.h index 7d67aa8..7df0082 100644 --- a/DirectXPage.xaml.h +++ b/DirectXPage.xaml.h @@ -91,7 +91,7 @@ namespace VBA10 StorageFolder^ tmpfolder; //function - task CopyDemoROM(void); + task CopyDemoROMAsync(void); // XAML low-level rendering event handler.