io load/save changes

Minizbot2012 3 years ago
parent 7715bc122c
commit 00fcb730cb

@ -8,7 +8,6 @@ import (
"encoding/json" "encoding/json"
"io" "io"
"io/fs" "io/fs"
"os"
"strings" "strings"
) )
@ -27,18 +26,16 @@ func init() {
} }
//LoadKM Load Orbmap KM structure //LoadKM Load Orbmap KM structure
func LoadKeymap(file string, dev *DeviceDef) *KeyMap { func LoadKeymap(file io.ReadCloser, dev *DeviceDef) *KeyMap {
mapped := new(KeyMap) mapped := new(KeyMap)
of, _ := os.Open(file)
defer of.Close()
mapped.Keymap = make([]uint16, dev.NumKeys) mapped.Keymap = make([]uint16, dev.NumKeys)
binary.Read(of, binary.LittleEndian, mapped.Keymap) binary.Read(file, binary.LittleEndian, mapped.Keymap)
binary.Read(of, binary.LittleEndian, mapped.Color) binary.Read(file, binary.LittleEndian, mapped.Color)
return mapped return mapped
} }
//SavePKMKeymap saves an orb after edit //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) binary.Write(file, binary.LittleEndian, mapped)
file.Close() file.Close()
} }

@ -27,15 +27,14 @@ func init() {
} }
//LoadKeymap Load Orbmap KM structure //LoadKeymap Load Orbmap KM structure
func LoadKeymap(file string, dev *DeviceDef) *KeyMap { func LoadKeymap(file io.ReadCloser, dev *DeviceDef) *KeyMap {
mapped := new(KeyMap) mapped := new(KeyMap)
of, _ := os.Open(file)
xdr.Unmarshal(of, mapped) xdr.Unmarshal(of, mapped)
return mapped return mapped
} }
//SavePKMKeymap saves an orb after edit //SavePKMKeymap saves an orb after edit
func SaveKeymap(mapped interface{}, file io.WriteCloser) { func SaveKeymap(file io.WriteCloser, mapped interface{}) {
xdr.Marshal(file, mapped) xdr.Marshal(file, mapped)
file.Close() file.Close()
} }

Loading…
Cancel
Save