Skip to content

Commit

Permalink
working current version detection, working import
Browse files Browse the repository at this point in the history
  • Loading branch information
twhiston committed Sep 25, 2024
1 parent 5adc7b1 commit b61a318
Show file tree
Hide file tree
Showing 7 changed files with 305 additions and 56 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.sqlite
_exported
dist/
36 changes: 34 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,47 @@
"request": "launch",
"mode": "auto",
"program": "main.go",
"args": "export InfernalMachines-Raw-Midi-5 --rnbo-version=1.3.3-alpha.0 --db=./oscqueryrunner-dev.sqlite --dir=./_exported"
"args": "export InfernalMachines-Raw-Midi-5 --rnbo-version=1.3.3-alpha.0 --db=./oscqueryrunner.sqlite --dir=./_exported"
},
{
"name": "Export Set without version",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "main.go",
"args": "export InfernalMachines-Raw-Midi-5 --db=./oscqueryrunner.sqlite --dir=./_exported"
},
{
"name": "Import Set",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "main.go",
"args": "import InfernalMachines-Raw-Midi-5 --db=./oscqueryrunner-dev.sqlite --dir=./_exported"
"args": "import InfernalMachines-Raw-Midi-5 --db=./oscqueryrunner.sqlite --dir=./_exported"
},
{
"name": "Import Named Set",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "main.go",
"args": "import InfernalMachines-Raw-Midi-5 --db=./oscqueryrunner.sqlite --dir=./_exported --name=dingus-machine"
},
{
"name": "Import Set with broken timestamp",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "main.go",
"args": "import InfernalMachines-Raw-Midi-5 --db=./oscqueryrunner.sqlite --dir=./_exported --timestamp=0"
},
{
"name": "Import Set explicit timestamp",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "main.go",
"args": "import InfernalMachines-Raw-Midi-5 --db=./oscqueryrunner.sqlite --dir=./_exported --timestamp=20240925-170825"
}
]
}
51 changes: 47 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,51 @@
# rnbo-set-manager

Manage your rnbo sets on your pi for backup and restore
Manage your rnbo sets on your pi for backup and restore.

## Findings
If you are using this tool it assumes you are somewhat comfortable poking around
in the rpi and in sqlite databases.

sqlite_sequence table auto updates.
set insert date field is automatic
Always backup your database before you do any imports!

## Installation

The easiest way to install this tool is to copy the built binary to your rpi.
Otherwise you will need to install the go toolchain and compile it yourself.


You can curl the latest release from your pi
`curl https://github.com/twhiston/rnbo-set-manager/releases/latest/rnbo-set-manager.zip`
and then unzip it and move it to somewhere in your path
`unzip rnbo-set-manager.zip && sudo mv ./rnbo-set-manager /usr/bin/path`

If you try to export a set and you get the error

```txt
Issue getting set
unable to open database file: out of memory (14)
```

It's actually to do with the permissions of the rnbo folder and you can fix it
as follows:

```bash
chmod 0775 ~/Documents/rnbo
# To undo this you can run
# chmod 0755 ~/Documents/rnbo
```

## Usage

`rnbo-set-manager --help`
shows all possible commands, arguments, flags etc...

DO NOT USE AS sudo USER!
It will affect you home path and won't save the exports where you expect them.

BACKUP YOUR DATABASE BEFORE IMPORTING ANYTHING!!!

## TODO

- dumb db backup command (copy db to a new name in selected folder)
- dumb db restore command
- dumb rnbo folder backup command (copy folder)
2 changes: 2 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#! /bin/zsh
env GOOS=linux GOARCH=arm go build -o ./dist/rnbo-set-manager
45 changes: 28 additions & 17 deletions cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import (
"log"
"os"
"path/filepath"
"slices"
"time"

"github.com/twhiston/rnbo-set-manager/rnbo"

"github.com/antandros/go-dpkg"
"github.com/antandros/go-pkgparser/model"
_ "github.com/glebarez/go-sqlite"
"github.com/spf13/cobra"
)
Expand All @@ -23,7 +25,9 @@ import (
var exportCmd = &cobra.Command{
Use: "export",
Short: "export set data from the rnbo sqlite database",
Long: `Export everything that you need to recreate a set from the rnbo database`,
Long: `Export everything that you need to recreate a set from the rnbo database
It is important to note that this will export data from the patcher table, so it expects
that when you import patchers with the correct ID's will already exist in the database`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Export Set")
if len(args) != 1 {
Expand All @@ -36,13 +40,28 @@ var exportCmd = &cobra.Command{

if rnboVer == "" {
rnboVer = determineRnboVersion()
if rnboVer == "" {
log.Fatal("Could not determine version of rnbooscquery, are you running this on an rpi?")
}
}
fmt.Println("RNBO version: " + rnboVer)

homeDir, err := os.UserHomeDir()
if err != nil {
log.Fatal(err)
}

rnboDB, _ := cmd.Flags().GetString("db")
if rnboDB == "" {
//~/Documents/rnbo/oscqueryrunner.sqlite
rnboDB = filepath.Join(homeDir, "Documents", "rnbo", "oscqueryrunner.sqlite")
}
fmt.Println("RNBO db: " + rnboDB)

exportDir, _ := cmd.Flags().GetString("dir")
if exportDir == "" {
exportDir = filepath.Join(homeDir, "Documents", "rnbo-set-manager-data")
}
fmt.Println("Export Base Dir: " + exportDir)

timeNow := time.Now().Format("20060102-150405")
Expand Down Expand Up @@ -100,16 +119,18 @@ var exportCmd = &cobra.Command{
}

func determineRnboVersion() string {
version := ""

packages, err := dpkg.GetPackages()
if err != nil {
log.Fatal(err)
}
fmt.Println(err)
resp, err := json.MarshalIndent(packages, "", "\t")
fmt.Println(err)
fmt.Println(string(resp))
//TODO: make this work!
return "1.3.3-alpha.0"

idx := slices.IndexFunc(packages, func(c model.Package) bool { return c.PackageName == "rnbooscquery" })
if idx != -1 {
version = packages[idx].Version
}
return version
}

func getSet(db *sql.DB, setId string, version string) rnbo.Set {
Expand Down Expand Up @@ -224,15 +245,5 @@ func init() {
rootCmd.AddCommand(exportCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// exportCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// exportCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
exportCmd.Flags().String("rnbo-version", "", "Set the rnbo runner version, leave blank to autodetect")
// exportCmd.Flags().String("db", "~/Documents/rnbo/oscqueryrunner.sqlite", "Specify the location to the db")
// exportCmd.Flags().String("dir", "~/Documents/rnbo-set-manager", "Specify save file location")
}
Loading

0 comments on commit b61a318

Please sign in to comment.