-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathApp.xaml.cpp
212 lines (171 loc) · 6.81 KB
/
App.xaml.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
//
// App.xaml.cpp
// Implementation of the App class.
//
#include "pch.h"
#include "App.xaml.h"
#include "DirectXPage.xaml.h"
#include "EmulatorSettings.h"
#include "live_connect.h"
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;
using namespace Windows::UI::ViewManagement;
using namespace Windows::ApplicationModel::Store;
ROMDatabase^ VBA10::App::ROMDB = nullptr;
live::live_client* VBA10::App::LiveClient = nullptr;
Platform::String^ VBA10::App::ExportFolderID = "";
bool VBA10::App::HasAds = true;
bool VBA10::App::IsPremium = false;
/// <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>
App::App()
{
//determine theme
if (EmulatorSettings::Current->Theme == 0)
this->RequestedTheme = ApplicationTheme::Light;
else if (EmulatorSettings::Current->Theme == 1)
this->RequestedTheme = ApplicationTheme::Dark;
InitializeComponent();
Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending);
Resuming += ref new EventHandler<Object^>(this, &App::OnResuming);
ROMDB = ref new ROMDatabase();
LiveClient = new live::live_client();
}
void App::CheckProductLicense()
{
HasAds = false;
IsPremium = true;
/* Since VBA10 is unpublished, enable all features
HasAds = true;
IsPremium = false;
#ifdef NDEBUG
//bool IsActive = CurrentApp::LicenseInformation->IsActive;
bool IsTrial = CurrentApp::LicenseInformation->IsTrial;
//auto expiredate = CurrentApp::LicenseInformation->ExpirationDate.UniversalTime;
if (CurrentApp::LicenseInformation->ProductLicenses->Lookup("noads_premium")->IsActive)
{
HasAds = false;
IsPremium = true;
return; //no need to check for other 2 licenses
}
if (CurrentApp::LicenseInformation->ProductLicenses->Lookup("removeads")->IsActive)
HasAds = false;
if (CurrentApp::LicenseInformation->ProductLicenses->Lookup("premiumfeatures")->IsActive)
IsPremium = true;
#endif
//revert pixel filter if not premium
if (!App::IsPremium)
{
EmulatorSettings::Current->PixelFilter = 0;
}
*/
}
/// <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);
}
void App::LaunchApp(ApplicationExecutionState previousState,FileActivatedEventArgs^ args)
{
#if _DEBUG
if (IsDebuggerPresent())
{
//DebugSettings->EnableFrameRateCounter = true;
}
#endif
//change minimum suze to 320 px
Windows::Foundation::Size minsize = { 320.0f, 320.0f };
ApplicationView::GetForCurrentView()->SetPreferredMinSize(minsize);
//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;
//check license
CheckProductLicense();
App::ROMDB->Initialize().then([this, previousState, args] {
if (m_directXPage == nullptr)
{
m_directXPage = ref new DirectXPage();
}
if (previousState == 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();
//import file
if (args != nullptr)
{
m_directXPage->ImportRomFromFile(args);
}
}, task_continuation_context::use_current());
}
void App::OnFileActivated(FileActivatedEventArgs^ args)
{
LaunchApp(args->PreviousExecutionState, args);
}
/// <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();
create_task(m_directXPage->SaveInternalState(ApplicationData::Current->LocalSettings->Values)).then([deferral]
{
deferral->Complete();
});
}
/// <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);
}