This commit is contained in:
Chris
2018-12-15 09:27:48 +00:00
parent a26f9b2042
commit 3efff9ea0e
2 changed files with 178 additions and 12 deletions

View File

@@ -1,3 +1,4 @@
VERSION=1.0.0-alpha2
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
@@ -10,8 +11,9 @@ GOWIN=CC=$(CC_WIN) CGO_ENABLED=1 GOOS=windows GOARCH=386
GOARM_SHARED=CC=$(CC_ARM) CGO_ENABLED=1 GOOS=linux GOARCH=arm
BINARY_NAME=bootstrap
BINARY_NAME_WIN=bootstrap.exe
BASE=bootstrap
BINARY_NAME=MiSTer-bootstrap-linux-amd64-$(VERSION)
BINARY_NAME_WIN=MiSTer-bootstrap-windows-amd64-$(VERSION).exe
all: clean build build-windows build-shared build-example
build: clean
@@ -19,11 +21,13 @@ build: clean
build-windows:
$(GOWIN) $(GOBUILD) -o bin/$(BINARY_NAME_WIN) -v src/main.go
build-shared:
$(GOBUILD) -o bin/$(BINARY_NAME).so -buildmode=c-shared -v src/main.go
$(GOBUILD) -o bin/$(BASE).so -buildmode=c-archive -v src/main.go
build-shared-arm: clean
$(GOARM_SHARED) $(GOBUILD) -o bin/$(BINARY_NAME).so -buildmode=c-shared -v src/main.go
$(GOARM_SHARED) $(GOBUILD) -o bin/$(BASE).a -buildmode=c-archive -v src/main.go
build-example: clean build-shared
$(CC) -o bin/$(BINARY_NAME)_example -I./bin -L./bin example/example.cpp bin/bootstrap.so
$(CC) -o bin/$(BASE)_example -I./bin -L./bin example/example.cpp bin/bootstrap.so
clean:
$(GOCLEAN)
rm -f bin/$(BASE)*
rm -f bin/$(BINARY_NAME)*
rm -f bin/$(BINARY_NAME_WIN)*

View File

@@ -3,6 +3,7 @@ package main
import "C"
import (
"crypto/tls"
"encoding/json"
"flag"
"fmt"
@@ -11,19 +12,116 @@ import (
"net/http"
"os"
"path/filepath"
"regexp"
"strings"
)
// Repo is the default repo structure.
type Repo struct {
File string `json:"file"`
Name string `json:"name"`
URL string `json:"url"`
File string `json:"file"`
Name string `json:"name"`
URL string `json:"url"`
}
func main() {
Update()
}
var metadata = map[string]string{
"Altair8800_Mister": "Computer",
"Amstrad_MiSTer": "Computer",
"Apogee_MiSTer": "Computer",
"Apple-II_MiSTer": "Computer",
"Aquarius_MISTer": "Computer",
"Arcade-Alibaba_MiSTer": "Arcade",
"Arcade-Amidar_MiSTer": "Arcade",
"Arcade-Azurian_MiSTer": "Arcade",
"Arcade-Bagman_MiSTer": "Arcade",
"Arcade-BlackHole_MiSTer": "Arcade",
"Arcade-BombJack_MiSTer": "Arcade",
"Arcade-BurgerTime_MiSTer": "Arcade",
"Arcade-BurningRubber_MiSTer": "Arcade",
"Arcade-Catacomb_MiSTer": "Arcade",
"Arcade-ComputerSpace_MiSTer": "Arcade",
"Arcade-CosmicAvenger_MiSTer": "Arcade",
"Arcade-CrazyClimber_MiSTer": "Arcade",
"Arcade-CrazyKong_MiSTer": "Arcade",
"Arcade-CrushRoller_MiSTer": "Arcade",
"Arcade-Defender_MiSTer": "Arcade",
"Arcade-DonkeyKong_MiSTer": "Arcade",
"Arcade-Dorodon_MiSTer": "Arcade",
"Arcade-DreamShopper_MiSTer": "Arcade",
"Arcade-Eeekk_MiSTer": "Arcade",
"Arcade-Eyes_MiSTer": "Arcade",
"Arcade-Frogger_MiSTer": "Arcade",
"Arcade-Galaga_MiSTer": "Arcade",
"Arcade-Galaxian_MiSTer": "Arcade",
"Arcade-Gorkans_MiSTer": "Arcade",
"Arcade-LadyBug_MiSTer": "Arcade",
"Arcade-LizardWizard_MiSTer": "Arcade",
"Arcade-MoonCresta_MiSTer": "Arcade",
"Arcade-MoonPatrol_MiSTer": "Arcade",
"Arcade-MrDoNightmare_MiSTer": "Arcade",
"Arcade-MrTNT_MiSTer": "Arcade",
"Arcade-MsPacman_MiSTer": "Arcade",
"Arcade-Omega_MiSTer": "Arcade",
"Arcade-Orbitron_MiSTer": "Arcade",
"Arcade-PacmanClub_MiSTer": "Arcade",
"Arcade-PacmanPlus_MiSTer": "Arcade",
"Arcade-Pacman_MiSTer": "Arcade",
"Arcade-PacmanicMiner_MiSTer": "Arcade",
"Arcade-Pengo_MiSTer": "Arcade",
"Arcade-Phoenix_MiSTer": "Arcade",
"Arcade-Pisces_MiSTer": "Arcade",
"Arcade-Ponpoko_MiSTer": "Arcade",
"Arcade-Pooyan_MiSTer": "Arcade",
"Arcade-Scramble_MiSTer": "Arcade",
"Arcade-SnapJack_MiSTer": "Arcade",
"Arcade-SuperGlob_MiSTer": "Arcade",
"Arcade-TheEnd_MiSTer": "Arcade",
"Arcade-TimePilot_MiSTer": "Arcade",
"Arcade-VanVanCar_MiSTer": "Arcade",
"Arcade-WarOfTheBugs_MiSTer": "Arcade",
"Arcade-Woodpecker_MiSTer": "Arcade",
"Arcade-Xevious_MiSTer": "Arcade",
"Archie_MiSTer": "Computer",
"Atari2600_MiSTer": "Console",
"Atari800_MiSTer": "Computer",
"BBCMicro_MiSTer": "Computer",
"BK0011M_MiSTer": "Computer",
"C16_MiSTer": "Computer",
"C64_MiSTer": "Computer",
"ColecoVision_MiSTer": "Console",
"Gameboy_MiSTer": "Console",
"Genesis_MiSTer": "Console",
"Jupiter_MiSTer": "Computer",
"Main_MiSTer": "Main",
"MSX_MiSTer": "Computer",
"MacPlus_MiSTer": "Computer",
"MemTest_MiSTer": "Utility",
"Menu_MiSTer": "Main",
"Minimig-AGA_MiSTer": "Computer",
"MultiComp_MiSTer": "Computer",
"NES_MiSTer": "Console",
"PET2001_MiSTer": "Computer",
"QL_MiSTer": "Computer",
"SAM-Coupe_MiSTer": "Computer",
"SMS_MiSTer": "Console",
"SNES_MiSTer": "Console",
"SharpMZ_MiSTer": "Computer",
"Specialist_MiSTer": "Computer",
"TI-99_4A_MiSTer": "Computer",
"TSConf_MiSTer": "Computer",
"TurboGrafx16_MiSTer": "Console",
"VIC20_MiSTer": "Computer",
"Vector-06C_MiSTer": "Computer",
"Vectrex_MiSTer": "Console",
"X68000_MiSTer": "Computer",
"ZX-Spectrum_MISTer": "Computer",
"ZX81_MiSTer": "Computer",
"ao486_MiSTer": "Computer",
}
//export Update
func Update() {
repo := flag.String("r", "https://raw.githubusercontent.com/OpenVGS/MiSTer-repository/master/repo.json", "Repo URL")
@@ -31,12 +129,16 @@ func Update() {
flag.Parse()
err := os.MkdirAll(*output, os.ModePerm)
absOutput, _ := filepath.Abs(*output)
err := os.MkdirAll(absOutput, os.ModePerm)
if err != nil {
log.Fatal("Error creating output directory:", err)
return
}
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
req, err := http.NewRequest("GET", *repo, nil)
if err != nil {
log.Fatal("Building repo request:", err)
@@ -59,15 +161,75 @@ func Update() {
log.Println(err)
}
for _, repo := range repos {
regex, err := regexp.Compile("\\d{8}")
if err != nil {
log.Fatal(err)
}
if _, err := os.Stat(fmt.Sprintf("%s/%s", *output, repo.File)); os.IsNotExist(err) {
for _, repo := range repos {
fmt.Println(repo.Name)
}
for _, repo := range repos {
coreType, found := metadata[repo.Name]
if found == false {
log.Println("Unrecognized repo", repo.Name)
if strings.Contains(repo.File, "Arcade") {
coreType = "Arcade"
} else {
coreType = "New"
}
}
outputDir := ""
if coreType != "Main" {
outputDir = fmt.Sprintf("%s/_%s", absOutput, coreType)
err := os.MkdirAll(outputDir, os.ModePerm)
if err != nil {
log.Fatal("Error creating output directory:", err)
return
}
} else {
outputDir = absOutput
}
if _, err := os.Stat(fmt.Sprintf("%s/%s", outputDir, repo.File)); os.IsNotExist(err) {
log.Printf("Downloading updated %s core...\n", repo.Name)
err := DownloadCore(fmt.Sprintf("%s/%s", *output, repo.File), repo.URL)
downloadLocation := ""
if coreType == "Main" {
if repo.Name == "Menu_MiSTer" {
downloadLocation = fmt.Sprintf("%s/%s", outputDir, "menu.rbf")
} else if repo.Name == "Main_MiSTer" {
downloadLocation = fmt.Sprintf("%s/%s", outputDir, "MiSTer")
}
} else {
downloadLocation = fmt.Sprintf("%s/%s", outputDir, repo.File)
}
err := DownloadCore(downloadLocation, repo.URL)
if err != nil {
panic(err)
}
globString := regex.ReplaceAllString(repo.File, "*")
files, _ := filepath.Glob(fmt.Sprintf("%s/%s", outputDir, globString))
currentFile := fmt.Sprintf("%s/%s", outputDir, repo.File)
fmt.Println("Current file", currentFile)
for _, file := range files {
if file != currentFile {
err := os.Remove(file)
if err != nil {
log.Fatal(err)
}
log.Println("Deleted:", file)
}
}
} else {
log.Printf("Core %s already latest version, skipping\n", repo.Name)
}