MainWindow.xaml.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System;
  2. using System.IO;
  3. using System.Net;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. using System.Windows.Input;
  7. namespace ftpmpv {
  8. public partial class MainWindow : Window {
  9. string currentPath;
  10. public MainWindow() {
  11. InitializeComponent();
  12. }
  13. private void Window_Loaded(object sender, RoutedEventArgs e) {
  14. TreeViewItem tvi = new TreeViewItem() {Header = "/"};
  15. dirs.Items.Add(tvi);
  16. listDir("/", tvi);
  17. }
  18. void listDir(string path, TreeViewItem tree) {
  19. FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://xis" + path);
  20. request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
  21. FtpWebResponse response = (FtpWebResponse)request.GetResponse();
  22. StreamReader sr = new StreamReader(response.GetResponseStream());
  23. files.Items.Clear();
  24. tree.Items.Clear();
  25. while (true) {
  26. string line = sr.ReadLine();
  27. if (line == null || line.Length == 0)
  28. break;
  29. string[] split = line.Split(new char[]{' '}, 9, StringSplitOptions.RemoveEmptyEntries);
  30. string mode = split[0];
  31. string name = split[8];
  32. if (mode[0] == 'd') {
  33. TreeViewItem tvi = new TreeViewItem() {Header = name};
  34. tree.Items.Add(tvi);
  35. } else
  36. files.Items.Add(name);
  37. }
  38. tree.ExpandSubtree();
  39. currentPath = path;
  40. }
  41. private void dirs_KeyUp(object sender, KeyEventArgs e) {
  42. if (e.Key == Key.Enter)
  43. dirsActivate();
  44. }
  45. private void dirs_MouseDoubleClick(object sender, MouseButtonEventArgs e) {
  46. dirsActivate();
  47. }
  48. private void dirsActivate() {
  49. TreeViewItem tvi = (TreeViewItem)dirs.SelectedItem;
  50. string path = "";
  51. TreeViewItem cur = tvi;
  52. while (true) {
  53. path = "/" + (string)cur.Header + path;
  54. if (cur.Parent != null && cur.Parent.GetType() == typeof(TreeViewItem))
  55. cur = (TreeViewItem)cur.Parent;
  56. else
  57. break;
  58. }
  59. path += "/";
  60. listDir(path, tvi);
  61. }
  62. private void files_KeyUp(object sender, KeyEventArgs e) {
  63. if (e.Key == Key.Enter)
  64. filesActivate();
  65. }
  66. private void files_MouseDoubleClick(object sender, MouseButtonEventArgs e) {
  67. filesActivate();
  68. }
  69. private void filesActivate() {
  70. string filename = (string)files.SelectedItem;
  71. Console.WriteLine("ftp://xis" + currentPath + filename);
  72. System.Diagnostics.Process.Start(@"D:\PRGMs\mpv\mpv.exe", "\"ftp://xis" + currentPath + filename + "\"");
  73. }
  74. }
  75. }