Exemple #1
0
        public MainForm()
        {
            InitializeComponent();

            transferManager  = null;
            searchNumber     = 0;
            nodeDialog       = new nodeDialog(this);
            directoryManager = new DirectoryManager(this);
            shareDialog      = new ShareDialog(this);
            noticeDialog     = new NoticeDialog("");
            joinDialog       = new JoinDialog(this);
            progressDialog   = new TransferProgressDialog(this);
            registryManager  = new RegistryManager();
            serverFolerMap   = new Dictionary <string, ShareFolder>();
            shareFolderMap   = new Dictionary <string, ShareFolder>();
            findDialog       = new FindNodeDialog(this, ref nodeDialog.keys_list, ref nodeDialog.find_keys_list);
            DoChangeBtnName(btnConnect, CONST.BTN_NAME_LOGIN);

            file_list = new List <string>();

            txtID.Text         = "cks1023";
            txtPassword.Text   = "1234";
            txtServerip.Text   = "127.0.0.1";
            txtServerport.Text = "35000";

            client         = new Client(this);
            rootFolderPath = new List <string[]>();
        }
Exemple #2
0
        protected override void OnAfterLabelEdit(NodeLabelEditEventArgs e)
        {
            String key1 = e.Node.FullPath;

            if (mainForm.nodeDialog.keys_list.ContainsKey(key1))
            {
                mainForm.nodeDialog.keys_list.Remove(key1);
            }

            this.BeginInvoke((MethodInvoker) delegate
            {
                mainForm.destKey    = e.Node.FullPath;
                int index           = mainForm.destKey.LastIndexOf("\\");
                String tempNodeName = mainForm.destKey.Substring(index + 1);

                //textBox1.Text = destKey;
                mainForm.nodeDialog.keys_list.Add(mainForm.destKey, tempNodeName);
                DirectoryManager.FolderNameChange(key1, mainForm.destKey);
            });
            base.OnAfterLabelEdit(e);
        }
Exemple #3
0
        public void ThreadReceiveFile(Socket sock, int fileCount)
        {
            byte[]        temp     = new byte[4];
            List <string> nodeList = new List <string>();

            byte[]        fileArray = new byte[CONST.BUFFER_SIZE];
            NetworkStream ns = new NetworkStream(sock);
            int           strlen = 0;
            string        key, name;

            TreeNode[] rootNode = new TreeNode[1];

            long fileLength = 0;

            lock (lockKey)
            {
                //업로드될 노드선택 (노드의키 받기)
                temp = new byte[4];
                ns.Read(temp, 0, temp.Length);
                strlen = BitConverter.ToInt32(temp, 0);
                temp   = new byte[strlen];
                ns.Read(temp, 0, temp.Length);
                key      = Encoding.UTF8.GetString(temp);
                rootNode = f.ClientTree.Nodes.Find(key, true);


                //파일인 노드 키 받기
                temp = new byte[4];
                ns.Read(temp, 0, temp.Length);
                strlen = BitConverter.ToInt32(temp, 0);
                temp   = new byte[strlen];
                ns.Read(temp, 0, temp.Length);
                string originalRoot = Encoding.UTF8.GetString(temp);

                //파일인 노드 키 받기
                temp = new byte[4];
                ns.Read(temp, 0, temp.Length);
                strlen = BitConverter.ToInt32(temp, 0);
                temp   = new byte[strlen];
                ns.Read(temp, 0, temp.Length);
                key = Encoding.UTF8.GetString(temp);

                //파일인 노드의 이름 받기
                temp = new byte[4];
                ns.Read(temp, 0, temp.Length);
                strlen = BitConverter.ToInt32(temp, 0);
                temp   = new byte[strlen];
                ns.Read(temp, 0, temp.Length);
                name = Encoding.UTF8.GetString(temp);

                string parentNode   = rootNode[0].Name + "\\" + originalRoot; //전송받을 파일의 상위폴더
                string fullNamePath = parentNode + "\\" + name;               //전송파일의 전체경로

                //파일크기받기(long)
                temp = new byte[8];
                ns.Read(temp, 0, temp.Length);
                fileLength = BitConverter.ToInt64(temp, 0);


                FileInfo fi = new FileInfo(fullNamePath);

                FileSecurity fSecurity = null;

                FileStream fileStream = null;
                //fSecurity = File.GetAccessControl(rootNode[0].Name);
                //fSecurity.AddAccessRule(new FileSystemAccessRule("NETWORK SERVICE",
                //    FileSystemRights.FullControl, AccessControlType.Allow));

                ////없는 폴더를 받았다면 상위의 폴더들을 만든다.
                DirectoryManager.CreateRootDir(parentNode);
                MyTreeView.MakeParentNode(rootNode[0], originalRoot);

                fileStream = File.Create(fullNamePath, CONST.BUFFER_SIZE);

                //File.SetAccessControl(rootNode[0].Name, fSecurity);

                if (fileLength < CONST.BUFFER_SIZE)
                {
                    fileArray = new byte[fileLength];
                    ns.Read(fileArray, 0, fileArray.Length);
                    fileStream.Write(fileArray, 0, fileArray.Length);
                }
                else
                {
                    int l         = 0;
                    int byteCount = (int)(fileLength / CONST.BUFFER_SIZE);
                    int remain    = (int)(fileLength - byteCount * CONST.BUFFER_SIZE);
                    //4바이트는 빈공간이 날라오므로 먼저 읽어버린다.
                    //ns.Read(new byte[4], 0, 4);

                    while (l < byteCount)
                    {
                        fileArray = new byte[CONST.BUFFER_SIZE];
                        ns.Read(fileArray, 0, fileArray.Length);
                        fileStream.Write(fileArray, 0, fileArray.Length);

                        l++;
                    }

                    //남은 여분의 크기를 받는다.
                    fileArray = new byte[remain];
                    ns.Read(fileArray, 0, fileArray.Length);
                    fileStream.Write(fileArray, 0, fileArray.Length);
                }

                fileStream.Close();
                fileStream.Dispose();

                f.ClientTree.Invoke(new Action(delegate()
                {
                    //이미 존재하는경우
                    if (f.ClientTree.Nodes.Find(fullNamePath, true).Length > 0)
                    {
                        ;
                    }

                    else if (f.ClientTree.Nodes.Find(parentNode, true).Length == 0)
                    {
                        rootNode[0].Nodes.Add(fullNamePath, name);
                    }
                    else
                    {
                        f.ClientTree.Nodes.Find(parentNode, true)[0].Nodes.Add(fullNamePath, name);
                    }
                }));
            }

            ns.Close();
            ns.Dispose();
        }