public void LoadGameFile(string fileName)
{
if (_fileWatcher != null)
{
_fileWatcher.EnableRaisingEvents = false;
_fileWatcher.Dispose();
_fileWatcher = null;
}
if (File.Exists(LOCK_FILE_NAME))
{
VerifyGameNotAlreadyOpenInAnotherEditor();
}
if (File.Exists(fileName + USER_DATA_FILE_SUFFIX))
{
LoadUserDataFile(fileName + USER_DATA_FILE_SUFFIX);
}
else
{
Factory.Events.OnLoadedUserData(null);
}
XmlDocument doc = new XmlDocument();
doc.Load(fileName);
if (doc.DocumentElement.Name != XML_ROOT_NODE_NAME)
{
throw new AGSEditorException("Invalid game data file. This is not a valid AGS game.");
}
string fileVersion = doc.DocumentElement.Attributes[XML_ATTRIBUTE_VERSION].InnerXml;
if ((fileVersion != LATEST_XML_VERSION) &&
(fileVersion != "3.0.1.1") &&
(fileVersion != "3.0.2.1") &&
(fileVersion != "3.0.2.2") &&
(fileVersion != "3.0.3.1") &&
(fileVersion != "2.80.1"))
{
throw new AGSEditorException("Game data file is from a newer version of AGS or an unsupported beta version. Please check the AGS website for a newer version of the editor.");
}
string gameSavedWithEditorVersion = null;
XmlAttribute editorVersionNode = doc.DocumentElement.Attributes[XML_ATTRIBUTE_EDITOR_VERSION];
if (editorVersionNode != null)
{
gameSavedWithEditorVersion = editorVersionNode.InnerText;
}
int? versionIndex = null;
XmlAttribute versionIndexNode = doc.DocumentElement.Attributes[XML_ATTRIBUTE_VERSION_INDEX];
if ((versionIndexNode == null) && (fileVersion == LATEST_XML_VERSION))
{
throw new AGSEditorException("Invalid format game data file");
}
else if (versionIndexNode != null)
{
// From 3.0.3 we switch to a simple integer version, it's easier to
// compare than using the 4-point version
versionIndex = Convert.ToInt32(versionIndexNode.InnerText);
if (versionIndex == 5)
{
throw new AGSEditorException("This game is from an unsupported beta version of AGS and cannot be loaded.");
}
if ((versionIndex < 1) || (versionIndex > LATEST_XML_VERSION_INDEX))
{
throw new AGSEditorException("Game data file is from " +
((gameSavedWithEditorVersion == null) ? "a newer version" : ("version " + gameSavedWithEditorVersion))
+ " of AGS or an unsupported beta version. Please check the AGS website for a newer version of the editor.");
}
}
_game.SavedXmlVersionIndex = versionIndex;
_game.SavedXmlVersion = fileVersion;
_game.SavedXmlEditorVersion = gameSavedWithEditorVersion;
_game.FromXml(doc.DocumentElement);
Factory.Events.OnGameLoad(doc.DocumentElement);
}