diff --git a/libsecondlife-cs/AssetSystem/AssetScript.cs b/libsecondlife-cs/AssetSystem/AssetScript.cs new file mode 100644 index 00000000..621539d1 --- /dev/null +++ b/libsecondlife-cs/AssetSystem/AssetScript.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace libsecondlife.AssetSystem +{ + public class AssetScript : Asset + { + private string _Source; + public string Source + { + get { return _Source; } + set + { + _Source = value.Replace("\r", ""); + setAsset(_Source); + } + } + + public AssetScript(LLUUID assetID, string source) + : base(assetID, Asset.ASSET_TYPE_SCRIPT, false, null) + { + _Source = source; + setAsset(source); + } + + public AssetScript(LLUUID assetID, byte[] assetData) + : base(assetID, Asset.ASSET_TYPE_SCRIPT, false, assetData) + { + _Source = System.Text.Encoding.UTF8.GetString(assetData).Trim(); + } + + private void setAsset(string source) + { + // Assume this is a string, add 1 for the null terminator + byte[] stringBytes = System.Text.Encoding.UTF8.GetBytes(source); + byte[] assetData = new byte[stringBytes.Length + 1]; + Array.Copy(stringBytes, 0, assetData, 0, stringBytes.Length); + SetAssetData(assetData); + } + + } +} diff --git a/libsecondlife-cs/InventorySystem/InventoryScript.cs b/libsecondlife-cs/InventorySystem/InventoryScript.cs new file mode 100644 index 00000000..7c0b8228 --- /dev/null +++ b/libsecondlife-cs/InventorySystem/InventoryScript.cs @@ -0,0 +1,138 @@ +using System; +using System.Collections.Generic; +using System.Text; +using libsecondlife.AssetSystem; + +namespace libsecondlife.InventorySystem +{ + public class InventoryScript : InventoryItem + { + public string Source + { + get + { + if ( Asset != null ) + { + return ((AssetScript)Asset).Source; + } + else + { + if ( (AssetID != null) && (AssetID != LLUUID.Zero) ) + { + base.iManager.AssetManager.GetInventoryAsset(this); + return ((AssetScript)Asset).Source; + } + } + return null; + } + set + { + base._Asset = new AssetScript(LLUUID.Random(), value); + LLUUID TransactionID = base.iManager.AssetManager.UploadAsset(Asset); + base.SetAssetTransactionIDs(Asset.AssetID, TransactionID); + } + } + + public InventoryScript(InventoryManager manager, string name, string description, LLUUID folderID, LLUUID uuidOwnerCreater) + : base(manager, name, description, folderID, 10, 10, uuidOwnerCreater) + { + } + + public InventoryScript(InventoryManager manager, InventoryItem ii) + : base(manager, ii.Name, ii.Description, ii.FolderID, ii.InvType, ii.Type, ii.CreatorID) + { + if ( ii.InvType != 10 || ii.Type != Asset.ASSET_TYPE_SCRIPT ) + throw new Exception("The InventoryItem cannot be converted to a Script, wrong InvType/Type."); + this.iManager = manager; + this._ItemID = ii._ItemID; + this._Asset = ii._Asset; + this._AssetID = ii._AssetID; + this._BaseMask = ii._BaseMask; + this._CRC = ii._CRC; + this._CreationDate = ii._CreationDate; + this._EveryoneMask = ii._EveryoneMask; + this._Flags = ii._Flags; + this._GroupID = ii._GroupID; + this._GroupMask = ii._GroupMask; + this._GroupOwned = ii._GroupOwned; + this._InvType = ii._InvType; + this._NextOwnerMask = ii._NextOwnerMask; + this._OwnerID = ii._OwnerID; + this._OwnerMask = ii._OwnerMask; + this._SalePrice = ii._SalePrice; + this._SaleType = ii._SaleType; + this._Type = ii._Type; + } + + internal override void SetAssetData(byte[] assetData) + { + if ( _Asset == null ) + { + if ( AssetID == null ) + { + _Asset = new AssetScript(AssetID, assetData); + } + else + { + _Asset = new AssetScript(LLUUID.Random(), assetData); + _AssetID = _Asset.AssetID; + } + } + else + { + _Asset.SetAssetData(assetData); + } + } + + public override string GetDisplayType() + { + return "Script"; + } + + override public string toXML(bool outputAssets) + { + string output = "