1
0

Main.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. using Nini.Config;
  28. using System;
  29. namespace OpenSim.Tools.Configger
  30. {
  31. public class Configger
  32. {
  33. public static int Main(string[] args)
  34. {
  35. ArgvConfigSource argvConfig = new ArgvConfigSource(args);
  36. argvConfig.AddSwitch("Startup", "format", "f");
  37. IConfig startupConfig = argvConfig.Configs["Startup"];
  38. string format = startupConfig.GetString("format", "ini");
  39. ConfigurationLoader loader = new ConfigurationLoader();
  40. IConfigSource s = loader.LoadConfigSettings();
  41. if (format == "mysql")
  42. {
  43. foreach (IConfig c in s.Configs)
  44. {
  45. foreach (string k in c.GetKeys())
  46. {
  47. string v = c.GetString(k);
  48. if (k.StartsWith("Include-"))
  49. continue;
  50. Console.WriteLine("insert ignore into config (section, name, value) values ('{0}', '{1}', '{2}');", c.Name, k, v);
  51. }
  52. }
  53. }
  54. else if (format == "xml")
  55. {
  56. Console.WriteLine("<Nini>");
  57. foreach (IConfig c in s.Configs)
  58. {
  59. int count = 0;
  60. foreach (string k in c.GetKeys())
  61. {
  62. if (k.StartsWith("Include-"))
  63. continue;
  64. count++;
  65. }
  66. if (count > 0)
  67. {
  68. Console.WriteLine("<Section Name=\"{0}\">", c.Name);
  69. foreach (string k in c.GetKeys())
  70. {
  71. string v = c.GetString(k);
  72. if (k.StartsWith("Include-"))
  73. continue;
  74. Console.WriteLine(" <Key Name=\"{0}\" Value=\"{1}\" />", k, v);
  75. }
  76. Console.WriteLine("</Section>");
  77. }
  78. }
  79. Console.WriteLine("</Nini>");
  80. }
  81. else if (format == "ini")
  82. {
  83. foreach (IConfig c in s.Configs)
  84. {
  85. int count = 0;
  86. foreach (string k in c.GetKeys())
  87. {
  88. if (k.StartsWith("Include-"))
  89. continue;
  90. count++;
  91. }
  92. if (count > 0)
  93. {
  94. Console.WriteLine("[{0}]", c.Name);
  95. foreach (string k in c.GetKeys())
  96. {
  97. string v = c.GetString(k);
  98. if (k.StartsWith("Include-"))
  99. continue;
  100. Console.WriteLine("{0} = \"{1}\"", k, v);
  101. }
  102. Console.WriteLine();
  103. }
  104. }
  105. }
  106. else
  107. {
  108. Console.WriteLine("Error: unknown format: {0}", format);
  109. }
  110. return 0;
  111. }
  112. }
  113. }