Пример #1
0
        public async Task <bool> UploadFileAsync(TreeNode node, FileInfo file)
        {
            Directory_Info dir = (Directory_Info)node.Tag;

            socket.CryptoSend(BlindNetUtil.StructToByte(dir), PacketType.DocFileUpload);

            File_Info fi = new File_Info();

            fi.id      = 0;
            fi.name    = file.Name;
            fi.size    = (uint)file.Length;
            fi.modDate = file.LastWriteTime.ToString();
            fi.type    = Path.GetExtension(file.FullName).Replace(".", "");
            socket.CryptoSend(BlindNetUtil.StructToByte(fi), PacketType.Info);

            FileStream fs = file.OpenRead();

            byte[] buffer = new byte[fs.Length];
            await fs.ReadAsync(buffer, 0, (int)fs.Length);

            fs.Close();

            SendFile(buffer);
            BlindPacket packet = socket.CryptoReceive();

            if (packet.header == PacketType.Fail)
            {
                return(false);
            }

            return(true);
        }
Пример #2
0
        public void UpdateDir(TreeNode node)
        {
            form.listview_File.BeginUpdate();
            form.listview_File.Items.Clear();
            node.Nodes.Clear();

            socket.CryptoSend(BitConverter.GetBytes(((Directory_Info)(node.Tag)).id), PacketType.DocDirInfo);
            while (true)
            {
                BlindPacket packet = socket.CryptoReceive();
                if (packet.header == PacketType.EOF)
                {
                    break;
                }

                Directory_Info dir     = BlindNetUtil.ByteToStruct <Directory_Info>(BlindNetUtil.ByteTrimEndNull(packet.data));
                TreeNode       subNode = new TreeNode();
                subNode.Tag                = dir;
                subNode.Text               = dir.name;
                subNode.ImageIndex         = 0;
                subNode.SelectedImageIndex = 0;
                node.Nodes.Add(subNode);

                ListViewItem item = new ListViewItem();
                item.Text = dir.name;
                item.SubItems.Add(dir.modDate);
                item.SubItems.Add(string.Empty);
                item.Tag        = dir.id;
                item.ImageIndex = 0;
                form.listview_File.Items.Add(item);
            }

            while (true)
            {
                BlindPacket packet = socket.CryptoReceive();
                if (packet.header == PacketType.EOF)
                {
                    break;
                }

                File_Info    file = BlindNetUtil.ByteToStruct <File_Info>(BlindNetUtil.ByteTrimEndNull(packet.data));
                ListViewItem item = new ListViewItem();
                item.Text       = file.name;
                item.ImageIndex = 1;
                item.SubItems.Add(file.modDate);
                item.SubItems.Add(file.type);
                item.SubItems.Add(ConvertSize(file.size));
                item.Tag = file.id;
                form.listview_File.Items.Add(item);
            }
            form.listview_File.EndUpdate();
        }
Пример #3
0
        public bool UpdateNameDir(TreeNode node, string name)
        {
            Directory_Info dir = (Directory_Info)(node.Tag);

            dir.name = name;
            socket.CryptoSend(BlindNetUtil.StructToByte(dir), PacketType.DocChngNameDir);

            BlindPacket packet = socket.CryptoReceive();

            if (packet.header == PacketType.Fail)
            {
                return(false);
            }
            return(true);
        }
Пример #4
0
        public bool AddDir(TreeNode node, string name)
        {
            Directory_Info dir = new Directory_Info();

            dir.id        = 0;
            dir.parent_id = ((Directory_Info)(node.Parent.Tag)).id;
            dir.name      = name;

            socket.CryptoSend(BlindNetUtil.StructToByte(dir), PacketType.DocAddDir);
            BlindPacket packet = socket.CryptoReceive();

            if (packet.header != PacketType.OK)
            {
                return(false);
            }
            node.Tag = BlindNetUtil.ByteToStruct <Directory_Info>(BlindNetUtil.ByteTrimEndNull(packet.data));
            return(true);
        }
Пример #5
0
        public void UpdateRoot()
        {
            form.treeview_Dir.Nodes.Clear();

            socket.CryptoSend(null, PacketType.DocRefresh);
            while (true)
            {
                BlindPacket packet = socket.CryptoReceive();
                if (packet.header == PacketType.EOF)
                {
                    break;
                }

                Directory_Info dir  = BlindNetUtil.ByteToStruct <Directory_Info>(BlindNetUtil.ByteTrimEndNull(packet.data));
                TreeNode       node = new TreeNode();
                node.Tag                = dir;
                node.Text               = dir.name;
                node.ImageIndex         = 0;
                node.SelectedImageIndex = 0;
                form.treeview_Dir.Nodes.Add(node);
            }
        }
Пример #6
0
        public async Task <TreeNode> UploadDirAsync(TreeNode node, string path)
        {
            Directory_Info dir = new Directory_Info();

            dir.id        = 0;
            dir.parent_id = ((Directory_Info)node.Tag).id;
            dir.name      = Path.GetFileName(path);
            socket.CryptoSend(BlindNetUtil.StructToByte(dir), PacketType.DocAddDir);

            BlindPacket packet = await Task.Run(() => socket.CryptoReceive());

            if (packet.header == PacketType.Fail)
            {
                return(null);
            }

            Directory_Info newDir  = BlindNetUtil.ByteToStruct <Directory_Info>(BlindNetUtil.ByteTrimEndNull(packet.data));
            TreeNode       newNode = new TreeNode();

            newNode.Tag                = newDir;
            newNode.Text               = newDir.name;
            newNode.ImageIndex         = 0;
            newNode.SelectedImageIndex = 0;

            form.progressBar.PerformStep();
            if (form.progressBar.Value < form.progressBar.Maximum)
            {
                form.progressBar.Value += 1;
            }
            form.progressBar.Value -= 1;
            form.label_percent.Text = (form.progressBar.Value * 100 / form.progressBar.Maximum) + "%";
#if DEBUG
            form.label_percent.Text = form.progressBar.Value.ToString();
#endif
            form.label_percent.Update();

            return(newNode);
        }