-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
161 lines (127 loc) · 3.52 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package main
import (
"flag"
"fmt"
"os"
"path"
"github.com/aymerick/charette/core"
"github.com/aymerick/charette/harvester"
)
const (
version = "0.0.1"
defaultRegions = "France,Europe,World,USA,Japan"
defaultOutput = "roms"
defaultTmpDir = ".~charette"
)
var (
// flags
fInput string
fOutput string
fTmpDir string
fRegions string
fStrict bool
fInsane bool
fUnzip bool
fKeepProto bool
fKeepBeta bool
fKeepSample bool
fKeepDemo bool
fKeepPirate bool
fKeepPromo bool
fQuiet bool
fDebug bool
fVersion bool
)
func init() {
// get current directory
curDir, err := os.Getwd()
if err != nil {
panic(err)
}
// flags
flag.StringVar(&fInput, "input", curDir, "Path to no-intro archives directory, or path to a single no-intro archive file")
flag.StringVar(&fOutput, "output", path.Join(curDir, defaultOutput), "Path to output directory")
flag.StringVar(&fTmpDir, "tmp", path.Join(curDir, defaultTmpDir), "Path to temporary working directory")
flag.StringVar(&fRegions, "regions", defaultRegions, "Preferred regions")
flag.BoolVar(&fStrict, "strict", false, "Skip games that are not in preferred regions")
flag.BoolVar(&fInsane, "insane", false, "Activates flags: -keep-proto -keep-beta -keep-sample -keep-demo -keep-pirate -keep-promo")
flag.BoolVar(&fUnzip, "unzip", false, "Unzip roms")
flag.BoolVar(&fKeepProto, "keep-proto", false, "Keep roms tagged with 'Promo'")
flag.BoolVar(&fKeepBeta, "keep-beta", false, "Keep roms tagged with 'Beta'")
flag.BoolVar(&fKeepSample, "keep-sample", false, "Keep roms tagged with 'Sample'")
flag.BoolVar(&fKeepDemo, "keep-demo", false, "Keep roms tagged with 'Demo'")
flag.BoolVar(&fKeepPirate, "keep-pirate", false, "Keep roms tagged with 'Pirate'")
flag.BoolVar(&fKeepPromo, "keep-promo", false, "Keep roms tagged with 'Promo'")
flag.BoolVar(&fQuiet, "quiet", false, "Activate quiet output")
flag.BoolVar(&fDebug, "debug", false, "Activate debug output")
flag.BoolVar(&fVersion, "version", false, "Display charette version")
}
func main() {
flag.Parse()
// check flags
if fVersion {
fmt.Println(version)
os.Exit(0)
}
if fInsane {
fKeepProto = true
fKeepBeta = true
fKeepSample = true
fKeepDemo = true
fKeepPirate = true
fKeepPromo = true
}
if fInput == "" {
fInput = curDir()
}
fInput = path.Clean(fInput)
if fOutput == "" {
fOutput = path.Join(curDir(), defaultOutput)
}
fOutput = path.Clean(fOutput)
if fTmpDir == "" {
fTmpDir = path.Join(curDir(), defaultTmpDir)
}
fTmpDir = path.Clean(fTmpDir)
if fDebug {
fQuiet = false
}
if !fQuiet {
fmt.Printf("charette v%s\n", version)
fmt.Printf(" input: %s\n", fInput)
fmt.Printf(" output: %s\n", fOutput)
fmt.Printf(" tmp dir: %s\n", fTmpDir)
}
if (fInput == fOutput) || (fInput == fTmpDir) {
panic("Output and tmp directories can't be the same as input directory")
}
// computes options
options := core.NewOptions()
options.Input = fInput
options.Output = fOutput
options.Tmp = fTmpDir
options.Regions = core.ExtractRegions(fRegions)
options.Strict = fStrict
options.KeepProto = fKeepProto
options.KeepBeta = fKeepBeta
options.KeepSample = fKeepSample
options.KeepDemo = fKeepDemo
options.KeepPirate = fKeepPirate
options.KeepPromo = fKeepPromo
options.Quiet = fQuiet
options.Debug = fDebug
options.Unzip = fUnzip
// run harvester
h := harvester.New(options)
if err := h.Run(); err != nil {
panic(err)
}
}
// curDir returns current directory
func curDir() string {
curDir, err := os.Getwd()
if err != nil {
panic(err)
}
return curDir
}