Form1.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 Nini.Config;
  39. namespace LaunchSLClient
  40. {
  41. public partial class Form1 : Form
  42. {
  43. string gridUrl = "";
  44. string sandboxUrl = "";
  45. string runUrl = "";
  46. string runLine = "";
  47. string exeFlags = "";
  48. string exePath = "";
  49. private MachineConfig m_machineConfig;
  50. private List<Grid> m_grids = new List<Grid>();
  51. public Form1()
  52. {
  53. InitializeComponent();
  54. m_machineConfig = getMachineConfig();
  55. m_machineConfig.GetClient(ref exePath, ref runLine, ref exeFlags);
  56. initializeGrids();
  57. ArrayList menuItems = new ArrayList();
  58. menuItems.Add("Please select one:");
  59. addLocalSims(ref menuItems);
  60. foreach (Grid grid in m_grids)
  61. {
  62. menuItems.Add(grid.Name + " - " + grid.URL);
  63. }
  64. comboBox1.DataSource = menuItems;
  65. }
  66. private MachineConfig getMachineConfig()
  67. {
  68. if (Environment.OSVersion.Platform == PlatformID.Unix)
  69. {
  70. if (File.Exists("/System/Library/Frameworks/Cocoa.framework/Cocoa"))
  71. {
  72. return new OSXConfig();
  73. }
  74. else
  75. {
  76. return new UnixConfig();
  77. }
  78. }
  79. else
  80. {
  81. return new WindowsConfig();
  82. }
  83. }
  84. private void initializeGrids()
  85. {
  86. string iniFile = "LaunchSLClient.ini";
  87. if (!File.Exists(iniFile))
  88. return;
  89. IniConfigSource configSource = new IniConfigSource(iniFile);
  90. foreach (IConfig config in configSource.Configs)
  91. {
  92. Grid grid = new Grid();
  93. grid.Name = config.Name;
  94. grid.LoginURI = config.GetString("loginURI", "");
  95. grid.URL = config.GetString("URL", "");
  96. m_grids.Add(grid);
  97. }
  98. }
  99. private void addLocalSandbox(ref ArrayList menuItems)
  100. {
  101. // build sandbox URL from Regions/default.xml
  102. // this is highly dependant on a standard default.xml
  103. if (File.Exists("Regions/default.xml"))
  104. {
  105. string sandboxHostName = "";
  106. string sandboxPort = "";
  107. string text;
  108. Regex myRegex = new Regex(".*internal_ip_port=\\\"(?<port>.*?)\\\".*external_host_name=\\\"(?<name>.*?)\\\".*");
  109. FileInfo defaultFile = new FileInfo("Regions/default.xml");
  110. StreamReader stream = defaultFile.OpenText();
  111. do
  112. {
  113. text = stream.ReadLine();
  114. if (text == null)
  115. {
  116. break;
  117. }
  118. MatchCollection theMatches = myRegex.Matches(text);
  119. foreach (Match theMatch in theMatches)
  120. {
  121. if (theMatch.Length != 0)
  122. {
  123. sandboxHostName = theMatch.Groups["name"].ToString();
  124. sandboxPort = theMatch.Groups["port"].ToString();
  125. }
  126. }
  127. } while (text != null);
  128. stream.Close();
  129. sandboxUrl = "http:\\" + sandboxHostName + ":" + sandboxPort;
  130. menuItems.Add("Local Sandbox");
  131. }
  132. }
  133. private void addLocalGrid(ref ArrayList menuItems)
  134. {
  135. //build local grid URL from network_servers_information.xml
  136. if (File.Exists("network_servers_information.xml"))
  137. {
  138. string text;
  139. FileInfo defaultFile = new FileInfo("network_servers_information.xml");
  140. Regex myRegex = new Regex(".*UserServerURL=\\\"(?<url>.*?)\\\".*");
  141. StreamReader stream = defaultFile.OpenText();
  142. do
  143. {
  144. text = stream.ReadLine();
  145. if (text == null)
  146. {
  147. break;
  148. }
  149. foreach (Match theMatch in myRegex.Matches(text))
  150. {
  151. if (theMatch.Length != 0)
  152. {
  153. gridUrl = theMatch.Groups["url"].ToString();
  154. }
  155. }
  156. } while (text != null);
  157. stream.Close();
  158. if (gridUrl != null)
  159. {
  160. menuItems.Add("Local Grid Server");
  161. }
  162. }
  163. }
  164. private void addLocalSims(ref ArrayList menuItems)
  165. {
  166. string configDir = m_machineConfig.GetConfigDir();
  167. if (!string.IsNullOrEmpty(configDir))
  168. {
  169. Directory.SetCurrentDirectory(configDir);
  170. addLocalSandbox(ref menuItems);
  171. addLocalGrid(ref menuItems);
  172. }
  173. }
  174. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  175. {
  176. if (comboBox1.Text == "Please select one:")
  177. {
  178. return;
  179. }
  180. else if (comboBox1.Text == "Local Sandbox")
  181. {
  182. runUrl=" -loginuri " + sandboxUrl;
  183. }
  184. else if (comboBox1.Text == "Local Grid Server")
  185. {
  186. runUrl = " -loginuri " + gridUrl;
  187. }
  188. else
  189. {
  190. foreach (Grid grid in m_grids)
  191. {
  192. if (comboBox1.Text == grid.Name + " - " + grid.URL)
  193. {
  194. if (grid.LoginURI != string.Empty)
  195. runUrl = " -loginuri " + grid.LoginURI;
  196. else
  197. runUrl = "";
  198. break;
  199. }
  200. }
  201. }
  202. System.Diagnostics.Process proc = new System.Diagnostics.Process();
  203. proc.StartInfo.FileName = runLine;
  204. proc.StartInfo.Arguments = exeFlags + " " + runUrl;
  205. proc.StartInfo.UseShellExecute = false;
  206. proc.StartInfo.RedirectStandardOutput = false;
  207. proc.StartInfo.WorkingDirectory = exePath;
  208. proc.Start();
  209. proc.WaitForExit();
  210. }
  211. }
  212. }