I succesfully saved an array of polygon class to a file. Im having trouble reading the array from the file.
I can get the first one but im not sure how to iterate to the next one on the file.
I put //******* where im having troubles.
public bool Load(List ret)
{
Polygon tmp = new Polygon();
StorageDevice device = StorageDevice.ShowStorageDeviceGuide();
// Open a storage container
StorageContainer container = device.OpenContainer("AISavedMaps");
// Get the path of the save game
string filename = Path.Combine(container.Path, "saving.xml");
// Check to see if the save exists
if (!File.Exists(filename))
// Notify the user there is no save
return false;
ret.Clear();
// Open the file
FileStream stream = File.Open(filename, FileMode.OpenOrCreate,
FileAccess.Read);
// Read the data from the file
// problem area,
//****************************************************
XmlSerializer serializer = new XmlSerializer(typeof(Polygon));
//while(stream.Read()
// XmlReader reader = new XmlTextReader(stream);
while (stream.Position != stream.Length)
{
tmp = (Polygon)serializer.Deserialize(stream);
ret.Add(tmp);
}
//****************************************************
// Close the file
stream.Close();
// or something like this (also crashes)
XmlSerializer serializer = new XmlSerializer(typeof(Polygon));
//while(stream.Read()
XmlReader reader = new XmlTextReader(stream);
while (serializer.CanDeserialize(reader))
{
ret.Add((Polygon)serializer.Deserialize(reader));
//serializer.d
}