Ejemplo n.º 1
0
        public static void SendClipboardFiles(Socket socket)
        {
            FileAttributes attr;
            FileInfo       fi;
            DirectoryInfo  di;

            string name;

            foreach (string path in Clipboard.GetFileDropList())
            {
                attr = File.GetAttributes(path);
                if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    di   = new DirectoryInfo(path);
                    name = path.Substring(di.FullName.Length - di.Name.Length);
                    //Console.WriteLine("Try to sending Dir: " + name);
                    MsgStream.Send(new DirMsgCBP(name, true), socket);
                    SeekAndSend(socket, path, di.FullName.Length - di.Name.Length);
                }
                else
                {
                    fi   = new FileInfo(path);
                    name = path.Substring(fi.DirectoryName.Length + 1);
                    //Console.WriteLine("Try to sending File: " + name);
                    MsgStream.Send(new FileMsgCBP(name, File.ReadAllBytes(path), true), socket);
                }
            }
        }
Ejemplo n.º 2
0
        public static void RecvClipboardFiles(Socket socket)
        {
            Message          o;
            StringCollection sc = new StringCollection();

            string path   = null;
            string tmpdir = Path.GetTempPath() + "PDS_project\\";

            //Console.WriteLine("Files stored in: "  + tmpdir);

            if (Directory.Exists(tmpdir))
            {
                Directory.Delete(tmpdir, true);
            }
            Directory.CreateDirectory(tmpdir);

            do
            {
                o = (Message)MsgStream.Receive(socket);

                if (o is FileMsgCBP)
                {
                    path = tmpdir + ((FileMsgCBP)o).name;
                    File.WriteAllBytes(path, ((FileMsgCBP)o).content);
                    if (((FileMsgCBP)o).root)
                    {
                        sc.Add(path);
                    }
                    //Console.WriteLine("Craeted new File: " + path);
                }

                if (o is DirMsgCBP)
                {
                    path = tmpdir + ((DirMsgCBP)o).name;
                    Directory.CreateDirectory(path);
                    if (((DirMsgCBP)o).root)
                    {
                        sc.Add(path);
                    }
                    //Console.WriteLine("Craeted new Dir: " + path);
                }
            }while (!(o is StopFileCBP));


            CBloader = new Thread((new CBLoaderThread()).run);
            CBloader.SetApartmentState(ApartmentState.STA);
            CBloader.Start(sc);

            CBloader.Join();

            MsgStream.Send(new ConfirmCBP(), socket);
        }
Ejemplo n.º 3
0
        private static void SeekAndSend(Socket socket, string path, int toCut)
        {
            string name;

            foreach (string dir in Directory.EnumerateDirectories(path))
            {
                name = dir.Substring(toCut);
                //Console.WriteLine("Try to sending Dir: " + name);
                MsgStream.Send(new DirMsgCBP(name, false), socket);
                SeekAndSend(socket, dir, toCut);
            }

            foreach (string file in Directory.EnumerateFiles(path))
            {
                name = file.Substring(toCut);
                //Console.WriteLine("Try to sending File: " + name);
                MsgStream.Send(new FileMsgCBP(name, File.ReadAllBytes(file), false), socket);
            }
        }