OSDN Git Service

Update copyright year
[radegast/radegast.git] / Radegast / GUI / Consoles / AnimDetail.cs
index 16b7219..c064378 100644 (file)
-using System;\r
-using System.Collections.Generic;\r
-using System.ComponentModel;\r
-using System.Drawing;\r
-using System.Data;\r
-using System.Text;\r
-using System.Windows.Forms;\r
-using System.IO;\r
-using OpenMetaverse;\r
-using OpenMetaverse.Assets;\r
-\r
-namespace Radegast\r
-{\r
-    public partial class AnimDetail : UserControl\r
-    {\r
-        private RadegastInstance instance;\r
-        private Avatar av;\r
-        private UUID anim;\r
-        private int n;\r
-        private AssetManager.AssetReceivedCallback assetCallback;\r
-        private InventoryManager.ItemCreatedFromAssetCallback invCallback;\r
-        private List<FriendInfo> friends;\r
-        private FriendInfo friend;\r
-\r
-        public AnimDetail(RadegastInstance instance, Avatar av, UUID anim, int n)\r
-        {\r
-            this.instance = instance;\r
-            this.av = av;\r
-            this.anim = anim;\r
-            this.n = n;\r
-\r
-            InitializeComponent();\r
-        }\r
-\r
-        private void AnimDetail_Load(object sender, EventArgs e)\r
-        {\r
-            if (File.Exists(instance.animCacheDir + "/" + anim + ".fail")) {\r
-                Visible = false;\r
-                return;\r
-            }\r
-\r
-            groupBox1.Text = "Animation " + n + " (" + anim + ") for " + av.Name;\r
-\r
-            friends = instance.Client.Friends.FriendList.FindAll(delegate(FriendInfo f) { return true; });\r
-\r
-            pnlSave.Visible = false;\r
-            boxAnimName.Text = "Animation " + n;\r
-            cbFriends.DropDownStyle = ComboBoxStyle.DropDownList;\r
-\r
-            foreach (FriendInfo f in friends) {\r
-                cbFriends.Items.Add(f);\r
-            }\r
-\r
-            if (File.Exists(instance.animCacheDir + "/" + anim + ".sla"))\r
-            {\r
-                pnlSave.Visible = true;\r
-                return;\r
-            }\r
-\r
-            if (assetCallback == null) {\r
-                assetCallback = new AssetManager.AssetReceivedCallback(Assets_OnAssetReceived);\r
-                instance.Client.Assets.OnAssetReceived += assetCallback;\r
-            }\r
-\r
-            instance.Client.Assets.RequestAsset(anim, AssetType.Animation, true);\r
-        }\r
-\r
-        private void btnSave_Click(object sender, EventArgs e)\r
-        {\r
-            WindowWrapper mainWindow = new WindowWrapper(frmMain.ActiveForm.Handle);\r
-            System.Windows.Forms.SaveFileDialog dlg = new SaveFileDialog();\r
-            dlg.AddExtension = true;\r
-            dlg.RestoreDirectory = true;\r
-            dlg.Title = "Save animation as...";\r
-            dlg.Filter = "Second Life Animation (*.sla)|*.sla";\r
-            DialogResult res = dlg.ShowDialog();\r
-\r
-            if (res == DialogResult.OK) {\r
-                try {\r
-                    byte[] data = File.ReadAllBytes(instance.animCacheDir + "/" + anim + ".sla");\r
-                    File.WriteAllBytes(dlg.FileName, data);\r
-                } catch (Exception ex) {\r
-                    Logger.Log("Saving animation failed: " + ex.Message, Helpers.LogLevel.Debug);\r
-                }\r
-            }\r
-        }\r
-\r
-        void Assets_OnAssetReceived(AssetDownload transfer, Asset asset)\r
-        {\r
-            if (transfer.AssetID != anim) return;\r
-\r
-            if (InvokeRequired) {\r
-                Invoke(new MethodInvoker(delegate()\r
-                {\r
-                    Assets_OnAssetReceived(transfer, asset);\r
-                }));\r
-                return;\r
-            }\r
-\r
-            if (transfer.Success) {\r
-                Logger.Log("Animation " + anim + " download success " + asset.AssetData.Length + " bytes.", Helpers.LogLevel.Debug);\r
-                File.WriteAllBytes(instance.animCacheDir + "/" + anim + ".sla", asset.AssetData);\r
-                pnlSave.Visible = true;\r
-            } else {\r
-                Logger.Log("Animation " + anim + " download failed.", Helpers.LogLevel.Debug);\r
-                FileStream f = File.Create(instance.animCacheDir + "/" + anim + ".fail");\r
-                f.Close();\r
-                Visible = false;\r
-            }\r
-        }\r
-\r
-        private void playBox_CheckStateChanged(object sender, EventArgs e)\r
-        {\r
-            if (playBox.CheckState == CheckState.Checked) {\r
-                instance.Client.Self.AnimationStart(anim, true);\r
-            } else {\r
-                instance.Client.Self.AnimationStop(anim, true);\r
-            }\r
-        }\r
-\r
-        private void btnSend_Click(object sender, EventArgs e)\r
-        {\r
-            if (invCallback == null) {\r
-                invCallback = new InventoryManager.ItemCreatedFromAssetCallback(On_ItemCreated);\r
-            }\r
-            byte[] data = File.ReadAllBytes(instance.animCacheDir + "/" + anim + ".sla");\r
-            instance.Client.Inventory.RequestCreateItemFromAsset(data, boxAnimName.Text, "(No description)", AssetType.Animation, InventoryType.Animation, instance.Client.Inventory.FindFolderForType(AssetType.Animation), invCallback);\r
-            lblStatus.Text = "Uploading...";\r
-            cbFriends.Enabled = false;\r
-        }\r
-\r
-        void On_ItemCreated(bool success, string status, UUID itemID, UUID assetID)\r
-        {\r
-            if (InvokeRequired) {\r
-                Invoke(new MethodInvoker(delegate()\r
-                {\r
-                    On_ItemCreated(success, status, itemID, assetID);\r
-                }\r
-                ));\r
-                return;\r
-            }\r
-\r
-            if (!success) {\r
-                lblStatus.Text = "Failed.";\r
-                Logger.Log("Failed creating asset", Helpers.LogLevel.Debug);\r
-                return;\r
-            } else {\r
-                Logger.Log("Created inventory item " + itemID.ToString(), Helpers.LogLevel.Info);\r
-\r
-                lblStatus.Text = "Sending to " + friend.Name;\r
-                Refresh();\r
-\r
-                // Fix the permissions on the new upload since they are fscked by default\r
-                InventoryItem item = instance.Client.Inventory.FetchItem(itemID, instance.Client.Self.AgentID, 1000);\r
-\r
-                if (item != null) {\r
-                    // item.Permissions.EveryoneMask = PermissionMask.All;\r
-                    item.Permissions.NextOwnerMask = PermissionMask.All;\r
-                    instance.Client.Inventory.RequestUpdateItem(item);\r
-\r
-\r
-                    // FIXME: We should be watching the callback for RequestUpdateItem instead of a dumb sleep\r
-                    System.Threading.Thread.Sleep(2000);\r
-\r
-                    \r
-\r
-                    Logger.Log("Sending item to " + friend.Name, Helpers.LogLevel.Info);\r
-                    instance.Client.Inventory.GiveItem(itemID, item.Name, AssetType.Animation, friend.UUID, true);\r
-                    lblStatus.Text = "Sent";\r
-                }\r
-            }\r
-\r
-            cbFriends.Enabled = true;\r
-        }\r
-\r
-\r
-        private void cbFriends_SelectedValueChanged(object sender, EventArgs e)\r
-        {\r
-            if (cbFriends.SelectedIndex >= 0) {\r
-                btnSend.Enabled = true;\r
-                friend = friends[cbFriends.SelectedIndex];\r
-            } else {\r
-                btnSend.Enabled = false;\r
-            }\r
-        }\r
-    }\r
-}\r
+// 
+// Radegast Metaverse Client
+// Copyright (c) 2009-2014, Radegast Development Team
+// All rights reserved.
+// 
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+// 
+//     * Redistributions of source code must retain the above copyright notice,
+//       this list of conditions and the following disclaimer.
+//     * Redistributions in binary form must reproduce the above copyright
+//       notice, this list of conditions and the following disclaimer in the
+//       documentation and/or other materials provided with the distribution.
+//     * Neither the name of the application "Radegast", nor the names of its
+//       contributors may be used to endorse or promote products derived from
+//       this software without specific prior written permission.
+// 
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// $Id$
+//
+using System;
+using System.Collections.Generic;
+using System.Windows.Forms;
+using System.IO;
+using OpenMetaverse;
+using OpenMetaverse.Assets;
+
+namespace Radegast
+{
+    public partial class AnimDetail : UserControl
+    {
+        private RadegastInstance instance;
+        private Avatar av;
+        private UUID anim;
+        private int n;
+        private List<FriendInfo> friends;
+        private FriendInfo friend;
+        private byte[] animData;
+
+        public AnimDetail(RadegastInstance instance, Avatar av, UUID anim, int n)
+        {
+            InitializeComponent();
+            Disposed += new EventHandler(AnimDetail_Disposed);
+            this.instance = instance;
+            this.av = av;
+            this.anim = anim;
+            this.n = n;
+        }
+
+        void AnimDetail_Disposed(object sender, EventArgs e)
+        {
+        }
+
+        private void AnimDetail_Load(object sender, EventArgs e)
+        {
+            if (Animations.ToDictionary().ContainsKey(anim))
+            {
+                Visible = false;
+                Dispose();
+                return;
+            }
+
+            groupBox1.Text = "Animation " + n + " (" + anim + ") for " + av.Name;
+
+            friends = instance.Client.Friends.FriendList.FindAll(delegate(FriendInfo f) { return true; });
+
+            pnlSave.Visible = false;
+            boxAnimName.Text = "Animation " + n;
+            cbFriends.DropDownStyle = ComboBoxStyle.DropDownList;
+
+            foreach (FriendInfo f in friends)
+            {
+                cbFriends.Items.Add(f);
+            }
+
+            instance.Client.Assets.RequestAsset(anim, AssetType.Animation, true, Assets_OnAssetReceived);
+        }
+
+        private void btnSave_Click(object sender, EventArgs e)
+        {
+            WindowWrapper mainWindow = new WindowWrapper(frmMain.ActiveForm.Handle);
+            System.Windows.Forms.SaveFileDialog dlg = new SaveFileDialog();
+            dlg.AddExtension = true;
+            dlg.RestoreDirectory = true;
+            dlg.Title = "Save animation as...";
+            dlg.Filter = "Second Life Animation (*.sla)|*.sla";
+            DialogResult res = dlg.ShowDialog();
+
+            if (res == DialogResult.OK)
+            {
+                try
+                {
+                    File.WriteAllBytes(dlg.FileName, animData);
+                }
+                catch (Exception ex)
+                {
+                    Logger.Log("Saving animation failed: " + ex.Message, Helpers.LogLevel.Debug);
+                }
+            }
+        }
+
+        void Assets_OnAssetReceived(AssetDownload transfer, Asset asset)
+        {
+            if (InvokeRequired)
+            {
+                Invoke(new MethodInvoker(() => Assets_OnAssetReceived(transfer, asset)));
+                return;
+            }
+
+            if (transfer.Success)
+            {
+                Logger.Log("Animation " + anim + " download success " + asset.AssetData.Length + " bytes.", Helpers.LogLevel.Debug);
+                pnlSave.Visible = true;
+                animData = asset.AssetData;
+            }
+            else
+            {
+                Logger.Log("Animation " + anim + " download failed.", Helpers.LogLevel.Debug);
+                Visible = false;
+                Dispose();
+            }
+        }
+
+        private void playBox_CheckStateChanged(object sender, EventArgs e)
+        {
+            if (playBox.CheckState == CheckState.Checked)
+            {
+                instance.Client.Self.AnimationStart(anim, true);
+            }
+            else
+            {
+                instance.Client.Self.AnimationStop(anim, true);
+            }
+        }
+
+        private void btnSend_Click(object sender, EventArgs e)
+        {
+            if (animData == null) return;
+
+            instance.Client.Inventory.RequestCreateItemFromAsset(animData, boxAnimName.Text, "(No description)", AssetType.Animation, InventoryType.Animation, instance.Client.Inventory.FindFolderForType(AssetType.Animation), On_ItemCreated);
+            lblStatus.Text = "Uploading...";
+            cbFriends.Enabled = false;
+        }
+
+        void On_ItemCreated(bool success, string status, UUID itemID, UUID assetID)
+        {
+            if (InvokeRequired)
+            {
+                Invoke(new MethodInvoker(delegate()
+                {
+                    On_ItemCreated(success, status, itemID, assetID);
+                }
+                ));
+                return;
+            }
+
+            if (!success)
+            {
+                lblStatus.Text = "Failed.";
+                Logger.Log("Failed creating asset", Helpers.LogLevel.Debug);
+                return;
+            }
+            else
+            {
+                Logger.Log("Created inventory item " + itemID.ToString(), Helpers.LogLevel.Info);
+
+                lblStatus.Text = "Sending to " + friend.Name;
+                Logger.Log("Sending item to " + friend.Name, Helpers.LogLevel.Info);
+
+                instance.Client.Inventory.GiveItem(itemID, boxAnimName.Text, AssetType.Animation, friend.UUID, false);
+                lblStatus.Text = "Sent";
+            }
+
+            cbFriends.Enabled = true;
+        }
+
+
+        private void cbFriends_SelectedValueChanged(object sender, EventArgs e)
+        {
+            if (cbFriends.SelectedIndex >= 0)
+            {
+                btnSend.Enabled = true;
+                friend = friends[cbFriends.SelectedIndex];
+            }
+            else
+            {
+                btnSend.Enabled = false;
+            }
+        }
+    }
+}