private void BeginLoadingTree(bool NoUser = false, bool ForceRebuild = false)
{
// KFreon: Move to backbone if necessary
if (!MainListView.InvokeRequired)
{
backbone.AddToBackBone(b =>
{
BeginLoadingTree(NoUser, ForceRebuild);
return true;
});
return;
}
DebugOutput.PrintLn("Beginning to load trees.");
// KFreon: Wait for GUI controls to be created
while (!ChangeButton.Parent.Created)
{
DebugOutput.PrintLn("Waiting for GUI to be created...");
System.Threading.Thread.Sleep(100);
}
this.Invoke(new Action(() =>
{
// KFreon: Close search list
TabSearchSplitter.SplitterDistance = 0;
// KFreon: Close context panel
ContextPanel.Height = 0;
}));
// KFreon: Loop over all trees
for (int i = 1; i < 4; i++)
{
// KFreon: Partly check tree we want
if (i == WhichGame)
{
DebugOutput.PrintLn("This is the tree we want: " + i);
if (!Texplorer2.SetupTree(ref Tree, pathCooked, WhichGame, MainTreeView, pathBIOGame))
continue;
}
else
{
// KFreon: Start tasks for trees we don't care about. Could keep these, but won't so trees can be loaded dynamically.
var y = i;
DebugOutput.PrintLn("This is a tree we don't care so much about: " + y);
Task.Run(() =>
{
TreeDB temptree = null;
MEExDirecs.SetupPathing(false);
string tempbio = MEExDirecs.GetDifferentPathBIOGame(y);
bool res = Texplorer2.SetupTree(ref temptree, MEExDirecs.GetDifferentPathCooked(y), y, null, tempbio);
bool temp = false;
if (res)
{
int status2;
temp = temptree.ReadFromFile(ExecFolder + "me" + y + "tree.bin", Path.GetDirectoryName(tempbio), ExecFolder + "ThumbnailCaches\\ME" + y + "ThumbnailCache\\", out status2);
}
DebugOutput.PrintLn(temp ? "Found ME" + y + " tree." : "ME" + y + " tree not found.");
ChangeTreeIndicators(y, temp);
return temp;
});
}
}
bool dostuff = ForceRebuild;
bool treefound = false;
DebugOutput.PrintLn("Dealing with main tree now...");
if (Tree == null)
MessageBox.Show("ME" + WhichGame + " not found!", "Forgetting something?", MessageBoxButtons.OK, MessageBoxIcon.Error);
else if (!dostuff && Tree != null)
{
int status = 0;
if (!LoadTreeFromFile(ExecFolder + "me" + WhichGame + "tree.bin", out status, true))
{
DebugOutput.PrintLn("Tree loading failed for: " + WhichGame);
// KFreon: Load failed, but user said rebuild
if (status == 1)
dostuff = true;
else if (!NoUser)
{
this.Invoke(new Action(() =>
{
if (MessageBox.Show("No ME" + WhichGame + " tree found. Do you want to build one?", "Damn Kai Leng...",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
dostuff = true;
}));
}
else if (status == 2) // KFreon: User cancelled rebuild
{
DebugOutput.PrintLn("Not rebuilding tree.");
OutputBoxPrintLn("Tree corrupt. Load cancelled!");
ChangeButton.Invoke(new Action(() => ChangeButton.Enabled = true));
return;
}
}
else
treefound = true;
}
// KFreon: Don't want else if here cos do stuff can change inside the !dostuff statement. Also this performs the ManageDLC stuff if tree not found
if (Tree == null)
{
DebugOutput.PrintLn("Tree was null. Probably cos gamefiles don't exist and tree wasn't loaded.");
// KFreon: Placeholder
OutputBoxPrintLn("ME" + WhichGame + " game files not found. Tree not loaded.");
StatusUpdater.UpdateText("ME" + WhichGame + " not found.");
}
else if (!treefound)
{
StatusUpdater.UpdateText("Preparing First Time Setup...");
DebugOutput.PrintLn("Preparing for FTCS...");
if (dostuff)
treefound = FirstTimeSetup();
else
{
OutputBoxPrintLn("Tree not found, and tree scan cancelled!");
StatusUpdater.UpdateText("Ready.");
}
}
else
treefound = true;
DebugOutput.PrintLn("Setting up GUI...");
ChangeTreeIndicators(WhichGame, treefound && Tree != null);
DebugOutput.PrintLn("Changing GUI before setting up search...");
gooey.ModifyControl("updateTOCs", treefound);
gooey.ModifyControl("SearchBox", treefound);
gooey.ModifyControl("regenerate", treefound);
gooey.ModifyControl("TPFMode", treefound);
gooey.ModifyControl("saveChanges", treefound);
if (treefound)
{
if (!cts.IsCancellationRequested)
SetupSearch();
else
{
StatusUpdater.UpdateText("Operation cancelled!");
OutputBoxPrintLn("Operation cancelled!");
}
}
Console.WriteLine("Finished function");
}