Skip to content

Commit

Permalink
2019年 04月 05日 星期五 22:37:29 CST
Browse files Browse the repository at this point in the history
  • Loading branch information
rocket049 committed Apr 5, 2019
1 parent dbac400 commit 86415b3
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 17 deletions.
1 change: 1 addition & 0 deletions client/libclient/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ func (s *FileSender) SendFileBody() {
}
msg, _ := MsgEncode(CmdFileClose, 0, s.to, b1[:4])
s.conn.Write(msg)
notifyMsg(&MsgType{CmdChat, s.to, 0, []byte("F OK\n")})
s.mutex1.Lock()
s.running = false
s.mutex1.Unlock()
Expand Down
8 changes: 8 additions & 0 deletions client/ui.vala
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,8 @@ label{
return;
}else if(typ1=="JSON"){
fname = @"ID:$(from)";
}else if(typ1=="F OK"){
fname = @"ID:$(from)";
}

switch(typ1){
Expand Down Expand Up @@ -831,6 +833,12 @@ label{
break;
user_online(from);
break;
case "F OK":
this.add_right_name_icon(fname,fsex);
this.add_text(_("[File transfer complete]"));
msg_mark(from.to_string());
msg_notify(fname);
break;
}
GLib.Idle.add(()=>{
var adj1 = this.msgs.get_adjustment();
Expand Down
14 changes: 7 additions & 7 deletions pclientbackend/exports.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,24 +534,24 @@ type SFParam struct {
PathName string
}

//SendFile 发送文件,参数:id,pathname
func (c *ChatClient) SendFile(to int64, pathName string) {
//SendFile 发送文件,参数:id,pathname;返回值: 0-成功,正在传送;1-内部错误;2-接收方忙。
func (c *ChatClient) SendFile(to int64, pathName string) int {
param := &SFParam{To: to, PathName: pathName}
if cSrv.fileSend != nil {
if cSrv.fileSend.status() {
notifyMsg(&MsgType{Cmd: CmdChat, From: 0, To: 0, Msg: []byte("OneOnly!\n")})
return
return 1
}
}
//log.Println(param.PathName);
var sender = new(FileSender)
sender.prepare(param.PathName, param.To, cSrv.conn)
ok, _ := sender.sendFileHeader()
if ok == false {
return
ret := sender.sendFileHeader()
if ret > 0 {
return ret
}
cSrv.fileSend = sender
go sender.sendFileBody()
return 0
}

//AddFriend 加入联系人
Expand Down
17 changes: 11 additions & 6 deletions pclientbackend/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,12 @@ func (s *FileSender) prepare(pathname string, to int64, conn1 io.Writer) {

var fileResp = make(chan MsgType, 1)

func (s *FileSender) sendFileHeader() (bool, uint32) {
//sendFileHeader return: 0-成功,正在传送;1-内部错误;2-接收方忙。
func (s *FileSender) sendFileHeader() int {
fh1, err := os.Stat(s.pathname)
if err != nil {
log.Println(err)
return false, 0
return 1
}
secs := strings.Split(s.pathname, ".")
var typ1 string
Expand All @@ -210,21 +211,24 @@ func (s *FileSender) sendFileHeader() (bool, uint32) {
b1, err := json.Marshal(fh2)
if err != nil {
log.Println(err)
return false, 0
return 1
}
msg, _ := MsgEncode(CmdFileHeader, 0, s.to, b1)
s.conn.Write(msg)
log.Printf("Send header: %s\n", fh2.Name)
res, ok := <-fileResp
if ok == false {
log.Println("internal error")
return false, 0
return 1
}
if res.Cmd == CmdFileBlock {
return 2
}
if binary.BigEndian.Uint32(res.Msg) != s.session {
return false, 0
return 1
}
s.size = fh1.Size()
return true, s.session
return 0
}

func (s *FileSender) cancelTrans() {
Expand Down Expand Up @@ -260,6 +264,7 @@ func (s *FileSender) sendFileBody() {
s.sendSize += int64(n)
msg, _ := MsgEncode(CmdFileContinued, 0, s.to, b1[:n+4])
s.conn.Write(msg)
notifyMsg(&MsgType{CmdChat, s.to, 0, []byte("F OK\n")})
}
msg, _ := MsgEncode(CmdFileClose, 0, s.to, b1[:4])
s.conn.Write(msg)
Expand Down
4 changes: 0 additions & 4 deletions pclientbackend/go.sum

This file was deleted.

Binary file modified share/locale/zh_CN/LC_MESSAGES/powerchat.mo
Binary file not shown.
3 changes: 3 additions & 0 deletions share/locale/zh_CN/LC_MESSAGES/powerchat.po
Original file line number Diff line number Diff line change
Expand Up @@ -411,3 +411,6 @@ msgstr "发送失败:未知错误"

msgid "Fail send file : peer block"
msgstr "发送失败:接收方忙"

msgid "[File transfer complete]"
msgstr "[文件发送完成]"

0 comments on commit 86415b3

Please sign in to comment.