private Asset CreateAssetWrapper(AssetType type) { Asset asset; switch (type) { case AssetType.Notecard: asset = new AssetNotecard(); break; case AssetType.LSLText: asset = new AssetScriptText(); break; case AssetType.LSLBytecode: asset = new AssetScriptBinary(); break; case AssetType.Texture: asset = new AssetTexture(); break; case AssetType.Object: asset = new AssetPrim(); break; case AssetType.Clothing: asset = new AssetClothing(); break; case AssetType.Bodypart: asset = new AssetBodypart(); break; case AssetType.Animation: asset = new AssetAnimation(); break; case AssetType.Sound: asset = new AssetSound(); break; case AssetType.Landmark: asset = new AssetLandmark(); break; case AssetType.Gesture: asset = new AssetGesture(); break; default: Logger.Log("Unimplemented asset type: " + type, Helpers.LogLevel.Error, Client); return null; } return asset; }
/// <summary> /// Add a simple script to the given part. /// </summary> /// <remarks> /// TODO: Accept input for item and asset IDs so that we have completely replicatable regression tests rather /// than a random component. /// </remarks> /// <param name="assetService"></param> /// <param name="part"></param> /// <param name="itemId">Item UUID for the script</param> /// <param name="assetId">Asset UUID for the script</param> /// <param name="scriptName">Name of the script to add</param> /// <param name="scriptSource">LSL script source</param> /// <returns>The item that was added</returns> public static TaskInventoryItem AddScript( IAssetService assetService, SceneObjectPart part, UUID itemId, UUID assetId, string scriptName, string scriptSource) { AssetScriptText ast = new AssetScriptText(); ast.Source = scriptSource; ast.Encode(); AssetBase asset = AssetHelpers.CreateAsset(assetId, AssetType.LSLText, ast.AssetData, UUID.Zero); assetService.Store(asset); TaskInventoryItem item = new TaskInventoryItem { Name = scriptName, AssetID = assetId, ItemID = itemId, Type = (int)AssetType.LSLText, InvType = (int)InventoryType.LSL }; part.Inventory.AddInventoryItem(item, true); return item; }
private static bool LoadAsset(string assetPath, byte[] data, AssetLoadedCallback assetCallback, long bytesRead, long totalBytes) { // Right now we're nastily obtaining the UUID from the filename string filename = assetPath.Remove(0, ArchiveConstants.ASSETS_PATH.Length); int i = filename.LastIndexOf(ArchiveConstants.ASSET_EXTENSION_SEPARATOR); if (i == -1) { Logger.Log(String.Format( "[OarFile]: Could not find extension information in asset path {0} since it's missing the separator {1}. Skipping", assetPath, ArchiveConstants.ASSET_EXTENSION_SEPARATOR), Helpers.LogLevel.Warning); return false; } string extension = filename.Substring(i); UUID uuid; UUID.TryParse(filename.Remove(filename.Length - extension.Length), out uuid); if (ArchiveConstants.EXTENSION_TO_ASSET_TYPE.ContainsKey(extension)) { AssetType assetType = ArchiveConstants.EXTENSION_TO_ASSET_TYPE[extension]; Asset asset = null; switch (assetType) { case AssetType.Animation: asset = new AssetAnimation(uuid, data); break; case AssetType.Bodypart: asset = new AssetBodypart(uuid, data); break; case AssetType.Clothing: asset = new AssetClothing(uuid, data); break; case AssetType.Gesture: asset = new AssetGesture(uuid, data); break; case AssetType.Landmark: asset = new AssetLandmark(uuid, data); break; case AssetType.LSLBytecode: asset = new AssetScriptBinary(uuid, data); break; case AssetType.LSLText: asset = new AssetScriptText(uuid, data); break; case AssetType.Notecard: asset = new AssetNotecard(uuid, data); break; case AssetType.Object: asset = new AssetPrim(uuid, data); break; case AssetType.Sound: asset = new AssetSound(uuid, data); break; case AssetType.Texture: asset = new AssetTexture(uuid, data); break; default: Logger.Log("[OarFile] Unhandled asset type " + assetType, Helpers.LogLevel.Error); break; } if (asset != null) { assetCallback(asset, bytesRead, totalBytes); return true; } } Logger.Log("[OarFile] Failed to load asset", Helpers.LogLevel.Warning); return false; }
private void tbtbSave_Click(object sender, EventArgs e) { InventoryManager.ScriptUpdatedCallback handler = (bool uploadSuccess, string uploadStatus, bool compileSuccess, List<string> compileMessages, UUID itemID, UUID assetID) => { if (!IsHandleCreated && instance.MonoRuntime) return; BeginInvoke(new MethodInvoker(() => { if (uploadSuccess && compileSuccess) { lblScripStatus.Text = "Saved OK"; } else { if (!compileSuccess) { lblScripStatus.Text = "Compilation failed"; if (compileMessages != null) { txtStatus.Show(); txtStatus.Text = string.Empty; for (int i = 0; i < compileMessages.Count; i++) { Match m = Regex.Match(compileMessages[i], @"\((?<line>\d+),\s*(?<column>\d+)\s*\)\s*:\s*(?<kind>\w+)\s*:\s*(?<msg>.*)", RegexOptions.IgnoreCase); if (m.Success) { int line = 1 + int.Parse(m.Groups["line"].Value, Utils.EnUsCulture); int column = 1 + int.Parse(m.Groups["column"].Value, Utils.EnUsCulture); string kind = m.Groups["kind"].Value; string msg = m.Groups["msg"].Value; instance.TabConsole.DisplayNotificationInChat( string.Format("{0} on line {1}, column {2}: {3}", kind, line, column, msg), ChatBufferTextStyle.Invisible); txtStatus.Text += string.Format("{0} (Ln {1}, Col {2}): {3}", kind, line, column, msg); if (i == 0) { rtb.CursorPosition = new RRichTextBox.CursorLocation(line - 1, column - 1); ReadCursorPosition(); rtb.Focus(); } } else { txtStatus.Text += compileMessages[i] + Environment.NewLine; instance.TabConsole.DisplayNotificationInChat(compileMessages[i]); } } } } else { lblScripStatus.Text = rtb.Text = "Failed to download."; } } } )); }; lblScripStatus.Text = "Saving..."; txtStatus.Hide(); txtStatus.Text = string.Empty; AssetScriptText n = new AssetScriptText(); n.Source = rtb.Text; n.Encode(); if (prim != null) { client.Inventory.RequestUpdateScriptTask(n.AssetData, script.UUID, prim.ID, cbMono.Checked, cbRunning.Checked, handler); } else { client.Inventory.RequestUpdateScriptAgentInventory(n.AssetData, script.UUID, cbMono.Checked, handler); } }
public static Asset CreateAssetWrapper(AssetType type, UUID uuid, byte[] data) { Asset asset; switch (type) { case AssetType.Animation: asset = new AssetAnimation(uuid, data); break; case AssetType.Gesture: asset = new AssetGesture(uuid, data); break; case AssetType.Landmark: asset = new AssetLandmark(uuid, data); break; case AssetType.Bodypart: asset = new AssetBodypart(uuid, data); break; case AssetType.Clothing: asset = new AssetClothing(uuid, data); break; case AssetType.LSLBytecode: asset = new AssetScriptBinary(uuid, data); break; case AssetType.LSLText: asset = new AssetScriptText(uuid, data); break; case AssetType.Notecard: asset = new AssetNotecard(uuid, data); break; case AssetType.Sound: asset = new AssetSound(uuid, data); break; case AssetType.Texture: asset = new AssetTexture(uuid, data); break; #if COGBOT_LIBOMV case AssetType.CallingCard: asset = new AssetCallingCard(uuid, data); break; #endif default: #if COGBOT_LIBOMV asset = new AssetMutable(type, uuid, data); Logger.Log("[OarFile] Not Implemented asset type " + type, Helpers.LogLevel.Error); #else throw new NotImplementedException("Unimplemented asset type: " + type); #endif break; } return asset; }
private void tbtbSave_Click(object sender, EventArgs e) { InventoryManager.ScriptUpdatedCallback handler = (bool uploadSuccess, string uploadStatus, bool compileSuccess, List <string> compileMessages, UUID itemID, UUID assetID) => { if (!IsHandleCreated && instance.MonoRuntime) { return; } BeginInvoke(new MethodInvoker(() => { if (uploadSuccess && compileSuccess) { lblScripStatus.Text = "Saved OK"; } else { if (!compileSuccess) { lblScripStatus.Text = "Compilation failed"; if (compileMessages != null) { txtStatus.Show(); txtStatus.Text = string.Empty; for (int i = 0; i < compileMessages.Count; i++) { Match m = Regex.Match(compileMessages[i], @"\((?<line>\d+),\s*(?<column>\d+)\s*\)\s*:\s*(?<kind>\w+)\s*:\s*(?<msg>.*)", RegexOptions.IgnoreCase); if (m.Success) { int line = 1 + int.Parse(m.Groups["line"].Value, Utils.EnUsCulture); int column = 1 + int.Parse(m.Groups["column"].Value, Utils.EnUsCulture); string kind = m.Groups["kind"].Value; string msg = m.Groups["msg"].Value; instance.TabConsole.DisplayNotificationInChat( string.Format("{0} on line {1}, column {2}: {3}", kind, line, column, msg), ChatBufferTextStyle.Invisible); txtStatus.Text += string.Format("{0} (Ln {1}, Col {2}): {3}", kind, line, column, msg); if (i == 0) { rtb.CursorPosition = new RRichTextBox.CursorLocation(line - 1, column - 1); ReadCursorPosition(); rtb.Focus(); } } else { txtStatus.Text += compileMessages[i] + Environment.NewLine; instance.TabConsole.DisplayNotificationInChat(compileMessages[i]); } } } } else { lblScripStatus.Text = rtb.Text = "Failed to download."; } } } )); }; lblScripStatus.Text = "Saving..."; txtStatus.Hide(); txtStatus.Text = string.Empty; AssetScriptText n = new AssetScriptText(); n.Source = rtb.Text; n.Encode(); if (prim != null) { client.Inventory.RequestUpdateScriptTask(n.AssetData, script.UUID, prim.ID, cbMono.Checked, cbRunning.Checked, handler); } else { client.Inventory.RequestUpdateScriptAgentInventory(n.AssetData, script.UUID, cbMono.Checked, handler); } }
private void TraverseDir(InventoryNode node, string path) { var nodes = new List <InventoryNode>(node.Nodes.Values); foreach (InventoryNode n in nodes) { traversed++; try { if (IsHandleCreated && (traversed % 13 == 0)) { BeginInvoke(new MethodInvoker(() => { lblStatus.Text = string.Format("Traversed {0} nodes...", traversed); })); } if (n.Data is InventoryFolder) { WriteCSVLine("Folder", path, n.Data.Name, "", "", "", ""); TraverseDir(n, Path.Combine(path, METAboltInstance.SafeFileName(n.Data.Name))); } else { InventoryItem item = (InventoryItem)n.Data; string creator = item.CreatorID == UUID.Zero ? string.Empty : instance.Names.Get(item.CreatorID, true); string lastOwner = item.LastOwnerID == UUID.Zero ? string.Empty : instance.Names.Get(item.LastOwnerID, true); string type = item.AssetType.ToString(); if (item.InventoryType == InventoryType.Wearable) { type = ((WearableType)item.Flags).ToString(); } string created = item.CreationDate.ToString("yyyy-MM-dd HH:mm:ss"); WriteCSVLine(type, path, item.Name, item.Description, created, creator, lastOwner); PermissionMask fullPerm = PermissionMask.Modify | PermissionMask.Copy | PermissionMask.Transfer; if ((item.Permissions.OwnerMask & fullPerm) != fullPerm) { continue; } string filePartial = Path.Combine(path, METAboltInstance.SafeFileName(n.Data.Name)); string fullName = folderName + filePartial; switch (item.AssetType) { case AssetType.LSLText: client.Settings.USE_ASSET_CACHE = false; fullName += ".lsl"; break; case AssetType.Notecard: fullName += ".txt"; break; case AssetType.Texture: fullName += ".png"; break; default: fullName += ".bin"; break; } string dirName = Path.GetDirectoryName(fullName); bool dateOK = item.CreationDate > new DateTime(1970, 1, 2); if ( (item.AssetType == AssetType.LSLText && cbScripts.Checked) || (item.AssetType == AssetType.Notecard && cbNoteCards.Checked) || (item.AssetType == AssetType.Texture && cbImages.Checked) ) { ListViewItem lvi = new ListViewItem(); lvi.Text = n.Data.Name; lvi.Tag = n.Data; lvi.Name = n.Data.UUID.ToString(); ListViewItem.ListViewSubItem fileName = new ListViewItem.ListViewSubItem(lvi, filePartial); lvi.SubItems.Add(fileName); ListViewItem.ListViewSubItem status = new ListViewItem.ListViewSubItem(lvi, "Fetching asset"); lvi.SubItems.Add(status); //bool cached = dateOK && File.Exists(fullName) && File.GetCreationTimeUtc(fullName) == item.CreationDate; //if (cached) //{ // status.Text = "Cached"; //} BeginInvoke(new MethodInvoker(() => { lvwFiles.Items.Add(lvi); lvwFiles.EnsureVisible(lvwFiles.Items.Count - 1); })); //if (cached) continue; Asset receivedAsset = null; using (AutoResetEvent done = new AutoResetEvent(false)) { if (item.AssetType == AssetType.Texture) { client.Assets.RequestImage(item.AssetUUID, (state, asset) => { if (state == TextureRequestState.Finished && asset != null && asset.Decode()) { receivedAsset = asset; done.Set(); } }); } else { client.Assets.RequestInventoryAsset(item, true, (AssetDownload transfer, Asset asset) => { if (transfer.Success) { receivedAsset = asset; } done.Set(); } ); } done.WaitOne(30 * 1000, false); } client.Settings.USE_ASSET_CACHE = true; if (receivedAsset == null) { BeginInvoke(new MethodInvoker(() => status.Text = "Failed to fetch asset")); } else { BeginInvoke(new MethodInvoker(() => status.Text = "Saving...")); try { if (!Directory.Exists(dirName)) { Directory.CreateDirectory(dirName); } switch (item.AssetType) { case AssetType.Notecard: AssetNotecard note = (AssetNotecard)receivedAsset; if (note.Decode()) { File.WriteAllText(fullName, note.BodyText, System.Text.Encoding.UTF8); if (dateOK) { File.SetCreationTimeUtc(fullName, item.CreationDate); File.SetLastWriteTimeUtc(fullName, item.CreationDate); } } else { Logger.Log(string.Format("Falied to decode asset for '{0}' - {1}", item.Name, receivedAsset.AssetID), Helpers.LogLevel.Warning, client); } break; case AssetType.LSLText: AssetScriptText script = (AssetScriptText)receivedAsset; if (script.Decode()) { File.WriteAllText(fullName, script.Source, System.Text.Encoding.UTF8); if (dateOK) { File.SetCreationTimeUtc(fullName, item.CreationDate); File.SetLastWriteTimeUtc(fullName, item.CreationDate); } } else { Logger.Log(string.Format("Falied to decode asset for '{0}' - {1}", item.Name, receivedAsset.AssetID), Helpers.LogLevel.Warning, client); } break; case AssetType.Texture: AssetTexture imgAsset = (AssetTexture)receivedAsset; var img = LoadTGAClass.LoadTGA(new MemoryStream(imgAsset.Image.ExportTGA())); img.Save(fullName, System.Drawing.Imaging.ImageFormat.Png); if (dateOK) { File.SetCreationTimeUtc(fullName, item.CreationDate); File.SetLastWriteTimeUtc(fullName, item.CreationDate); } break; } BeginInvoke(new MethodInvoker(() => { fileName.Text = fullName; status.Text = "Saved"; lblStatus.Text = string.Format("Saved {0} items", ++fetched); })); } catch (Exception ex) { BeginInvoke(new MethodInvoker(() => status.Text = "Failed to save " + Path.GetFileName(fullName) + ": " + ex.Message)); } } } } } catch { } } }
public static Asset CreateAssetWrapper(AssetType type, UUID uuid, byte[] data) { Asset asset; switch (type) { case AssetType.Animation: asset = new AssetAnimation(uuid, data); break; case AssetType.Gesture: asset = new AssetGesture(uuid, data); break; case AssetType.Landmark: asset = new AssetLandmark(uuid, data); break; case AssetType.Bodypart: asset = new AssetBodypart(uuid, data); break; case AssetType.Clothing: asset = new AssetClothing(uuid, data); break; case AssetType.LSLBytecode: asset = new AssetScriptBinary(uuid, data); break; case AssetType.LSLText: asset = new AssetScriptText(uuid, data); break; case AssetType.Notecard: asset = new AssetNotecard(uuid, data); break; case AssetType.Sound: asset = new AssetSound(uuid, data); break; case AssetType.Texture: asset = new AssetTexture(uuid, data); break; #if COGBOT_LIBOMV case AssetType.CallingCard: asset = new AssetCallingCard(uuid, data); break; #endif default: #if COGBOT_LIBOMV asset = new AssetMutable(type, uuid, data); Logger.Log("[OarFile] Not Implemented asset type " + type, Helpers.LogLevel.Error); #else throw new NotImplementedException("Unimplemented asset type: " + type); #endif break; } return(asset); }