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:
parent
2fc216cb1b
commit
62bf674365
4 changed files with 55 additions and 53 deletions
|
@ -57,6 +57,7 @@ type Croc struct {
|
||||||
StateString string
|
StateString string
|
||||||
Bar *progressbar.ProgressBar
|
Bar *progressbar.ProgressBar
|
||||||
FileInfo models.FileStats
|
FileInfo models.FileStats
|
||||||
|
OtherIP string
|
||||||
|
|
||||||
// special for window
|
// special for window
|
||||||
WindowRecipientPrompt bool
|
WindowRecipientPrompt bool
|
||||||
|
|
|
@ -47,7 +47,6 @@ func (cr *Croc) receive(forceSend int, serverAddress string, tcpPorts []string,
|
||||||
var sessionKey []byte
|
var sessionKey []byte
|
||||||
var transferTime time.Duration
|
var transferTime time.Duration
|
||||||
var hash256 []byte
|
var hash256 []byte
|
||||||
var otherIP string
|
|
||||||
var progressFile string
|
var progressFile string
|
||||||
var resumeFile bool
|
var resumeFile bool
|
||||||
var tcpConnections []comm.Comm
|
var tcpConnections []comm.Comm
|
||||||
|
@ -103,8 +102,8 @@ func (cr *Croc) receive(forceSend int, serverAddress string, tcpPorts []string,
|
||||||
switch step {
|
switch step {
|
||||||
case 0:
|
case 0:
|
||||||
// sender has initiated, sends their ip address
|
// sender has initiated, sends their ip address
|
||||||
otherIP = string(message)
|
cr.OtherIP = string(message)
|
||||||
log.Debugf("sender IP: %s", otherIP)
|
log.Debugf("sender IP: %s", cr.OtherIP)
|
||||||
|
|
||||||
// recipient begins by sending address
|
// recipient begins by sending address
|
||||||
ip := ""
|
ip := ""
|
||||||
|
@ -284,7 +283,7 @@ func (cr *Croc) receive(forceSend int, serverAddress string, tcpPorts []string,
|
||||||
// start the ui for pgoress
|
// start the ui for pgoress
|
||||||
cr.StateString = "Recieving file..."
|
cr.StateString = "Recieving file..."
|
||||||
bytesWritten := 0
|
bytesWritten := 0
|
||||||
fmt.Fprintf(os.Stderr, "\nReceiving (<-%s)...\n", otherIP)
|
fmt.Fprintf(os.Stderr, "\nReceiving (<-%s)...\n", cr.OtherIP)
|
||||||
cr.Bar = progressbar.NewOptions(
|
cr.Bar = progressbar.NewOptions(
|
||||||
int(cr.FileInfo.Size),
|
int(cr.FileInfo.Size),
|
||||||
progressbar.OptionSetRenderBlankState(true),
|
progressbar.OptionSetRenderBlankState(true),
|
||||||
|
|
|
@ -48,7 +48,6 @@ func (cr *Croc) send(forceSend int, serverAddress string, tcpPorts []string, isL
|
||||||
var f *os.File
|
var f *os.File
|
||||||
defer f.Close() // ignore the error if it wasn't opened :(
|
defer f.Close() // ignore the error if it wasn't opened :(
|
||||||
var fileHash []byte
|
var fileHash []byte
|
||||||
var otherIP string
|
|
||||||
var startTransfer time.Time
|
var startTransfer time.Time
|
||||||
var tcpConnections []comm.Comm
|
var tcpConnections []comm.Comm
|
||||||
blocksToSkip := make(map[int64]struct{})
|
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))
|
c.WriteMessage(websocket.BinaryMessage, []byte(ip))
|
||||||
case 1:
|
case 1:
|
||||||
// first receive the IP address from the sender
|
// first receive the IP address from the sender
|
||||||
otherIP = string(message)
|
cr.OtherIP = string(message)
|
||||||
log.Debugf("recipient IP: %s", otherIP)
|
log.Debugf("recipient IP: %s", cr.OtherIP)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
// recipient might want file! start gathering information about file
|
// 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")
|
return errors.New("recipient refused file")
|
||||||
}
|
}
|
||||||
cr.StateString = "Transfer in progress..."
|
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
|
// send file, compure hash simultaneously
|
||||||
startTransfer = time.Now()
|
startTransfer = time.Now()
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
humanize "github.com/dustin/go-humanize"
|
||||||
"github.com/schollz/croc/src/cli"
|
"github.com/schollz/croc/src/cli"
|
||||||
"github.com/schollz/croc/src/croc"
|
"github.com/schollz/croc/src/croc"
|
||||||
"github.com/schollz/croc/src/utils"
|
"github.com/schollz/croc/src/utils"
|
||||||
|
@ -82,12 +83,17 @@ func main() {
|
||||||
|
|
||||||
go func(done chan bool) {
|
go func(done chan bool) {
|
||||||
for {
|
for {
|
||||||
if cr.FileInfo.SentName != "" {
|
if cr.OtherIP != "" && cr.FileInfo.SentName != "" {
|
||||||
labels[0].UpdateTextFromGoroutine(fmt.Sprintf("Sending %s", 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 {
|
if cr.Bar != nil {
|
||||||
barState := cr.Bar.State()
|
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)
|
labels[2].UpdateTextFromGoroutine(cr.StateString)
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
@ -129,64 +135,61 @@ func main() {
|
||||||
}
|
}
|
||||||
var fn = folderDialog.SelectedFiles()[0]
|
var fn = folderDialog.SelectedFiles()[0]
|
||||||
if len(fn) == 0 {
|
if len(fn) == 0 {
|
||||||
dialog(fmt.Sprintf("No folder selected"))
|
labels[2].SetText(fmt.Sprintf("No folder selected"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var codePhrase = widgets.QInputDialog_GetText(window, "croc", "Enter code phrase:",
|
var codePhrase = widgets.QInputDialog_GetText(window, "croc", "Enter code phrase:",
|
||||||
widgets.QLineEdit__Normal, "", true, core.Qt__Dialog, core.Qt__ImhNone)
|
widgets.QLineEdit__Normal, "", true, core.Qt__Dialog, core.Qt__ImhNone)
|
||||||
if len(codePhrase) < 3 {
|
if len(codePhrase) < 3 {
|
||||||
dialog(fmt.Sprintf("Invalid codephrase: '%s'", codePhrase))
|
labels[2].SetText(fmt.Sprintf("Invalid codephrase: '%s'", codePhrase))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// change into the receiving directory
|
||||||
cwd, _ := os.Getwd()
|
cwd, _ := os.Getwd()
|
||||||
|
defer os.Chdir(cwd)
|
||||||
|
os.Chdir(fn)
|
||||||
|
|
||||||
|
cr := croc.Init(true)
|
||||||
|
cr.WindowRecipientPrompt = true
|
||||||
|
|
||||||
|
done := make(chan bool)
|
||||||
go func() {
|
go func() {
|
||||||
os.Chdir(fn)
|
|
||||||
defer os.Chdir(cwd)
|
|
||||||
|
|
||||||
cr := croc.Init(true)
|
|
||||||
cr.WindowRecipientPrompt = true
|
|
||||||
|
|
||||||
done := make(chan bool)
|
|
||||||
|
|
||||||
go func(done chan bool) {
|
|
||||||
for {
|
|
||||||
if cr.WindowReceivingString != "" {
|
|
||||||
var question = widgets.QMessageBox_Question(window, "croc", fmt.Sprintf("%s?", cr.WindowReceivingString), widgets.QMessageBox__Yes|widgets.QMessageBox__No, 0)
|
|
||||||
if question == widgets.QMessageBox__Yes {
|
|
||||||
cr.WindowRecipientAccept = true
|
|
||||||
labels[0].UpdateTextFromGoroutine(cr.WindowReceivingString)
|
|
||||||
} else {
|
|
||||||
cr.WindowRecipientAccept = false
|
|
||||||
labels[2].UpdateTextFromGoroutine("canceled")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cr.WindowRecipientPrompt = false
|
|
||||||
cr.WindowReceivingString = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
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[2].UpdateTextFromGoroutine(cr.StateString)
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
select {
|
|
||||||
case _ = <-done:
|
|
||||||
labels[2].UpdateTextFromGoroutine(cr.StateString)
|
|
||||||
return
|
|
||||||
default:
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}(done)
|
|
||||||
|
|
||||||
cr.Receive(codePhrase)
|
cr.Receive(codePhrase)
|
||||||
done <- true
|
done <- true
|
||||||
isWorking = false
|
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)
|
||||||
|
if question == widgets.QMessageBox__Yes {
|
||||||
|
cr.WindowRecipientAccept = true
|
||||||
|
labels[0].UpdateTextFromGoroutine(cr.WindowReceivingString)
|
||||||
|
} else {
|
||||||
|
cr.WindowRecipientAccept = false
|
||||||
|
labels[2].UpdateTextFromGoroutine("canceled")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
cr.WindowRecipientPrompt = false
|
||||||
|
cr.WindowReceivingString = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
if cr.Bar != nil {
|
||||||
|
barState := cr.Bar.State()
|
||||||
|
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)
|
||||||
|
select {
|
||||||
|
case _ = <-done:
|
||||||
|
labels[2].UpdateTextFromGoroutine(cr.StateString)
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
widget.Layout().AddWidget(receiveButton)
|
widget.Layout().AddWidget(receiveButton)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue