This repository was archived by the owner on Jan 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.go
98 lines (77 loc) · 2.09 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
"strings"
)
func getDataPath() string {
homeDir, err := os.UserHomeDir()
if err != nil {
panic("Unable to determine your home directory to location options.json")
}
return filepath.Join(homeDir, "/Library/Pioneer/rekordbox")
}
func getRekordboxConfig(path string) RekordboxConfig {
homeDir, err := os.UserHomeDir()
if err != nil {
panic("Unable to determine your home directory to location options.json")
}
optionsFilePath := filepath.Join(homeDir, "/Library/Application Support/Pioneer/rekordboxAgent/storage/", "options.json")
// read file
data, err := ioutil.ReadFile(optionsFilePath)
if err != nil {
fmt.Print(err)
}
// json data
var obj RekordboxConfig
// unmarshall it
err = json.Unmarshal(data, &obj)
if err != nil {
fmt.Println("error:", err)
}
return obj
}
func FileExists(name string) bool {
if _, err := os.Stat(name); err != nil {
if os.IsNotExist(err) {
return false
}
}
return true
}
func getEncryptedPassword(asarPath string) string {
f, err := os.Open(asarPath)
if err != nil {
panic("Cannot open asar file: " + asarPath)
}
// Search for the password
data, err := ioutil.ReadAll(f)
re := regexp.MustCompile(`pass: \".*\"`)
result := re.FindAllString(string(data), 10)[0]
password := strings.Split(result, ": ")[1]
// Remove the quotation marks
password = strings.Replace(password, `"`, "", -1)
return password
}
func getAsarFilePath(root string) string {
return filepath.Join(root, "/Contents/MacOS/rekordboxAgent.app/Contents/Resources/app.asar")
}
func getEncryptedPasswordDataFromConfig(config RekordboxConfig) string {
if len(config.Options) < 2 {
panic("Unable to read Rekordbox Config file to get password.")
}
if len(config.Options[1]) < 2 {
panic("Unable to read Rekordbox Config file to get password.")
}
return config.Options[1][1]
}
func getDatabaseFilePath(root string) string {
return filepath.Join(root, "master.db")
}
func getImagePath(dataPath string, imagePath string) string {
return filepath.Join(dataPath, "share", imagePath)
}