ArchiverModule.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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 System;
  28. using System.Collections.Generic;
  29. using System.IO;
  30. using System.Reflection;
  31. using log4net;
  32. using NDesk.Options;
  33. using Nini.Config;
  34. using OpenSim.Region.Framework.Interfaces;
  35. using OpenSim.Region.Framework.Scenes;
  36. namespace OpenSim.Region.CoreModules.World.Archiver
  37. {
  38. /// <summary>
  39. /// This module loads and saves OpenSimulator region archives
  40. /// </summary>
  41. public class ArchiverModule : INonSharedRegionModule, IRegionArchiverModule
  42. {
  43. private static readonly ILog m_log =
  44. LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  45. public Scene Scene { get; private set; }
  46. public IRegionCombinerModule RegionCombinerModule { get; private set; }
  47. /// <value>
  48. /// The file used to load and save an opensimulator archive if no filename has been specified
  49. /// </value>
  50. protected const string DEFAULT_OAR_BACKUP_FILENAME = "region.oar";
  51. public string Name
  52. {
  53. get { return "RegionArchiverModule"; }
  54. }
  55. public Type ReplaceableInterface
  56. {
  57. get { return null; }
  58. }
  59. public void Initialise(IConfigSource source)
  60. {
  61. //m_log.Debug("[ARCHIVER] Initialising");
  62. }
  63. public void AddRegion(Scene scene)
  64. {
  65. Scene = scene;
  66. Scene.RegisterModuleInterface<IRegionArchiverModule>(this);
  67. //m_log.DebugFormat("[ARCHIVER]: Enabled for region {0}", scene.RegionInfo.RegionName);
  68. }
  69. public void RegionLoaded(Scene scene)
  70. {
  71. RegionCombinerModule = scene.RequestModuleInterface<IRegionCombinerModule>();
  72. }
  73. public void RemoveRegion(Scene scene)
  74. {
  75. }
  76. public void Close()
  77. {
  78. }
  79. /// <summary>
  80. /// Load a whole region from an opensimulator archive.
  81. /// </summary>
  82. /// <param name="cmdparams"></param>
  83. public void HandleLoadOarConsoleCommand(string module, string[] cmdparams)
  84. {
  85. bool mergeOar = false;
  86. bool skipAssets = false;
  87. OptionSet options = new OptionSet().Add("m|merge", delegate (string v) { mergeOar = v != null; });
  88. options.Add("s|skip-assets", delegate (string v) { skipAssets = v != null; });
  89. // Send a message to the region ready module
  90. /* bluewall* Disable this for the time being
  91. IRegionReadyModule rready = m_scene.RequestModuleInterface<IRegionReadyModule>();
  92. if (rready != null)
  93. {
  94. rready.OarLoadingAlert("load");
  95. }
  96. */
  97. List<string> mainParams = options.Parse(cmdparams);
  98. // m_log.DebugFormat("MERGE OAR IS [{0}]", mergeOar);
  99. //
  100. // foreach (string param in mainParams)
  101. // m_log.DebugFormat("GOT PARAM [{0}]", param);
  102. if (mainParams.Count > 2)
  103. {
  104. DearchiveRegion(mainParams[2], mergeOar, skipAssets, Guid.Empty);
  105. }
  106. else
  107. {
  108. DearchiveRegion(DEFAULT_OAR_BACKUP_FILENAME, mergeOar, skipAssets, Guid.Empty);
  109. }
  110. }
  111. /// <summary>
  112. /// Save a region to a file, including all the assets needed to restore it.
  113. /// </summary>
  114. /// <param name="cmdparams"></param>
  115. public void HandleSaveOarConsoleCommand(string module, string[] cmdparams)
  116. {
  117. Dictionary<string, object> options = new Dictionary<string, object>();
  118. OptionSet ops = new OptionSet();
  119. // legacy argument [obsolete]
  120. ops.Add("p|profile=", delegate(string v) { Console.WriteLine("\n WARNING: -profile option is obsolete and it will not work. Use -home instead.\n"); });
  121. // preferred
  122. ops.Add("h|home=", delegate(string v) { options["home"] = v; });
  123. ops.Add("noassets", delegate(string v) { options["noassets"] = v != null; });
  124. ops.Add("publish", v => options["wipe-owners"] = v != null);
  125. ops.Add("perm=", delegate(string v) { options["checkPermissions"] = v; });
  126. List<string> mainParams = ops.Parse(cmdparams);
  127. if (mainParams.Count > 2)
  128. {
  129. ArchiveRegion(mainParams[2], options);
  130. }
  131. else
  132. {
  133. ArchiveRegion(DEFAULT_OAR_BACKUP_FILENAME, options);
  134. }
  135. }
  136. public void ArchiveRegion(string savePath, Dictionary<string, object> options)
  137. {
  138. ArchiveRegion(savePath, Guid.Empty, options);
  139. }
  140. public void ArchiveRegion(string savePath, Guid requestId, Dictionary<string, object> options)
  141. {
  142. m_log.InfoFormat(
  143. "[ARCHIVER]: Writing archive for region {0} to {1}", Scene.RegionInfo.RegionName, savePath);
  144. new ArchiveWriteRequestPreparation(this, savePath, requestId).ArchiveRegion(options);
  145. }
  146. public void ArchiveRegion(Stream saveStream)
  147. {
  148. ArchiveRegion(saveStream, Guid.Empty);
  149. }
  150. public void ArchiveRegion(Stream saveStream, Guid requestId)
  151. {
  152. ArchiveRegion(saveStream, requestId, new Dictionary<string, object>());
  153. }
  154. public void ArchiveRegion(Stream saveStream, Guid requestId, Dictionary<string, object> options)
  155. {
  156. new ArchiveWriteRequestPreparation(this, saveStream, requestId).ArchiveRegion(options);
  157. }
  158. public void DearchiveRegion(string loadPath)
  159. {
  160. DearchiveRegion(loadPath, false, false, Guid.Empty);
  161. }
  162. public void DearchiveRegion(string loadPath, bool merge, bool skipAssets, Guid requestId)
  163. {
  164. m_log.InfoFormat(
  165. "[ARCHIVER]: Loading archive to region {0} from {1}", Scene.RegionInfo.RegionName, loadPath);
  166. new ArchiveReadRequest(Scene, loadPath, merge, skipAssets, requestId).DearchiveRegion();
  167. }
  168. public void DearchiveRegion(Stream loadStream)
  169. {
  170. DearchiveRegion(loadStream, false, false, Guid.Empty);
  171. }
  172. public void DearchiveRegion(Stream loadStream, bool merge, bool skipAssets, Guid requestId)
  173. {
  174. new ArchiveReadRequest(Scene, loadStream, merge, skipAssets, requestId).DearchiveRegion();
  175. }
  176. }
  177. }