Example #1
0
// processGameFile processes game file at given path
func (a *Archive) processGameFile(filePath string) error {
	r := rom.New(filePath)
	if err := r.Fill(); err != nil {
		return err
	}

	if skip, msg := a.skip(r); skip {
		if a.Options.Debug {
			a.log(fmt.Sprintf("Skipped '%s': %s\n", r.Filename, msg))
		}

		a.Skipped++

		return nil
	}

	if a.Games[r.Name] == nil {
		// it's a new game
		a.Games[r.Name] = rom.NewGame()
	}

	a.Games[r.Name].AddRom(r)

	return nil
}
Example #2
0
// selectGameArchiveRom selects only one rom from given game archive directory, mark it as already selected then copy it to output
func (a *Archive) selectGameArchiveRom(dir string) error {
	files, err := ioutil.ReadDir(dir)
	if err != nil {
		return err
	}

	g := rom.NewGame()

	// process roms
	for _, file := range files {
		if file.IsDir() {
			a.log(fmt.Sprintf("ERR: Skipped unexpected directory in game archive: %s\n", file.Name()))
		} else {
			filePath := path.Join(dir, file.Name())

			r := rom.New(filePath)
			if err := r.Fill(); err != nil {
				return err
			}

			if skip, msg := a.skip(r); skip {
				if a.Options.Debug {
					a.log(fmt.Sprintf("Skipped '%s': %s\n", r.Filename, msg))
				}

				a.Skipped++
			} else {
				g.AddRom(r)
			}

			a.Processed++
		}
	}

	// select best rom
	if err := a.moveGameBestRom(g); err != nil {
		return err
	}

	gName, _ := rom.NameAndRegions(path.Base(dir))
	a.Games[gName] = g

	return nil
}