Beispiel #1
0
func main() {
	flag.Parse()
	if *version {
		fmt.Println(versionStr)
		return
	}
	runtime.GOMAXPROCS(runtime.NumCPU())
	if *startPprof {
		go http.ListenAndServe(":8080", nil)
	}

	xmlOpts := &rom.XMLOpts{
		RomDir:     *romDir,
		RomXMLDir:  *romPath,
		NestImgDir: *nestedImageDir,
		ImgDir:     *imageDir,
		ImgXMLDir:  *imagePath,
		ImgSuffix:  *imageSuffix,
		ThumbOnly:  *thumbOnly,
		NoDownload: !*downloadImages,
		ImgFormat:  *imgFormat,
		ImgWidth:   *maxWidth,
	}
	var ifmt string
	if *mame {
		ifmt = *mameImg
	} else {
		ifmt = *gdbImg
	}
	for _, t := range strings.Split(ifmt, ",") {
		xmlOpts.ImgPriority = append(xmlOpts.ImgPriority, ds.ImgType(t))
	}
	gameOpts := &rom.GameOpts{
		AddNotFound:    *addNotFound,
		NoPrettyName:   !*useNoIntroName,
		UseFilename:    *useFilename,
		NoStripUnicode: !*stripUnicode,
	}
	sources := []ds.DS{}
	if *mame {
		*useGDB = false
		*useOVGDB = false
		mds, err := ds.NewMAME("")
		defer mds.Close()
		if err != nil {
			fmt.Println(err)
			return
		}
		sources = append(sources, mds)
	}
	var hasher *ds.Hasher
	if *useGDB || *useOVGDB {
		var err error
		hasher, err = ds.NewHasher(sha1.New)
		if err != nil {
			fmt.Println(err)
			return
		}
	}
	if *useGDB {
		if !*skipCheck {
			ok := gdb.IsUp()
			if !ok {
				fmt.Println("It appears that thegamesdb.net isn't up. If you are sure it is use -skip_check to bypass this error.")
				return
			}
		}
		hm, err := ds.CachedHashMap("")
		if err != nil {
			fmt.Println(err)
			return
		}
		sources = append(sources, &ds.GDB{HM: hm, Hasher: hasher})
	}
	if *useOVGDB {
		o, err := ds.NewOVGDB(hasher)
		if err != nil {
			fmt.Println(err)
			return
		}
		defer o.Close()
		sources = append(sources, o)
	}
	if !*scrapeAll {
		err := Scrape(sources, xmlOpts, gameOpts)
		if err != nil {
			fmt.Println(err)
			return
		}
	} else {
		romFolders, err := GetRomFolders()
		if err != nil {
			fmt.Println(err)
			return
		}
		for _, rf := range romFolders {
			log.Printf("Starting System %s", rf)
			xmlOpts.RomDir = rf
			xmlOpts.RomXMLDir = rf
			p := filepath.Join(rf, "images")
			xmlOpts.ImgDir = p
			xmlOpts.ImgXMLDir = p
			out := filepath.Join(rf, "gamelist.xml")
			*outputFile = out
			err := Scrape(sources, xmlOpts, gameOpts)
			if err != nil {
				fmt.Println(err)
				return
			}
		}
	}
}
Beispiel #2
0
func main() {
	flag.Parse()
	if *version {
		fmt.Println(versionStr)
		return
	}
	runtime.GOMAXPROCS(runtime.NumCPU())
	if *startPprof {
		go http.ListenAndServe(":8080", nil)
	}

	xmlOpts := &rom.XMLOpts{
		RomDir:     *romDir,
		RomXMLDir:  *romPath,
		NestImgDir: *nestedImageDir,
		ImgDir:     *imageDir,
		ImgXMLDir:  *imagePath,
		ImgSuffix:  *imageSuffix,
		ThumbOnly:  *thumbOnly,
		NoDownload: !*downloadImages,
		ImgFormat:  *imgFormat,
		ImgWidth:   *maxWidth,
	}
	var arcadeImg []ds.ImgType
	var consoleImg []ds.ImgType
	for _, t := range strings.Split(*mameImg, ",") {
		arcadeImg = append(arcadeImg, ds.ImgType(t))
	}
	for _, t := range strings.Split(*gdbImg, ",") {
		consoleImg = append(consoleImg, ds.ImgType(t))
	}
	gameOpts := &rom.GameOpts{
		AddNotFound:    *addNotFound,
		NoPrettyName:   !*useNoIntroName,
		UseFilename:    *useFilename,
		NoStripUnicode: !*stripUnicode,
	}

	var arcadeSources []ds.DS
	var consoleSources []ds.DS
	if *mame && !*scrapeAll {
		*useGDB = false
		*useOVGDB = false
	}
	if *mame || *scrapeAll {
		mds, err := ds.NewMAME("")
		defer mds.Close()
		if err != nil {
			fmt.Println(err)
			return
		}
		arcadeSources = append(arcadeSources, mds)
	}
	var hasher *ds.Hasher
	if *useGDB || *useOVGDB {
		var err error
		hasher, err = ds.NewHasher(sha1.New)
		if err != nil {
			fmt.Println(err)
			return
		}
	}
	hm, err := ds.CachedHashMap("")
	if err != nil {
		fmt.Println(err)
		return
	}
	if *useGDB {
		if !*skipCheck {
			ok := gdb.IsUp()
			if !ok {
				fmt.Println("It appears that thegamesdb.net isn't up. If you are sure it is use -skip_check to bypass this error.")
				return
			}
		}
		consoleSources = append(consoleSources, &ds.GDB{HM: hm, Hasher: hasher})
	}
	if *useOVGDB {
		o, err := ds.NewOVGDB(hasher)
		if err != nil {
			fmt.Println(err)
			return
		}
		defer o.Close()
		consoleSources = append(consoleSources, o)
	}
	consoleSources = append(consoleSources, &ds.ScummVM{HM: hm})
	if !*scrapeAll {
		var sources []ds.DS
		if *mame {
			sources = arcadeSources
			xmlOpts.ImgPriority = arcadeImg
		} else {
			sources = consoleSources
			xmlOpts.ImgPriority = consoleImg
		}
		err := Scrape(sources, xmlOpts, gameOpts)
		if err != nil {
			fmt.Println(err)
			return
		}
	} else {
		systems, err := GetSystems()
		if err != nil {
			fmt.Println(err)
			return
		}
		for _, s := range systems {
			log.Printf("Starting System %s", s.Path)
			xmlOpts.RomDir = s.Path
			xmlOpts.RomXMLDir = s.Path
			p := filepath.Join(s.Path, "images")
			xmlOpts.ImgDir = p
			xmlOpts.ImgXMLDir = p
			out := filepath.Join(s.Path, "gamelist.xml")
			*outputFile = out
			var sources []ds.DS
			switch s.Platform {
			case "arcade", "neogeo":
				sources = arcadeSources
				xmlOpts.ImgPriority = arcadeImg
			default:
				sources = consoleSources
				xmlOpts.ImgPriority = consoleImg
			}
			err := Scrape(sources, xmlOpts, gameOpts)
			if err != nil {
				fmt.Println(err)
				return
			}
		}
	}
}