Files
vba10/App.xaml.cpp

213 lines
6.8 KiB
C++
Raw Permalink Normal View History

2015-06-06 18:17:15 +00:00
//
// App.xaml.cpp
// Implementation of the App class.
//
#include "pch.h"
#include "App.xaml.h"
2015-06-06 18:17:15 +00:00
#include "DirectXPage.xaml.h"
2015-08-02 15:48:12 +00:00
#include "EmulatorSettings.h"
#include "live_connect.h"
2015-06-06 18:17:15 +00:00
using namespace VBA10;
using namespace Platform;
using namespace Windows::ApplicationModel;
using namespace Windows::ApplicationModel::Activation;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::Storage;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Controls::Primitives;
using namespace Windows::UI::Xaml::Data;
using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Interop;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Navigation;
2015-08-02 15:48:12 +00:00
using namespace Windows::UI::ViewManagement;
2015-08-22 16:59:37 +00:00
using namespace Windows::ApplicationModel::Store;
2015-06-18 17:33:07 +00:00
ROMDatabase^ VBA10::App::ROMDB = nullptr;
2015-08-03 17:00:09 +00:00
live::live_client* VBA10::App::LiveClient = nullptr;
Platform::String^ VBA10::App::ExportFolderID = "";
2015-08-22 16:59:37 +00:00
bool VBA10::App::HasAds = true;
bool VBA10::App::IsPremium = false;
2015-06-18 17:33:07 +00:00
2015-06-06 18:17:15 +00:00
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
2015-06-18 17:33:07 +00:00
2015-06-06 18:17:15 +00:00
App::App()
{
2015-08-25 17:15:11 +00:00
//determine theme
if (EmulatorSettings::Current->Theme == 0)
this->RequestedTheme = ApplicationTheme::Light;
else if (EmulatorSettings::Current->Theme == 1)
this->RequestedTheme = ApplicationTheme::Dark;
2015-06-06 18:17:15 +00:00
InitializeComponent();
Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending);
Resuming += ref new EventHandler<Object^>(this, &App::OnResuming);
2015-06-18 17:33:07 +00:00
ROMDB = ref new ROMDatabase();
2015-08-03 17:00:09 +00:00
LiveClient = new live::live_client();
2015-06-06 18:17:15 +00:00
}
2015-08-22 16:59:37 +00:00
void App::CheckProductLicense()
{
HasAds = false;
IsPremium = true;
/* Since VBA10 is unpublished, enable all features
2015-08-22 16:59:37 +00:00
HasAds = true;
IsPremium = false;
2016-03-27 02:56:19 +00:00
#ifdef NDEBUG
2015-08-24 13:01:32 +00:00
//bool IsActive = CurrentApp::LicenseInformation->IsActive;
bool IsTrial = CurrentApp::LicenseInformation->IsTrial;
2015-08-24 13:01:32 +00:00
//auto expiredate = CurrentApp::LicenseInformation->ExpirationDate.UniversalTime;
2015-08-22 16:59:37 +00:00
2015-08-24 13:01:32 +00:00
if (CurrentApp::LicenseInformation->ProductLicenses->Lookup("noads_premium")->IsActive)
2015-08-22 16:59:37 +00:00
{
HasAds = false;
IsPremium = true;
return; //no need to check for other 2 licenses
}
2015-08-24 13:01:32 +00:00
if (CurrentApp::LicenseInformation->ProductLicenses->Lookup("removeads")->IsActive)
2015-08-22 16:59:37 +00:00
HasAds = false;
2015-08-24 13:01:32 +00:00
if (CurrentApp::LicenseInformation->ProductLicenses->Lookup("premiumfeatures")->IsActive)
2015-08-22 16:59:37 +00:00
IsPremium = true;
2016-03-27 02:56:19 +00:00
#endif
2015-08-22 16:59:37 +00:00
//revert pixel filter if not premium
if (!App::IsPremium)
{
EmulatorSettings::Current->PixelFilter = 0;
}
*/
2015-08-22 16:59:37 +00:00
}
2015-06-06 18:17:15 +00:00
/// <summary>
/// Invoked when the application is launched normally by the end user. Other entry points
/// will be used when the application is launched to open a specific file, to display
/// search results, and so forth.
/// </summary>
/// <param name="e">Details about the launch request and process.</param>
void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ e)
{
LaunchApp(e->PreviousExecutionState, nullptr);
2015-06-06 18:17:15 +00:00
}
void App::LaunchApp(ApplicationExecutionState previousState,FileActivatedEventArgs^ args)
{
2015-08-28 14:19:58 +00:00
#if _DEBUG
if (IsDebuggerPresent())
{
//DebugSettings->EnableFrameRateCounter = true;
}
#endif
2015-06-13 19:11:53 +00:00
//change minimum suze to 320 px
Windows::Foundation::Size minsize = { 320.0f, 320.0f };
2015-08-02 15:48:12 +00:00
ApplicationView::GetForCurrentView()->SetPreferredMinSize(minsize);
2015-09-04 13:36:42 +00:00
//apply theme to title bar
auto titleBar = ApplicationView::GetForCurrentView()->TitleBar;
// set up our brushes
SolidColorBrush^ bkgColor = (SolidColorBrush^)(Current->Resources->Lookup("TitleBarBackgroundThemeBrush"));
SolidColorBrush^ btnHoverColor = (SolidColorBrush^)(Current->Resources->Lookup("TitleBarButtonHoverThemeBrush"));
SolidColorBrush^ btnPressedColor = (SolidColorBrush^)(Current->Resources->Lookup("TitleBarButtonPressedThemeBrush"));
Windows::UI::Color foregroundColor = (Windows::UI::Color)(Current->Resources->Lookup("TitleBarForegroundColor"));
Windows::UI::Color inactiveForegroundColor = (Windows::UI::Color)(Current->Resources->Lookup("TitleBarInactiveForegroundColor"));
// override colors!
titleBar->BackgroundColor = bkgColor->Color;
titleBar->ForegroundColor = foregroundColor;
titleBar->ButtonBackgroundColor = bkgColor->Color;
titleBar->ButtonForegroundColor = foregroundColor;
titleBar->ButtonHoverBackgroundColor = btnHoverColor->Color;
titleBar->ButtonHoverForegroundColor = foregroundColor;
titleBar->ButtonPressedBackgroundColor = btnPressedColor->Color;
titleBar->ButtonPressedForegroundColor = foregroundColor;
titleBar->InactiveBackgroundColor = bkgColor->Color;
titleBar->InactiveForegroundColor = inactiveForegroundColor;
titleBar->ButtonInactiveBackgroundColor = bkgColor->Color;
titleBar->ButtonInactiveForegroundColor = inactiveForegroundColor;
2015-08-22 16:59:37 +00:00
//check license
CheckProductLicense();
2015-06-13 19:11:53 +00:00
App::ROMDB->Initialize().then([this, previousState, args] {
if (m_directXPage == nullptr)
{
m_directXPage = ref new DirectXPage();
}
2015-06-06 18:17:15 +00:00
if (previousState == ApplicationExecutionState::Terminated)
{
m_directXPage->LoadInternalState(ApplicationData::Current->LocalSettings->Values);
}
2015-06-06 18:17:15 +00:00
// Place the page in the current window and ensure that it is active.
Window::Current->Content = m_directXPage;
Window::Current->Activate();
//import file
if (args != nullptr)
{
m_directXPage->ImportRomFromFile(args);
}
}, task_continuation_context::use_current());
}
void App::OnFileActivated(FileActivatedEventArgs^ args)
{
LaunchApp(args->PreviousExecutionState, args);
2015-06-06 18:17:15 +00:00
}
/// <summary>
/// Invoked when application execution is being suspended. Application state is saved
/// without knowing whether the application will be terminated or resumed with the contents
/// of memory still intact.
/// </summary>
/// <param name="sender">The source of the suspend request.</param>
/// <param name="e">Details about the suspend request.</param>
void App::OnSuspending(Object^ sender, SuspendingEventArgs^ e)
{
(void) sender; // Unused parameter
auto deferral = e->SuspendingOperation->GetDeferral();
2015-06-06 18:17:15 +00:00
create_task(m_directXPage->SaveInternalState(ApplicationData::Current->LocalSettings->Values)).then([deferral]
{
deferral->Complete();
});
2015-06-06 18:17:15 +00:00
}
/// <summary>
/// Invoked when application execution is being resumed.
/// </summary>
/// <param name="sender">The source of the resume request.</param>
/// <param name="args">Details about the resume request.</param>
void App::OnResuming(Object ^sender, Object ^args)
{
(void) sender; // Unused parameter
(void) args; // Unused parameter
m_directXPage->LoadInternalState(ApplicationData::Current->LocalSettings->Values);
}