OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
Main.cs
Go to the documentation of this file.
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 OpenSimulator 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 
28 using Nini.Config;
29 using System;
30 
31 namespace OpenSim.Tools.Configger
32 {
33  public class Configger
34  {
35  public static int Main(string[] args)
36  {
37  ArgvConfigSource argvConfig = new ArgvConfigSource(args);
38 
39  argvConfig.AddSwitch("Startup", "format", "f");
40  argvConfig.AddSwitch("Startup", "inifile");
41 
42  IConfig startupConfig = argvConfig.Configs["Startup"];
43 
44  string format = startupConfig.GetString("format", "ini");
45 
47  IConfigSource s = loader.LoadConfigSettings(startupConfig);
48 
49  if (format == "mysql")
50  {
51  foreach (IConfig c in s.Configs)
52  {
53  foreach (string k in c.GetKeys())
54  {
55  string v = c.GetString(k);
56 
57  if (k.StartsWith("Include-"))
58  continue;
59  Console.WriteLine("insert ignore into config (section, name, value) values ('{0}', '{1}', '{2}');", c.Name, k, v);
60  }
61  }
62  }
63  else if (format == "xml")
64  {
65  Console.WriteLine("<Nini>");
66 
67  foreach (IConfig c in s.Configs)
68  {
69  int count = 0;
70 
71  foreach (string k in c.GetKeys())
72  {
73  if (k.StartsWith("Include-"))
74  continue;
75 
76  count++;
77  }
78 
79  if (count > 0)
80  {
81  Console.WriteLine("<Section Name=\"{0}\">", c.Name);
82 
83  foreach (string k in c.GetKeys())
84  {
85  string v = c.GetString(k);
86 
87  if (k.StartsWith("Include-"))
88  continue;
89  Console.WriteLine(" <Key Name=\"{0}\" Value=\"{1}\" />", k, v);
90  }
91 
92  Console.WriteLine("</Section>");
93  }
94  }
95  Console.WriteLine("</Nini>");
96  }
97  else if (format == "ini")
98  {
99  foreach (IConfig c in s.Configs)
100  {
101  int count = 0;
102 
103  foreach (string k in c.GetKeys())
104  {
105  if (k.StartsWith("Include-"))
106  continue;
107 
108  count++;
109  }
110 
111  if (count > 0)
112  {
113  Console.WriteLine("[{0}]", c.Name);
114 
115  foreach (string k in c.GetKeys())
116  {
117  string v = c.GetString(k);
118 
119  if (k.StartsWith("Include-"))
120  continue;
121  Console.WriteLine("{0} = \"{1}\"", k, v);
122  }
123 
124  Console.WriteLine();
125  }
126  }
127  }
128  else
129  {
130  Console.WriteLine("Error: unknown format: {0}", format);
131  }
132 
133  return 0;
134  }
135  }
136 }
Loads the Configuration files into nIni
static int Main(string[] args)
Definition: Main.cs:35