summaryrefslogtreecommitdiff
path: root/indra/llcommon/llassettype.cpp
blob: 368c85acb0f9217afbc3da0f85024f578a560d54 (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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/** 
 * @file llassettype.cpp
 * @brief Implementatino of LLAssetType functionality.
 *
 * $LicenseInfo:firstyear=2001&license=viewergpl$
 * 
 * Copyright (c) 2001-2007, Linden Research, Inc.
 * 
 * Second Life Viewer Source Code
 * The source code in this file ("Source Code") is provided by Linden Lab
 * to you under the terms of the GNU General Public License, version 2.0
 * ("GPL"), unless you have obtained a separate licensing agreement
 * ("Other License"), formally executed by you and Linden Lab.  Terms of
 * the GPL can be found in doc/GPL-license.txt in this distribution, or
 * online at http://secondlife.com/developers/opensource/gplv2
 * 
 * There are special exceptions to the terms and conditions of the GPL as
 * it is applied to this Source Code. View the full text of the exception
 * in the file doc/FLOSS-exception.txt in this software distribution, or
 * online at http://secondlife.com/developers/opensource/flossexception
 * 
 * By copying, modifying or distributing this software, you acknowledge
 * that you have read and understood your obligations described above,
 * and agree to abide by those obligations.
 * 
 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
 * COMPLETENESS OR PERFORMANCE.
 * $/LicenseInfo$
 */

#include "linden_common.h"

#include "llassettype.h"

#include "llstring.h"
#include "lltimer.h"

// I added lookups for exact text of asset type enums in addition to the ones below, so shoot me. -Steve

struct asset_info_t
{
	LLAssetType::EType type;
	const char* desc;
};

asset_info_t asset_types[] =
{
	{ LLAssetType::AT_TEXTURE, "TEXTURE" },
	{ LLAssetType::AT_SOUND, "SOUND" },
	{ LLAssetType::AT_CALLINGCARD, "CALLINGCARD" },
	{ LLAssetType::AT_LANDMARK, "LANDMARK" },
	{ LLAssetType::AT_SCRIPT, "SCRIPT" },
	{ LLAssetType::AT_CLOTHING, "CLOTHING" },
	{ LLAssetType::AT_OBJECT, "OBJECT" },
	{ LLAssetType::AT_NOTECARD, "NOTECARD" },
	{ LLAssetType::AT_CATEGORY, "CATEGORY" },
	{ LLAssetType::AT_ROOT_CATEGORY, "ROOT_CATEGORY" },
	{ LLAssetType::AT_LSL_TEXT, "LSL_TEXT" },
	{ LLAssetType::AT_LSL_BYTECODE, "LSL_BYTECODE" },
	{ LLAssetType::AT_TEXTURE_TGA, "TEXTURE_TGA" },
	{ LLAssetType::AT_BODYPART, "BODYPART" },
	{ LLAssetType::AT_TRASH, "TRASH" },
	{ LLAssetType::AT_SNAPSHOT_CATEGORY, "SNAPSHOT_CATEGORY" },
	{ LLAssetType::AT_LOST_AND_FOUND, "LOST_AND_FOUND" },
	{ LLAssetType::AT_SOUND_WAV, "SOUND_WAV" },
	{ LLAssetType::AT_IMAGE_TGA, "IMAGE_TGA" },
	{ LLAssetType::AT_IMAGE_JPEG, "IMAGE_JPEG" },
	{ LLAssetType::AT_ANIMATION, "ANIMATION" },
	{ LLAssetType::AT_GESTURE, "GESTURE" },
	{ LLAssetType::AT_SIMSTATE, "SIMSTATE" },
	{ LLAssetType::AT_NONE, "NONE" },
};

LLAssetType::EType LLAssetType::getType(const std::string& sin)
{
	std::string s = sin;
	LLStringUtil::toUpper(s);
	for (S32 idx = 0; ;idx++)
	{
		asset_info_t* info = asset_types + idx;
		if (info->type == LLAssetType::AT_NONE)
			break;
		if (s == info->desc)
			return info->type;
	}
	return LLAssetType::AT_NONE;
}

std::string LLAssetType::getDesc(LLAssetType::EType type)
{
	for (S32 idx = 0; ;idx++)
	{
		asset_info_t* info = asset_types + idx;
		if (type == info->type)
			return info->desc;
		if (info->type == LLAssetType::AT_NONE)
			break;
	}
	return "BAD TYPE";
}

//============================================================================

// The asset type names are limited to 8 characters.
// static
const char* LLAssetType::mAssetTypeNames[LLAssetType::AT_COUNT] =
{ 
	"texture",
	"sound",
	"callcard",
	"landmark",
	"script",
	"clothing",
	"object",
	"notecard",
	"category",
	"root",
	"lsltext",
	"lslbyte",
	"txtr_tga",// Intentionally spelled this way.  Limited to eight characters.
	"bodypart",
	"trash",
	"snapshot",
	"lstndfnd",
	"snd_wav",
	"img_tga",
	"jpeg",
	"animatn",
	"gesture",
	"simstate",
};

// This table is meant for decoding to human readable form. Put any
// and as many printable characters you want in each one.
// See also llinventory.cpp INVENTORY_TYPE_HUMAN_NAMES
const char* LLAssetType::mAssetTypeHumanNames[LLAssetType::AT_COUNT] =
{ 
	"texture",
	"sound",
	"calling card",
	"landmark",
	"legacy script",
	"clothing",
	"object",
	"note card",
	"folder",
	"root",
	"lsl2 script",
	"lsl bytecode",
	"tga texture",
	"body part",
	"trash",
	"snapshot",
	"lost and found",
	"sound",
	"targa image",
	"jpeg image",
	"animation",
	"gesture",
	"simstate",
};

///----------------------------------------------------------------------------
/// class LLAssetType
///----------------------------------------------------------------------------

// static
const char* LLAssetType::lookup( LLAssetType::EType type )
{
	if( (type >= 0) && (type < AT_COUNT ))
	{
		return mAssetTypeNames[ S32( type ) ];
	}
	else
	{
		return "-1";
	}
}

// static
LLAssetType::EType LLAssetType::lookup( const char* name )
{
	return lookup(ll_safe_string(name));
}

LLAssetType::EType LLAssetType::lookup( const std::string& name )
{
	for( S32 i = 0; i < AT_COUNT; i++ )
	{
		if( name == mAssetTypeNames[i] )
		{
			// match
			return (EType)i;
		}
	}
	return AT_NONE;
}

// static
const char* LLAssetType::lookupHumanReadable(LLAssetType::EType type)
{
	if( (type >= 0) && (type < AT_COUNT ))
	{
		return mAssetTypeHumanNames[S32(type)];
	}
	else
	{
		return NULL;
	}
}

// static
LLAssetType::EType LLAssetType::lookupHumanReadable( const char* name )
{
	return lookupHumanReadable(ll_safe_string(name));
}

LLAssetType::EType LLAssetType::lookupHumanReadable( const std::string& name )
{
	for( S32 i = 0; i < AT_COUNT; i++ )
	{
		if( name == mAssetTypeHumanNames[i] )
		{
			// match
			return (EType)i;
		}
	}
	return AT_NONE;
}

EDragAndDropType LLAssetType::lookupDragAndDropType( EType asset )
{
	switch( asset )
	{
	case AT_TEXTURE:		return DAD_TEXTURE;
	case AT_SOUND:			return DAD_SOUND;
	case AT_CALLINGCARD:	return DAD_CALLINGCARD;
	case AT_LANDMARK:		return DAD_LANDMARK;
	case AT_SCRIPT:			return DAD_NONE;
	case AT_CLOTHING:		return DAD_CLOTHING;
	case AT_OBJECT:			return DAD_OBJECT;
	case AT_NOTECARD:		return DAD_NOTECARD;
	case AT_CATEGORY:		return DAD_CATEGORY;
	case AT_ROOT_CATEGORY:	return DAD_ROOT_CATEGORY;
	case AT_LSL_TEXT:		return DAD_SCRIPT;
	case AT_BODYPART:		return DAD_BODYPART;
	case AT_ANIMATION:		return DAD_ANIMATION;
	case AT_GESTURE:		return DAD_GESTURE;
	default: 				return DAD_NONE;
	};
}

// static. Generate a good default description
void LLAssetType::generateDescriptionFor(LLAssetType::EType type,
										 std::string& desc)
{
	const S32 BUF_SIZE = 30;
	char time_str[BUF_SIZE];	/* Flawfinder: ignore */
	time_t now;
	time(&now);
	memset(time_str, '\0', BUF_SIZE);
	strftime(time_str, BUF_SIZE - 1, "%Y-%m-%d %H:%M:%S ", localtime(&now));
	desc.assign(time_str);
	desc.append(LLAssetType::lookupHumanReadable(type));
}