Load() public static method

public static Load ( string path, List pathArgs = null ) : void
path string
pathArgs List
return void
示例#1
0
        private void LoadGame(string path, List <string> pathArgs = null)
        {
            try
            {
                Game.Load(path, pathArgs);
                Text = Game.CurrentGame.Name;
            }
            catch (GameXmlException ex)
            {
                // this builds a dialog message to tell the user where the error is in the XML file

                StringBuilder message = new StringBuilder("There is an error in one of your game files.\n\n");
                if (ex.File != null)
                {
                    message.Append("File: ").Append(ex.File).Append('\n');
                }
                if (ex.Line != 0)
                {
                    message.Append("Line: ").Append(ex.Line.ToString()).Append('\n');
                }
                if (ex.Entity != null)
                {
                    message.Append("Entity: ").Append(ex.Entity).Append('\n');
                }
                if (ex.Tag != null)
                {
                    message.Append("Tag: ").Append(ex.Tag).Append('\n');
                }
                if (ex.Attribute != null)
                {
                    message.Append("Attribute: ").Append(ex.Attribute).Append('\n');
                }

                message.Append("\n").Append(ex.Message);

                MessageBox.Show(message.ToString(), "Game Load Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                Game.CurrentGame.Unload();
            }
            catch (System.IO.FileNotFoundException ex)
            {
                MessageBox.Show("I'm sorry, I couldn't the following file. Perhaps the file path is incorrect?\n\n" + ex.FileName, "C# MegaMan Engine", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Game.CurrentGame.Unload();
            }
            catch (XmlException ex)
            {
                MessageBox.Show("Your XML is badly formatted.\n\nFile: " + ex.SourceUri + "\n\nError: " + ex.Message, "C# MegaMan Engine", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Game.CurrentGame.Unload();
            }

            this.OnActivated(new EventArgs());
        }
示例#2
0
        private bool LoadGame(string path, List <string> pathArgs = null, bool silenceErrorMessages = false)
        {
            try
            {
                Game.Load(path, pathArgs);
                Text = Game.CurrentGame.Name;

                lastGameWithPath = path;
                LoadCurrentConfig();

                OnGameLoadedChanged();

                return(true);
            }
            catch (GameXmlException ex)
            {
                if (silenceErrorMessages == false)
                {
                    // this builds a dialog message to tell the user where the error is in the XML file

                    StringBuilder message = new StringBuilder("There is an error in one of your game files.\n\n");
                    if (ex.File != null)
                    {
                        message.Append("File: ").Append(ex.File).Append('\n');
                    }
                    if (ex.Line != 0)
                    {
                        message.Append("Line: ").Append(ex.Line.ToString()).Append('\n');
                    }
                    if (ex.Entity != null)
                    {
                        message.Append("Entity: ").Append(ex.Entity).Append('\n');
                    }
                    if (ex.Tag != null)
                    {
                        message.Append("Tag: ").Append(ex.Tag).Append('\n');
                    }
                    if (ex.Attribute != null)
                    {
                        message.Append("Attribute: ").Append(ex.Attribute).Append('\n');
                    }

                    message.Append("\n").Append(ex.Message);

                    MessageBox.Show(message.ToString(), "Game Load Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                Game.CurrentGame.Unload();
            }
            catch (System.IO.FileNotFoundException ex)
            {
                if (silenceErrorMessages == false)
                {
                    MessageBox.Show("I'm sorry, I couldn't the following file. Perhaps the file path is incorrect?\n\n" + ex.Message, "C# MegaMan Engine", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                Game.CurrentGame.Unload();
            }
            catch (XmlException ex)
            {
                if (silenceErrorMessages == false)
                {
                    MessageBox.Show("Your XML is badly formatted.\n\nFile: " + ex.SourceUri + "\n\nError: " + ex.Message, "C# MegaMan Engine", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                Game.CurrentGame.Unload();
            }
            catch (Exception ex)
            {
                if (silenceErrorMessages == false)
                {
                    MessageBox.Show("There was an error loading the game.\n\n" + ex.Message, "C# MegaMan Engine", MessageBoxButtons.OK, MessageBoxIcon.Error);

#if DEBUG
                    // Get stack trace for the exception with source file information
                    var st = new StackTrace(ex, true);
                    // Get the top stack frame
                    var frame = st.GetFrame(0);
                    // Get the line number from the stack frame
                    var line = frame.GetFileLineNumber();

                    MessageBox.Show("StackTrace: " + st + " Frame: " + frame + " Line: " + line, "C# MegaMan Engine", MessageBoxButtons.OK, MessageBoxIcon.Error);
#endif
                }
                Game.CurrentGame.Unload();
            }

            // Only call if if current form is the active one
            if ((IntPtr)GetForegroundWindow() == this.Handle)
            {
                this.OnActivated(new EventArgs());
            }

            return(false);
        }