Ejemplo n.º 1
0
func main() {
	flag.Parse()
	fn := flag.Arg(0)
	f, err := os.Open(fn)
	if err != nil {
		fatalf("Cannot open ggpk file %s: %s", fn, err)
	}
	defer f.Close()

	rootNode, err := record.GGG(f)
	if err != nil {
		fatalf("Cannot read ggpk signature: %s", err)
	}

	if rootNode.Header.Tag != "GGPK" {
		fatal("This file is not ggpk file, or corrupted.")
	}

	nodes, err := rootNode.Children(f)
	if err != nil {
		fatalf("Cannot read root node from ggpk: %s", err)
	}

	log.Print("Checking ...")
	for _, node := range nodes {
		doHeader(node, f, "")
	}
	log.Print("All ok.")
}
Ejemplo n.º 2
0
// FromGGPK builds afs structure from ggpk file
func FromGGPK(f *os.File) (root *Directory, err error) {
	// test if we can seek, also ensure we are at very beginning of file
	if _, err = f.Seek(0, 0); err != nil {
		return
	}

	// read GGPK sign
	rootNode, err := record.GGG(f)
	if err != nil {
		return
	}
	if rootNode.Header.Tag != "GGPK" {
		return root, errors.New("This file is not GGPK file")
	}

	// find root directory
	nodes, err := rootNode.Children(f)
	if err != nil {
		log.Fatalf("Cannot read root nodes from ggpk: %s", err)
	}
	var rootDirNode record.RecordHeader
	for _, n := range nodes {
		if n.Tag == "PDIR" {
			rootDirNode = n
			break
		}
	}

	if rootDirNode.Tag != "PDIR" {
		return root, errors.New("Cannot find root directory from ggpk")
	}

	// create afs root
	rootdir, err := record.ReadDir(f, rootDirNode)
	if err != nil {
		return
	}
	if rootdir.Name != "" {
		return root, errors.New("root dir name is not empty")
	}
	root = FromDirectoryRecord(rootDirNode, rootdir, 0)
	root.Path = "/"

	for _, e := range rootdir.Entries {
		if err = doEntry(f, e, root); err != nil {
			return
		}
	}

	sort.Sort(ByName(root.Files))
	sort.Sort(ByPath(root.Subfolders))
	return
}