Main.cs 4.8 KB

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