Exemplo n.º 1
0
        public bool send_file_invite(string target_stu_num, string file, int file_invite_id = 99999)
        {
            master.refresh();
            IPAddress tar_ip = find_ip(target_stu_num);

            if (tar_ip != null)
            {
                try
                {
                    SKMsgInfoFileInvite smifi = new SKMsgInfoFileInvite();
                    smifi.id        = file_invite_id;
                    smifi.stu_num   = my_stu_num;
                    smifi.timestamp = DateTime.Now;
                    smifi.type      = SKMsgInfoBase.mestype.FILE_INVITE;
                    smifi.file_name = Path.GetFileName(file);
                    long len = (new FileInfo(file)).Length;
                    if (len > int.MaxValue)
                    {
                        throw new Exception("文件不能大于2G");
                    }
                    smifi.size = (int)len;
                    return(clients.SendNotFile(smifi, tar_ip, target_stu_num));
                }
                catch (Exception)
                {
                    return(false);
                }
            }
            return(false);
        }
Exemplo n.º 2
0
        public void rev_file_invite(SKMsgInfoFileInvite e)
        {
            DialogResult dr = MessageBox.Show("是否接收文件?\n文件名为" + e.file_name + "\n文件大小为:" + (e.size / 1024) + "KB\n若您正在接收上一文件,将会终止传输", "接收文件确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (dr != System.Windows.Forms.DialogResult.Yes)
            {
                core.send_response(friend.stu_num, e.id + 1);
                add_text_rich1("\r\n你没有同意接收文件", Color.Blue);
            }
            else
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Title    = "选择保存文件位置";
                sfd.FileName = e.file_name;
                DialogResult drr = sfd.ShowDialog();
                if (drr == System.Windows.Forms.DialogResult.OK)
                {
                    bool   is_file  = false;
                    string filename = "";
                    try
                    {
                        filename = Path.GetFileName(sfd.FileName);
                        if (filename != null && filename != "")
                        {
                            is_file = true;
                        }
                    }
                    catch (Exception)
                    {
                        is_file = false;
                    }
                    if (is_file)
                    {
                        rev_file_full_name = sfd.FileName;
                        core.send_response(friend.stu_num, e.id);
                        add_text_rich1("\r\n你同意了接收文件请求,即将开始接收", Color.Blue);
                        if (waiting_file_rev)
                        {
                            core.rev_abort(friend.stu_num);
                        }
                        file_pieces.Clear();
                        waiting_file_rev = true;
                    }
                    else
                    {
                        core.send_response(friend.stu_num, e.id + 1);
                        waiting_file_rev = false;
                        add_text_rich1("\r\n你没有同意接收文件", Color.Blue);
                    }
                }
                else
                {
                    add_text_rich1("\r\n你没有同意接收文件", Color.Blue);
                    core.send_response(friend.stu_num, e.id + 1);
                    waiting_file_rev = false;
                }
            }
        }