Example #1
0
        public Xb2Fs(string directory)
        {
            string baseDir = Path.Combine(directory, "base");
            string dlcDir  = Path.Combine(directory, "dlc");

            if (!Directory.Exists(baseDir))
            {
                throw new DirectoryNotFoundException($"Could not find {baseDir}");
            }

            var dirs = new List <string>();

            if (Directory.Exists(dlcDir))
            {
                string[] dlcDirs = Directory.GetDirectories(dlcDir);
                dirs.AddRange(dlcDirs);
            }
            dirs.Add(baseDir);

            for (int i = 0; i < dirs.Count; i++)
            {
                foreach (string file in Directory.GetFiles(dirs[i], "*", SearchOption.AllDirectories))
                {
                    string path = Helpers.GetRelativePath(file, dirs[i]);
                    path = path.Replace('\\', '/');
                    if (path[0] != '/')
                    {
                        path = '/' + path;
                    }
                    if (path == "key.bin")
                    {
                        continue;
                    }
                    Files[path] = new FsFile(file, i);
                    //Files.Add(path, new FsFile(file, i));
                }
            }

            string arh = Path.Combine(baseDir, "bf2.arh");
            string ard = Path.Combine(baseDir, "bf2.ard");

            if (File.Exists(arh) && File.Exists(ard))
            {
                Archive = new FileArchive(arh, ard);
                foreach (FileInfo file in Archive.FileInfo.Where(x => x.Filename != null)) //Todo: Investigate
                {
                    Files.Add(file.Filename, new FsFile(file.Filename, -1));
                }
            }
        }
Example #2
0
        public static void Extract(FileArchive archive, string outDir, IProgressReport progress = null)
        {
            FileInfo[] fileInfos = archive.FileInfo.Where(x => !string.IsNullOrWhiteSpace(x.Filename)).ToArray();
            progress?.SetTotal(fileInfos.Length);
            progress?.LogMessage("Extracting ARD archive");

            foreach (FileInfo fileInfo in fileInfos)
            {
                string filename = Path.Combine(outDir, fileInfo.Filename.TrimStart('/'));
                string dir      = Path.GetDirectoryName(filename) ?? throw new InvalidOperationException();
                Directory.CreateDirectory(dir);

                using (var outStream = new FileStream(filename, FileMode.Create, FileAccess.Write))
                {
                    archive.OutputFile(fileInfo, outStream);
                }
                progress?.ReportAdd(1);
            }
        }