2015-06-18 17:33:07 +00:00
|
|
|
|
//
|
|
|
|
|
|
// ExportPage.xaml.cpp
|
|
|
|
|
|
// Implementation of the ExportPage class
|
|
|
|
|
|
//
|
2015-07-08 13:47:53 +00:00
|
|
|
|
#include "pch.h"
|
2015-06-18 17:33:07 +00:00
|
|
|
|
#include "ExportPage.xaml.h"
|
2015-08-05 13:33:30 +00:00
|
|
|
|
#include "App.xaml.h"
|
2015-08-06 14:24:47 +00:00
|
|
|
|
#include "SelectFilePane.xaml.h"
|
|
|
|
|
|
#include "SelectFilesPane.xaml.h"
|
2015-08-08 02:00:51 +00:00
|
|
|
|
#include "Definitions.h"
|
|
|
|
|
|
#include "ppltasks_extra.h"
|
2015-08-22 21:51:33 +00:00
|
|
|
|
#include "AdControl.xaml.h"
|
2015-08-08 02:00:51 +00:00
|
|
|
|
|
2015-06-18 17:33:07 +00:00
|
|
|
|
|
|
|
|
|
|
using namespace VBA10;
|
|
|
|
|
|
|
|
|
|
|
|
using namespace Platform;
|
|
|
|
|
|
using namespace Windows::Foundation;
|
|
|
|
|
|
using namespace Windows::Foundation::Collections;
|
|
|
|
|
|
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::Media;
|
|
|
|
|
|
using namespace Windows::UI::Xaml::Navigation;
|
2015-08-08 02:00:51 +00:00
|
|
|
|
using namespace Windows::UI::Popups;
|
2015-08-05 13:33:30 +00:00
|
|
|
|
|
2015-08-06 14:24:47 +00:00
|
|
|
|
|
2015-06-18 17:33:07 +00:00
|
|
|
|
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
|
|
|
|
|
|
|
|
|
|
|
|
ExportPage::ExportPage()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
2015-08-22 21:51:33 +00:00
|
|
|
|
|
|
|
|
|
|
//create ad control
|
|
|
|
|
|
if (App::HasAds)
|
|
|
|
|
|
{
|
|
|
|
|
|
AdControl^ adControl = ref new AdControl();
|
|
|
|
|
|
LayoutRoot->Children->Append(adControl);
|
|
|
|
|
|
adControl->SetValue(Grid::RowProperty, 2);
|
|
|
|
|
|
}
|
2015-06-18 17:33:07 +00:00
|
|
|
|
}
|
2015-08-05 13:33:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ExportPage::Page_Loaded(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
|
|
|
|
|
|
{
|
|
|
|
|
|
//try re-sign in silently because access token expires every 1 hour
|
|
|
|
|
|
if (EmulatorSettings::Current->SignedIn)
|
|
|
|
|
|
{
|
|
|
|
|
|
//live::live_client* LiveClient = new live::live_client();
|
|
|
|
|
|
App::LiveClient->login(L"wl.skydrive_update wl.signin", true)
|
|
|
|
|
|
.then([this](bool isLoggedIn)
|
|
|
|
|
|
{
|
|
|
|
|
|
signin_Completed(isLoggedIn);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ExportPage::SignInbtn_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
|
|
|
|
|
|
{
|
|
|
|
|
|
App::LiveClient->login(L"wl.skydrive_update wl.signin", false)
|
|
|
|
|
|
.then([this](bool isLoggedIn)
|
|
|
|
|
|
{
|
|
|
|
|
|
signin_Completed(isLoggedIn);
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ExportPage::signin_Completed(bool isLoggedIn)
|
|
|
|
|
|
{
|
2015-10-06 04:54:26 +00:00
|
|
|
|
auto loader = Windows::ApplicationModel::Resources::ResourceLoader::GetForViewIndependentUse();
|
2015-09-25 05:18:39 +00:00
|
|
|
|
|
2015-08-05 13:33:30 +00:00
|
|
|
|
if (isLoggedIn)
|
|
|
|
|
|
{
|
2015-09-25 05:18:39 +00:00
|
|
|
|
this->SignInbtn->Content = loader->GetString("SignedInText");
|
2015-08-05 13:33:30 +00:00
|
|
|
|
this->SignInbtn->IsEnabled = false;
|
|
|
|
|
|
this->exportOneDrivebtn->IsEnabled = true;
|
|
|
|
|
|
EmulatorSettings::Current->SignedIn = true;
|
2015-08-08 02:00:51 +00:00
|
|
|
|
|
|
|
|
|
|
//get the export folder id
|
|
|
|
|
|
if (App::ExportFolderID == "")
|
|
|
|
|
|
{
|
|
|
|
|
|
App::LiveClient->get(L"/me/skydrive/files")
|
2015-08-23 05:33:43 +00:00
|
|
|
|
.then([this](task<web::json::value> tv)
|
2015-08-08 02:00:51 +00:00
|
|
|
|
{
|
2015-08-23 05:33:43 +00:00
|
|
|
|
try
|
2015-08-08 02:00:51 +00:00
|
|
|
|
{
|
2015-08-23 05:33:43 +00:00
|
|
|
|
auto v = tv.get();
|
2015-08-08 02:00:51 +00:00
|
|
|
|
|
2015-08-23 05:33:43 +00:00
|
|
|
|
//int test = v[L"data"].as_array().size();
|
|
|
|
|
|
for (const auto& it : (v[L"data"]).as_array())
|
2015-08-08 02:00:51 +00:00
|
|
|
|
{
|
2015-08-23 05:33:43 +00:00
|
|
|
|
auto album = it;
|
|
|
|
|
|
|
|
|
|
|
|
wstring name = album[L"name"].as_string();
|
|
|
|
|
|
wstring type = album[L"type"].as_string();
|
|
|
|
|
|
if (name == EXPORT_FOLDER && (type == L"folder" || type == L"album"))
|
|
|
|
|
|
{
|
|
|
|
|
|
App::ExportFolderID = ref new String(album[L"id"].as_string().c_str());
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-08-08 02:00:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-08-23 05:33:43 +00:00
|
|
|
|
if (App::ExportFolderID == "") //need to create the folder
|
2015-08-08 02:00:51 +00:00
|
|
|
|
{
|
2015-08-23 05:33:43 +00:00
|
|
|
|
web::json::value data;
|
|
|
|
|
|
data[U("name")] = web::json::value::string(EXPORT_FOLDER);
|
|
|
|
|
|
|
|
|
|
|
|
create_task(App::LiveClient->post(L"/me/skydrive", data))
|
|
|
|
|
|
.then([](web::json::value v)
|
|
|
|
|
|
{
|
2015-08-08 02:00:51 +00:00
|
|
|
|
App::ExportFolderID = ref new String(v[L"id"].as_string().c_str());
|
|
|
|
|
|
|
2015-08-23 05:33:43 +00:00
|
|
|
|
});
|
|
|
|
|
|
}
|
2015-08-08 02:00:51 +00:00
|
|
|
|
}
|
2015-08-23 05:33:43 +00:00
|
|
|
|
//catch (const concurrency::task_canceled &) {}
|
|
|
|
|
|
catch (...) {}
|
2015-08-08 02:00:51 +00:00
|
|
|
|
});
|
|
|
|
|
|
}
|
2015-08-05 13:33:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2015-09-25 05:18:39 +00:00
|
|
|
|
this->SignInbtn->Content = loader->GetString("SignInText");
|
2015-08-05 13:33:30 +00:00
|
|
|
|
this->SignInbtn->IsEnabled = true;
|
|
|
|
|
|
this->exportOneDrivebtn->IsEnabled = false;
|
|
|
|
|
|
EmulatorSettings::Current->SignedIn = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ExportPage::exportOneDrivebtn_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
|
|
|
|
|
|
{
|
2015-10-06 04:54:26 +00:00
|
|
|
|
auto loader = Windows::ApplicationModel::Resources::ResourceLoader::GetForViewIndependentUse();
|
2015-09-25 05:18:39 +00:00
|
|
|
|
|
2015-08-06 14:24:47 +00:00
|
|
|
|
//get a list of rom
|
|
|
|
|
|
Vector<Platform::String ^> ^romNames = ref new Vector<Platform::String ^>();
|
|
|
|
|
|
for (int i = 0; i < App::ROMDB->AllROMDBEntries->Size; i++)
|
|
|
|
|
|
romNames->Append(App::ROMDB->AllROMDBEntries->GetAt(i)->DisplayName);
|
|
|
|
|
|
|
|
|
|
|
|
//open panel to let user select rom
|
|
|
|
|
|
Popup ^statePopup = ref new Popup();
|
|
|
|
|
|
statePopup->IsLightDismissEnabled = true;
|
|
|
|
|
|
|
2015-09-25 05:18:39 +00:00
|
|
|
|
SelectFilePane ^pane = ref new SelectFilePane(romNames, loader->GetString("SelectROMText"));
|
2015-08-06 14:24:47 +00:00
|
|
|
|
statePopup->Child = pane;
|
|
|
|
|
|
pane->Width = titleBar->ActualWidth;//statePopup->Width;
|
|
|
|
|
|
pane->MaxHeight = Window::Current->Bounds.Height - 48; //statePopup->MaxHeight;
|
|
|
|
|
|
|
|
|
|
|
|
pane->FileSelectedCallback = ref new FileSelectedDelegate([=](int selectedIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
ROMDBEntry^ entry = App::ROMDB->AllROMDBEntries->GetAt(selectedIndex);
|
|
|
|
|
|
|
|
|
|
|
|
//get list of save files
|
|
|
|
|
|
Search::QueryOptions ^options = ref new Search::QueryOptions();
|
|
|
|
|
|
options->FileTypeFilter->Append("*");
|
|
|
|
|
|
options->IndexerOption = Search::IndexerOption::DoNotUseIndexer;
|
2015-10-13 23:38:55 +00:00
|
|
|
|
options->UserSearchFilter = "\"" + entry->DisplayName + "\"";
|
2015-08-06 14:24:47 +00:00
|
|
|
|
create_task(entry->Folder->CreateFileQueryWithOptions(options)->GetFilesAsync())
|
2015-09-25 05:18:39 +00:00
|
|
|
|
.then([this, loader](IVectorView<StorageFile ^> ^files)
|
2015-08-06 14:24:47 +00:00
|
|
|
|
{
|
|
|
|
|
|
//open panel to let user select file
|
|
|
|
|
|
Popup ^statePopup = ref new Popup();
|
|
|
|
|
|
statePopup->IsLightDismissEnabled = true;
|
|
|
|
|
|
|
|
|
|
|
|
Vector<Platform::String ^> ^fileNames = ref new Vector<Platform::String ^>();
|
|
|
|
|
|
for (int i = 0; i < files->Size; i++)
|
|
|
|
|
|
fileNames->Append(files->GetAt(i)->Name);
|
|
|
|
|
|
|
2015-09-25 05:18:39 +00:00
|
|
|
|
SelectFilesPane ^pane = ref new SelectFilesPane(fileNames, loader->GetString("SelectFileExportText"));
|
2015-08-06 14:24:47 +00:00
|
|
|
|
statePopup->Child = pane;
|
|
|
|
|
|
pane->Width = titleBar->ActualWidth;//statePopup->Width;
|
|
|
|
|
|
pane->MaxHeight = Window::Current->Bounds.Height - 48; //statePopup->MaxHeight;
|
|
|
|
|
|
|
|
|
|
|
|
pane->FilesSelectedCallback = ref new FilesSelectedDelegate([=](IVector<int>^ selectedIndices)
|
|
|
|
|
|
{
|
2015-08-08 02:00:51 +00:00
|
|
|
|
|
|
|
|
|
|
if (App::ExportFolderID != "")
|
|
|
|
|
|
{
|
2015-08-08 03:59:19 +00:00
|
|
|
|
|
2015-08-08 02:00:51 +00:00
|
|
|
|
vector<task<web::json::value>> tasks;
|
2015-08-06 14:24:47 +00:00
|
|
|
|
|
2015-08-08 02:00:51 +00:00
|
|
|
|
for (int i = 0; i < selectedIndices->Size; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto file = files->GetAt(selectedIndices->GetAt(i));
|
|
|
|
|
|
String^ path = App::ExportFolderID + L"/files/" + file->Name; //need to handle space in name
|
|
|
|
|
|
|
|
|
|
|
|
tasks.emplace_back(App::LiveClient->upload(web::uri::encode_uri(path->Data()), file));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-09-25 05:18:39 +00:00
|
|
|
|
when_all(begin(tasks), end(tasks)).then([this, loader](task<std::vector<web::json::value>> t)
|
2015-08-08 02:00:51 +00:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
t.get();
|
2015-09-25 05:18:39 +00:00
|
|
|
|
this->Dispatcher->RunAsync(CoreDispatcherPriority::Normal, ref new DispatchedHandler([loader]()
|
2015-08-08 02:00:51 +00:00
|
|
|
|
{
|
2015-09-25 05:18:39 +00:00
|
|
|
|
MessageDialog ^dialog = ref new MessageDialog(loader->GetString("UploadSuccessText"));
|
2015-08-08 02:00:51 +00:00
|
|
|
|
dialog->ShowAsync();
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2015-08-23 05:33:43 +00:00
|
|
|
|
|
|
|
|
|
|
catch (const std::exception &)
|
2015-08-08 02:00:51 +00:00
|
|
|
|
{
|
2015-09-25 05:18:39 +00:00
|
|
|
|
this->Dispatcher->RunAsync(CoreDispatcherPriority::Normal, ref new DispatchedHandler([loader]()
|
2015-08-23 05:33:43 +00:00
|
|
|
|
{
|
2015-09-25 05:18:39 +00:00
|
|
|
|
MessageDialog ^dialog = ref new MessageDialog(loader->GetString("NetworkErrorText"));
|
2015-08-23 05:33:43 +00:00
|
|
|
|
dialog->ShowAsync();
|
|
|
|
|
|
}));
|
2015-08-08 02:00:51 +00:00
|
|
|
|
}
|
2015-08-23 05:33:43 +00:00
|
|
|
|
catch (Exception^) {}
|
2015-08-08 02:00:51 +00:00
|
|
|
|
|
|
|
|
|
|
});
|
2015-08-08 03:59:19 +00:00
|
|
|
|
|
2015-08-08 02:00:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2015-09-25 05:18:39 +00:00
|
|
|
|
MessageDialog ^dialog = ref new MessageDialog(loader->GetString("ExportFolderError"), loader->GetString("ErrorText"));
|
2015-08-08 02:00:51 +00:00
|
|
|
|
dialog->ShowAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//int test = selectedIndices->Size;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-08-06 14:24:47 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
auto transform = ((UIElement^)titleBar)->TransformToVisual(nullptr);
|
|
|
|
|
|
|
|
|
|
|
|
Windows::Foundation::Point point = transform->TransformPoint(Windows::Foundation::Point());
|
|
|
|
|
|
statePopup->HorizontalOffset = point.X + 1; //+ selectStateBtn->ActualWidth / 2.0f - pane->Width / 2.0f;
|
|
|
|
|
|
statePopup->VerticalOffset = point.Y + titleBar->ActualHeight;
|
|
|
|
|
|
|
|
|
|
|
|
statePopup->IsOpen = true;
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
auto transform = ((UIElement^)titleBar)->TransformToVisual(nullptr);
|
|
|
|
|
|
|
|
|
|
|
|
Windows::Foundation::Point point = transform->TransformPoint(Windows::Foundation::Point());
|
|
|
|
|
|
statePopup->HorizontalOffset = point.X + 1; //+ selectStateBtn->ActualWidth / 2.0f - pane->Width / 2.0f;
|
|
|
|
|
|
statePopup->VerticalOffset = point.Y + titleBar->ActualHeight;
|
|
|
|
|
|
|
|
|
|
|
|
statePopup->IsOpen = true;
|
|
|
|
|
|
}
|
2015-08-05 13:33:30 +00:00
|
|
|
|
|
2015-08-08 02:00:51 +00:00
|
|
|
|
|