Ejemplo n.º 1
0
Archivo: main.go Proyecto: sbinet/romba
func lookup(cmd *commander.Command, args []string) {
	if len(args) == 0 {
		return
	}

	for _, arg := range args {
		exists, err := archive.PathExists(arg)
		if err != nil {
			fmt.Fprintf(os.Stderr, "failed to stat %s: %v\n", arg, err)
			os.Exit(1)
		}
		if exists {
			hh, err := archive.HashesForFile(arg)
			if err != nil {
				fmt.Fprintf(os.Stderr, "failed to compute hashes for %s: %v\n", arg, err)
				os.Exit(1)
			}

			found, err := lookupByHash(hh.Sha1)
			if err != nil {
				fmt.Fprintf(os.Stderr, "failed to lookup by sha1 hash for %s: %v\n", arg, err)
				os.Exit(1)
			}
			if found {
				continue
			}
			found, err = lookupByHash(hh.Md5)
			if err != nil {
				fmt.Fprintf(os.Stderr, "failed to lookup by md5 hash for %s: %v\n", arg, err)
				os.Exit(1)
			}
			if found {
				continue
			}

			found, err = lookupByHash(hh.Crc)
			if err != nil {
				fmt.Fprintf(os.Stderr, "failed to lookup by crc hash for %s: %v\n", arg, err)
				os.Exit(1)
			}
		} else {
			hash, err := hex.DecodeString(arg)
			if err != nil {
				fmt.Fprintf(os.Stderr, "failed to decode hex string %s: %v\n", arg, err)
				os.Exit(1)
			}
			_, err = lookupByHash(hash)
			if err != nil {
				fmt.Fprintf(os.Stderr, "failed to lookup by hash for %s: %v\n", arg, err)
				os.Exit(1)
			}
		}
	}

}
Ejemplo n.º 2
0
func (pw *buildWorker) Process(path string, size int64) error {
	hashes, err := archive.HashesForFile(path)
	if err != nil {
		return err
	}

	dat, err := pw.pm.rs.romDB.GetDat(hashes.Sha1)
	if err != nil {
		return err
	}

	if dat == nil {
		// TODO(uwe): maybe parse it and add it to the DB
		glog.Warningf("did not find a DAT for %s, maybe a refresh is needed", path)
		return nil
	}

	reldatdir, err := filepath.Rel(pw.pm.commonRootPath, filepath.Dir(path))
	if err != nil {
		return err
	}

	datdir := filepath.Join(pw.pm.outpath, reldatdir)

	glog.Infof("buildWorker processing %s, reldatdir=%s, datdir=%s", path, reldatdir, datdir)

	err = os.MkdirAll(datdir, 0777)
	if err != nil {
		return err
	}

	for _, game := range dat.Games {
		for _, rom := range game.Roms {
			err = pw.pm.rs.romDB.CompleteRom(rom)
			if err != nil {
				return err
			}
		}
	}

	datComplete, err := pw.pm.rs.depot.BuildDat(dat, datdir)
	if err != nil {
		return err
	}

	glog.Infof("finished building dat %s in directory %s\n", dat.Name, datdir)
	if !datComplete {
		glog.Info("dat has missing roms")
	}
	return nil
}
Ejemplo n.º 3
0
func (pw *buildWorker) Process(path string, size int64) error {
	hashes, err := archive.HashesForFile(path)
	if err != nil {
		return err
	}

	dat, err := pw.pm.rs.romDB.GetDat(hashes.Sha1)
	if err != nil {
		return err
	}

	if dat == nil {
		glog.Warningf("did not find a DAT for %s, parsing it", path)
		dat, _, err = parser.Parse(path)
		if err != nil {
			return err
		}

		glog.V(4).Infof("parsed dat=%s", types.PrintShortDat(dat))
	}

	reldatdir, err := filepath.Rel(pw.pm.commonRootPath, filepath.Dir(path))
	if err != nil {
		return err
	}

	datdir := filepath.Join(pw.pm.outpath, reldatdir)

	glog.Infof("buildWorker processing %s, reldatdir=%s, datdir=%s", path, reldatdir, datdir)

	err = os.MkdirAll(datdir, 0777)
	if err != nil {
		return err
	}

	for _, game := range dat.Games {
		for _, rom := range game.Roms {
			err = pw.pm.rs.romDB.CompleteRom(rom)
			if err != nil {
				return err
			}
		}
	}

	datInComplete := false
	if pw.pm.fixdatOnly {
		datInComplete, err = pw.pm.rs.depot.FixDat(dat, datdir, pw.pm.numSubWorkers, pw.pm.deduper)
	} else {
		datInComplete, err = pw.pm.rs.depot.BuildDat(dat, datdir, pw.pm.numSubWorkers, pw.pm.deduper)
	}

	if err != nil {
		return err
	}

	glog.Infof("finished building dat %s in directory %s", dat.Name, datdir)
	if datInComplete {
		glog.Info("dat has missing roms")
	}
	return nil
}