From bc49a0bc5df9e600af1e291fad3719949a592685 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 6 May 2011 00:09:08 +0100 Subject: Add "dump asset" command to the asset service for debugging purposes. This command dumps the asset with the given id to a file with the same name. --- OpenSim/Services/AssetService/AssetService.cs | 43 +++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'OpenSim/Services/AssetService') diff --git a/OpenSim/Services/AssetService/AssetService.cs b/OpenSim/Services/AssetService/AssetService.cs index e1f90b6..25a91f2 100644 --- a/OpenSim/Services/AssetService/AssetService.cs +++ b/OpenSim/Services/AssetService/AssetService.cs @@ -26,9 +26,12 @@ */ using System; +using System.Collections.Generic; +using System.IO; using System.Reflection; using Nini.Config; using log4net; +using NDesk.Options; using OpenSim.Framework; using OpenSim.Framework.Console; using OpenSim.Data; @@ -60,6 +63,13 @@ namespace OpenSim.Services.AssetService "delete asset", "delete asset ", "Delete asset from database", HandleDeleteAsset); + + MainConsole.Instance.Commands.AddCommand("kfs", false, + "dump asset", + "dump asset ", + "Dump asset to a file", + "The filename is the same as the ID given.", + HandleDumpAsset); if (m_AssetLoader != null) { @@ -189,6 +199,39 @@ namespace OpenSim.Services.AssetService return false; } + + void HandleDumpAsset(string module, string[] args) + { + if (args.Length < 3) + { + MainConsole.Instance.Output("Usage is dump asset "); + return; + } + + string rawAssetId = args[2]; + UUID assetId; + + if (!UUID.TryParse(rawAssetId, out assetId)) + { + MainConsole.Instance.OutputFormat("ERROR: {0} is not a valid ID format", rawAssetId); + return; + } + + AssetBase asset = m_Database.GetAsset(assetId); + if (asset == null) + { + MainConsole.Instance.OutputFormat("ERROR: No asset found with ID {0}", assetId); + return; + } + + using (FileStream fs = new FileStream(rawAssetId, FileMode.CreateNew)) + { + using (BinaryWriter bw = new BinaryWriter(fs)) + { + bw.Write(asset.Data); + } + } + } void HandleShowDigest(string module, string[] args) { -- cgit v1.1