protected override void OnNavigatedTo(NavigationEventArgs e) { //build the list List <ExportFileItem> filelist = new List <ExportFileItem>(); //check in-game save and add using (var iso = IsolatedStorageFile.GetUserStoreForApplication()) { int index = currentEntry.FileName.LastIndexOf('.'); int diff = currentEntry.FileName.Length - 1 - index; String sramName = currentEntry.FileName.Substring(0, currentEntry.FileName.Length - diff) + "sav"; String sramPath = FileHandler.ROM_DIRECTORY + "/" + FileHandler.SAVE_DIRECTORY + "/" + sramName; if (iso.FileExists(sramPath)) { ExportFileItem item = new ExportFileItem() { Name = sramName, Path = sramPath }; filelist.Add(item); } } //add save states foreach (var savestate in currentEntry.Savestates) { String path = FileHandler.ROM_DIRECTORY + "/" + FileHandler.SAVE_DIRECTORY + "/" + savestate.FileName; ExportFileItem item = new ExportFileItem() { Name = savestate.FileName, Path = path }; filelist.Add(item); } this.fileList.ItemsSource = filelist; this.fileList.CheckedItems.CheckAll(); base.OnNavigatedTo(e); }
private async void Export_Click(object sender, EventArgs e) { if (fileList.CheckedItems.Count == 0) { MessageBox.Show(AppResources.ExportNoSelection); return; } //can only export 1 file if use cloudsix if (backupMedium == "cloudsix" && fileList.CheckedItems.Count > 1 && ZipCheckBox.IsChecked.Value == false) { MessageBox.Show(AppResources.CloudSixOneFileLimitText); return; } if (this.uploading) { MessageBox.Show(AppResources.BackupWaitForUpload, AppResources.ErrorCaption, MessageBoxButton.OK); return; } //zip file if users choose to do so if (ZipCheckBox.IsChecked.Value) { using (ZipFile zip = new ZipFile()) { using (var iso = IsolatedStorageFile.GetUserStoreForApplication()) { foreach (ExportFileItem file in fileList.CheckedItems) { IsolatedStorageFileStream fs = iso.OpenFile(file.Path, System.IO.FileMode.Open); zip.AddEntry(file.Name, fs); } MemoryStream stream = new MemoryStream(); zip.Save(stream); if (backupMedium == "cloudsix") { var saver = new CloudSixSaver(currentEntry.DisplayName + ".zip", stream); await saver.Launch(); } else if (backupMedium == "onedrive") { var indicator = SystemTray.GetProgressIndicator(this); indicator.IsIndeterminate = true; this.uploading = true; bool errors = false; try { LiveConnectClient client = new LiveConnectClient(this.session); String folderID = await CreateExportFolder(client); indicator.Text = String.Format(AppResources.UploadProgressText, currentEntry.DisplayName + ".zip"); stream.Seek(0, SeekOrigin.Begin); await client.UploadAsync(folderID, currentEntry.DisplayName + ".zip", stream, OverwriteOption.Overwrite); } catch (Exception ex) { MessageBox.Show(String.Format(AppResources.BackupErrorUpload, ex.Message), AppResources.ErrorCaption, MessageBoxButton.OK); errors = true; } this.uploading = false; if (errors) { MessageBox.Show(AppResources.BackupUploadUnsuccessful, AppResources.ErrorCaption, MessageBoxButton.OK); } else { MessageBox.Show(AppResources.BackupUploadSuccessful); } #if GBC indicator.Text = AppResources.ApplicationTitle2; #else indicator.Text = AppResources.ApplicationTitle; #endif indicator.IsIndeterminate = false; } //end of if (backupMedium == "onedrive") stream.Close(); } } } else //does not use zip function { using (var iso = IsolatedStorageFile.GetUserStoreForApplication()) { if (backupMedium == "cloudsix") { ExportFileItem file = this.fileList.CheckedItems[0] as ExportFileItem; using (IsolatedStorageFileStream fs = iso.OpenFile(file.Path, System.IO.FileMode.Open)) { var saver = new CloudSixSaver(file.Name, fs); await saver.Launch(); } } else if (backupMedium == "onedrive") { var indicator = SystemTray.GetProgressIndicator(this); indicator.IsIndeterminate = true; this.uploading = true; bool errors = false; try { LiveConnectClient client = new LiveConnectClient(this.session); String folderID = await CreateExportFolder(client); foreach (ExportFileItem file in this.fileList.CheckedItems) { indicator.Text = String.Format(AppResources.UploadProgressText, file.Name); using (IsolatedStorageFileStream fs = iso.OpenFile(file.Path, System.IO.FileMode.Open)) { await client.UploadAsync(folderID, file.Name, fs, OverwriteOption.Overwrite); } } } catch (Exception ex) { MessageBox.Show(String.Format(AppResources.BackupErrorUpload, ex.Message), AppResources.ErrorCaption, MessageBoxButton.OK); errors = true; } this.uploading = false; if (errors) { MessageBox.Show(AppResources.BackupUploadUnsuccessful, AppResources.ErrorCaption, MessageBoxButton.OK); } else { MessageBox.Show(AppResources.BackupUploadSuccessful); } #if GBC indicator.Text = AppResources.ApplicationTitle2; #else indicator.Text = AppResources.ApplicationTitle; #endif indicator.IsIndeterminate = false; } } //IsolatedStorage } //using zip upload or not }