Skip to content

Commit

Permalink
can now import multiple files from local Storage
Browse files Browse the repository at this point in the history
  • Loading branch information
duchuule committed Aug 8, 2015
1 parent c37b982 commit 47f0d39
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 63 deletions.
7 changes: 3 additions & 4 deletions ExportPage.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ void ExportPage::exportOneDrivebtn_Click(Platform::Object^ sender, Windows::UI::

if (App::ExportFolderID != "")
{
create_task([selectedIndices, files, this]()
{

vector<task<web::json::value>> tasks;

for (int i = 0; i < selectedIndices->Size; i++)
Expand All @@ -174,7 +173,7 @@ void ExportPage::exportOneDrivebtn_Click(Platform::Object^ sender, Windows::UI::
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)
when_all(begin(tasks), end(tasks)).then([this](task<std::vector<web::json::value>> t)
{
try
{
Expand All @@ -194,7 +193,7 @@ void ExportPage::exportOneDrivebtn_Click(Platform::Object^ sender, Windows::UI::
}

});
});

}
else
{
Expand Down
136 changes: 84 additions & 52 deletions ImportPage.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "ImportPage.xaml.h"
#include "Database\ROMDBEntry.h"
#include "Database\ROMDatabase.h"
#include "SelectFilePane.xaml.h"
#include "SelectFilesPane.xaml.h"
#include "App.xaml.h"
#include "FileBrowserPane.xaml.h"

Expand Down Expand Up @@ -99,72 +99,104 @@ void ImportPage::chooseFolderbtn_Click(Platform::Object^ sender, Windows::UI::Xa
for (int i = 0; i < files->Size; i++)
fileNames->Append(files->GetAt(i)->Name);

SelectFilePane ^pane = ref new SelectFilePane(fileNames, "Select file to import");
SelectFilesPane ^pane = ref new SelectFilesPane(fileNames, "Select file(s) to import");
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)
pane->FilesSelectedCallback = ref new FilesSelectedDelegate([=](IVector<int>^ selectedIndices)
{
StorageFile^ file = files->GetAt(selectedIndex);
//calculate 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);
vector<task<void>> tasks;

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

//create rom entry
ROMDBEntry^ entry = ref new ROMDBEntry(1, pfilenamenoext, file->Name, this->tmpfolder->Path,
this->tmptoken, psnapshotname);

entry->Folder = this->tmpfolder;

App::ROMDB->AllROMDBEntries->Append(entry);

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/");

}).then([entry](StorageFolder^ assetFolder)
{
return assetFolder->GetFileAsync("no_snapshot.png");
}).then([entry](StorageFile ^file)
{
//copy snapshot file to would be location
return file->CopyAsync(entry->Folder, entry->SnapshotUri, NameCollisionOption::ReplaceExisting);

}).then([entry](StorageFile ^file)
{
//open file
return file->OpenAsync(FileAccessMode::Read);
}).then([entry](IRandomAccessStream^ stream)
for (int i = 0; i < selectedIndices->Size; i++)
{
//load bitmap image for snapshot
entry->Snapshot = ref new BitmapImage();
return entry->Snapshot->SetSourceAsync(stream);


}).then([](task<void> t)
StorageFile^ file = files->GetAt(selectedIndices->GetAt(i));

//calculate 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());


//create rom entry
ROMDBEntry^ entry = ref new ROMDBEntry(1, pfilenamenoext, file->Name, this->tmpfolder->Path,
this->tmptoken, psnapshotname);

entry->Folder = this->tmpfolder;

App::ROMDB->AllROMDBEntries->Append(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/");

}).then([entry](StorageFolder^ assetFolder)
{
return assetFolder->GetFileAsync("no_snapshot.png");
}).then([entry](StorageFile ^file)
{
//copy snapshot file to would be location
return file->CopyAsync(entry->Folder, entry->SnapshotUri, NameCollisionOption::ReplaceExisting);

}).then([entry](StorageFile ^file)
{
//open file
return file->OpenAsync(FileAccessMode::Read);
}).then([entry](IRandomAccessStream^ stream)
{
//load bitmap image for snapshot
entry->Snapshot = ref new BitmapImage();
return entry->Snapshot->SetSourceAsync(stream);


}).then([](task<void> t)
{
try
{
t.get();

}
catch (Platform::Exception ^ex)
{
}
})

); //end of tasks.emplace_back
}

when_all(begin(tasks), end(tasks)).then([this](task<void> t)
{
try
{
t.get();
// .get() didn't throw, so we succeeded, print out success message
MessageDialog ^dialog = ref new MessageDialog("File imported successfully.");
dialog->ShowAsync();
this->Dispatcher->RunAsync(CoreDispatcherPriority::Normal, ref new DispatchedHandler([]()
{
// .get() didn't throw, so we succeeded, print out success message
MessageDialog ^dialog = ref new MessageDialog("Files imported successfully.");
dialog->ShowAsync();
}));

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


});

});
Expand Down
19 changes: 12 additions & 7 deletions SelectFilesPane.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,18 @@
</ListBox>


<Button Content="OK" Grid.Row="2"
Width="120"
HorizontalAlignment="Center"
Margin="0,4,0,4"
x:Name="OkBtn"
Click="OkBtn_Click"
/>

<Button Content="OK"
Width="120"
HorizontalAlignment="Center"
Margin="0,4,0,4"
x:Name="OkBtn"
Click="OkBtn_Click"
Grid.Row="2"
/>




</Grid>
</UserControl>
3 changes: 3 additions & 0 deletions SelectFilesPane.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,6 @@ void SelectFilesPane::OkBtn_Click(Platform::Object^ sender, Windows::UI::Xaml::R
if (this->FilesSelectedCallback)
FilesSelectedCallback(selectedIndices);
}



1 change: 1 addition & 0 deletions SelectFilesPane.xaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ namespace VBA10
bool initdone;
Platform::Collections::Vector<Windows::Storage::StorageFile^>^ fileVector;
void OkBtn_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void CancelBtn_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
};
}

0 comments on commit 47f0d39

Please sign in to comment.