private void _Up_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { string filename = openFileDialog1.FileName; FileInfo file = new FileInfo(filename); if (file.Exists) { FileStream stream = new FileStream(filename, FileMode.Open, FileAccess.Read); Re: long key = DateTime.Now.Ticks; if (UpFileList.ContainsKey(key)) { System.Threading.Thread.Sleep(1); goto Re; } UpFileList.Add(key, stream); string upfilename = CurrentDir + file.Name; if (CurrentDir[CurrentDir.Length - 1] != '\\') { upfilename = CurrentDir + "\\" + file.Name; } UpFile upfile = new UpFile() { FullName = upfilename, Size = stream.Length, UpKey = key, }; SocketManager.Send(BufferFormatV2.FormatFCA(upfile, Deflate.Compress)); } } }
private void listView1_DragDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { string str = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString(); FileInfo file = new FileInfo(str); if (file.Exists) { FileStream stream = new FileStream(str, FileMode.Open, FileAccess.Read); Re: long key = DateTime.Now.Ticks; if (UpFileList.ContainsKey(key)) { System.Threading.Thread.Sleep(1); goto Re; } UpFileList.Add(key, stream); string upfilename = CurrentDir + file.Name; if (CurrentDir[CurrentDir.Length - 1] != '\\') { upfilename = CurrentDir + "\\" + file.Name; } UpFile upfile = new UpFile() { FullName = upfilename, Size = stream.Length, UpKey = key, }; SocketManager.Send(BufferFormatV2.FormatFCA(upfile, Deflate.Compress)); } } else if (e.Data.GetDataPresent(DataFormats.Text)) { MessageBox.Show((e.Data.GetData(DataFormats.Text)).ToString(), "提示信息", MessageBoxButtons.OK); } }
private void UpFileEx(string cudir,string name) { FileInfo file = new FileInfo(name); if (file.Exists) { FileStream stream = new FileStream(name, FileMode.Open, FileAccess.Read); Re: long key = DateTime.Now.Ticks; if (UpFileList.ContainsKey(key)) { System.Threading.Thread.Sleep(1); goto Re; } UpFileList.Add(key, stream); string upfilename = System.IO.Path.Combine(cudir,file.Name); UpFile upfile = new UpFile() { FullName = upfilename, Size = stream.Length, UpKey = key, }; SocketManager.Send(BufferFormatV2.FormatFCA(upfile, Deflate.Compress)); } else { DirectoryInfo dir = new DirectoryInfo(name); if (dir.Exists) { string fullname =System.IO.Path.Combine(cudir,dir.Name); PackHandler.NewDir ndir = new PackHandler.NewDir() { DirName = fullname }; SocketManager.Send(BufferFormatV2.FormatFCA(ndir, Deflate.Compress)); foreach (var item in dir.GetFileSystemInfos()) { UpFileEx(fullname, item.FullName); } } } }