Example #1
0
        public bool Load(string filename)
        {
            IsCompiledFile = false;

            if (System.IO.Path.GetExtension(filename) == ".quest")
            {
                filename = LoadCompiledFile(filename);
            }

            XmlReader reader = null;

            try
            {
                reader = XmlReader.Create(filename);

                do
                {
                    reader.Read();
                } while (reader.NodeType != XmlNodeType.Element);

                if (reader.Name == "asl")
                {
                    string version = reader.GetAttribute("version");

                    if (string.IsNullOrEmpty(version))
                    {
                        AddError("No ASL version number found");
                    }

                    if (!s_versions.ContainsKey(version))
                    {
                        AddError("Unknown ASL version");
                    }
                    else
                    {
                        m_version = s_versions[version];
                        if (m_version < WorldModelVersion.v510)
                        {
                            AddError("Unsupported ASL version - must be v5.1 or later");
                        }
                    }

                    string originalFile = reader.GetAttribute("original");

                    if (!string.IsNullOrEmpty(originalFile) && System.IO.Path.GetExtension(originalFile) == ".quest")
                    {
                        LoadCompiledFile(originalFile);
                    }

                    if (!string.IsNullOrEmpty(originalFile))
                    {
                        FilenameUpdated(originalFile);
                    }
                }
                else
                {
                    AddError("File must begin with an ASL element");
                }

                LoadXML(reader);
            }
            catch (XmlException e)
            {
                AddError(string.Format("Invalid XML: {0}", e.Message));
            }
            catch (Exception e)
            {
                AddError(string.Format("Error: {0}", e.Message));
            }
            finally
            {
                if (reader != null) reader.Close();
            }

            if (m_errors.Count == 0)
            {
                ResolveGame();
                ValidateGame();
            }

            return (m_errors.Count == 0);
        }
        public bool Load(string filename)
        {
            IsCompiledFile = false;

            if (System.IO.Path.GetExtension(filename) == ".quest")
            {
                filename = LoadCompiledFile(filename);
            }

            XmlReader reader = null;

            try
            {
                reader = XmlReader.Create(filename);

                do
                {
                    reader.Read();
                } while (reader.NodeType != XmlNodeType.Element);

                if (reader.Name == "asl")
                {
                    string version = reader.GetAttribute("version");

                    if (string.IsNullOrEmpty(version))
                    {
                        AddError("No ASL version number found");
                    }

                    if (!s_versions.ContainsKey(version))
                    {
                        AddError("Unknown ASL version");
                    }
                    else
                    {
                        m_version = s_versions[version];
                        if (m_version < WorldModelVersion.v510)
                        {
                            AddError("Unsupported ASL version - must be v5.1 or later");
                        }
                    }

                    string originalFile = reader.GetAttribute("original");

                    if (!string.IsNullOrEmpty(originalFile) && System.IO.Path.GetExtension(originalFile) == ".quest")
                    {
                        LoadCompiledFile(originalFile);
                    }

                    if (!string.IsNullOrEmpty(originalFile))
                    {
                        FilenameUpdated(originalFile);
                    }
                }
                else
                {
                    AddError("File must begin with an ASL element");
                }

                LoadXML(reader);
            }
            catch (XmlException e)
            {
                AddError(string.Format("Invalid XML: {0}", e.Message));
            }
            catch (Exception e)
            {
                AddError(string.Format("Error: {0}", e.Message));
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }

            if (m_errors.Count == 0)
            {
                ResolveGame();
            }

            return(m_errors.Count == 0);
        }