Application.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using log4net.Config;
  29. using Nini.Config;
  30. using OpenSim.Framework;
  31. using OpenSim.Framework.Console;
  32. namespace OpenSim
  33. {
  34. public class Application
  35. {
  36. public static string iniFilePath = "";
  37. //could move our main function into OpenSimMain and kill this class
  38. [STAThread]
  39. public static void Main(string[] args)
  40. {
  41. // First line
  42. AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
  43. XmlConfigurator.Configure();
  44. Console.WriteLine("OpenSim " + VersionInfo.Version + "\n");
  45. Console.Write("Performing compatibility checks... ");
  46. string supported = String.Empty;
  47. if (Util.IsEnvironmentSupported(ref supported))
  48. {
  49. Console.WriteLine(" Environment is compatible.\n");
  50. }
  51. else
  52. {
  53. Console.WriteLine(" Environment is unsupported (" + supported + ")\n");
  54. }
  55. Console.WriteLine("Starting...\n");
  56. Culture.SetCurrentCulture();
  57. ArgvConfigSource configSource = new ArgvConfigSource(args);
  58. configSource.Alias.AddAlias("On", true);
  59. configSource.Alias.AddAlias("Off", false);
  60. configSource.Alias.AddAlias("True", true);
  61. configSource.Alias.AddAlias("False", false);
  62. configSource.AddSwitch("Startup", "background");
  63. configSource.AddSwitch("Startup", "inifile");
  64. configSource.AddSwitch("Startup", "gridmode");
  65. configSource.AddSwitch("Startup", "physics");
  66. configSource.AddSwitch("Startup", "useexecutepath");
  67. configSource.AddConfig("StandAlone");
  68. configSource.AddConfig("Network");
  69. bool background = configSource.Configs["Startup"].GetBoolean("background", false);
  70. if (background)
  71. {
  72. OpenSimMain sim = new OpenSimMain(configSource);
  73. sim.StartUp();
  74. }
  75. else
  76. {
  77. OpenSimMain sim = new OpenSimMainConsole(configSource);
  78. sim.StartUp();
  79. while (true)
  80. {
  81. MainConsole.Instance.Prompt();
  82. }
  83. }
  84. }
  85. private static bool _IsHandlingException = false; // Make sure we don't go recursive on ourself
  86. /// <summary>
  87. /// Global exception handler -- all unhandlet exceptions end up here :)
  88. /// </summary>
  89. /// <param name="sender"></param>
  90. /// <param name="e"></param>
  91. private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
  92. {
  93. if (_IsHandlingException)
  94. return;
  95. _IsHandlingException = true;
  96. // TODO: Add config option to allow users to turn off error reporting
  97. // TODO: Post error report (disabled for now)
  98. string msg = String.Empty;
  99. msg += "\r\n";
  100. msg += "APPLICATION EXCEPTION DETECTED: " + e.ToString() + "\r\n";
  101. msg += "\r\n";
  102. msg += "Exception: " + e.ExceptionObject.ToString() + "\r\n";
  103. Exception ex = (Exception)e.ExceptionObject;
  104. if (ex.InnerException != null)
  105. msg += "InnerException: " + ex.InnerException.ToString() + "\r\n";
  106. msg += "\r\n";
  107. msg += "Application is terminating: " + e.IsTerminating.ToString() + "\r\n";
  108. // Do we not always want to see exception messages?
  109. // if (e.IsTerminating)
  110. MainConsole.Instance.Error("[APPLICATION]: " + msg);
  111. // Try to post errormessage to an URL
  112. try
  113. {
  114. // DISABLED UNTIL WE CAN DISCUSS IF THIS IS MORALLY RIGHT OR NOT
  115. // Note! Needs reference to System.Web
  116. //System.Net.WebClient wc = new WebClient();
  117. //wc.DownloadData("http://www.opensimulator.org/ErrorReport.php?Msg=" +
  118. // System.Web.HttpUtility.UrlEncode(msg));
  119. //wc.Dispose();
  120. }
  121. catch (Exception)
  122. {
  123. // Ignore
  124. }
  125. _IsHandlingException=false;
  126. }
  127. }
  128. }