aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tools/mass test client/Commands/Inventory/DumpOutfitCommand.cs
blob: 8347accfd321bf7bec6f4b9a83540e07b3530083 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System;
using System.Text;
using System.IO;
using System.Collections.Generic;
using libsecondlife;
using libsecondlife.Utilities.Assets;
using libsecondlife.Utilities.Appearance;

namespace libsecondlife.TestClient
{
    public class DumpOutfitCommand : Command
    {
        libsecondlife.Utilities.Assets.AssetManager Assets;
        List<LLUUID> OutfitAssets = new List<LLUUID>();

        public DumpOutfitCommand(TestClient testClient)
        {
            Name = "dumpoutfit";
            Description = "Dumps all of the textures from an avatars outfit to the hard drive. Usage: dumpoutfit [avatar-uuid]";

            Assets = new AssetManager(testClient);
            Assets.OnImageReceived += new AssetManager.ImageReceivedCallback(Assets_OnImageReceived);
        }

        public override string Execute(string[] args, LLUUID fromAgentID)
        {
            if (args.Length != 1)
                return "Usage: dumpoutfit [avatar-uuid]";

            LLUUID target;

            if (!LLUUID.TryParse(args[0], out target))
                return "Usage: dumpoutfit [avatar-uuid]";

            lock (Client.AvatarList)
            {
                foreach (Avatar avatar in Client.AvatarList.Values)
                {
                    if (avatar.ID == target)
                    {
                        StringBuilder output = new StringBuilder("Downloading ");

                        lock (OutfitAssets) OutfitAssets.Clear();

                        foreach (KeyValuePair<uint, LLObject.TextureEntryFace> face in avatar.Textures.FaceTextures)
                        {
                            ImageType type = ImageType.Normal;

                            switch ((AppearanceManager.TextureIndex)face.Key)
                            {
                                case AppearanceManager.TextureIndex.HeadBaked:
                                case AppearanceManager.TextureIndex.EyesBaked:
                                case AppearanceManager.TextureIndex.UpperBaked:
                                case AppearanceManager.TextureIndex.LowerBaked:
                                case AppearanceManager.TextureIndex.SkirtBaked:
                                    type = ImageType.Baked;
                                    break;
                            }

                            Assets.RequestImage(face.Value.TextureID, type, 100000.0f, 0);

                            output.Append(((AppearanceManager.TextureIndex)face.Key).ToString());
                            output.Append(" ");
                        }

                        return output.ToString();
                    }
                }
            }

            return "Couldn't find avatar " + target.ToStringHyphenated();
        }

        private void Assets_OnImageReceived(ImageDownload image)
        {
            if (image.Success)
            {
                try
                {
                    File.WriteAllBytes(image.ID.ToStringHyphenated() + ".jp2", image.AssetData);
                    Console.WriteLine("Wrote JPEG2000 image " + image.ID.ToStringHyphenated() + ".jp2");

                    byte[] tgaFile = OpenJPEGNet.OpenJPEG.DecodeToTGA(image.AssetData);
                    File.WriteAllBytes(image.ID.ToStringHyphenated() + ".tga", tgaFile);
                    Console.WriteLine("Wrote TGA image " + image.ID.ToStringHyphenated() + ".tga");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }
            }
            else
            {
                Console.WriteLine("Failed to download image " + image.ID.ToStringHyphenated());
            }
        }
    }
}