diff --git a/README.md b/README.md index 10dc2d1..7232cad 100644 --- a/README.md +++ b/README.md @@ -110,12 +110,12 @@ int main() { - [ ] RenameRemote(oldVanityPath, newVanityPath string) error - [ ] ShearRemote(vanityPath string, onlyShearAgeFile bool) error - [ ] RunJob() (*syncListsT, error) -- [ ] synccommon +- [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) - [X] ~~ShearAgeFileLocal(vanityPath string) error~~ (not for use outside of libmutton) - [X] ~~ShearLocal(vanityPath, clientDeviceID string, onlyShearAgeFile bool) (string, bool, error)~~ (not for use outside of libmutton) - - [ ] WalkEntryDir() ([]string, []string, error) + - [X] WalkEntryDir() ([]string, []string, error) - [X] ~~GetAllEntryData() (EntryMapT, error)~~ (not easy to port to C; also not needed) - [ ] syncserver - [ ] GetRemoteDataFromServer(clientDeviceID string) diff --git a/config.go b/config.go new file mode 100644 index 0000000..b7dd6b1 --- /dev/null +++ b/config.go @@ -0,0 +1,60 @@ +package main + +// #include +// #include "types.h" +import "C" +import ( + "github.com/rwinkhart/libmutton/config" +) + +// LoadOfficialCfg returns the currently set (libmutton official) values in the libmutton config file. +// r0: err +// +// r1: OfflineMode (bool) +// +// r2: SSHUser (string) +// +// r3: SSHIP (string) +// +// r4: SSHPort (string) +// +// r5: SSHEntryRootPath (string) +// +// r6: SSHAgeDirPath (string) +// +// r7: SSHKeyPath (string) +// +// r8: SSHKeyProtected (bool) +// +// r9: SSHIsWindows (bool) +// +//export LoadOfficialCfg +func LoadOfficialCfg() (*C.char, bool, C.PascalString, C.PascalString, C.PascalString, C.PascalString, C.PascalString, C.PascalString, bool, bool) { + cfg, err := config.Load() + if err != nil { + return C.CString(err.Error()), false, getPascalString(""), getPascalString(""), getPascalString(""), getPascalString(""), getPascalString(""), getPascalString(""), false, false + } + return nil, safeBoolDeref(cfg.Libmutton.OfflineMode), getPascalString(safeStringDeref(cfg.Libmutton.SSHUser)), getPascalString(safeStringDeref(cfg.Libmutton.SSHIP)), getPascalString(safeStringDeref(cfg.Libmutton.SSHPort)), getPascalString(safeStringDeref(cfg.Libmutton.SSHEntryRootPath)), getPascalString(safeStringDeref(cfg.Libmutton.SSHAgeDirPath)), getPascalString(safeStringDeref(cfg.Libmutton.SSHKeyPath)), safeBoolDeref(cfg.Libmutton.SSHKeyProtected), safeBoolDeref(cfg.Libmutton.SSHIsWindows) +} + +// WriteOfficialCfg writes the provided (libmutton official) values to the libmutton config file. +// r0: err +// +//export WriteOfficialCfg +func WriteOfficialCfg(appendMode bool, OfflineMode bool, SSHUser, SSHIP, SSHPort, SSHEntryRootPath, SSHAgeDirPath, SSHKeyPath C.PascalString, SSHKeyProtected, SSHIsWindows bool) *C.char { + var cfg config.CfgT + cfg.Libmutton.OfflineMode = &OfflineMode + cfg.Libmutton.SSHUser = new(C.GoStringN(SSHUser.data, SSHUser.len)) + cfg.Libmutton.SSHIP = new(C.GoStringN(SSHIP.data, SSHIP.len)) + cfg.Libmutton.SSHPort = new(C.GoStringN(SSHPort.data, SSHPort.len)) + cfg.Libmutton.SSHEntryRootPath = new(C.GoStringN(SSHEntryRootPath.data, SSHEntryRootPath.len)) + cfg.Libmutton.SSHAgeDirPath = new(C.GoStringN(SSHAgeDirPath.data, SSHAgeDirPath.len)) + cfg.Libmutton.SSHKeyPath = new(C.GoStringN(SSHKeyPath.data, SSHKeyPath.len)) + cfg.Libmutton.SSHKeyProtected = &SSHKeyProtected + cfg.Libmutton.SSHIsWindows = &SSHIsWindows + err := config.Write(&cfg, appendMode) + if err != nil { + return C.CString(err.Error()) + } + return nil +} diff --git a/crypt.go b/crypt.go index cbe0bd4..0678312 100644 --- a/crypt.go +++ b/crypt.go @@ -13,7 +13,7 @@ import ( // // r1: decLines (pointer to C-allocated array) // -// r2: length decLines array +// r2: decLines length // //export DecryptFileToSlice func DecryptFileToSlice(realPath, rcwPassword C.PascalString) (*C.char, *C.PascalString, C.int) { diff --git a/synccommon.go b/synccommon.go new file mode 100644 index 0000000..ef14718 --- /dev/null +++ b/synccommon.go @@ -0,0 +1,28 @@ +package main + +// #include +// #include "types.h" +import "C" +import ( + "github.com/rwinkhart/libmutton/synccommon" +) + +// WalkEntryDir returns: +// r0: err +// +// r1: files (pointer to C-allocated array) +// +// r2: files length +// +// r3: dirs (pointer to C-allocated array) +// +// r4: dirs length +// +//export WalkEntryDir +func WalkEntryDir() (*C.char, *C.PascalString, C.int, *C.PascalString, C.int) { + files, dirs, err := synccommon.WalkEntryDir() + if err != nil { + return C.CString(err.Error()), nil, 0, nil, 0 + } + return nil, getCPascalStringArrayFromStringSlice(files), C.int(len(files)), getCPascalStringArrayFromStringSlice(dirs), C.int(len(dirs)) +}