Form1.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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 System.IO;
  29. using System.Collections;
  30. using System.Collections.Generic;
  31. using System.ComponentModel;
  32. using System.Data;
  33. using System.Diagnostics;
  34. using System.Drawing;
  35. using System.Text;
  36. using System.Text.RegularExpressions;
  37. using System.Windows.Forms;
  38. using Microsoft.Win32;
  39. namespace LaunchSLClient
  40. {
  41. public partial class Form1 : Form
  42. {
  43. const string deepGridUrl = "http://user.deepgrid.com:8002/";
  44. const string osGridUrl = "http://www.osgrid.org:8002/";
  45. const string openLifeGridUrl = "http://logingrid.net:8002";
  46. string gridUrl = "";
  47. string sandboxUrl = "";
  48. string runUrl = "";
  49. string runLine = "";
  50. string exeFlags = "";
  51. string exePath = "";
  52. private void addLocalSandbox(ref ArrayList menuItems)
  53. {
  54. // build sandbox URL from Regions\default.xml
  55. // this is highly dependant on a standard default.xml
  56. if (File.Exists(@"Regions\default.xml"))
  57. {
  58. string sandboxHostName = "";
  59. string sandboxPort = "";
  60. string text;
  61. Regex myRegex = new Regex(".*internal_ip_port=\\\"(?<port>.*?)\\\".*external_host_name=\\\"(?<name>.*?)\\\".*");
  62. FileInfo defaultFile = new FileInfo(@"Regions\default.xml");
  63. StreamReader stream = defaultFile.OpenText();
  64. do
  65. {
  66. text = stream.ReadLine();
  67. if (text == null)
  68. {
  69. break;
  70. }
  71. MatchCollection theMatches = myRegex.Matches(text);
  72. foreach (Match theMatch in theMatches)
  73. {
  74. if (theMatch.Length != 0)
  75. {
  76. sandboxHostName = theMatch.Groups["name"].ToString();
  77. sandboxPort = theMatch.Groups["port"].ToString();
  78. }
  79. }
  80. } while (text != null);
  81. stream.Close();
  82. sandboxUrl = "http:\\" + sandboxHostName + ":" + sandboxPort;
  83. menuItems.Add("Local Sandbox");
  84. }
  85. }
  86. private void addLocalGrid(ref ArrayList menuItems)
  87. {
  88. //build local grid URL from network_servers_information.xml
  89. // this is highly dependant on a standard default.xml
  90. if (File.Exists(@"network_servers_information.xml"))
  91. {
  92. string text;
  93. FileInfo defaultFile = new FileInfo(@"network_servers_information.xml");
  94. Regex myRegex = new Regex(".*UserServerURL=\\\"(?<url>.*?)\\\".*");
  95. StreamReader stream = defaultFile.OpenText();
  96. do
  97. {
  98. text = stream.ReadLine();
  99. if (text == null)
  100. {
  101. break;
  102. }
  103. foreach (Match theMatch in myRegex.Matches(text))
  104. {
  105. if (theMatch.Length != 0)
  106. {
  107. gridUrl = theMatch.Groups["url"].ToString();
  108. }
  109. }
  110. } while (text != null);
  111. stream.Close();
  112. if (gridUrl != null)
  113. {
  114. menuItems.Add("Local Grid Server");
  115. }
  116. }
  117. }
  118. private void addLocalSims(ref ArrayList menuItems)
  119. {
  120. // find opensim directory
  121. RegistryKey exeKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\OpenSim\OpenSim");
  122. if (exeKey != null)
  123. {
  124. Object simPath = exeKey.GetValue("Path");
  125. Directory.SetCurrentDirectory(simPath.ToString()); //this should be set to wherever we decide to put the binaries
  126. addLocalSandbox(ref menuItems);
  127. addLocalGrid(ref menuItems);
  128. }
  129. else
  130. {
  131. MessageBox.Show("No OpenSim installed. Showing public grids only", "No OpenSim");
  132. }
  133. }
  134. private void getClient(ref string exePath, ref string runLine, ref string exeFlags)
  135. {
  136. // get executable path from registry
  137. RegistryKey regKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Linden Research, Inc.\SecondLife");
  138. if (regKey == null)
  139. {
  140. regKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Linden Research, Inc.\SecondLife");
  141. if (regKey == null)
  142. {
  143. throw new LauncherException("Can't find Second Life. Are you sure it is installed?", "LauncherException.Form1");
  144. }
  145. }
  146. string exe = regKey.GetValue("Exe").ToString();
  147. exeFlags = regKey.GetValue("Flags").ToString();
  148. exePath = regKey.GetValue("").ToString();
  149. runLine = exePath + "\\" + exe;
  150. Registry.LocalMachine.Flush();
  151. Registry.LocalMachine.Close();
  152. }
  153. public Form1()
  154. {
  155. InitializeComponent();
  156. ArrayList menuItems = new ArrayList();
  157. getClient(ref exePath, ref runLine, ref exeFlags);
  158. menuItems.Add("Please select one:");
  159. addLocalSims(ref menuItems);
  160. menuItems.Add("OSGrid - www.osgrid.org");
  161. menuItems.Add("DeepGrid - www.deepgrid.com");
  162. menuItems.Add("OpenlifeGrid - www.openlifegrid.com");
  163. menuItems.Add("Linden Labs - www.secondlife.com");
  164. comboBox1.DataSource = menuItems;
  165. }
  166. private void radioButton1_CheckedChanged(object sender, EventArgs e)
  167. {
  168. }
  169. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  170. {
  171. if (comboBox1.Text == "Please select one:") { return; }
  172. if (comboBox1.Text == "Local Sandbox") { runUrl=" -loginuri " + sandboxUrl;}
  173. if (comboBox1.Text == "Local Grid Server") { runUrl = " -loginuri " + gridUrl; }
  174. if (comboBox1.Text == "DeepGrid - www.deepgrid.com") { runUrl = " -loginuri " + deepGridUrl; }
  175. if (comboBox1.Text == "OSGrid - www.osgrid.org") { runUrl = " -loginuri " + osGridUrl; }
  176. if (comboBox1.Text == "OpenlifeGrid - www.openlifegrid.com") { runUrl = " -loginuri " + openLifeGridUrl; }
  177. if (comboBox1.Text == "Linden Labs - www.secondlife.com") { runUrl = ""; }
  178. System.Diagnostics.Process proc = new System.Diagnostics.Process();
  179. proc.StartInfo.FileName = runLine;
  180. proc.StartInfo.Arguments = exeFlags.ToString() + " " + runUrl;
  181. proc.StartInfo.UseShellExecute = false;
  182. proc.StartInfo.RedirectStandardOutput = false;
  183. proc.StartInfo.WorkingDirectory = exePath.ToString();
  184. proc.Start();
  185. proc.WaitForExit();
  186. }
  187. }
  188. }