Skip to content

Commit

Permalink
add import save from onedrive
Browse files Browse the repository at this point in the history
delete more stuff if it is from private storage
  • Loading branch information
duchuule committed Aug 5, 2015
1 parent 458df2d commit 2b07693
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 12 deletions.
2 changes: 1 addition & 1 deletion FileBrowserPane.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

<TextBlock x:Name="txtLoading" Grid.Row="1"
Text="Loading..."
Margin="8,8,0,8"
Margin="12,8,0,8"
Visibility="Collapsed"
FontSize="18"/>

Expand Down
65 changes: 60 additions & 5 deletions FileBrowserPane.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void FileBrowserPane::fileList_SelectionChanged(Platform::Object^ sender, Window

item->Downloading = true;
//download file
DownloadFile(item).then([this, item](size_t size)
DownloadFile(item, CreationCollisionOption::GenerateUniqueName).then([this, item](size_t size)
{
//update rom dabatase
//calculate snapshot name
Expand All @@ -202,9 +202,10 @@ void FileBrowserPane::fileList_SelectionChanged(Platform::Object^ sender, Window

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(0, item->File->DisplayName, item->File->Name, ApplicationData::Current->LocalFolder->Path,
ROMDBEntry^ entry = ref new ROMDBEntry(0, pfilenamenoext, item->File->Name, ApplicationData::Current->LocalFolder->Path,
"none", psnapshotname);

entry->Folder = ApplicationData::Current->LocalFolder;
Expand Down Expand Up @@ -254,6 +255,45 @@ void FileBrowserPane::fileList_SelectionChanged(Platform::Object^ sender, Window
});


}
else if (item->Type == OneDriveItemType::SRAM || item->Type == OneDriveItemType::Savestate)
{
if (item->Downloading) //prevent double downloading of 1 file
return;

//get the save name without extension
wstring name(item->Name->Begin(), item->Name->End());
int index = name.find_last_of('.');
//wstring ext = name.substr(index + 1);

wstring filenamenoext = name.substr(0, index);


Platform::String^ pfilenamenoext = ref new Platform::String(filenamenoext.c_str());

ROMDBEntry^ entry = App::ROMDB->GetEntryFromName(pfilenamenoext);

if (entry == nullptr)
{
MessageDialog ^dialog = ref new MessageDialog("Could not find a matching ROM name.", "Error");
dialog->ShowAsync();
}
else
{
//start download the file
item->Downloading = true;
DownloadFile(item, CreationCollisionOption::ReplaceExisting).then([item, entry](size_t size)
{
item->Downloading = false;

//if the file is ingame save then prevent autoloading
if (item->Type == OneDriveItemType::SRAM)
entry->AutoLoadLastState = false;

MessageDialog ^dialog = ref new MessageDialog(item->File->Name + " was imported successfully.");
dialog->ShowAsync();
});
}
}
else
{
Expand All @@ -263,9 +303,9 @@ void FileBrowserPane::fileList_SelectionChanged(Platform::Object^ sender, Window

}

task<size_t> FileBrowserPane::DownloadFile(OneDriveFileItem^ item)
task<size_t> FileBrowserPane::DownloadFile(OneDriveFileItem^ item, CreationCollisionOption collitionOption)
{
return create_task(ApplicationData::Current->LocalFolder->CreateFileAsync(item->Name, CreationCollisionOption::GenerateUniqueName))
return create_task(ApplicationData::Current->LocalFolder->CreateFileAsync(item->Name, collitionOption))
.then([this, item] (StorageFile^ file)
{
item->File = file;
Expand All @@ -276,9 +316,12 @@ task<size_t> FileBrowserPane::DownloadFile(OneDriveFileItem^ item)
{
return t.get();
}
catch (COMException^ e)
catch (Platform::Exception^ ex)
{
// We'll handle the specific errors below.
MessageDialog ^dialog = ref new MessageDialog("Error: " + ex->Message);
dialog->ShowAsync();

size_t length = 0;
return length;
}
Expand Down Expand Up @@ -366,6 +409,18 @@ void FileBrowserPane::backBtn_Click(Platform::Object^ sender, Windows::UI::Xaml:
return;
}

//check to see if any thing is downloading
for (unsigned int i = 0; i < this->fileVector->Size; i++)
{
OneDriveFileItem^ item = this->fileVector->GetAt(i);
if (item->Downloading)
{
MessageDialog ^dialog = ref new MessageDialog("Please wait until all files have finished downloading.");
dialog->ShowAsync();
return;
}
}

//remove last folder in stack
this->onedriveStack->RemoveAtEnd();

Expand Down
2 changes: 1 addition & 1 deletion FileBrowserPane.xaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace VBA10
void client_GetCompleted(web::json::value v);
bool loading;//keep track of when the app is loading new data
void backBtn_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
Concurrency::task<size_t> DownloadFile(OneDriveFileItem^ item);
Concurrency::task<size_t> DownloadFile(OneDriveFileItem^ item, Windows::Storage::CreationCollisionOption collitionOption);
//Windows::Storage::StorageFile^ tmpfile;
};
}
2 changes: 1 addition & 1 deletion ImportPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
Width="120"
Margin =" 0, 0, 8, 0"/>

<Button x:Name="importOneDriveROMbtn" Content="Import"
<Button x:Name="importOneDriveROMbtn" Content="Import R/S"
Click="importOneDriveROMbtn_Click"
Width="120"
IsEnabled="False"
Expand Down
3 changes: 2 additions & 1 deletion ImportPage.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,10 @@ void ImportPage::chooseFolderbtn_Click(Platform::Object^ sender, Windows::UI::Xa

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, file->DisplayName, file->Name, this->tmpfolder->Path,
ROMDBEntry^ entry = ref new ROMDBEntry(1, pfilenamenoext, file->Name, this->tmpfolder->Path,
this->tmptoken, psnapshotname);

entry->Folder = this->tmpfolder;
Expand Down
59 changes: 56 additions & 3 deletions SelectROMPane.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ void SelectROMPane::ShowContextMenu(ROMDBEntry^ entry, Windows::Foundation::Rect
MessageDialog ^dialog;

if (entry->LocationType == 0) //private folder
dialog = ref new MessageDialog("This will delete the ROM file from the app's private storage. Continue?", "Confirm");
dialog = ref new MessageDialog("This will *delete* the ROM file and save files from the app's private storage. Continue?", "Confirm");

else
dialog = ref new MessageDialog("This will remove the ROM entry from the app's list. Your actual ROM files and save files will not be affected. Continue?", "Confirm");
Expand All @@ -479,10 +479,63 @@ void SelectROMPane::ShowContextMenu(ROMDBEntry^ entry, Windows::Foundation::Rect

if (entry->LocationType == 0)
{
wstring name(entry->FileName->Begin(), entry->FileName->End());
int index = name.find_last_of('.');
//wstring ext = name.substr(index + 1);

wstring filenamenoext = name.substr(0, index);

wstring snapshotname = filenamenoext + L".jpg";
Platform::String^ psnapshotname = ref new Platform::String(snapshotname.c_str());

wstring autosavename = filenamenoext + L"9.sgm";
Platform::String^ pautosavename = ref new Platform::String(autosavename.c_str());

wstring sramname = filenamenoext + L".sav";
Platform::String^ psramname = ref new Platform::String(sramname.c_str());

//delete the rom file
create_task(entry->Folder->GetFileAsync(entry->FileName)).then([] (StorageFile^ file)
create_task(entry->Folder->GetFileAsync(entry->FileName)).then([] (task<StorageFile^> tfile)
{
try
{
StorageFile^ file = tfile.get();
file->DeleteAsync();
}
catch (Platform::Exception^) {}
});

//delete the snapshot file
create_task(entry->Folder->GetFileAsync(psnapshotname)).then([](task<StorageFile^> tfile)
{
try
{
StorageFile^ file = tfile.get();
file->DeleteAsync();
}
catch (Platform::Exception^) {}
});

//delete the auto save file
create_task(entry->Folder->GetFileAsync(pautosavename)).then([](task<StorageFile^> tfile)
{
try
{
StorageFile^ file = tfile.get();
file->DeleteAsync();
}
catch (Platform::Exception^) {}
});

//delete the sram file
create_task(entry->Folder->GetFileAsync(psramname)).then([](task<StorageFile^> tfile)
{
file->DeleteAsync();
try
{
StorageFile^ file = tfile.get();
file->DeleteAsync();
}
catch (Platform::Exception^) {}
});

}
Expand Down

0 comments on commit 2b07693

Please sign in to comment.