diff --git a/App.xaml.cpp b/App.xaml.cpp
index ba3c486..0937128 100644
--- a/App.xaml.cpp
+++ b/App.xaml.cpp
@@ -88,13 +88,13 @@ void App::CheckProductLicense()
/// Details about the launch request and process.
void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ e)
{
-#if _DEBUG
- if (IsDebuggerPresent())
- {
- //DebugSettings->EnableFrameRateCounter = true;
- }
-#endif
+ LaunchApp(e->PreviousExecutionState, nullptr);
+
+}
+
+void App::LaunchApp(ApplicationExecutionState previousState,FileActivatedEventArgs^ args)
+{
//change minimum suze to 320 px
Windows::Foundation::Size minsize = { 320.0f, 320.0f };
ApplicationView::GetForCurrentView()->SetPreferredMinSize(minsize);
@@ -102,36 +102,36 @@ void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEvent
//check license
CheckProductLicense();
- App::ROMDB->Initialize().then([this, e] {
+ App::ROMDB->Initialize().then([this, previousState, args] {
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();
-
- //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)
+ 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);
+
+
+
}
///
diff --git a/App.xaml.h b/App.xaml.h
index 8293b59..b1fbe55 100644
--- a/App.xaml.h
+++ b/App.xaml.h
@@ -30,11 +30,16 @@ namespace VBA10
static bool IsPremium;
static void CheckProductLicense();
+ protected:
+ virtual void OnFileActivated(Windows::ApplicationModel::Activation::FileActivatedEventArgs^ args) override;
private:
void OnSuspending(Platform::Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ e);
void OnResuming(Platform::Object ^sender, Platform::Object ^args);
+ void LaunchApp(Windows::ApplicationModel::Activation::ApplicationExecutionState previousState,
+ Windows::ApplicationModel::Activation::FileActivatedEventArgs^ args);
+
DirectXPage^ m_directXPage;
diff --git a/Database/ROMDatabase.cpp b/Database/ROMDatabase.cpp
index ba13f88..134d5e3 100644
--- a/Database/ROMDatabase.cpp
+++ b/Database/ROMDatabase.cpp
@@ -25,64 +25,67 @@ using namespace VBA10;
-ROMDatabase::ROMDatabase()
+ROMDatabase::ROMDatabase() : initialized(false)
{
}
task ROMDatabase::Initialize(void)
{
-
- return create_task(Windows::Storage::ApplicationData::Current->LocalFolder->CreateFileAsync(ROMDB_FILE_NAME, CreationCollisionOption::OpenIfExists))
+ if (initialized)
+ return create_task([] {});
+ else
+ return create_task(Windows::Storage::ApplicationData::Current->LocalFolder->CreateFileAsync(ROMDB_FILE_NAME, CreationCollisionOption::OpenIfExists))
.then([this](StorageFile^ file)
- {
- db = ref new SQLiteWinRT::Database(file);
+ {
+ db = ref new SQLiteWinRT::Database(file);
- //open database
- return db->OpenAsync(SQLiteWinRT::SqliteOpenMode::OpenReadWrite);
+ //open database
+ return db->OpenAsync(SQLiteWinRT::SqliteOpenMode::OpenReadWrite);
- }).then([this]
- {
- //create table if not exist
- return db->ExecuteStatementAsync("CREATE TABLE IF NOT EXISTS ROMTABLE ( "\
- "LOCATIONTYPE INT NOT NULL,"\
- "DISPLAYNAME TEXT NOT NULL,"\
- "FILENAME TEXT NOT NULL,"\
- "FOLDERPATH TEXT NOT NULL,"\
- "TOKEN TEXT NOT NULL,"\
- "LASTPLAYED INT NOT NULL,"\
- "LASTSAVEINDEX INT NOT NULL, "\
- "AUTOSAVEINDEX INT NOT NULL, "\
- "SNAPSHOTURI TEXT NOT NULL );");
- }).then([this]
- {
- return db->PrepareStatementAsync("SELECT * FROM ROMTABLE ORDER BY DISPLAYNAME ASC;");
+ }).then([this]
+ {
+ //create table if not exist
+ return db->ExecuteStatementAsync("CREATE TABLE IF NOT EXISTS ROMTABLE ( "\
+ "LOCATIONTYPE INT NOT NULL,"\
+ "DISPLAYNAME TEXT NOT NULL,"\
+ "FILENAME TEXT NOT NULL,"\
+ "FOLDERPATH TEXT NOT NULL,"\
+ "TOKEN TEXT NOT NULL,"\
+ "LASTPLAYED INT NOT NULL,"\
+ "LASTSAVEINDEX INT NOT NULL, "\
+ "AUTOSAVEINDEX INT NOT NULL, "\
+ "SNAPSHOTURI TEXT NOT NULL );");
+ }).then([this]
+ {
+ return db->PrepareStatementAsync("SELECT * FROM ROMTABLE ORDER BY DISPLAYNAME ASC;");
- }).then([this](SQLiteWinRT::Statement^ stmt)
- {
- statement = stmt;
- return RetrieveQuerry();
+ }).then([this](SQLiteWinRT::Statement^ stmt)
+ {
+ statement = stmt;
+ return RetrieveQuerry();
- }).then([this] (Vector^ ret)
- {
- _allROMDBEntries = ret;
+ }).then([this] (Vector^ ret)
+ {
+ _allROMDBEntries = ret;
- //load rom entry
- return LoadSnapshotImage();
- }).then([this](task t)
- {
- //check to see if any entry failed to load (due to deleted folder)
- for (int i = 0; i < _allROMDBEntries->Size; i++)
+ //load rom entry
+ return LoadSnapshotImage();
+ }).then([this](task t)
{
- auto entry = _allROMDBEntries->GetAt(i);
- if (!entry->Folder)
+ //check to see if any entry failed to load (due to deleted folder)
+ for (int i = 0; i < _allROMDBEntries->Size; i++)
{
- _allROMDBEntries->RemoveAt(i);
- i--;
+ auto entry = _allROMDBEntries->GetAt(i);
+ if (!entry->Folder)
+ {
+ _allROMDBEntries->RemoveAt(i);
+ i--;
+ }
}
- }
- return t.get();
- });
+ initialized = true;
+ return t.get();
+ });
diff --git a/Database/ROMDatabase.h b/Database/ROMDatabase.h
index 080b8d6..294a7b6 100644
--- a/Database/ROMDatabase.h
+++ b/Database/ROMDatabase.h
@@ -53,6 +53,7 @@ namespace VBA10
PC::Vector^ _allROMDBEntries;
task LoadSnapshotImage();
Platform::String^ ReplaceSingleQuote(Platform::String^ pstr);
+ bool initialized;
};
diff --git a/DirectXPage.xaml b/DirectXPage.xaml
index 917a5ba..a638a73 100644
--- a/DirectXPage.xaml
+++ b/DirectXPage.xaml
@@ -103,7 +103,7 @@
-
+
diff --git a/DirectXPage.xaml.cpp b/DirectXPage.xaml.cpp
index 184b4ab..ce10651 100644
--- a/DirectXPage.xaml.cpp
+++ b/DirectXPage.xaml.cpp
@@ -50,6 +50,7 @@ using namespace Windows::UI::ViewManagement;
using namespace Windows::Graphics::Imaging;
using namespace Windows::Globalization; //to get date time
using namespace Windows::System::Display;
+using namespace Windows::ApplicationModel::Activation;
using namespace std;
@@ -61,10 +62,6 @@ using namespace VBA10::Controls;
DirectXPage^ DirectXPage::_current;
-Frame^ DirectXPage::AppFrame::get()
-{
- return frame;
-}
DirectXPage::DirectXPage():
m_windowVisible(true),
@@ -229,17 +226,18 @@ DirectXPage::DirectXPage():
CopyDemoROMAsync()
.then([this] //NOTE: this let CopyDemonROM to run on UI thread
{
- //open menu, need dispatcher to move it to UI thread, otherwise exception
- this->Dispatcher->RunAsync(CoreDispatcherPriority::Normal, ref new DispatchedHandler([this]()
- {
- RootSplitView->IsPaneOpen = true;
- }));
+ RootSplitView->IsPaneOpen = true;
- });
+ }, task_continuation_context::use_current());
}
+
+void DirectXPage::OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e)
+{
+}
+
void DirectXPage::OnHardwareBackButtonPressed(Platform::Object^ sender,
Windows::Phone::UI::Input::BackPressedEventArgs ^args )
{
@@ -890,4 +888,30 @@ task DirectXPage::UpdateDBEntry()
}
+void DirectXPage::ImportRomFromFile(FileActivatedEventArgs^ args)
+{
+ StorageFile^ file = (StorageFile^)(args->Files->GetAt(0));
+
+ //calculate folder path and snapshot name
+ Platform::String ^file_path = file->Path;
+ wstring wfilepath(file_path->Begin(), file_path->End());
+ wstring folderpath;
+ wstring filename;
+ wstring filenamenoext;
+ wstring ext;
+ splitFilePath(wfilepath, folderpath, filename, filenamenoext, ext);
+
+ wstring snapshotname = filenamenoext + L".jpg";
+ Platform::String^ psnapshotname = ref new Platform::String(snapshotname.c_str());
+ Platform::String^ pfilenamenoext = ref new Platform::String(filenamenoext.c_str());
+
+ //calculate token
+ replace(folderpath.begin(), folderpath.end(), ':', '_');
+ replace(folderpath.begin(), folderpath.end(), '/', '_');
+ replace(folderpath.begin(), folderpath.end(), '\\', '_');
+ Platform::String^ ptoken = ref new Platform::String(folderpath.c_str());
+
+
+
+}
diff --git a/DirectXPage.xaml.h b/DirectXPage.xaml.h
index 6de352c..77f7fff 100644
--- a/DirectXPage.xaml.h
+++ b/DirectXPage.xaml.h
@@ -37,13 +37,16 @@ namespace VBA10
DirectXPage();
virtual ~DirectXPage();
-
+
void LoadInternalState(Windows::Foundation::Collections::IPropertySet^ state);
//from AppShell
property Windows::UI::Xaml::Controls::Frame^ AppFrame
{
- Windows::UI::Xaml::Controls::Frame^ get();
+ Windows::UI::Xaml::Controls::Frame^ get()
+ {
+ return this->contentFrame; //contentFrame is defined in xaml
+ };
}
void GoToPage(int pageindex);
@@ -52,10 +55,10 @@ namespace VBA10
void LoadState();
void Reset();
void SelectSaveState(int slot);
-
-
- //from AppShell
+
+
+ //from AppShell
internal:
static property DirectXPage^ Current
@@ -73,7 +76,12 @@ namespace VBA10
task SaveSnapshot();
task UpdateDBEntry();
task SaveBeforeStop();
+ void ImportRomFromFile(Windows::ApplicationModel::Activation::FileActivatedEventArgs^ args);
+
+ protected:
+ virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
+
private:
//variables
bool loadingDialogOpen;
@@ -82,7 +90,7 @@ namespace VBA10
//function
task CopyDemoROMAsync(void);
-
+
// XAML low-level rendering event handler.
void OnRendering(Platform::Object^ sender, Platform::Object^ args);
@@ -110,7 +118,7 @@ namespace VBA10
Windows::Foundation::EventRegistrationToken m_eventToken;
//back button
- void OnHardwareBackButtonPressed(Platform::Object^ sender, Windows::Phone::UI::Input::BackPressedEventArgs ^args);
+ void OnHardwareBackButtonPressed(Platform::Object^ sender, Windows::Phone::UI::Input::BackPressedEventArgs ^args);
// Independent input handling functions.
void OnPointerPressed(CoreWindow ^window, PointerEventArgs ^args);
@@ -119,7 +127,7 @@ namespace VBA10
// Resources used to render the DirectX content in the XAML page background.
std::shared_ptr m_deviceResources;
- std::unique_ptr m_main;
+ std::unique_ptr m_main;
bool m_windowVisible;
//from AppShell
@@ -132,10 +140,11 @@ namespace VBA10
static DirectXPage^ _current;
Windows::System::Display::DisplayRequest^ g_DisplayRequest;
-
+
+
void TogglePaneButton_UnChecked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void TogglePaneButton_Checked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void CloseMenu();
-};
+ };
}
diff --git a/EmulatorFileHandler.cpp b/EmulatorFileHandler.cpp
index 1d4bda3..4849707 100644
--- a/EmulatorFileHandler.cpp
+++ b/EmulatorFileHandler.cpp
@@ -139,10 +139,10 @@ namespace VBA10
task ParseVBAIniAsync()
{
- //if(iniParsed)
- //{
- // return create_task([](){}); //this will make make the operation continue on another thread!!!!
- //}
+ if(iniParsed)
+ {
+ return create_task([](){}); //this will launch on another thread!!!
+ }
auto reader = make_shared();
@@ -412,7 +412,7 @@ namespace VBA10
return ParseVBAIniAsync().then([emulator]()
{
return emulator->StopROMAsync();
- }).then([file]()
+ }, task_continuation_context::use_current()).then([file]()
{
return GetBytesFromFileAsync(file);
})
diff --git a/ImportPage.xaml.cpp b/ImportPage.xaml.cpp
index db99838..355d4d6 100644
--- a/ImportPage.xaml.cpp
+++ b/ImportPage.xaml.cpp
@@ -140,18 +140,32 @@ void ImportPage::chooseFolderbtn_Click(Platform::Object^ sender, Windows::UI::Xa
Platform::String^ pfilenamenoext = ref new Platform::String(filenamenoext.c_str());
- //create rom entry
- ROMDBEntry^ entry = ref new ROMDBEntry(1, pfilenamenoext, file->Name, (*tmpfolder)->Path,
- *tmptoken, psnapshotname);
+ //create rom entry or just return the original
+ bool exist = false;
+ ROMDBEntry^ entry = nullptr;
+ for (int j = 0; j < App::ROMDB->AllROMDBEntries->Size; j++)
+ {
+ entry = App::ROMDB->AllROMDBEntries->GetAt(j);
+ if (entry->FileName == file->Name && entry->Token == *tmptoken)
+ {
+ exist = true;
+ break;
+ }
+ }
+
+ if (!exist)
+ {
+ entry = ref new ROMDBEntry(1, pfilenamenoext, file->Name, (*tmpfolder)->Path,
+ *tmptoken, psnapshotname);
- entry->Folder = *tmpfolder;
+ entry->Folder = *tmpfolder;
- App::ROMDB->AllROMDBEntries->Append(entry);
+ App::ROMDB->AllROMDBEntries->Append(entry);
- tasks.emplace_back(
- create_task(App::ROMDB->AddAsync(entry)).then([entry] {
+ tasks.emplace_back(
+ create_task(App::ROMDB->AddAsync(entry)).then([entry] {
//copy the default snapshot file over
StorageFolder ^installDir = Windows::ApplicationModel::Package::Current->InstalledLocation;
return installDir->GetFolderAsync("Assets/");
@@ -180,14 +194,15 @@ void ImportPage::chooseFolderbtn_Click(Platform::Object^ sender, Windows::UI::Xa
try
{
t.get();
-
+
}
- catch (Platform::Exception ^ex)
+ catch (...)
{
}
- })
-
- ); //end of tasks.emplace_back
+ })
+
+ ); //end of tasks.emplace_back
+ }
}
when_all(begin(tasks), end(tasks)).then([this](task t)
@@ -203,7 +218,7 @@ void ImportPage::chooseFolderbtn_Click(Platform::Object^ sender, Windows::UI::Xa
}));
}
- catch (Platform::Exception^ e)
+ catch (...)
{
// We'll handle the specific errors below.
}
@@ -230,10 +245,7 @@ void ImportPage::chooseFolderbtn_Click(Platform::Object^ sender, Windows::UI::Xa
}
-void ImportPage::ImportFile(StorageFile^ file)
-{
-}
diff --git a/ImportPage.xaml.h b/ImportPage.xaml.h
index ae14d44..a9668a5 100644
--- a/ImportPage.xaml.h
+++ b/ImportPage.xaml.h
@@ -19,7 +19,7 @@ namespace VBA10
{
public:
ImportPage();
- void ImportFile(Windows::Storage::StorageFile^ file);
+