Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
Optimize BundleExporter and fix DirectoryRecord reading
Browse files Browse the repository at this point in the history
  • Loading branch information
aianlinb authored Sep 27, 2020
1 parent 2037982 commit 32e43b1
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 65 deletions.
141 changes: 77 additions & 64 deletions BundleExporter/Program.cs
Original file line number Diff line number Diff line change
@@ -1,65 +1,78 @@
using System;
using System.IO;
using System.Linq;

namespace BundleExporter
{
class Program
{
static void Main()
{
if (!File.Exists("_.index.bin"))
{
Console.WriteLine("File not found: _.index.bin");
Console.WriteLine("Click enter to exit . . .");
Console.ReadLine();
return;
}
if (!File.Exists("LibBundle.dll"))
{
Console.WriteLine("File not found: oo2core_8_win64.dll");
Console.WriteLine("Click enter to exit . . .");
Console.ReadLine();
return;
}
if (!File.Exists("oo2core_8_win64.dll"))
{
Console.WriteLine("File not found: oo2core_8_win64.dll");
Console.WriteLine("Click enter to exit . . .");
Console.ReadLine();
return;
}

var ic = new LibBundle.IndexContainer("_.index.bin");
Console.WriteLine("Found:");
Console.WriteLine(ic.Bundles.Length.ToString() + " BundleRecords");
Console.WriteLine(ic.Directorys.Length.ToString() + " DirectoryRecords");
Console.WriteLine(ic.Files.Length.ToString() + " FileRecords");
Console.WriteLine("");

var ExistFiles = ic.Files.Where(o => File.Exists(o.bundleRecord.Name));
Console.Write("Exporting files . . . (");
int count = 0;
var str = "/" + ExistFiles.Count().ToString() + ")";
foreach (var f in ExistFiles)
{
count++;
Console.CursorLeft = 23;
Console.Write(count);
Console.Write(str);
try
{
var path = ic.Hashes[f.Hash];
if (!Directory.Exists(Path.GetDirectoryName(path)))
Directory.CreateDirectory(Path.GetDirectoryName(path));
var fi = File.Create(path);
fi.Write(f.Read(), 0, f.Size);
}
catch (System.Collections.Generic.KeyNotFoundException) { }
}
Console.WriteLine(Environment.NewLine);
Console.WriteLine("Click enter to exit . . .");
Console.ReadLine();
}
}
using System;
using System.IO;
using System.Linq;

namespace BundleExporter
{
class Program
{
static void Main()
{
if (!File.Exists("_.index.bin"))
{
Console.WriteLine("File not found: _.index.bin");
Console.WriteLine("Click enter to exit . . .");
Console.ReadLine();
return;
}
if (!File.Exists("LibBundle.dll"))
{
Console.WriteLine("File not found: oo2core_8_win64.dll");
Console.WriteLine("Click enter to exit . . .");
Console.ReadLine();
return;
}
if (!File.Exists("oo2core_8_win64.dll"))
{
Console.WriteLine("File not found: oo2core_8_win64.dll");
Console.WriteLine("Click enter to exit . . .");
Console.ReadLine();
return;
}

var ic = new LibBundle.IndexContainer("_.index.bin");
Console.WriteLine("Found:");
Console.WriteLine(ic.Bundles.Length.ToString() + " BundleRecords");
Console.WriteLine(ic.Files.Length.ToString() + " FileRecords");
Console.WriteLine(ic.Directorys.Length.ToString() + " DirectoryRecords");
var ExistBundle = ic.Bundles.Where(o => File.Exists(o.Name));
Console.WriteLine(ExistBundle.Count().ToString() + " bundle.bin");
Console.WriteLine("");

int count = 0;
foreach (var b in ExistBundle)
count += b.Files.Count;
Console.Write("Exporting files . . . (");
var str = "/" + count.ToString() + ")";
count = 0;
foreach (var b in ExistBundle)
{
var data = b.Bundle.Read();
foreach (var f in b.Files)
{
count++;
Console.CursorLeft = 23;
Console.Write(count);
Console.Write(str);
try
{
var path = ic.Hashes[f.Hash];
Directory.CreateDirectory(Path.GetDirectoryName(path));
var by = new byte[f.Size];
data.Position = f.Offset;
data.Read(by, 0, f.Size);
File.WriteAllBytes(path, by);
}
catch (Exception e)
{
Console.Error.WriteLine(e.ToString());
}
}
data.Close();
}
Console.WriteLine(Environment.NewLine);
Console.WriteLine("Click enter to exit . . .");
Console.ReadLine();
}
}
}
2 changes: 1 addition & 1 deletion LibBundle/IndexContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public IndexContainer(string path) : base(path)
var temp = new List<string>();
bool Base = false;
br2.BaseStream.Seek(d.Offset, SeekOrigin.Begin);
while (br2.BaseStream.Position - d.Offset < d.RecursiveSize)
while (br2.BaseStream.Position - d.Offset <= d.RecursiveSize - 4)
{
int index = br2.ReadInt32();
if (index == 0)
Expand Down

0 comments on commit 32e43b1

Please sign in to comment.