file resumption support
This commit is contained in:
parent
d5231b13db
commit
792e84d5f9
35
lib.go
35
lib.go
|
@ -208,6 +208,7 @@ func _startCwtch(appDir string, torPath string) {
|
|||
event.ProtocolEngineStopped,
|
||||
event.RetryServerRequest,
|
||||
event.ManifestReceived,
|
||||
event.FileDownloaded,
|
||||
}
|
||||
settings := utils.ReadGlobalSettings()
|
||||
settingsJson, _ := json.Marshal(settings)
|
||||
|
@ -759,23 +760,48 @@ func c_CheckDownloadStatus(profilePtr *C.char, profileLen C.int, fileKeyPtr *C.c
|
|||
|
||||
func CheckDownloadStatus(profileOnion, fileKey string) {
|
||||
profile := application.GetPeer(profileOnion)
|
||||
if path, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey)); exists {
|
||||
path, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.path", fileKey))
|
||||
if _, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey)); exists {
|
||||
eventHandler.Push(event.NewEvent(event.FileDownloaded, map[event.Field]string{
|
||||
ProfileOnion: profileOnion,
|
||||
event.FileKey: fileKey,
|
||||
event.FilePath: path,
|
||||
event.TempFile: "",
|
||||
}))
|
||||
} else if path, exists = profile.GetAttribute(attr.GetLocalScope(fmt.Sprintf("%s.path", fileKey))); exists {
|
||||
} else {
|
||||
log.Infof("CheckDownloadStatus found .path but not .complete")
|
||||
eventHandler.Push(event.NewEvent(event.FileDownloadProgressUpdate, map[event.Field]string{
|
||||
ProfileOnion: profileOnion,
|
||||
event.FileKey: fileKey,
|
||||
event.Progress: ??,
|
||||
event.FileSizeInChunks: ??,
|
||||
event.Progress: "-1",
|
||||
event.FileSizeInChunks: "-1",
|
||||
event.FilePath: path,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
//export c_VerifyOrResumeDownload
|
||||
func c_VerifyOrResumeDownload(profile_ptr *C.char, profile_len C.int, handle_ptr *C.char, handle_len C.int, filekey_ptr *C.char, filekey_len C.int) {
|
||||
profile := C.GoStringN(profile_ptr, profile_len)
|
||||
handle := C.GoStringN(handle_ptr, handle_len)
|
||||
filekey := C.GoStringN(filekey_ptr, filekey_len)
|
||||
VerifyOrResumeDownload(profile, handle, filekey)
|
||||
}
|
||||
|
||||
func VerifyOrResumeDownload(profileOnion, handle, fileKey string) {
|
||||
profile := application.GetPeer(profileOnion)
|
||||
if manifestFilePath, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%v.manifest", fileKey)); exists {
|
||||
if downloadfilepath, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.path", fileKey)); exists {
|
||||
log.Infof("resuming %s", fileKey)
|
||||
DownloadFile(profileOnion, handle, downloadfilepath, manifestFilePath, fileKey)
|
||||
} else {
|
||||
log.Errorf("found manifest path but not download path for %s", fileKey)
|
||||
}
|
||||
} else {
|
||||
log.Errorf("no stored manifest path found for %s", fileKey)
|
||||
}
|
||||
}
|
||||
|
||||
//export c_ResetTor
|
||||
func c_ResetTor() {
|
||||
ResetTor()
|
||||
|
@ -1091,7 +1117,6 @@ func LaunchServer(onion string) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
//export c_StopServer
|
||||
func c_StopServer(onionPtr *C.char, onionLen C.int) {
|
||||
StopServer(C.GoStringN(onionPtr, onionLen))
|
||||
|
|
Reference in New Issue