diff --git a/README.md b/README.md index 001c91c..d6ac1b1 100644 --- a/README.md +++ b/README.md @@ -103,13 +103,13 @@ int main() { - [X] ~~GetSysProcAttr() *syscall.SysProcAttr~~ (not for use outside of libmutton) - [X] GetVanityPath(realPath string) string - [ ] syncclient - - [ ] AddFolderRemote(vanityPath string) error - - [ ] GenDeviceID(oldDeviceID, prefix string) (string, string, bool, error) - - [ ] GetSSHClient() (*ssh.Client, bool, *bool, *string, *string, error) - - [ ] GetSSHOutput(sshClient *ssh.Client, cmd, stdin string) ([]byte, error) - - [ ] RenameRemote(oldVanityPath, newVanityPath string) error - - [ ] ShearRemote(vanityPath string, onlyShearAgeFile bool) error - - [ ] RunJob() (*syncListsT, error) + - [X] AddFolderRemote(vanityPath string) error + - [X] GenDeviceID(oldDeviceID, prefix string) (string, string, bool, error) + - [X] ~~GetSSHClient() (*ssh.Client, bool, *bool, *string, *string, error)~~ (not for use outside of libmutton) + - [X] ~~GetSSHOutput(sshClient *ssh.Client, cmd, stdin string) ([]byte, error)~~ (not for use outside of libmutton) + - [X] RenameRemote(oldVanityPath, newVanityPath string) error + - [X] ShearRemote(vanityPath string, onlyShearAgeFile bool) error + - [X] RunJob() (*syncListsT, error) - [X] synccommon - [X] ~~AddFolderLocal(vanityPath string) error~~ (not for use outside of libmutton) - [X] ~~RenameLocal(oldVanityPath, newVanityPath string) error~~ (not for use outside of libmutton) diff --git a/clip.go b/clip.go index 57c3beb..045a406 100644 --- a/clip.go +++ b/clip.go @@ -14,8 +14,7 @@ import ( // //export ClearProcess func ClearProcess(assignedContents C.PascalString) *C.char { - err := clip.ClearProcess(C.GoStringN(assignedContents.data, assignedContents.len)) - if err != nil { + if err := clip.ClearProcess(C.GoStringN(assignedContents.data, assignedContents.len)); err != nil { return C.CString(err.Error()) } return nil @@ -26,8 +25,7 @@ func ClearProcess(assignedContents C.PascalString) *C.char { // //export CopyShortcut func CopyShortcut(realPath C.PascalString, field int, rcwPassword C.PascalString) *C.char { - err := clip.CopyShortcut(C.GoStringN(realPath.data, realPath.len), field, []byte(C.GoStringN(rcwPassword.data, rcwPassword.len))) - if err != nil { + if err := clip.CopyShortcut(C.GoStringN(realPath.data, realPath.len), field, []byte(C.GoStringN(rcwPassword.data, rcwPassword.len))); err != nil { return C.CString(err.Error()) } return nil @@ -38,8 +36,7 @@ func CopyShortcut(realPath C.PascalString, field int, rcwPassword C.PascalString // //export CopyString func CopyString(clearClipboardAutomatically bool, copySubject C.PascalString) *C.char { - err := clip.CopyString(clearClipboardAutomatically, C.GoStringN(copySubject.data, copySubject.len)) - if err != nil { + if err := clip.CopyString(clearClipboardAutomatically, C.GoStringN(copySubject.data, copySubject.len)); err != nil { return C.CString(err.Error()) } return nil diff --git a/syncclient.go b/syncclient.go new file mode 100644 index 0000000..9667358 --- /dev/null +++ b/syncclient.go @@ -0,0 +1,90 @@ +package main + +// #include +// #include "types.h" +import "C" +import ( + "github.com/rwinkhart/libmutton/syncclient" +) + +// AddFolderRemote returns: +// r0: err +// +//export AddFolderRemote +func AddFolderRemote(vanityPath C.PascalString) *C.char { + if err := syncclient.AddFolderRemote(C.GoStringN(vanityPath.data, vanityPath.len)); err != nil { + return C.CString(err.Error()) + } + return nil +} + +// RenameRemote returns: +// r0: err +// +//export RenameRemote +func RenameRemote(oldVanityPath, newVanityPath C.PascalString) *C.char { + if err := syncclient.RenameRemote(C.GoStringN(oldVanityPath.data, oldVanityPath.len), C.GoStringN(newVanityPath.data, newVanityPath.len)); err != nil { + return C.CString(err.Error()) + } + return nil +} + +// ShearRemote returns: +// r0: err +// +//export ShearRemote +func ShearRemote(vanityPath C.PascalString, onlyShearAgeFile bool) *C.char { + if err := syncclient.ShearRemote(C.GoStringN(vanityPath.data, vanityPath.len), onlyShearAgeFile); err != nil { + return C.CString(err.Error()) + } + return nil +} + +// GenDeviceID returns: +// r0: err +// +// r1: remoteEntryRoot +// +// r2: remoteAgeDir +// +// r3: isWindows +// +//export GenDeviceID +func GenDeviceID(oldDeviceID, prefix C.PascalString) (*C.char, C.PascalString, C.PascalString, bool) { + var remoteEntryRoot, remoteAgeDir string + var isWindows bool + var err error + if oldDeviceID.len < 1 { + remoteEntryRoot, remoteAgeDir, isWindows, err = syncclient.GenDeviceID(nil, C.GoStringN(prefix.data, prefix.len)) + } else { + remoteEntryRoot, remoteAgeDir, isWindows, err = syncclient.GenDeviceID(new(C.GoStringN(oldDeviceID.data, oldDeviceID.len)), C.GoStringN(prefix.data, prefix.len)) + } + if err != nil { + return C.CString(err.Error()), C.PascalString{data: nil, len: 0}, C.PascalString{data: nil, len: 0}, false + } + return nil, getPascalString(remoteEntryRoot), getPascalString(remoteAgeDir), isWindows +} + +// RunJob returns: +// r0: err +// +// r1: deleteList (pointer to C-allocated array) +// +// r2: deleteList length +// +// r3: downloadList (pointer to C-allocated array) +// +// r4: downloadList length +// +// r5: uploadList (pointer to C-allocated array) +// +// r6: uploadList length +// +//export RunJob +func RunJob() (*C.char, *C.PascalString, C.int, *C.PascalString, C.int, *C.PascalString, C.int) { + lists, err := syncclient.RunJob() + if err != nil { + return C.CString(err.Error()), nil, 0, nil, 0, nil, 0 + } + return nil, getCPascalStringArrayFromStringSlice(lists.Delete), C.int(len(lists.Delete)), getCPascalStringArrayFromStringSlice(lists.Download), C.int(len(lists.Download)), getCPascalStringArrayFromStringSlice(lists.Upload), C.int(len(lists.Upload)) +}