Пример #1
0
func main() {
	flag.Parse()
	if *versionFlag {
		getVersion()
		return
	}

	if len(os.Args) < 3 {
		fmt.Println("Usage:", os.Args[0], "filename.vpk", "target_directory")
		return
	}

	MAIN_FILE := os.Args[1]
	TARGET := os.Args[2]
	ignoreExt := map[string]bool{}
	ignorePath := []string{}

	if len(os.Args) > 3 {
		for _, arg := range os.Args[3:] {
			if strings.HasPrefix(arg, ".") {
				ignoreExt[arg] = true
			} else {
				ignorePath = append(ignorePath, arg)
			}
		}
	}

	f, err := os.Open(MAIN_FILE)
	eh(err)
	defer f.Close()

	vpkFile, err := vpk.ReadVPKFile(f)
	eh(err)

	for _, filename := range vpkFile.ListFiles() {
		if ignoreExt[path.Ext(filename)] {
			continue
		}
		ignore := false
		for _, path := range ignorePath {
			if strings.HasPrefix(filename, path) {
				ignore = true
				break
			}
		}
		if ignore {
			continue
		}
		dir := path.Dir(TARGET + "/" + filename)
		eh(os.MkdirAll(dir, 0777))
		data, err := vpkFile.GetReader(vpkFile.GetFileInfo(filename), MAIN_FILE)
		fd, err := os.Create(path.Join(dir, path.Base(filename)))
		eh(err)
		io.Copy(fd, data)
		eh(fd.Close())
		eh(data.Close())
	}
}
Пример #2
0
func main() {
	if len(os.Args) != 2 {
		fmt.Println("Usage:", os.Args[0], "filename.vpk")
		return
	}
	MAIN_FILE := os.Args[1]

	f, err := os.Open(MAIN_FILE)
	eh(err)
	defer f.Close()

	vpkFile, err := vpk.ReadVPKFile(f)
	eh(err)

	for _, filename := range vpkFile.ListFiles() {
		sha := sha1.New()
		data, err := vpkFile.GetReader(vpkFile.GetFileInfo(filename), MAIN_FILE)
		eh(err)
		io.Copy(sha, data)
		eh(data.Close())
		fmt.Printf("%x  %s\n", sha.Sum(nil), filename)
	}
}
Пример #3
0
func main() {
	flag.Parse()
	if *versionFlag {
		getVersion()
		return
	}

	if len(os.Args) < 3 {
		fmt.Println("Usage:", os.Args[0], "filename.vpk", "target_directory")
		return
	}

	MAIN_FILE := os.Args[1]
	TARGET := os.Args[2]
	includeExt := map[string]bool{}
	excludeExt := map[string]bool{}
	includePath := []string{}
	excludePath := []string{}
	includeAny := false

	if len(os.Args) > 3 {
		for _, arg := range os.Args[3:] {
			switch {
			case strings.HasPrefix(arg, "+."):
				includeExt[arg[1:]] = true
				includeAny = true
			case strings.HasPrefix(arg, "-."):
				excludeExt[arg[1:]] = true
			case strings.HasPrefix(arg, "+"):
				includePath = append(includePath, arg)
				includeAny = true
			case strings.HasPrefix(arg, "-"):
				excludePath = append(excludePath, arg)
			default:
				fmt.Println("Warning: unknown switch '%s'", arg)
			}
		}
	}

	f, err := os.Open(MAIN_FILE)
	if err != nil {
		panic(err)
	}
	defer f.Close()

	vpkFile, err := vpk.ReadVPKFile(f)
	if err != nil {
		panic(err)
	}

	for _, filename := range vpkFile.ListFiles() {
		ignore := includeAny
		ext := path.Ext(filename)

		if excludeExt[ext] {
			ignore = true
		}
		if includeExt[ext] {
			ignore = false
		}

		for _, path := range excludePath {
			if strings.HasPrefix(filename, path) {
				ignore = true
				break
			}
		}

		for _, path := range includePath {
			if strings.HasPrefix(filename, path) {
				ignore = false
				break
			}
		}

		if ignore {
			continue
		}

		fmt.Println("extracting", filename)

		dir := path.Dir(TARGET + "/" + filename)
		if err := os.MkdirAll(dir, 0777); err != nil {
			panic(err)
		}

		data, err := vpkFile.GetReader(vpkFile.GetFileInfo(filename), MAIN_FILE)
		if err != nil {
			panic(err)
		}

		fd, err := os.Create(path.Join(dir, path.Base(filename)))
		if err != nil {
			panic(err)
		}

		io.Copy(fd, data)
		fd.Close()
		data.Close()
	}
}