-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor code and added multidisc game handling
- Loading branch information
Showing
11 changed files
with
491 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,5 +17,5 @@ | |
/output | ||
main | ||
main.exe | ||
/bin/* | ||
/build/* | ||
/ISOs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
.PHONY: build | ||
|
||
build: | ||
go build -o bin/psioHelperLinux main.go && GOOS=windows GOARCH=386 go build -o bin/psioHelper.exe main.go && GOOS=darwin GOARCH=amd64 go build -o bin/psioHelperMac main.go | ||
go build -o build/psioHelperLinux main.go && GOOS=windows GOARCH=386 go build -o build/psioHelper.exe main.go && GOOS=darwin GOARCH=amd64 go build -o build/psioHelperMac main.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package bin | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"path/filepath" | ||
|
||
"github.com/ncirocco/psio-helper/files" | ||
binmerge "github.com/ncirocco/psx-bin-merge" | ||
) | ||
|
||
//Merge merges the bin files in the origin directory and outputs them in the destination directory | ||
func Merge(originDir string, destinationDir string) error { | ||
cueFiles, err := files.GetFilesByExtension(originDir, files.CueExtension) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
fmt.Printf("Attempting to merge bins for %d found CUE sheets\n\n", len(cueFiles)) | ||
|
||
for _, cue := range cueFiles { | ||
fmt.Printf("Merging bin for %s\n", filepath.Base(cue)) | ||
err := binmerge.Merge(cue, destinationDir) | ||
if err != nil { | ||
fmt.Printf("Error processing %s. Message: %s\n", cue, err) | ||
} | ||
} | ||
|
||
fmt.Print("\n\n") | ||
|
||
return nil | ||
} |
Empty file.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package cu2 | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
|
||
cuetocu2 "github.com/ncirocco/cue-to-cu2" | ||
"github.com/ncirocco/psio-helper/files" | ||
) | ||
|
||
//Generate creates the cu2 files for all the found cue in the given directory | ||
func Generate(dir string, removeCue bool) error { | ||
cueFiles, err := files.GetFilesByExtension(dir, files.CueExtension) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
fmt.Printf("Attempting to generate CU2 sheets for %d found CUE sheets\n\n", len(cueFiles)) | ||
|
||
for _, cue := range cueFiles { | ||
fmt.Printf("Generating cu2 for %s\n", filepath.Base(cue)) | ||
err := cuetocu2.Generate(cue, filepath.Dir(cue)) | ||
if err != nil { | ||
fmt.Printf("Error processing %s. Message: %s\n", cue, err) | ||
} | ||
|
||
if removeCue { | ||
os.Remove(cue) | ||
} | ||
} | ||
|
||
fmt.Print("\n\n") | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package files | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
//Cu2Extension cu2 | ||
const Cu2Extension string = "cu2" | ||
|
||
//CueExtension cue | ||
const CueExtension string = "cue" | ||
|
||
//BinExtension bin | ||
const BinExtension string = "bin" | ||
|
||
const fileNameMaxLength int = 60 | ||
|
||
//GetFilesByExtension returns a list of the existing files with the given extension in the given directory | ||
func GetFilesByExtension(path string, extension string) ([]string, error) { | ||
var files []string | ||
err := filepath.Walk(path, | ||
func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if strings.ToLower(filepath.Ext(path)) == "."+extension { | ||
files = append(files, path) | ||
} | ||
|
||
return nil | ||
}) | ||
|
||
return files, err | ||
} | ||
|
||
// HasFilesWithExtension returns true if the directory has files with the given extension | ||
func HasFilesWithExtension(path string, extension string) (bool, error) { | ||
var files []string | ||
err := filepath.Walk(path, | ||
func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if strings.ToLower(filepath.Ext(path)) == "."+extension { | ||
files = append(files, path) | ||
} | ||
|
||
return nil | ||
}) | ||
|
||
return len(files) > 0, err | ||
} | ||
|
||
// TrimNames shortens the file names to the PSIO limit of 60 chars. | ||
func TrimNames(dir string) error { | ||
err := filepath.Walk(dir, | ||
func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ext := filepath.Ext(path) | ||
if (ext != "."+BinExtension && ext != "."+CueExtension && ext != "."+Cu2Extension) || len(filepath.Base(path)) <= fileNameMaxLength { | ||
return nil | ||
} | ||
|
||
fmt.Printf("File name for %s is longer than 60, trimming it.\n", filepath.Base(path)) | ||
|
||
newName := filepath.Join(filepath.Dir(path), filepath.Base(path)[:fileNameMaxLength-len(ext)]+ext) | ||
|
||
if _, err := os.Stat(newName); err == nil { | ||
fmt.Printf("can't rename %s. please rename it manually", filepath.Base(path)) | ||
|
||
return nil | ||
} | ||
|
||
os.Rename(path, newName) | ||
|
||
return nil | ||
}) | ||
|
||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package images | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"io" | ||
"log" | ||
"net/http" | ||
"os" | ||
"path" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/ncirocco/psio-helper/files" | ||
psxserialnumber "github.com/ncirocco/psx-serial-number" | ||
) | ||
|
||
const imagesEndpoint string = "https://ncirocco.github.io/PSIO-Library/images/covers_by_id/%s.bmp" | ||
|
||
// GetImages downloads the images for the given directory | ||
func GetImages(dir string) error { | ||
bins, err := files.GetFilesByExtension(dir, files.BinExtension) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
fmt.Printf("Attempting to download covers for %d found discs\n\n", len(bins)) | ||
|
||
for _, bin := range bins { | ||
fmt.Printf("Downloading image for %s\n", filepath.Base(bin)) | ||
serial, err := psxserialnumber.GetSerial(bin) | ||
if err != nil { | ||
fmt.Println(err) | ||
continue | ||
} | ||
|
||
err = downloadFile(serial, filepath.Dir(bin)) | ||
if err != nil { | ||
fmt.Printf("%s for %s - serial %s\n", err, bin, serial) | ||
continue | ||
} | ||
} | ||
|
||
fmt.Print("\n\n") | ||
|
||
return nil | ||
} | ||
|
||
func downloadFile(code string, dir string) error { | ||
resp, err := http.Get(fmt.Sprintf(imagesEndpoint, strings.ToLower(code))) | ||
if err != nil { | ||
return err | ||
} | ||
defer resp.Body.Close() | ||
|
||
if resp.StatusCode != 200 { | ||
return errors.New("Image not found") | ||
} | ||
|
||
out, err := os.Create(filepath.Join(dir, path.Base(resp.Request.URL.String()))) | ||
if err != nil { | ||
return err | ||
} | ||
defer out.Close() | ||
|
||
_, err = io.Copy(out, resp.Body) | ||
return err | ||
} |
Oops, something went wrong.