* Fixed SL asset type enum to mime type conversion and added more helper functions for going back and forth between enums and mime types

slimupdates
John Hurliman 2010-02-19 15:28:35 -08:00
parent c033223c63
commit eb22fde96c
1 changed files with 166 additions and 31 deletions

View File

@ -34,56 +34,191 @@ using System.Text;
using System.Collections.Generic; using System.Collections.Generic;
using log4net; using log4net;
using OpenSim.Framework; using OpenSim.Framework;
using OpenMetaverse;
namespace OpenSim.Server.Base namespace OpenSim.Server.Base
{ {
public static class ServerUtils public static class ServerUtils
{ {
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
#region SL / file extension / content-type conversions
public static string SLAssetTypeToContentType(int assetType) public static string SLAssetTypeToContentType(int assetType)
{ {
switch (assetType) switch ((AssetType)assetType)
{ {
case 0: case AssetType.Texture:
return "image/jp2"; return "image/x-j2c";
case 1: case AssetType.Sound:
return "application/ogg"; return "application/ogg";
case 2: case AssetType.CallingCard:
return "application/x-metaverse-callingcard"; return "application/vnd.ll.callingcard";
case 3: case AssetType.Landmark:
return "application/x-metaverse-landmark"; return "application/vnd.ll.landmark";
case 5: case AssetType.Clothing:
return "application/x-metaverse-clothing"; return "application/vnd.ll.clothing";
case 6: case AssetType.Object:
return "application/x-metaverse-primitive"; return "application/vnd.ll.primitive";
case 7: case AssetType.Notecard:
return "application/x-metaverse-notecard"; return "application/vnd.ll.notecard";
case 8: case AssetType.Folder:
return "application/x-metaverse-folder"; return "application/vnd.ll.folder";
case 10: case AssetType.RootFolder:
return "application/x-metaverse-lsl"; return "application/vnd.ll.rootfolder";
case 11: case AssetType.LSLText:
return "application/x-metaverse-lso"; return "application/vnd.ll.lsltext";
case 12: case AssetType.LSLBytecode:
return "application/vnd.ll.lslbyte";
case AssetType.TextureTGA:
case AssetType.ImageTGA:
return "image/tga"; return "image/tga";
case 13: case AssetType.Bodypart:
return "application/x-metaverse-bodypart"; return "application/vnd.ll.bodypart";
case 17: case AssetType.TrashFolder:
return "application/vnd.ll.trashfolder";
case AssetType.SnapshotFolder:
return "application/vnd.ll.snapshotfolder";
case AssetType.LostAndFoundFolder:
return "application/vnd.ll.lostandfoundfolder";
case AssetType.SoundWAV:
return "audio/x-wav"; return "audio/x-wav";
case 19: case AssetType.ImageJPEG:
return "image/jpeg"; return "image/jpeg";
case 20: case AssetType.Animation:
return "application/x-metaverse-animation"; return "application/vnd.ll.animation";
case 21: case AssetType.Gesture:
return "application/x-metaverse-gesture"; return "application/vnd.ll.gesture";
case 22: case AssetType.Simstate:
return "application/x-metaverse-simstate"; return "application/x-metaverse-simstate";
case AssetType.Unknown:
default: default:
return "application/octet-stream"; return "application/octet-stream";
} }
} }
public static sbyte ContentTypeToSLAssetType(string contentType)
{
switch (contentType)
{
case "image/x-j2c":
case "image/jp2":
return (sbyte)AssetType.Texture;
case "application/ogg":
return (sbyte)AssetType.Sound;
case "application/vnd.ll.callingcard":
case "application/x-metaverse-callingcard":
return (sbyte)AssetType.CallingCard;
case "application/vnd.ll.landmark":
case "application/x-metaverse-landmark":
return (sbyte)AssetType.Landmark;
case "application/vnd.ll.clothing":
case "application/x-metaverse-clothing":
return (sbyte)AssetType.Clothing;
case "application/vnd.ll.primitive":
case "application/x-metaverse-primitive":
return (sbyte)AssetType.Object;
case "application/vnd.ll.notecard":
case "application/x-metaverse-notecard":
return (sbyte)AssetType.Notecard;
case "application/vnd.ll.folder":
return (sbyte)AssetType.Folder;
case "application/vnd.ll.rootfolder":
return (sbyte)AssetType.RootFolder;
case "application/vnd.ll.lsltext":
case "application/x-metaverse-lsl":
return (sbyte)AssetType.LSLText;
case "application/vnd.ll.lslbyte":
case "application/x-metaverse-lso":
return (sbyte)AssetType.LSLBytecode;
case "image/tga":
// Note that AssetType.TextureTGA will be converted to AssetType.ImageTGA
return (sbyte)AssetType.ImageTGA;
case "application/vnd.ll.bodypart":
case "application/x-metaverse-bodypart":
return (sbyte)AssetType.Bodypart;
case "application/vnd.ll.trashfolder":
return (sbyte)AssetType.TrashFolder;
case "application/vnd.ll.snapshotfolder":
return (sbyte)AssetType.SnapshotFolder;
case "application/vnd.ll.lostandfoundfolder":
return (sbyte)AssetType.LostAndFoundFolder;
case "audio/x-wav":
return (sbyte)AssetType.SoundWAV;
case "image/jpeg":
return (sbyte)AssetType.ImageJPEG;
case "application/vnd.ll.animation":
case "application/x-metaverse-animation":
return (sbyte)AssetType.Animation;
case "application/vnd.ll.gesture":
case "application/x-metaverse-gesture":
return (sbyte)AssetType.Gesture;
case "application/x-metaverse-simstate":
return (sbyte)AssetType.Simstate;
case "application/octet-stream":
default:
return (sbyte)AssetType.Unknown;
}
}
public static sbyte ContentTypeToSLInvType(string contentType)
{
switch (contentType)
{
case "image/x-j2c":
case "image/jp2":
case "image/tga":
case "image/jpeg":
return (sbyte)InventoryType.Texture;
case "application/ogg":
case "audio/x-wav":
return (sbyte)InventoryType.Sound;
case "application/vnd.ll.callingcard":
case "application/x-metaverse-callingcard":
return (sbyte)InventoryType.CallingCard;
case "application/vnd.ll.landmark":
case "application/x-metaverse-landmark":
return (sbyte)InventoryType.Landmark;
case "application/vnd.ll.clothing":
case "application/x-metaverse-clothing":
case "application/vnd.ll.bodypart":
case "application/x-metaverse-bodypart":
return (sbyte)InventoryType.Wearable;
case "application/vnd.ll.primitive":
case "application/x-metaverse-primitive":
return (sbyte)InventoryType.Object;
case "application/vnd.ll.notecard":
case "application/x-metaverse-notecard":
return (sbyte)InventoryType.Notecard;
case "application/vnd.ll.folder":
return (sbyte)InventoryType.Folder;
case "application/vnd.ll.rootfolder":
return (sbyte)InventoryType.RootCategory;
case "application/vnd.ll.lsltext":
case "application/x-metaverse-lsl":
case "application/vnd.ll.lslbyte":
case "application/x-metaverse-lso":
return (sbyte)InventoryType.LSL;
case "application/vnd.ll.trashfolder":
case "application/vnd.ll.snapshotfolder":
case "application/vnd.ll.lostandfoundfolder":
return (sbyte)InventoryType.Folder;
case "application/vnd.ll.animation":
case "application/x-metaverse-animation":
return (sbyte)InventoryType.Animation;
case "application/vnd.ll.gesture":
case "application/x-metaverse-gesture":
return (sbyte)InventoryType.Gesture;
case "application/x-metaverse-simstate":
return (sbyte)InventoryType.Snapshot;
case "application/octet-stream":
default:
return (sbyte)InventoryType.Unknown;
}
}
#endregion SL / file extension / content-type conversions
public static byte[] SerializeResult(XmlSerializer xs, object data) public static byte[] SerializeResult(XmlSerializer xs, object data)
{ {
MemoryStream ms = new MemoryStream(); MemoryStream ms = new MemoryStream();