private void LoadTPF(string file)
{
EnableSecondProgressBar(true);
// KFreon: Open TPF and set some properties
SaltTPF.ZipReader zippy = new SaltTPF.ZipReader(file);
zippy.Description = "TPF Details\n\nFilename: \n" + zippy._filename + "\n\nComment: \n" + zippy.EOFStrct.Comment + "\nNumber of stored files: " + zippy.Entries.Count;
zippy.Scanned = false;
int zippyInd = zippys.Count;
zippys.Add(zippy);
int numEntries = zippy.Entries.Count;
// KFreon: Setup nodes and GUI elements
this.Invoke(new Action(() =>
{
CurrentProg.ChangeProgressBar(0, numEntries);
CurrentStatusLabel.Text = "Processing file: " + Path.GetFileName(file);
}));
DebugOutput.PrintLn("Loading file: " + Path.GetFileName(file));
// KFreon: Get hash info from TPF
// KFreon: Get individual hashes without duplicate lines
// Heff: Fix weird uppercase X
List<string> parts = GetHashesFromTPF(zippy);
if (parts == null)
return;
// KFreon: Thread TPF loading
ParallelOptions po = new ParallelOptions();
po.MaxDegreeOfParallelism = Properties.Settings.Default.NumThreads;
DebugOutput.PrintLn("Reading TPF using " + po.MaxDegreeOfParallelism + " threads.");
List<TPFTexInfo> temptexes = new List<TPFTexInfo>();
for (int i = 0; i < numEntries; i++)
{
temptexes.Add(new TPFTexInfo());
}
Parallel.For(0, numEntries, po, i =>
{
// KFreon: Add TPF entries to TotalTexes list
TPFTexInfo tmpTex = new TPFTexInfo(zippy.Entries[i].Filename, i, null, zippy, WhichGame);
// KFreon: Find and set hash
foreach (string line in parts)
if (line.ToLowerInvariant().Contains(tmpTex.FileName.ToLowerInvariant()))
{
tmpTex.Hash = KFreonLib.Textures.Methods.FormatTexmodHashAsUint(line);
tmpTex.OriginalHash = tmpTex.Hash;
tmpTex.FileName = line.Split('|')[1].Replace("\r", "");
break;
}
// KFreon: If hash gen failed, notify
if (!tmpTex.isDef && tmpTex.Hash == 0)
DebugOutput.PrintLn("Failure to get hash for entry " + i + " in " + file);
// KFreon: Get details
if (!tmpTex.isDef)
tmpTex.EnumerateDetails();
temptexes[i] = tmpTex;
// Heff: cancel background loaders
if (cts.IsCancellationRequested)
return;
CurrentProg.IncrementBar();
});
// KFreon: Load textures into list and treeview
LoadedTexes.AddRange(temptexes);
EnableSecondProgressBar(false);
}