-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
136 lines (115 loc) · 3.73 KB
/
main.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package main
import (
"flag"
"fmt"
"log"
"os"
"path/filepath"
"github.com/ncirocco/psio-helper/bin"
"github.com/ncirocco/psio-helper/cu2"
"github.com/ncirocco/psio-helper/files"
"github.com/ncirocco/psio-helper/images"
"github.com/ncirocco/psio-helper/multidisc"
)
func main() {
defaultOriginDir, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
defaultDestinationDir := filepath.Join(defaultOriginDir, "output")
autoCmd := flag.NewFlagSet("auto", flag.ExitOnError)
autoDirPtr := autoCmd.String("dir", defaultOriginDir, "Directory containing the files to be processed")
autoDestinationDirPtr := autoCmd.String("destinationDir", defaultDestinationDir, "Directory to store the processed files")
mergeCmd := flag.NewFlagSet("merge", flag.ExitOnError)
mergeDirPtr := mergeCmd.String("dir", defaultOriginDir, "Directory containing the files to be processed")
mergeDestinationDirPtr := mergeCmd.String("destinationDir", defaultDestinationDir, "Directory to store the processed files")
cu2Cmd := flag.NewFlagSet("cu2", flag.ExitOnError)
cu2DirPtr := cu2Cmd.String("dir", defaultOriginDir, "Directory containing the cue files to be converted")
cu2RemovePtr := cu2Cmd.Bool("removeCue", false, "If set to true, the original cue file will be removed")
imagesCmd := flag.NewFlagSet("images", flag.ExitOnError)
imagesDirPtr := imagesCmd.String("dir", defaultOriginDir, "Directory containing the bin files to get the images")
multidiscCmd := flag.NewFlagSet("multidisc", flag.ExitOnError)
multidiscDirPtr := multidiscCmd.String("dir", defaultOriginDir, "Directory containing the multidisc bin files")
flag.Usage = usage
flag.Parse()
if len(os.Args) < 2 {
err = all(defaultOriginDir, defaultDestinationDir)
if err != nil {
log.Fatal(err)
}
os.Exit(0)
}
switch os.Args[1] {
case "auto":
autoCmd.Parse(os.Args[2:])
err = all(*autoDirPtr, *autoDestinationDirPtr)
if err != nil {
log.Fatal(err)
}
case "merge":
mergeCmd.Parse(os.Args[2:])
err = bin.Merge(*mergeDirPtr, *mergeDestinationDirPtr)
if err != nil {
log.Fatal(err)
}
case "cu2":
cu2Cmd.Parse(os.Args[2:])
err = cu2.Generate(*cu2DirPtr, *cu2RemovePtr)
if err != nil {
log.Fatal(err)
}
case "images":
imagesCmd.Parse(os.Args[2:])
err = images.GetImages(*imagesDirPtr)
if err != nil {
log.Fatal(err)
}
case "multidisc":
multidiscCmd.Parse(os.Args[2:])
err = multidisc.Multidisc(*multidiscDirPtr)
if err != nil {
log.Fatal(err)
}
default:
fmt.Println(fmt.Sprintf("%s is not a valid command", os.Args[1]))
os.Exit(1)
}
}
func all(originDir string, destinationDir string) error {
if _, err := os.Stat(originDir); os.IsNotExist(err) {
return err
}
err := bin.Merge(originDir, destinationDir)
if err != nil {
return err
}
err = cu2.Generate(destinationDir, true)
if err != nil {
return err
}
err = multidisc.Multidisc(destinationDir)
if err != nil {
return err
}
err = images.GetImages(destinationDir)
if err != nil {
return err
}
err = files.TrimNames(destinationDir)
if err != nil {
return err
}
return nil
}
func usage() {
fmt.Printf("usage: %s <command> [<args>]\n", os.Args[0])
fmt.Println("\nCommands:")
fmt.Println(" auto - Merges bin files and generates cu2 sheets for all the files in the given directory")
fmt.Println(" merge - Merges all the bin files in a given directory")
fmt.Println(" cu2 - Generates the cu2 sheet for each cue sheet in the given directory")
fmt.Println(" image - Downloads covers for the bin files in the given directory")
fmt.Println(" multidisc - Groups the discs that belong to the same game and generates the necessary multidisc.lst files")
fmt.Print("\n")
fmt.Printf("To see more details for a particular command run %s <command> -h\n", os.Args[0])
fmt.Print("\n")
}