Compare commits
No commits in common. "75e0ee2ba3a1ce5842ee0d855e3664cc68869855" and "2b9bc6f09f362395eb2701b23f30569c05c02219" have entirely different histories.
75e0ee2ba3
...
2b9bc6f09f
|
|
@ -5,8 +5,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"errors"
|
|
||||||
"io/fs"
|
|
||||||
|
|
||||||
"github.com/alexflint/go-arg"
|
"github.com/alexflint/go-arg"
|
||||||
|
|
||||||
|
|
@ -19,9 +17,7 @@ type Arguments struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ArgPack struct {
|
type ArgPack struct {
|
||||||
Input string `arg:"positional,required"`
|
Input string `arg:"positional,required"`
|
||||||
Force bool `arg:"--force"`
|
|
||||||
Output string `arg:"--output,-o"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ArgUnPack struct {
|
type ArgUnPack struct {
|
||||||
|
|
@ -77,17 +73,9 @@ func pack(args *ArgPack) error {
|
||||||
|
|
||||||
// TODO: put this in the json file?
|
// TODO: put this in the json file?
|
||||||
|
|
||||||
if args.Output != "" {
|
outname := args.Input[:len(args.Input)-len(".json")]+".studybox"
|
||||||
sb.Filename = args.Output
|
fmt.Println(outname)
|
||||||
}
|
err = sb.Write(outname)
|
||||||
|
|
||||||
// outname := args.Input[:len(args.Input)-len(".json")]+".studybox"
|
|
||||||
if exists(sb.Filename) && !args.Force {
|
|
||||||
return fmt.Errorf("%s already exists or cannot be written to", sb.Filename)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println(sb.Filename)
|
|
||||||
err = sb.Write(sb.Filename)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -129,19 +117,6 @@ func unpack(args *ArgUnPack) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func exists(filename string) bool {
|
|
||||||
_, err := os.Stat(filename)
|
|
||||||
if err == nil {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
if errors.Is(err, fs.ErrNotExist) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
//func main_old() {
|
//func main_old() {
|
||||||
// if len(os.Args) < 3 {
|
// if len(os.Args) < 3 {
|
||||||
// fmt.Println("Missing command")
|
// fmt.Println("Missing command")
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ func Import(filename string) (*StudyBox, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
sbj := &StudyBoxJson{ Filename: filename }
|
sbj := &StudyBoxJson{}
|
||||||
err = json.Unmarshal(raw, sbj)
|
err = json.Unmarshal(raw, sbj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Unable to unmarshal json: %v", err)
|
return nil, fmt.Errorf("Unable to unmarshal json: %v", err)
|
||||||
|
|
@ -28,7 +28,6 @@ func Import(filename string) (*StudyBox, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
sb := &StudyBox{
|
sb := &StudyBox{
|
||||||
Filename: sbj.Filename,
|
|
||||||
Data: &TapeData{Pages: []*Page{}},
|
Data: &TapeData{Pages: []*Page{}},
|
||||||
Audio: audio,
|
Audio: audio,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type StudyBox struct {
|
type StudyBox struct {
|
||||||
Filename string
|
|
||||||
Data *TapeData
|
Data *TapeData
|
||||||
Audio *TapeAudio
|
Audio *TapeAudio
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ func (sb *StudyBox) Write(filename string) error {
|
||||||
|
|
||||||
fmt.Println("Writing to " + filename)
|
fmt.Println("Writing to " + filename)
|
||||||
|
|
||||||
return os.WriteFile(filename, raw, 0666)
|
return os.WriteFile(filename, raw, 0777)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sb *StudyBox) rawBytes() ([]byte, error) {
|
func (sb *StudyBox) rawBytes() ([]byte, error) {
|
||||||
|
|
@ -56,9 +56,7 @@ func (sb *StudyBox) rawBytes() ([]byte, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// This length is the full size of the chunk, including the format from the
|
err = binary.Write(buffer, binary.LittleEndian, uint32(len(sb.Audio.Data)))
|
||||||
// switch below.
|
|
||||||
err = binary.Write(buffer, binary.LittleEndian, uint32(len(sb.Audio.Data)+4))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -83,7 +81,8 @@ func (sb *StudyBox) rawBytes() ([]byte, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = buffer.Write(sb.Audio.Data[0 : uint32(len(sb.Audio.Data))])
|
// For some reason there's 4 extra bytes. no idea why. chomp them off.
|
||||||
|
_, err = buffer.Write(sb.Audio.Data[0 : uint32(len(sb.Audio.Data))-4])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue