From 00fcb730cbf94db54bd79132dccf11ef1efe0f7a Mon Sep 17 00:00:00 2001 From: Minizbot2012 Date: Wed, 28 Jul 2021 02:41:03 -0400 Subject: [PATCH] io load/save changes --- devices/devices_json.go | 11 ++++------- devices/devices_xdr.go | 5 ++--- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/devices/devices_json.go b/devices/devices_json.go index d3106f7..b2925aa 100644 --- a/devices/devices_json.go +++ b/devices/devices_json.go @@ -8,7 +8,6 @@ import ( "encoding/json" "io" "io/fs" - "os" "strings" ) @@ -27,18 +26,16 @@ func init() { } //LoadKM Load Orbmap KM structure -func LoadKeymap(file string, dev *DeviceDef) *KeyMap { +func LoadKeymap(file io.ReadCloser, dev *DeviceDef) *KeyMap { mapped := new(KeyMap) - of, _ := os.Open(file) - defer of.Close() mapped.Keymap = make([]uint16, dev.NumKeys) - binary.Read(of, binary.LittleEndian, mapped.Keymap) - binary.Read(of, binary.LittleEndian, mapped.Color) + binary.Read(file, binary.LittleEndian, mapped.Keymap) + binary.Read(file, binary.LittleEndian, mapped.Color) return mapped } //SavePKMKeymap saves an orb after edit -func SaveKeymap(mapped interface{}, file io.WriteCloser) { +func SaveKeymap(file io.WriteCloser, mapped interface{}) { binary.Write(file, binary.LittleEndian, mapped) file.Close() } diff --git a/devices/devices_xdr.go b/devices/devices_xdr.go index 633e751..31e5e6b 100644 --- a/devices/devices_xdr.go +++ b/devices/devices_xdr.go @@ -27,15 +27,14 @@ func init() { } //LoadKeymap Load Orbmap KM structure -func LoadKeymap(file string, dev *DeviceDef) *KeyMap { +func LoadKeymap(file io.ReadCloser, dev *DeviceDef) *KeyMap { mapped := new(KeyMap) - of, _ := os.Open(file) xdr.Unmarshal(of, mapped) return mapped } //SavePKMKeymap saves an orb after edit -func SaveKeymap(mapped interface{}, file io.WriteCloser) { +func SaveKeymap(file io.WriteCloser, mapped interface{}) { xdr.Marshal(file, mapped) file.Close() }