private void BulkExtractTPFButton_Click(object sender, EventArgs e)
{
string outputPath = null;
var dialog = new CommonOpenFileDialog();
dialog.IsFolderPicker = true;
dialog.EnsurePathExists = true;
dialog.Title = "Select folder containing multiple TPF's to extract.";
if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
outputPath = dialog.FileName;
else
return;
OverallProgressBar.Value = 0;
var tpfs = Directory.EnumerateFiles(outputPath);
OverallProgressBar.Maximum = tpfs.Count();
foreach (var item in tpfs)
{
if (!item.EndsWith(".tpf", StringComparison.OrdinalIgnoreCase)) // KFreon: TPF's only.
continue;
SaltTPF.ZipReader zippy = new SaltTPF.ZipReader(item);
OverallStatusLabel.Text = "Extracting " + Path.GetFileName(zippy._filename);
// KFreon: Create individual directory
string extractPath = Path.Combine(outputPath, Path.GetFileNameWithoutExtension(zippy._filename));
Directory.CreateDirectory(extractPath);
List<string> hashes = GetHashesFromTPF(zippy, false);
for (int i = 0; i < zippy.Entries.Count - 1; i++)
{
var entry = zippy.Entries[i];
string filename = entry.Filename;
string hash = hashes[i].Split('|').First();
if (!filename.Contains(hash))
{
string tempname = Path.GetFileNameWithoutExtension(filename);
filename = filename.Replace(tempname, tempname + "_" + hash);
}
if (File.Exists(Path.Combine(extractPath, filename)))
continue;
entry.Extract(false, Path.Combine(extractPath, filename));
}
OverallProgressBar.Value++;
}
OverallProgressBar.Value = OverallProgressBar.Maximum;
MessageBox.Show("Done");
}