0
0
Fork 0
mirror of https://github.com/schollz/croc.git synced 2025-10-11 13:21:00 +02:00

add more info to win

This commit is contained in:
Zack Scholl 2018-10-19 06:36:45 -07:00
parent 2fc216cb1b
commit 62bf674365
4 changed files with 55 additions and 53 deletions

View file

@ -57,6 +57,7 @@ type Croc struct {
StateString string
Bar *progressbar.ProgressBar
FileInfo models.FileStats
OtherIP string
// special for window
WindowRecipientPrompt bool

View file

@ -47,7 +47,6 @@ func (cr *Croc) receive(forceSend int, serverAddress string, tcpPorts []string,
var sessionKey []byte
var transferTime time.Duration
var hash256 []byte
var otherIP string
var progressFile string
var resumeFile bool
var tcpConnections []comm.Comm
@ -103,8 +102,8 @@ func (cr *Croc) receive(forceSend int, serverAddress string, tcpPorts []string,
switch step {
case 0:
// sender has initiated, sends their ip address
otherIP = string(message)
log.Debugf("sender IP: %s", otherIP)
cr.OtherIP = string(message)
log.Debugf("sender IP: %s", cr.OtherIP)
// recipient begins by sending address
ip := ""
@ -284,7 +283,7 @@ func (cr *Croc) receive(forceSend int, serverAddress string, tcpPorts []string,
// start the ui for pgoress
cr.StateString = "Recieving file..."
bytesWritten := 0
fmt.Fprintf(os.Stderr, "\nReceiving (<-%s)...\n", otherIP)
fmt.Fprintf(os.Stderr, "\nReceiving (<-%s)...\n", cr.OtherIP)
cr.Bar = progressbar.NewOptions(
int(cr.FileInfo.Size),
progressbar.OptionSetRenderBlankState(true),

View file

@ -48,7 +48,6 @@ func (cr *Croc) send(forceSend int, serverAddress string, tcpPorts []string, isL
var f *os.File
defer f.Close() // ignore the error if it wasn't opened :(
var fileHash []byte
var otherIP string
var startTransfer time.Time
var tcpConnections []comm.Comm
blocksToSkip := make(map[int64]struct{})
@ -128,8 +127,8 @@ func (cr *Croc) send(forceSend int, serverAddress string, tcpPorts []string, isL
c.WriteMessage(websocket.BinaryMessage, []byte(ip))
case 1:
// first receive the IP address from the sender
otherIP = string(message)
log.Debugf("recipient IP: %s", otherIP)
cr.OtherIP = string(message)
log.Debugf("recipient IP: %s", cr.OtherIP)
go func() {
// recipient might want file! start gathering information about file
@ -357,7 +356,7 @@ func (cr *Croc) send(forceSend int, serverAddress string, tcpPorts []string, isL
return errors.New("recipient refused file")
}
cr.StateString = "Transfer in progress..."
fmt.Fprintf(os.Stderr, "\rSending (->%s)...\n", otherIP)
fmt.Fprintf(os.Stderr, "\rSending (->%s)...\n", cr.OtherIP)
// send file, compure hash simultaneously
startTransfer = time.Now()

View file

@ -8,6 +8,7 @@ import (
"path/filepath"
"time"
humanize "github.com/dustin/go-humanize"
"github.com/schollz/croc/src/cli"
"github.com/schollz/croc/src/croc"
"github.com/schollz/croc/src/utils"
@ -82,12 +83,17 @@ func main() {
go func(done chan bool) {
for {
if cr.FileInfo.SentName != "" {
labels[0].UpdateTextFromGoroutine(fmt.Sprintf("Sending %s", cr.FileInfo.SentName))
if cr.OtherIP != "" && cr.FileInfo.SentName != "" {
bytesString := humanize.Bytes(uint64(cr.FileInfo.Size))
fileOrFolder := "file"
if cr.FileInfo.IsDir {
fileOrFolder = "folder"
}
labels[0].UpdateTextFromGoroutine(fmt.Sprintf("Sending %s %s '%s' to %s", bytesString, fileOrFolder, cr.FileInfo.SentName, cr.OtherIP))
}
if cr.Bar != nil {
barState := cr.Bar.State()
labels[1].UpdateTextFromGoroutine(fmt.Sprintf("%2.1f%% [%2.0f:%2.0f]", barState.CurrentPercent*100, barState.SecondsSince, barState.SecondsLeft))
labels[1].UpdateTextFromGoroutine(fmt.Sprintf("%2.1f%% [%2.0fs:%2.0fs]", barState.CurrentPercent*100, barState.SecondsSince, barState.SecondsLeft))
}
labels[2].UpdateTextFromGoroutine(cr.StateString)
time.Sleep(100 * time.Millisecond)
@ -129,29 +135,31 @@ func main() {
}
var fn = folderDialog.SelectedFiles()[0]
if len(fn) == 0 {
dialog(fmt.Sprintf("No folder selected"))
labels[2].SetText(fmt.Sprintf("No folder selected"))
return
}
var codePhrase = widgets.QInputDialog_GetText(window, "croc", "Enter code phrase:",
widgets.QLineEdit__Normal, "", true, core.Qt__Dialog, core.Qt__ImhNone)
if len(codePhrase) < 3 {
dialog(fmt.Sprintf("Invalid codephrase: '%s'", codePhrase))
labels[2].SetText(fmt.Sprintf("Invalid codephrase: '%s'", codePhrase))
return
}
// change into the receiving directory
cwd, _ := os.Getwd()
go func() {
os.Chdir(fn)
defer os.Chdir(cwd)
os.Chdir(fn)
cr := croc.Init(true)
cr.WindowRecipientPrompt = true
done := make(chan bool)
go func(done chan bool) {
go func() {
cr.Receive(codePhrase)
done <- true
isWorking = false
}()
for {
if cr.WindowReceivingString != "" {
var question = widgets.QMessageBox_Question(window, "croc", fmt.Sprintf("%s?", cr.WindowReceivingString), widgets.QMessageBox__Yes|widgets.QMessageBox__No, 0)
@ -169,7 +177,7 @@ func main() {
if cr.Bar != nil {
barState := cr.Bar.State()
labels[1].UpdateTextFromGoroutine(fmt.Sprintf("%2.1f%% [%2.0f:%2.0f]", barState.CurrentPercent*100, barState.SecondsSince, barState.SecondsLeft))
labels[1].UpdateTextFromGoroutine(fmt.Sprintf("%2.1f%% [%2.0fs:%2.0fs]", barState.CurrentPercent*100, barState.SecondsSince, barState.SecondsLeft))
}
labels[2].UpdateTextFromGoroutine(cr.StateString)
time.Sleep(100 * time.Millisecond)
@ -181,12 +189,7 @@ func main() {
continue
}
}
}(done)
cr.Receive(codePhrase)
done <- true
isWorking = false
}()
})
widget.Layout().AddWidget(receiveButton)