private void ListViewItem_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e) { ListView item = sender as ListView; if (item.DataContext != null) { FileInfoDataList model = item.SelectedItem as FileInfoDataList; if (model == null) { return; } if (!_mainVM.Islist) { return; } string name = ""; //if (model.Hash == null) name = model.Name; //else name = model.Hash; if (model.Type == "文件夹") { _mainVM.LoadItems(name); } } }
private void ParseDirectoryRecursive(object path) { try { do { FileInfoDataList ss = ShowSharefile.ReceiveShare(); if (ss.Name == "") { break; } int asdf = ss.Name.LastIndexOf(@"\"); string a = ss.Name.Substring(0, asdf + 1); if (Directory != a) { continue; } ss.Name = ss.Name.Substring(asdf + 1, ss.Name.Length - asdf - 1); Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, (ThreadStart) delegate { FileInfoDataList si = ShowSharefile.GetInfo(ss); if (si != null) { FileItemInfo.Add(si); } Thread.Sleep(5); }); } while (true); } catch (Exception) { ; } }
public FileInfoDataList GetInfo(FileInfoDataList si) { Icon largeIcon = null; Icon smallIcon = null; GetItem(si.Type, ref largeIcon, ref smallIcon); ImageSource lar = null; ImageSource sma = null; try { lar = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon (largeIcon.Handle, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); sma = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon (smallIcon.Handle, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); } catch (Exception) { return(null); } if (si.Type == "文件夹") { lar = sma = new BitmapImage(new Uri(@"D:\C++\C#\系统图标\xpxtfjtb 080.png", UriKind.RelativeOrAbsolute)); } return(new FileInfoDataList(si, lar, sma)); }
private void Get_He_ListView(object sender, System.Windows.Input.MouseButtonEventArgs e) { ListView item = e.Source as ListView; if (item.DataContext != null) { FileInfoDataList model = item.SelectedItem as FileInfoDataList; _mainVM.SeleteInfo = model; } }
private void ListViewItem_SelectionClick(object sender, SelectionChangedEventArgs e) { if (e.RoutedEvent.Name == "SelectionChanged") { ListView item = sender as ListView; if (item.DataContext != null) { FileInfoDataList model = item.SelectedItem as FileInfoDataList; _mainVM.SeleteInfo = model; } } }
private void ShareFile_SelectionChange(object sender, SelectionChangedEventArgs e) { ListView item = sender as ListView; if (item.DataContext != null) { FileInfoDataList model = item.SelectedItem as FileInfoDataList; if (model == null) { return; } if (model.Type == "文件夹") { _mainVM.Selection_ShareFile = model; } } }
private void Share_DoubleCilk(object sender, System.Windows.Input.MouseButtonEventArgs e) { ListView item = sender as ListView; if (item.DataContext != null) { FileInfoDataList model = item.SelectedItem as FileInfoDataList; if (model == null) { return; } if (model.Type == "文件夹") { _mainVM.Show_ShareFile(model.Name, _mainVM.ShareLoact); } } }
private void Get_ListViewItem(object sender, System.Windows.Input.MouseButtonEventArgs e) { ListView item = sender as ListView; if (item.DataContext != null) { FileInfoDataList model = item.SelectedItem as FileInfoDataList; if (model == null) { return; } string name = ""; //if (model.Hash == null) name = model.Name; //else name = model.Hash; _mainVM.SeleteInfo = model; } }
public FileInfoDataList GetInfo(FileInfoDataList si) { Icon largeIcon = null; Icon smallIcon = null; GetItem(si.Type, ref largeIcon, ref smallIcon); ImageSource lar = null; ImageSource sma = null; try { lar = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon (largeIcon.Handle, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); sma = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon (smallIcon.Handle, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); } catch (Exception) { return(null); } if (si.Type == "文件夹") { //StreamResourceInfo resourceInfo = Application.GetResourceStream(new Uri(@"images\icon.jpg", UriKind.Relative)); //_image = new BitmapImage(); //_image.BeginInit(); //_image.StreamSource = resourceInfo.Stream; //_image.EndInit(); lar = sma = pu; //Assembly asm = Assembly.GetExecutingAssembly(); //string asd = this.GetType().Namespace; //Stream imageStream = asm.GetManifestResourceStream(this.GetType().Namespace + ".images.FolderIcon.png"); //var sam1 = sma as BitmapImage; //lar = sma; //sam1 = new BitmapImage(); //sam1.BeginInit(); //sam1.StreamSource = imageStream; //sam1.EndInit(); //lar = sma; } return(new FileInfoDataList(si, lar, sma)); }
public FileInfoDataList ReceiveShare() { Share sh = new Share(); if (newSock == null) { return(null); } byte[] b = new byte[315]; int r = newSock.Receive(b, SocketFlags.None); if (r == 0) { return(null); } sh = (Share)S_B.BytesToStruct(b, new Share().GetType()); FileInfoDataList si = new FileInfoDataList(sh.name, sh.type, sh.size, sh.hash, null, null); return(si); }
private void Show_Root(ObservableCollection <FileInfoDataList> list, bool first_execution) { FileInfoDataList sh = new FileInfoDataList(); foreach (var item in _sh.SharePath.Keys) { Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, (ThreadStart) delegate { sh.Name = item; sh.IsFolder = true; sh.Size = null; sh = ShowSharefile.GetInfo(sh); if (first_execution) { Root_Name.Add(item); } list.Add(sh); }); } }
public void Open_shareFile(FileInfoDataList d) { if (Selection_ShareFile == null) { return; } if (_sh.SharePath.ContainsKey(Selection_ShareFile.Name)) { Local_Address = _sh.SharePath[Selection_ShareFile.Name]; } else { Local_Address += (@"\" + Selection_ShareFile.Name); } FileInfo f = null; try { f = new FileInfo(Local_Address); } catch (Exception e) { MessageBox.Show(e.Data.ToString()); return; } try { if (f.Attributes == FileAttributes.Directory) { System.Diagnostics.Process.Start("explorer", Local_Address); } else { System.Diagnostics.Process.Start(Local_Address); } } catch (Exception e) { MessageBox.Show(e.Data.ToString()); } }
private void GetDirList(string strBaseDir, ObservableCollection <FileInfoDataList> list) { try { DirectoryInfo di = new DirectoryInfo(strBaseDir); DirectoryInfo[] diA = di.GetDirectories(); FileInfo[] files = di.GetFiles(); foreach (var item in files) { Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, (ThreadStart) delegate { FileInfoDataList sh = new FileInfoDataList(); sh.Name = item.Name; sh.IsFolder = false; sh.Size = null; sh = ShowSharefile.GetInfo(sh); list.Add(sh); }); } foreach (var item in diA) { Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, (ThreadStart) delegate { FileInfoDataList sh = new FileInfoDataList(); sh.Name = item.Name; sh.IsFolder = true; sh.Size = null; sh = ShowSharefile.GetInfo(sh); list.Add(sh); }); } } catch (Exception) { ; } }
public void Delete_ShareFile(FileInfoDataList d) { if (Selection_ShareFile == null) { return; } if (_sh.SharePath.ContainsKey(Selection_ShareFile.Name)) { Local_Address = _sh.SharePath[Selection_ShareFile.Name]; } else { Local_Address += (@"\" + Selection_ShareFile.Name); } if (d.Type == "文件夹") { Delete_Directory(Local_Address); } else { FileInfo f = new FileInfo(Local_Address); f.Delete(); } }
private void OnSearch(object obj) { Islist = false; if (_preSearchTime == null) { _preSearchTime = DateTime.Now; } else { var now = DateTime.Now; var spanTime = now - _preSearchTime; if (spanTime < _elapsedTime) { MessageBox.Show(string.Format("每次搜索间隔不能超过{0}秒", _elapsedTime.Seconds.ToString())); return; } else { _preSearchTime = DateTime.Now; } } IsBusy_Main = true; try { List <string> nameList = FileName.Split(' ').ToList(); nameList.RemoveAll(new Predicate <string>(T => T == string.Empty)); Task <List <FileInfoData> > task = _client.SearchFileAsync(nameList, true); FileItemInfo.Clear(); if (_ctsSearch != null) { if (!_ctsSearch.Token.CanBeCanceled) { _ctsSearch.Cancel(); } } task.ContinueWith(T => { ThreadPool.QueueUserWorkItem(delegate { IsBusy_Main = false; if (T.Result != null) { _ctsSearch = new CancellationTokenSource(); Task listTask = new Task(() => { foreach (var item in T.Result) { try { Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, (ThreadStart) delegate { FileInfoDataList f = new FileInfoDataList(item); f = ShowSharefile.GetInfo(f); if (item != null) { FileItemInfo.Add(f); } Thread.Sleep(30); }); } catch (Exception) { //throw; } } }, _ctsSearch.Token); listTask.Start(); } }); }); } catch (Exception e) { if (ErrorOccur != null) { ErrorOccur(this, new ModelEventArgs(ModelEventType.Exception) { ModelException = e }); } } }
private void CreatDowndLoadThread(object p) { FileInfoDataList SeleteInfo1 = (FileInfoDataList)p; if (SeleteInfo1 == null) { return; } #region MyRegion //if (SeleteInfo1.Hash.Length < 36) //{ // MessageBox.Show("根目录不能下载"); // return; //} #endregion if (SeleteInfo1.IsFolder == true) { MessageBox.Show("根目录不能下载"); return; } Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, (ThreadStart) delegate { DownLoad d = new DownLoad(); LoadInfo l = new LoadInfo(); //l.name = @"DriverGenius2012"; //l.type = "文件夹"; d.RootDirectory = CurrentDownloadPath + @"\"; l.name = SeleteInfo1.Name; if (SeleteInfo1.Size == null) { l.size = 0; } else { l.size = (long)SeleteInfo1.Size; } l.type = SeleteInfo1.Type; DownListInfo sm = d.CreatDownLoad(l); if (sm == null) { return; } sm.ID = d.ID = DownInfo.Count; sm.State = "下载"; sm.Hash = SeleteInfo.Hash; DownInfo.Add(sm); Down_d.Add(d); for (int i = 0; i < Down_d.Count; i++) { Down_d[i].Maxseepd = Limit_DownLoad_Speed; Down_d[i].Sum = Down_d.Count; } d.Percentage += Refresh; //if (ShowSharefile == null) { Task <int> task = _client.DownloadRequestAsync(SeleteInfo.Hash, d.Port); task.ContinueWith(T => { }); } //else ShowSharefile.SendDirectoryName(@":\" + Directory + @"\" + l.name); Serialization(@"./config/ImportDownLoadInfo", DownInfo); }); }