private void loadCollectionFile(string fileName, bool keepCurrentCreatures = false)
{
XmlSerializer reader = new XmlSerializer(typeof(CreatureCollection));
if (!System.IO.File.Exists(fileName))
{
MessageBox.Show("Save file with name \"" + fileName + "\" does not exist!", "File not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
List<Creature> oldCreatures = null;
if (keepCurrentCreatures)
oldCreatures = creatureCollection.creatures;
System.IO.FileStream file = System.IO.File.OpenRead(fileName);
// for the case the collectionfile has no multipliers, keep the current ones
double[][] oldMultipliers = creatureCollection.multipliers;
try
{
creatureCollection = (CreatureCollection)reader.Deserialize(file);
}
catch (Exception e)
{
MessageBox.Show("File Couldn't be opened, we thought you should know.\nErrormessage:\n\n" + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
file.Close();
return;
}
file.Close();
if (creatureCollection.multipliers == null)
{
creatureCollection.multipliers = oldMultipliers;
if (creatureCollection.multipliers == null)
creatureCollection.multipliers = Values.V.statMultipliers;
}
applyMultipliersToValues();
assignCollectionClasses();
if (keepCurrentCreatures)
creatureCollection.creatures.AddRange(oldCreatures);
else
{
currentFileName = fileName;
fileSync.changeFile(currentFileName);
creatureBoxListView.Clear();
}
filterListAllowed = false;
checkBoxShowDead.Checked = creatureCollection.showDeads;
checkBoxShowUnavailableCreatures.Checked = creatureCollection.showUnavailable;
checkBoxShowNeuteredCreatures.Checked = creatureCollection.showNeutered;
filterListAllowed = true;
setCollectionChanged(keepCurrentCreatures);
// creatures loaded.
creatureBoxListView.CreatureCollection = creatureCollection;
for (int s = 0; s < 8; s++)
{
statIOs[s].cc = creatureCollection;
testingIOs[s].cc = creatureCollection;
}
lastAutoSaveBackup = DateTime.Now.AddMinutes(-10);
// calculate creature values
recalculateAllCreaturesValues();
if (creatureCollection.creatures.Count > 0)
tabControlMain.SelectedTab = tabPageLibrary;
creatureBoxListView.maxDomLevel = creatureCollection.maxDomLevel;
// pedigree
pedigree1.Clear();
// breedingPlan
breedingPlan1.Clear();
updateParents(creatureCollection.creatures);
updateCreatureListings();
// apply last sorting
this.listViewLibrary.Sort();
Properties.Settings.Default.LastSaveFile = fileName;
}