async private void DeleteFile_Click(object sender, RoutedEventArgs e) { if (this.FileList.SelectedIndex < 0) { return; } string itemName = this.FileList.SelectedItem.ToString(); FileOrFolderInformation f = this.currentFolderContents.Contents.Find(x => x.Name == itemName); if (f.IsFolder) { System.Windows.MessageBox.Show(String.Format("Cannot delete directory {0}!", this.FileList.SelectedItem.ToString())); } else { await this.portal.DeleteFileAsync( "LocalAppData", f.Name, this.currentFolderName, this.CurrentPackageFullName ); this.FillListFiles(); } }
private void FileList_MouseDoubleClick(object sender, MouseButtonEventArgs e) { if (this.FileList.SelectedIndex < 0) { return; } string itemName = this.FileList.SelectedItem.ToString(); if (itemName == "..") { if (currentFolderName == null) { // don't do anything } else { int i = this.currentFolderName.LastIndexOf('/'); if (i < 0) { this.currentFolderName = null; } else { this.currentFolderName = currentFolderName.Substring(0, i - 1); // Console.WriteLine(currentFolderName); } this.FillListFiles(); } } else { FileOrFolderInformation f = this.currentFolderContents.Contents.Find(x => x.Name == itemName); if (f.IsFolder) { // check if selected item is file, then ignore // if directory then enter, append name to currentFoldername after // // relist directory if (this.currentFolderName == null) { this.currentFolderName = itemName; // Console.WriteLine(currentFolderName); } else { this.currentFolderName += "//" + itemName; //Console.WriteLine(currentFolderName); } this.FillListFiles(); } else { // download } } }
async private void DownloadFile_Click(object sender, RoutedEventArgs e) { if (this.FileList.SelectedIndex < 0) { return; } string itemName = this.FileList.SelectedItem.ToString(); FileOrFolderInformation f = this.currentFolderContents.Contents.Find(x => x.Name == itemName); if (f.IsFolder) { System.Windows.MessageBox.Show(String.Format("Cannot delete directory {0}!", this.FileList.SelectedItem.ToString())); } else { using (SaveFileDialog saveFileDialog = new SaveFileDialog()) { saveFileDialog.InitialDirectory = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath).ToString(); saveFileDialog.RestoreDirectory = true; saveFileDialog.FileName = f.Name; if ((saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) && (saveFileDialog.FileName != "")) { System.IO.Stream data = await this.portal.GetFileAsync( "LocalAppData", f.Name, this.currentFolderName, this.CurrentPackageFullName ); using (var fileStream = System.IO.File.Create(saveFileDialog.FileName)) { data.Seek(0, System.IO.SeekOrigin.Begin); data.CopyTo(fileStream); } } } } }