Skip to content

Commit

Permalink
can now export files, just need some polish
Browse files Browse the repository at this point in the history
  • Loading branch information
duchuule committed Aug 8, 2015
1 parent 58daff4 commit ec24cb1
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 9 deletions.
1 change: 1 addition & 0 deletions App.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ using namespace Windows::UI::ViewManagement;

ROMDatabase^ VBA10::App::ROMDB = nullptr;
live::live_client* VBA10::App::LiveClient = nullptr;
Platform::String^ VBA10::App::ExportFolderID = "";

/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
Expand Down
1 change: 1 addition & 0 deletions App.xaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace VBA10
internal:
static ROMDatabase^ ROMDB;
static live::live_client* LiveClient;
static Platform::String^ ExportFolderID;



Expand Down
2 changes: 1 addition & 1 deletion Database/ROMDatabase.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "ROMDatabase.h"
#include "ppltasks_extra.h";
#include "ppltasks_extra.h"

#include <collection.h>

Expand Down
3 changes: 2 additions & 1 deletion Definitions.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#define DEFAULT_SNAPSHOT L"Assets/no_snapshot.png"
#define DEFAULT_SNAPSHOT L"Assets/no_snapshot.png"
#define EXPORT_FOLDER L"VBA10 Export"

using namespace Windows::Storage;

Expand Down
4 changes: 2 additions & 2 deletions EmulatorSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#include "Emulator.h"

using namespace Windows::System;
using namespace Windows::Storage;

#define MONITOR_30HZ 0
#define MONITOR_60HZ 1
Expand Down Expand Up @@ -571,6 +569,7 @@ namespace VBA10
Platform::String^ FullScreenKey = "FullScreenKey";
Platform::String^ SignedInKey = "SignedInKey";


#pragma region button positions
Platform::String^ PadLeftPKey = "PadLeftPKey";
Platform::String^ PadBottomPKey = "PadBottomPKey";
Expand Down Expand Up @@ -622,6 +621,7 @@ namespace VBA10
const bool SignedInDefault = false;



#pragma region button positions (in cm based on 6x10cm phone)
const double PadLeftPDefault = 0.1f; //from left
const double PadBottomPDefault = 0.9f; //from bottom
Expand Down
90 changes: 88 additions & 2 deletions ExportPage.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include "App.xaml.h"
#include "SelectFilePane.xaml.h"
#include "SelectFilesPane.xaml.h"
#include "Definitions.h"
#include "ppltasks_extra.h"


using namespace VBA10;

Expand All @@ -20,7 +23,7 @@ using namespace Windows::UI::Xaml::Data;
using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Navigation;

using namespace Windows::UI::Popups;


// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
Expand Down Expand Up @@ -66,6 +69,42 @@ void ExportPage::signin_Completed(bool isLoggedIn)
this->SignInbtn->IsEnabled = false;
this->exportOneDrivebtn->IsEnabled = true;
EmulatorSettings::Current->SignedIn = true;

//get the export folder id
if (App::ExportFolderID == "")
{
App::LiveClient->get(L"/me/skydrive/files")
.then([this](web::json::value v)
{
//int test = v[L"data"].as_array().size();
for (const auto& it : (v[L"data"]).as_array())
{
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;
}

}

if (App::ExportFolderID == "") //need to create the folder
{
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)
{
App::ExportFolderID = ref new String(v[L"id"].as_string().c_str());

});
}
});
}
}
else
{
Expand Down Expand Up @@ -120,7 +159,53 @@ void ExportPage::exportOneDrivebtn_Click(Platform::Object^ sender, Windows::UI::

pane->FilesSelectedCallback = ref new FilesSelectedDelegate([=](IVector<int>^ selectedIndices)
{


if (App::ExportFolderID != "")
{
create_task([selectedIndices, files, this]()
{
vector<task<web::json::value>> tasks;

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));
}

return when_all(begin(tasks), end(tasks)).then([this](task<std::vector<web::json::value>> t)
{
try
{
t.get();
this->Dispatcher->RunAsync(CoreDispatcherPriority::Normal, ref new DispatchedHandler([]()
{
MessageDialog ^dialog = ref new MessageDialog("Upload completed successfully.");
dialog->ShowAsync();
}));



}
catch (Platform::Exception^ e)
{
// We'll handle the specific errors below.
}

});
});
}
else
{
MessageDialog ^dialog = ref new MessageDialog("Could not find export folder.", "Error");
dialog->ShowAsync();
}

//int test = selectedIndices->Size;



});

auto transform = ((UIElement^)titleBar)->TransformToVisual(nullptr);
Expand All @@ -146,3 +231,4 @@ void ExportPage::exportOneDrivebtn_Click(Platform::Object^ sender, Windows::UI::
statePopup->IsOpen = true;
}


2 changes: 1 addition & 1 deletion ImportPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
Margin="0,8,0,0"
/>
<TextBlock TextWrapping="Wrap"
Text="Use this option to import roms and save files from OneDrive, which will be copied to the app's private storage. NOTE: It is recommended that you store the roms on an user-accessible folder and use the Local Storage option to import them, which will prevents loss of progress if you the app every becomes corrupted."
Text="Use this option to import roms and save files from OneDrive, which will be copied to the app's private storage. NOTE: It is recommended that you store the roms on an user-accessible folder and use the Local Storage option to import them, which will prevent loss of progress if you the app every becomes corrupted."
Margin=" 0, 4, 0, 4" />


Expand Down
6 changes: 4 additions & 2 deletions SelectFilesPane.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding}"
FontSize="18"/>
<TextBlock Text="{Binding}"
FontSize="18"
/>

</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
Expand Down
22 changes: 22 additions & 0 deletions SelectFilesPane.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,30 @@ SelectFilesPane::SelectFilesPane(IVector<Platform::String^>^ list, Platform::Str

void SelectFilesPane::OkBtn_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
Vector<int>^ selectedIndices = ref new Vector<int> ();

for (int i = 0; i < this->fileList->SelectedItems->Size; i++)
{
String^ selectedName = (String^)this->fileList->SelectedItems->GetAt(i);
//find the index of this item
for (int j = 0; j < this->fileList->Items->Size; j++)
{
String^ name = (String^)this->fileList->Items->GetAt(j);
if (selectedName == name)
{
selectedIndices->Append(j);
break;
}
}
}


//close the pane
auto dp = this->Parent;
Popup^ pop = (Popup^)dp;
pop->IsOpen = false;

//return the file to whatever windows that call it
if (this->FilesSelectedCallback)
FilesSelectedCallback(selectedIndices);
}

0 comments on commit ec24cb1

Please sign in to comment.