private void buttonUploadLocal_Click(object sender, RoutedEventArgs e) { const int bufferSize = 4096; var dialog = new System.Windows.Forms.OpenFileDialog(); dialog.Title = "选择文件"; var result = dialog.ShowDialog(); if (result == System.Windows.Forms.DialogResult.Cancel) { return; } VFS.Directory dir = vfs.NewDirectory(currentDirectory); if (dir.Contains(dialog.SafeFileName)) { System.Windows.Forms.MessageBox.Show("文件夹下已存在同名文件或文件夹", "添加失败", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return; } try { // 写入文件 using (var reader = new System.IO.BinaryReader(new System.IO.FileStream(dialog.FileName, System.IO.FileMode.Open))) { var file = vfs.NewFile(currentDirectory + dialog.SafeFileName, VFS.FileMode.Create); byte[] buffer = new byte[bufferSize]; int count; while ((count = reader.Read(buffer, 0, buffer.Length)) != 0) { file.Write(buffer, 0, (uint)count); } } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("添加文件失败 :-(", "添加失败", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return; } Reload(); }
private void buttonRename_Click(object sender, RoutedEventArgs e) { var item = (DirectoryItem)listView.SelectedItem; if (item == null) { return; } XamDialogWindow win = CreateDialogWindow(150); win.Header = "重命名"; StackPanel stack = new StackPanel(); stack.VerticalAlignment = VerticalAlignment.Center; stack.Margin = new Thickness(10); Label label = new Label(); label.Content = "请输入新文件" + (item.isDirectory ? "夹" : "") + "名"; stack.Children.Add(label); TextBox txtName = new TextBox(); txtName.Text = item.name; stack.Children.Add(txtName); StackPanel stackButton = new StackPanel(); stackButton.Orientation = Orientation.Horizontal; stackButton.HorizontalAlignment = HorizontalAlignment.Center; stack.Children.Add(stackButton); Button btnOK = new Button(); btnOK.Content = "重命名"; btnOK.Padding = new Thickness(10, 0, 10, 0); btnOK.Margin = new Thickness(10); stackButton.Children.Add(btnOK); Button btnCancel = new Button(); btnCancel.Content = "取消"; btnCancel.Padding = new Thickness(10, 0, 10, 0); btnCancel.Margin = new Thickness(10); stackButton.Children.Add(btnCancel); FadeOutWindow(); win.Content = stack; win.IsModal = true; windowContainer.Children.Add(win); txtName.Focus(); btnOK.Click += delegate { VFS.Directory dir = vfs.NewDirectory(currentDirectory); if (dir.Contains(txtName.Text)) { System.Windows.Forms.MessageBox.Show("新文件或文件夹名已存在", "重命名失败", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); txtName.Focus(); return; } try { dir.Rename(item.name, txtName.Text); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message, "重命名失败", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); txtName.Focus(); return; } win.Close(); windowContainer.Children.Remove(win); FadeInWindow(); Reload(); }; btnCancel.Click += delegate { win.Close(); windowContainer.Children.Remove(win); FadeInWindow(); }; }
private void buttonNewFile_Click(object sender, RoutedEventArgs e) { XamDialogWindow win = CreateDialogWindow(150); win.Header = "创建文件"; StackPanel stack = new StackPanel(); stack.VerticalAlignment = VerticalAlignment.Center; stack.Margin = new Thickness(10); Label label = new Label(); label.Content = "请输入文件名"; stack.Children.Add(label); TextBox txtName = new TextBox(); txtName.Text = "文本文件.txt"; stack.Children.Add(txtName); StackPanel stackButton = new StackPanel(); stackButton.Orientation = Orientation.Horizontal; stackButton.HorizontalAlignment = HorizontalAlignment.Center; stack.Children.Add(stackButton); Button btnOK = new Button(); btnOK.Content = "创建"; btnOK.Padding = new Thickness(10, 0, 10, 0); btnOK.Margin = new Thickness(10); stackButton.Children.Add(btnOK); Button btnCancel = new Button(); btnCancel.Content = "取消"; btnCancel.Padding = new Thickness(10, 0, 10, 0); btnCancel.Margin = new Thickness(10); stackButton.Children.Add(btnCancel); FadeOutWindow(); win.Content = stack; win.IsModal = true; windowContainer.Children.Add(win); txtName.Focus(); btnOK.Click += delegate { VFS.Directory dir = vfs.NewDirectory(currentDirectory); if (dir.Contains(txtName.Text)) { System.Windows.Forms.MessageBox.Show("该文件或文件夹已存在", "创建失败", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); txtName.Focus(); return; } try { VFS.File file = vfs.NewFile(currentDirectory + txtName.Text, VFS.FileMode.CreateNew); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message, "创建失败", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); txtName.Focus(); return; } win.Close(); windowContainer.Children.Remove(win); FadeInWindow(); Reload(); }; btnCancel.Click += delegate { win.Close(); windowContainer.Children.Remove(win); FadeInWindow(); }; }