コード例 #1
0
ファイル: AGT.cs プロジェクト: ch1c4c/RiceTools
        public override ArchiveFile AddFile(string filePath)
        {
            var file = new AGTFile(this, Path.GetFileName(filePath), filePath);

            Files.Add(file);
            Archive.FileList.Add(file);

            return(file);
        }
コード例 #2
0
ファイル: AGT.cs プロジェクト: ch1c4c/RiceTools
        public override void Load(string filePath)
        {
            byte[] fileBuf = File.ReadAllBytes(filePath);

            for (int i = 32; i < fileBuf.Length; i++)
            {
                fileBuf[i] ^= xorKey[i % xorKey.Length];
            }

            var paths = new List <string>();

            using (var ms = new MemoryStream(fileBuf))
                using (var br = new BinaryReader(ms))
                {
                    ms.Position = 16;
                    int fileCount = br.ReadInt32();

                    ms.Position = 32;

                    RootFolder = new AGTFolder(this);

                    for (int i = 0; i < fileCount; i++)
                    {
                        int    chunkHeadersPos    = br.ReadInt32();
                        int    chunkCount         = br.ReadInt32();
                        int    decompressedLength = br.ReadInt32();
                        int    pathLength         = br.ReadInt32();
                        string path = Encoding.GetEncoding("ISO-8859-1").GetString(br.ReadBytes(pathLength));

                        string[] dirSplit = path.Split('\\');
                        string   filename = dirSplit[dirSplit.Length - 1];

                        ushort[] chunkLengths     = new ushort[chunkCount];
                        byte[][] compressedChunks = new byte[chunkCount][];

                        using (var chunkms = new MemoryStream(fileBuf))
                            using (var chunkbr = new BinaryReader(chunkms))
                            {
                                chunkms.Position = chunkHeadersPos;

                                for (int chunki = 0; chunki < chunkCount; chunki++)
                                {
                                    chunkLengths[chunki] = chunkbr.ReadUInt16();
                                }

                                for (int chunki = 0; chunki < chunkCount; chunki++)
                                {
                                    ushort zlibHeader = chunkbr.ReadUInt16();
                                    compressedChunks[chunki] = chunkbr.ReadBytes(chunkLengths[chunki] - 2);
                                }
                            }

                        var activeFolder = RootFolder as AGTFolder;
                        for (int j = 0; j < dirSplit.Length - 1; j++)
                        {
                            string curName = dirSplit[j];

                            var folder = activeFolder.SubFolders.FirstOrDefault(f => f.Name == curName) as AGTFolder;
                            if (folder == null)
                            {
                                folder = new AGTFolder(this, activeFolder, curName);
                                activeFolder.SubFolders.Add(folder);
                            }
                            activeFolder = folder;
                        }

                        var newFile = new AGTFile(activeFolder, filename, compressedChunks, decompressedLength);
                        activeFolder.Files.Add(newFile);
                        FileList.Add(newFile);
                    }
                }
        }