示例#1
0
文件: BAR.cs 项目: Truthkey/OpenKH
 public BAR(Stream file)
 {
     if (!file.CanRead || !file.CanSeek)
     {
         throw new NotSupportedException("Cannot read or seek in stream");
     }
     using (var br = new BinaryReader(file))
     {
         if (file.Length < 16 || br.ReadUInt32() != 0x01524142)
         {
             throw new InvalidDataException("Invalid signature");
         }
         int fileC = br.ReadInt32();
         fileList = new List<BARFile>(fileC);
         Debug.WriteLine("Loading BAR with " + fileC + " files");
         file.Position = 16;
         for (int i = 0; i < fileC; i++)
         {
             var bf = new BARFile();
             bf.type = br.ReadUInt32();
             {
                 byte[] b = br.ReadBytes(4);
                 Buffer.BlockCopy(b, 0, bf._id, 0, 4);
             }
             long lpos = file.Position + 8;
             uint pos = br.ReadUInt32();
             int len = br.ReadInt32();
             file.Position = pos;
             bf.data = br.ReadBytes(len);
             fileList.Add(bf);
             file.Position = lpos;
         }
     }
     //BinaryReader should close file
 }
示例#2
0
文件: BAR.cs 项目: weimingtom/OpenKH
 public void save(Stream file)
 {
     if (!file.CanWrite)
     {
         throw new NotSupportedException("Cannot write to stream");
     }
     using (var bw = new BinaryWriter(file))
     {
         long basePos = file.Position;
         bw.Write(0x01524142u);
         int fileC = fileList.Count;
         bw.Write(fileC);
         bw.Write(0u);
         bw.Write(0u);
         uint offset = 16 * ((uint)fileC + 1);
         for (int i = 0; i < fileC; i++)
         {
             file.Position = basePos + 16 * (i + 1);
             BARFile bf = fileList[i];
             bw.Write(bf.type);
             bw.Write(bf._id);
             bw.Write(offset);
             bw.Write(bf.data.Length);
             uint szPad = (uint)Math.Ceiling((double)bf.data.Length / 16) * 16;
             file.Position = basePos + offset;
             bw.Write(bf.data);
             offset += szPad;
         }
     }
     //BinaryWriter should close file
 }
示例#3
0
文件: Program.cs 项目: hqdmyjsw/aoeo
        static void extractbar(string path, string saveTo, bool autoconvert)
        {
            Console.WriteLine("Converting BAR file (extract to directory): {0}", path);
            BARFile barfile = new BARFile(path);

            DirectoryInfo newpath = Directory.CreateDirectory(saveTo);

            foreach (BAREntry e in barfile)
            {
                string filepath = string.Format("{0}/{1}", newpath.FullName, e.filename);

                if (!Directory.Exists(filepath))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(filepath));
                }

                using (Stream file = File.OpenWrite(filepath))
                {
                    CopyStream(barfile.ExtractFileStream(e), file);
                }
                Console.WriteLine("Extracted {0}", filepath);

                if (autoconvert)
                {
                    Convert(filepath, saveTo);
                }
            }
        }
示例#4
0
文件: BAR.cs 项目: weimingtom/OpenKH
 public BAR(Stream file)
 {
     if (!file.CanRead || !file.CanSeek)
     {
         throw new NotSupportedException("Cannot read or seek in stream");
     }
     using (var br = new BinaryReader(file))
     {
         if (file.Length < 16 || br.ReadUInt32() != 0x01524142)
         {
             throw new InvalidDataException("Invalid signature");
         }
         int fileC = br.ReadInt32();
         fileList = new List <BARFile>(fileC);
         Debug.WriteLine("Loading BAR with " + fileC + " files");
         file.Position = 16;
         for (int i = 0; i < fileC; i++)
         {
             var bf = new BARFile();
             bf.type = br.ReadUInt32();
             {
                 byte[] b = br.ReadBytes(4);
                 Buffer.BlockCopy(b, 0, bf._id, 0, 4);
             }
             long lpos = file.Position + 8;
             uint pos  = br.ReadUInt32();
             int  len  = br.ReadInt32();
             file.Position = pos;
             bf.data       = br.ReadBytes(len);
             fileList.Add(bf);
             file.Position = lpos;
         }
     }
     //BinaryReader should close file
 }
示例#5
0
文件: Overlord.cs 项目: Weesals/ModHQ
        public void FromAOMDirectory(AOMDirectory directory, Action <LogCapture> onLoad)
        {
            if (loaded != false)
            {
                loaded = false;
                NotifyPropertyChanged("IsLoaded", "IsNotLoaded");
            }
            TextureFile  = null;
            Texture2File = null;
            DataFile     = null;
            Data2File    = null;
            Directory    = directory;
            int    toLoad    = 0;
            Action CheckLoad = delegate {
                ++toLoad;
                if (toLoad == 6)
                {
                    Load(onLoad);
                }
            };

            LoadBar(AOMDirectory.TexturesBAR, (bar) => { TextureFile = bar; CheckLoad(); });
            LoadBar(AOMDirectory.Textures2BAR, (bar) => { Texture2File = bar; CheckLoad(); });
            LoadBar(AOMDirectory.DataBAR, (bar) => { DataFile = bar; CheckLoad(); });
            LoadBar(AOMDirectory.Data2BAR, (bar) => { Data2File = bar; CheckLoad(); });
            LoadBar(AOMDirectory.SoundsBAR, (bar) => { SoundsFile = bar; CheckLoad(); });
            LoadBar(AOMDirectory.Sounds2BAR, (bar) => { Sounds2File = bar; CheckLoad(); });
        }
示例#6
0
        public BARFile GetFile(string name)
        {
            BARFile file;

            lock (barCache) {
                if (!barCache.TryGetValue(name, out file))
                {
                    barCache.Add(name, file = BARFile.Load(Path.Combine(InstallPath, name)));
                }
            }
            return(file);
        }
示例#7
0
 public BARViewModel(BARFile file, string name)
 {
     Name   = name;
     Source = file;
     Root   = new FolderViewModel(name, this);
     if (file != null)
     {
         foreach (var subFile in file.Files)
         {
             string directory = Path.GetDirectoryName(subFile.Name);
             var    folder    = Root;
             if (!string.IsNullOrEmpty(directory))
             {
                 if (folders.ContainsKey(directory))
                 {
                     folder = folders[directory];
                 }
                 else
                 {
                     string[] folderNames = directory.Split(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
                     for (int f = 0; f < folderNames.Length; ++f)
                     {
                         var folderName = folderNames[f];
                         var subFolder  = folder.Folders.FirstOrDefault(subF => subF.Name == folderName);
                         if (subFolder == null)
                         {
                             subFolder = new FolderViewModel(folderName, this);
                             folder.AddFolder(subFolder);
                         }
                         folder = subFolder;
                     }
                     // Doesnt add parent directories created, but idk if safe the
                     // directory name might not match.. might have a slash after
                     // or use the wrong slashes
                     folders.Add(directory, folder);
                 }
             }
             folder.AddFile(new FileViewModel(subFile, this));
         }
     }
 }
示例#8
0
文件: Overlord.cs 项目: Weesals/ModHQ
 public XMBFile LoadXMB(BARFile barFile, string fileName)
 {
     return(Directory.LoadXMB(barFile.SourceFilename, fileName));
 }