// the thread structure for running
 private void threadCreate(Func <Func <string, string>, TcpClient, bool> act, bool needWait)
 {
     toRun = new Thread(() =>
     {
         cmd.passiveDataAction(string.Format(CommandConstant.CMD_FMT_BREAKPOINT, offset), act, needWait);
     });
 }
Exemple #2
0
        // reload the server box of file
        private void refreshFtp()
        {
            LVFtp.Items.Clear();
            if (!BoxFtpPath.Text.Equals("\\"))
            {
                ListViewItem it = new ListViewItem();
                it.Text = "..";
                it.SubItems.Add("directory");
                LVFtp.Items.Add(it);
            }


            // rsy56640
            // consider when no task or no connection.
            // and use `Select` to detect the whether the connection is ok.
            if (cmd == null)
            {
                return;
            }

            ArrayList writeList = new ArrayList();

            writeList.Add(cmd.tcp.Client);
            ArrayList listenList = new ArrayList();

            listenList.Add(cmd.tcp.Client);
            Socket.Select(listenList, writeList, null, 1000);

            if (listenList.Count == 0)// || writeList.Count != 0)
            {
                cmd.passiveDataAction(CommandConstant.CMD_LIST, (send, data) =>
                {
                    StreamReader reader = new StreamReader(data.GetStream(), cmd.encoder);
                    string s;
                    while ((s = reader.ReadLine()) != null)
                    {
                        var size        = Convert.ToUInt64(Regex.Match(s.Substring(24), @"\d+").ToString());
                        ListViewItem it = new ListViewItem();

                        // a simple function for finding elements, does not consider generality and robustness
                        // for it's only used here.
                        Func <string, int, int> findNthSection = (str, n) =>
                        {
                            int start = 0;
                            while (str[start] == ' ')
                            {
                                ++start;
                            }
                            int count = 0;
                            bool cont = false;
                            while (start < str.Length)
                            {
                                if (str[start++] == ' ')
                                {
                                    if (!cont)
                                    {
                                        cont = true;
                                    }
                                    else
                                    {
                                        ;
                                    }
                                }
                                else if (cont)
                                {
                                    if (++count == n)
                                    {
                                        return(start - 1);
                                    }
                                    else
                                    {
                                        cont = false;
                                    }
                                }
                            }
                            return(start);
                        };
                        it.Text = s.Substring(findNthSection(s, 8));

                        ///*
                        // * Reeker - fix bug with FTP filename
                        // * before this, filename for files which are not modified this year will lose its first char
                        // * */
                        //// get the filename according to whether the file is modified this year
                        //if (s[48] == ':')
                        //    it.Text = s.Substring(52);
                        //else
                        //    it.Text = s.Substring(51);
                        ////end

                        if (s[0] == 'd')
                        {
                            it.SubItems.Add("directory");
                        }
                        else
                        {
                            it.SubItems.Add(size.ToString());
                        }
                        LVFtp.Items.Add(it);
                    }
                    return(true);
                }, true);
            }
            else
            {
                //cmd.tcp.Client.Close();
                task = null;
            }
        }