2 // Radegast Metaverse Client
3 // Copyright (c) 2009-2014, Radegast Development Team
4 // All rights reserved.
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
9 // * Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 // * Neither the name of the application "Radegast", nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 using System.Windows.Forms;
33 using System.Text.RegularExpressions;
35 using System.Reflection;
37 using CommandLine.Text;
38 #if (COGBOT_LIBOMV || USE_STHREADS)
40 using Thread = ThreadPoolUtil.Thread;
41 using ThreadPool = ThreadPoolUtil.ThreadPool;
42 using Monitor = ThreadPoolUtil.Monitor;
44 using System.Threading;
48 public class CommandLine
50 [Option("u", "username", HelpText = "Username, use quotes to supply \"First Last\"")]
51 public string Username = string.Empty;
53 [Option("p", "password", HelpText = "Account password")]
54 public string Password = string.Empty;
56 [Option("a", "autologin", HelpText = "Automatially login with provided user credentials")]
57 public bool AutoLogin = false;
59 [Option("g", "grid", HelpText = "Grid ID to login into, try --list-grids to see IDs used for this parameter")]
60 public string Grid = string.Empty;
62 [Option("l", "location", HelpText = "Login location: last, home or regionname. Regioname can also be in format regionname/x/y/z")]
63 public string Location = string.Empty;
65 [Option(null, "list-grids", HelpText = "Lists grid IDs used for --grid option")]
66 public bool ListGrids = false;
68 [Option(null, "loginuri", HelpText = "Use this URI to login (don't use with --grid)")]
69 public string LoginUri = string.Empty;
71 [Option(null, "no-sound", HelpText = "Disable sound")]
72 public bool DisableSound = false;
75 public HelpText GetHeader()
77 HelpText header = new HelpText(Properties.Resources.RadegastTitle);
78 header.AdditionalNewLineAfterOption = true;
79 header.Copyright = new CopyrightInfo("Radegast Development Team", 2009, 2014);
80 header.AddPreOptionsLine("http://radegast.org/");
84 [HelpOption("h", "help", HelpText = "Display this help screen.")]
85 public string GetUsage()
87 HelpText usage = GetHeader();
88 usage.AddOptions(this);
89 usage.AddPostOptionsLine("Example: automatically login user called Some Resident to his last location on the Second Life main grid (agni)");
90 usage.AddPostOptionsLine("Radegast -a -g agni -u \"Some Resident\" -p \"secret\" -l last");
91 return usage.ToString();
95 public static class MainProgram
98 /// Parsed command line options
100 public static CommandLine CommandLine;
102 static void RunRadegast(string[] args)
104 // Increase the number of IOCP threads available. Mono defaults to a tragically low number
105 int workerThreads, iocpThreads;
106 ThreadPool.GetMaxThreads(out workerThreads, out iocpThreads);
108 if (workerThreads < 500 || iocpThreads < 1000)
110 if (workerThreads < 500) workerThreads = 500;
111 if (iocpThreads < 1000) iocpThreads = 1000;
112 ThreadPool.SetMaxThreads(workerThreads, iocpThreads);
115 // Read command line options
116 CommandLine = new CommandLine();
117 CommandLineParser parser = new CommandLineParser(new CommandLineParserSettings(Console.Error));
118 if (!parser.ParseArguments(args, CommandLine))
123 // Change current working directory to Radegast install dir
124 Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
126 Application.EnableVisualStyles();
127 Application.SetCompatibleTextRenderingDefault(false);
129 // See if we only wanted to display list of grids
130 if (CommandLine.ListGrids)
132 Console.WriteLine(CommandLine.GetHeader());
134 GridManager grids = new GridManager();
135 Console.WriteLine("Use Grid ID as the parameter for --grid");
136 Console.WriteLine("{0,-25} - {1}", "Grid ID", "Grid Name");
137 Console.WriteLine("========================================================");
139 for (int i = 0; i < grids.Count; i++)
141 Console.WriteLine("{0,-25} - {1}", grids[i].ID, grids[i].Name);
147 // Create main Radegast instance
148 RadegastInstance instance = RadegastInstance.GlobalInstance;
149 Application.Run(instance.MainForm);
150 OpenMetaverse.WorkPool.Shutdown();
154 /// The main entry point for the application.
157 static void Main(string[] args)
159 if (System.Diagnostics.Debugger.IsAttached)
171 string errMsg = "Unhandled " + e.ToString() + ": " +
172 e.Message + Environment.NewLine +
173 e.StackTrace + Environment.NewLine;
175 OpenMetaverse.Logger.Log(errMsg, OpenMetaverse.Helpers.LogLevel.Error);
177 string dlgMsg = "Radegast has encoutered an unrecoverable errror." + Environment.NewLine +
178 "Would you like to send the error report to help improve Radegast?";
180 var res = MessageBox.Show(dlgMsg, "Unrecoverable error", MessageBoxButtons.YesNo, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
182 if (res == DialogResult.Yes)
184 var reporter = new ErrorReporter("http://api.radegast.org/svc/error_report");
185 reporter.SendExceptionReport(e);