diff options
author | gareth | 2007-05-08 00:10:04 +0000 |
---|---|---|
committer | gareth | 2007-05-08 00:10:04 +0000 |
commit | 5b6afeafbc249ba88dcc20d1fbc98ce12418b21b (patch) | |
tree | 78861e5f6ae871d63c83b4ab1cc4c55ea184ed6d /ExportBot/Commands/DumpOutfitCommand.cs | |
parent | ZOMG! (diff) | |
download | opensim-SC_OLD-5b6afeafbc249ba88dcc20d1fbc98ce12418b21b.zip opensim-SC_OLD-5b6afeafbc249ba88dcc20d1fbc98ce12418b21b.tar.gz opensim-SC_OLD-5b6afeafbc249ba88dcc20d1fbc98ce12418b21b.tar.bz2 opensim-SC_OLD-5b6afeafbc249ba88dcc20d1fbc98ce12418b21b.tar.xz |
Brought in TestClient code for teh fork
Diffstat (limited to 'ExportBot/Commands/DumpOutfitCommand.cs')
-rw-r--r-- | ExportBot/Commands/DumpOutfitCommand.cs | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/ExportBot/Commands/DumpOutfitCommand.cs b/ExportBot/Commands/DumpOutfitCommand.cs new file mode 100644 index 0000000..2d3d0d8 --- /dev/null +++ b/ExportBot/Commands/DumpOutfitCommand.cs | |||
@@ -0,0 +1,98 @@ | |||
1 | using System; | ||
2 | using System.Text; | ||
3 | using System.IO; | ||
4 | using System.Collections.Generic; | ||
5 | using libsecondlife; | ||
6 | using libsecondlife.Utilities.Assets; | ||
7 | using libsecondlife.Utilities.Appearance; | ||
8 | |||
9 | namespace libsecondlife.TestClient | ||
10 | { | ||
11 | public class DumpOutfitCommand : Command | ||
12 | { | ||
13 | libsecondlife.Utilities.Assets.AssetManager Assets; | ||
14 | List<LLUUID> OutfitAssets = new List<LLUUID>(); | ||
15 | |||
16 | public DumpOutfitCommand(TestClient testClient) | ||
17 | { | ||
18 | Name = "dumpoutfit"; | ||
19 | Description = "Dumps all of the textures from an avatars outfit to the hard drive. Usage: dumpoutfit [avatar-uuid]"; | ||
20 | |||
21 | Assets = new AssetManager(testClient); | ||
22 | Assets.OnImageReceived += new AssetManager.ImageReceivedCallback(Assets_OnImageReceived); | ||
23 | } | ||
24 | |||
25 | public override string Execute(string[] args, LLUUID fromAgentID) | ||
26 | { | ||
27 | if (args.Length != 1) | ||
28 | return "Usage: dumpoutfit [avatar-uuid]"; | ||
29 | |||
30 | LLUUID target; | ||
31 | |||
32 | if (!LLUUID.TryParse(args[0], out target)) | ||
33 | return "Usage: dumpoutfit [avatar-uuid]"; | ||
34 | |||
35 | lock (Client.AvatarList) | ||
36 | { | ||
37 | foreach (Avatar avatar in Client.AvatarList.Values) | ||
38 | { | ||
39 | if (avatar.ID == target) | ||
40 | { | ||
41 | StringBuilder output = new StringBuilder("Downloading "); | ||
42 | |||
43 | lock (OutfitAssets) OutfitAssets.Clear(); | ||
44 | |||
45 | foreach (KeyValuePair<uint, LLObject.TextureEntryFace> face in avatar.Textures.FaceTextures) | ||
46 | { | ||
47 | ImageType type = ImageType.Normal; | ||
48 | |||
49 | switch ((AppearanceManager.TextureIndex)face.Key) | ||
50 | { | ||
51 | case AppearanceManager.TextureIndex.HeadBaked: | ||
52 | case AppearanceManager.TextureIndex.EyesBaked: | ||
53 | case AppearanceManager.TextureIndex.UpperBaked: | ||
54 | case AppearanceManager.TextureIndex.LowerBaked: | ||
55 | case AppearanceManager.TextureIndex.SkirtBaked: | ||
56 | type = ImageType.Baked; | ||
57 | break; | ||
58 | } | ||
59 | |||
60 | Assets.RequestImage(face.Value.TextureID, type, 100000.0f, 0); | ||
61 | |||
62 | output.Append(((AppearanceManager.TextureIndex)face.Key).ToString()); | ||
63 | output.Append(" "); | ||
64 | } | ||
65 | |||
66 | return output.ToString(); | ||
67 | } | ||
68 | } | ||
69 | } | ||
70 | |||
71 | return "Couldn't find avatar " + target.ToStringHyphenated(); | ||
72 | } | ||
73 | |||
74 | private void Assets_OnImageReceived(ImageDownload image) | ||
75 | { | ||
76 | if (image.Success) | ||
77 | { | ||
78 | try | ||
79 | { | ||
80 | File.WriteAllBytes(image.ID.ToStringHyphenated() + ".jp2", image.AssetData); | ||
81 | Console.WriteLine("Wrote JPEG2000 image " + image.ID.ToStringHyphenated() + ".jp2"); | ||
82 | |||
83 | byte[] tgaFile = OpenJPEGNet.OpenJPEG.DecodeToTGA(image.AssetData); | ||
84 | File.WriteAllBytes(image.ID.ToStringHyphenated() + ".tga", tgaFile); | ||
85 | Console.WriteLine("Wrote TGA image " + image.ID.ToStringHyphenated() + ".tga"); | ||
86 | } | ||
87 | catch (Exception e) | ||
88 | { | ||
89 | Console.WriteLine(e.ToString()); | ||
90 | } | ||
91 | } | ||
92 | else | ||
93 | { | ||
94 | Console.WriteLine("Failed to download image " + image.ID.ToStringHyphenated()); | ||
95 | } | ||
96 | } | ||
97 | } | ||
98 | } | ||