Exemple #1
0
        private int GetImageIndex(string name)
        {
            string extname = System.IO.Path.GetExtension(name);

            //if (extname.IndexOf(".exe") >= 0)
            //{
            //    return 4;
            //}
            //else if (extname.IndexOf(".dll") >= 0)
            //{
            //    return 3;
            //}
            //else
            //{


            string filename = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "Icon" + extname);

            if (!File.Exists(filename))
            {
                File.Create(filename).Close();
            }

            return(SystemICO.FileIconIndex(filename));

            //}
        }
Exemple #2
0
        void SocketManager_BinaryInput(byte[] data)
        {
            ReadBytesV2 read = new ReadBytesV2(data, Deflate.Decompress);
            int         lengt;
            int         cmd;

            if (read.ReadInt32(out lengt) && lengt == read.Length && read.ReadInt32(out cmd))
            {
                PackType cmdtype = (PackType)cmd;

                switch (cmdtype)
                {
                case PackType.GetDisk:
                case PackType.Dir:
                {
                    Dir dir;
                    if (read.ReadObject <Dir>(out dir))
                    {
                        this.BeginInvoke(new EventHandler((a, b) =>
                            {
                                if (dir.IsSuccess)
                                {
                                    this.button1.Enabled = true;
                                    this.button1.Text    = "上层目录";

                                    this.listView1.Clear();

                                    dir.FileSystemList.Sort(new Comparison <FileSystem>((a1, a2) =>
                                    {
                                        if (a1.FileType == FileType.Dir && a2.FileType == FileType.Dir)
                                        {
                                            return(a1.Name.CompareTo(a2.Name));
                                        }
                                        else if (a1.FileType != FileType.Dir && a2.FileType != FileType.Dir)
                                        {
                                            return(a1.Name.CompareTo(a2.Name));
                                        }
                                        else if (a1.FileType == FileType.Dir && a2.FileType == FileType.File)
                                        {
                                            return(-1);
                                        }
                                        else if (a2.FileType == FileType.Dir && a1.FileType == FileType.File)
                                        {
                                            return(1);
                                        }
                                        else
                                        {
                                            return(0);
                                        }
                                    }));


                                    SystemICO.ListViewSysImages(this.listView1);
                                    int x1 = 0, x2 = 0;
                                    foreach (FileSystem p in dir.FileSystemList)
                                    {
                                        if (p.FileType == FileType.File)
                                        {
                                            this.listView1.Items.Add(new ListViewItem()
                                            {
                                                Text       = p.Name,
                                                ImageIndex = GetImageIndex(p.Name),
                                                Tag        = p
                                            });
                                            x1++;
                                        }
                                        else
                                        {
                                            this.listView1.Items.Add(new ListViewItem()
                                            {
                                                Text       = p.Name,
                                                ImageIndex = 1,
                                                Tag        = p
                                            });

                                            x2++;
                                        }
                                    }

                                    if (!string.IsNullOrEmpty(Path))
                                    {
                                        string apath = dir.DirName;

                                        apath = apath.Remove(0, Path.Length);

                                        if (string.IsNullOrEmpty(apath))
                                        {
                                            apath = "\\";
                                        }

                                        this.textBox1.Text = apath;
                                    }
                                    else
                                    {
                                        this.textBox1.Text = dir.DirName;
                                    }

                                    CurrentDir = dir.DirName;

                                    this.label2.Text = "共找到目录:" + x2 + "个,文件:" + x1 + "个";
                                }
                                else
                                {
                                    MessageBox.Show(dir.Msg);
                                }
                            }));
                    }
                }
                break;

                case PackType.DelFile:
                {
                    DelFile dfile;
                    if (read.ReadObject <DelFile>(out dfile))
                    {
                        this.BeginInvoke(new EventHandler((a, b) =>
                            {
                                string isErr = "";
                                foreach (DelFileName p in dfile.DelFileList)
                                {
                                    if (!p.IsSuccess)
                                    {
                                        isErr += p.Msg + "\r\n";
                                    }
                                }

                                if (isErr == "")
                                {
                                    MessageBox.Show("删除成功");
                                }
                                else
                                {
                                    MessageBox.Show(isErr);
                                }

                                GotoDir();
                            }));
                    }
                }
                break;

                case PackType.NewDir:
                {
                    PackHandler.NewDir ndir;
                    if (read.ReadObject <PackHandler.NewDir>(out ndir))
                    {
                        this.BeginInvoke(new EventHandler((a, b) =>
                            {
                                if (ndir.IsSuccess)
                                {
                                    GotoDir();
                                }
                                else
                                {
                                    MessageBox.Show(ndir.Msg);
                                    GotoDir();
                                }
                            }));
                    }
                }
                break;

                case PackType.MoveFileSystem:
                {
                    PackHandler.MoveFileSystem mfs;

                    if (read.ReadObject <PackHandler.MoveFileSystem>(out mfs))
                    {
                        this.BeginInvoke(new EventHandler((a, b) =>
                            {
                                if (!mfs.IsSuccess)
                                {
                                    MessageBox.Show(mfs.Msg);
                                    GotoDir();
                                }

                                if (this.MoveFile != null)
                                {
                                    if (mfs.OldName == MoveFile.FullName)
                                    {
                                        GotoDir();

                                        this.MoveFile = null;
                                    }
                                }
                            }));
                    }
                }
                break;

                case PackType.Run:
                {
                    Run run;
                    if (read.ReadObject <Run>(out run))
                    {
                        this.BeginInvoke(new EventHandler((a, b) =>
                            {
                                if (run.IsSuccess)
                                {
                                    MessageBox.Show("运行成功");
                                }
                                else
                                {
                                    MessageBox.Show(run.Msg);
                                }
                            }));
                    }
                }
                break;

                case PackType.Down:
                {
                    Down down;
                    if (read.ReadObject <Down>(out down))
                    {
                        this.BeginInvoke(new EventHandler((a, b) =>
                            {
                                if (down.IsSuccess)
                                {
                                    DownFile downwin = new DownFile(down);
                                    downwin.Show();
                                }
                                else
                                {
                                    MessageBox.Show(down.Msg);
                                }
                            }));
                    }
                }
                break;

                case PackType.UpFile:
                {
                    UpFile upFile;
                    if (read.ReadObject <UpFile>(out upFile))
                    {
                        if (!upFile.IsSuccess)
                        {
                            this.BeginInvoke(new EventHandler((a, b) =>
                                {
                                    MessageBox.Show("上传文件发生错误:" + upFile.Msg);
                                }));
                        }
                        else
                        {
                            if (UpFileList.ContainsKey(upFile.UpKey))
                            {
                                this.BeginInvoke(new EventHandler((a, b) =>
                                    {
                                        FileStream stream = UpFileList[upFile.UpKey];

                                        UpFiles win = new UpFiles(this, upFile.FullName, upFile.UpKey, stream);
                                        win.Show();
                                    }));
                            }
                            else
                            {
                                this.BeginInvoke(new EventHandler((a, b) =>
                                    {
                                        MessageBox.Show("上传文件发生错误:无法找到KEY所指定的文件");
                                    }));
                            }
                        }
                    }
                }
                break;

                case PackType.UpClose:
                {
                    long key;
                    if (read.ReadInt64(out key))
                    {
                        if (UpFileList.ContainsKey(key))
                        {
                            this.UpFileList[key].Close();
                            this.UpFileList.Remove(key);
                            this.BeginInvoke(new EventHandler((a, b) =>
                                {
                                    if (UpFileClose != null)
                                    {
                                        UpFileClose(key);
                                    }
                                }));
                        }
                    }
                }
                break;

                case PackType.ReBytes:
                {
                    long downkey;

                    if (read.ReadInt64(out downkey))
                    {
                        long startpostion;
                        int  size;

                        if (read.ReadInt64(out startpostion) && read.ReadInt32(out size))
                        {
                            if (this.UpFileList.ContainsKey(downkey))
                            {
                                FileStream strem = UpFileList[downkey];

                                strem.Position = startpostion;

                                byte[] xdata = new byte[size];

                                strem.Read(xdata, 0, xdata.Length);


                                BufferFormatV2 buff = new BufferFormatV2((int)PackType.DataSet);
                                buff.AddItem(downkey);
                                buff.AddItem(startpostion);
                                buff.AddItem(xdata);
                                SocketManager.Send(buff.Finish());
                            }
                            else
                            {
                                BufferFormatV2 buff = new BufferFormatV2((int)PackType.UpClose);
                                buff.AddItem(downkey);
                                SocketManager.Send(buff.Finish());
                            }
                        }
                    }
                }
                break;
                }
            }
        }