Example #1
0
 public static BARFile Load(string filename)
 {
     if (!File.Exists(filename)) return null;
     var file = File.OpenRead(filename);
     var bar = new BARFile() {
         stream = file,
         SourceFilename = filename,
     };
     var reader = new BinaryReader(file);
     reader.Read(bar.Id = new byte[8], 0, 8);
     int unknown = reader.ReadInt32();
     int entryC = reader.ReadInt32();
     bar.DirectorySize = reader.ReadInt32();
     bar.DirectoryOffset = reader.ReadInt32();
     int unknown2 = reader.ReadInt32();
     file.Seek(bar.DirectoryOffset, SeekOrigin.Begin);
     int[] offsets = new int[entryC];
     for (int o = 0; o < offsets.Length; ++o) offsets[o] = reader.ReadInt32();
     for (int e = 0; e < entryC; ++e) {
         Entry entry = new Entry();
         entry.Offset = reader.ReadInt32();
         entry.Size = reader.ReadInt32();
         entry.Size2 = reader.ReadInt32();
         byte b0 = reader.ReadByte(),
             b1 = reader.ReadByte(),
             b2 = reader.ReadByte(),
             b3 = reader.ReadByte();
         if (b3 != 0) file.Position += 4;
         for (var c = reader.ReadChar(); c != '\0'; c = reader.ReadChar()) {
             entry.Name += c;
         }
         bar.entries.Add(entry);
     }
     return bar;
 }
Example #2
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));
         }
     }
 }
Example #3
0
        public static BARFile Load(string filename)
        {
            if (!File.Exists(filename))
            {
                return(null);
            }
            var file = File.OpenRead(filename);
            var bar  = new BARFile()
            {
                stream         = file,
                SourceFilename = filename,
            };
            var reader = new BinaryReader(file);

            reader.Read(bar.Id = new byte[8], 0, 8);
            int unknown = reader.ReadInt32();
            int entryC  = reader.ReadInt32();

            bar.DirectorySize   = reader.ReadInt32();
            bar.DirectoryOffset = reader.ReadInt32();
            int unknown2 = reader.ReadInt32();

            file.Seek(bar.DirectoryOffset, SeekOrigin.Begin);
            int[] offsets = new int[entryC];
            for (int o = 0; o < offsets.Length; ++o)
            {
                offsets[o] = reader.ReadInt32();
            }
            for (int e = 0; e < entryC; ++e)
            {
                Entry entry = new Entry();
                entry.Offset = reader.ReadInt32();
                entry.Size   = reader.ReadInt32();
                entry.Size2  = reader.ReadInt32();
                byte b0 = reader.ReadByte(),
                     b1 = reader.ReadByte(),
                     b2 = reader.ReadByte(),
                     b3 = reader.ReadByte();
                if (b3 != 0)
                {
                    file.Position += 4;
                }
                for (var c = reader.ReadChar(); c != '\0'; c = reader.ReadChar())
                {
                    entry.Name += c;
                }
                bar.entries.Add(entry);
            }
            return(bar);
        }
Example #4
0
 public FileViewModel(BARFile.Entry entry, BARViewModel owner)
     : base(owner)
 {
     Entry = entry;
     Name = Path.GetFileName(Entry.Name);
 }
Example #5
0
 public Stream GetFileStream(BARFile.Entry entry)
 {
     return Source.GetFileStream(entry);
 }