Ejemplo n.º 1
0
func HashesForGZFile(inpath string) (*Hashes, error) {
	file, err := os.Open(inpath)
	if err != nil {
		return nil, err
	}
	defer file.Close()

	gzipReader, err := cgzip.NewReader(file)
	if err != nil {
		return nil, err
	}
	defer gzipReader.Close()

	return hashesForReader(gzipReader)
}
Ejemplo n.º 2
0
func (depot *Depot) buildGame(game *types.Game, datPath string) (*types.Game, error) {
	gamePath := filepath.Join(datPath, game.Name+zipSuffix)
	gameFile, err := os.Create(gamePath)
	if err != nil {
		return nil, err
	}
	defer gameFile.Close()

	gameTorrent, err := torrentzip.NewWriter(gameFile)
	if err != nil {
		return nil, err
	}
	defer gameTorrent.Close()

	var fixGame *types.Game

	for _, rom := range game.Roms {
		if rom.Sha1 == nil {
			glog.Warningf("game %s has rom with missing SHA1 %s", game.Name, rom.Name)
			if fixGame == nil {
				fixGame = new(types.Game)
				fixGame.Name = game.Name
				fixGame.Description = game.Description
			}

			fixGame.Roms = append(fixGame.Roms, rom)
			continue
		}

		romGZ, err := depot.OpenRomGZ(rom)
		if err != nil {
			return nil, err
		}

		if romGZ == nil {
			glog.Warningf("game %s has missing rom %s (sha1 %s)", game.Name, rom.Name, hex.EncodeToString(rom.Sha1))
			if fixGame == nil {
				fixGame = new(types.Game)
				fixGame.Name = game.Name
				fixGame.Description = game.Description
			}

			fixGame.Roms = append(fixGame.Roms, rom)
			continue
		}

		src, err := cgzip.NewReader(romGZ)
		if err != nil {
			return nil, err
		}

		dst, err := gameTorrent.Create(rom.Name)
		if err != nil {
			return nil, err
		}

		_, err = io.Copy(dst, src)
		if err != nil {
			return nil, err
		}

		src.Close()
		romGZ.Close()
	}
	return fixGame, nil
}