示例#1
0
        private void ExportButton_Click(object sender, RoutedEventArgs e)
        {
            if (_SaveFileDialog == null)
            {
                _SaveFileDialog                 = new SaveFileDialog();
                _SaveFileDialog.Filter          = "C# Source File (*.cs)|*.cs";
                _SaveFileDialog.CheckPathExists = true;
                _SaveFileDialog.Title           = "Save Class";
            }

            if (_SaveFileDialog.ShowDialog() == true)
            {
                try
                {
                    ShowLoading("Exporting to C# file");

                    Button button = (Button)sender;
                    uint   serial = (uint)button.Tag;

                    ContainerItem item = App.Window.SpyHelper.FindContainerItem(serial);
                    QueryPropertiesResponsePacket properties = App.Window.SpyHelper.FindFirstPacket(serial, typeof(QueryPropertiesResponsePacket)) as QueryPropertiesResponsePacket;

                    if (item != null)
                    {
                        using (FileStream stream = File.Open(_SaveFileDialog.FileName, FileMode.Create, FileAccess.Write, FileShare.None))
                        {
                            UltimaItemGenerator.Generate(stream, item.ItemID, item.Hue, item.Amount, properties);
                        }
                    }
                }
                catch (Exception ex)
                {
                    ErrorWindow.Show(ex);
                }
                finally
                {
                    HideLoading();
                }
            }
        }
示例#2
0
        private void GenerateCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            if (_SaveFileDialog == null)
            {
                _SaveFileDialog                 = new SaveFileDialog();
                _SaveFileDialog.Filter          = "C# Source File (*.cs)|*.cs";
                _SaveFileDialog.CheckPathExists = true;
                _SaveFileDialog.Title           = "Save Class";
            }

            if (_SaveFileDialog.ShowDialog() == true)
            {
                try
                {
                    App.Window.ShowLoading();

                    if (e.Parameter is GenericGumpPacket)
                    {
                        GenericGumpPacket gump = (GenericGumpPacket)e.Parameter;

                        using (FileStream stream = File.Open(_SaveFileDialog.FileName, FileMode.Create, FileAccess.Write, FileShare.None))
                        {
                            UltimaGumpGenerator.Generate(stream, gump);
                        }
                    }
                    else if (e.Parameter is WorldObjectPacket)
                    {
                        WorldObjectPacket             item       = (WorldObjectPacket)e.Parameter;
                        QueryPropertiesResponsePacket properties = _SpyHelper.FindFirstPacket(item.Serial, typeof(QueryPropertiesResponsePacket)) as QueryPropertiesResponsePacket;

                        using (FileStream stream = File.Open(_SaveFileDialog.FileName, FileMode.Create, FileAccess.Write, FileShare.None))
                        {
                            UltimaItemGenerator.Generate(stream, item.ObjectID, item.Hue, item.Amount, properties);
                        }
                    }
                    else if (e.Parameter is ContainerItem)
                    {
                        ContainerItem item = (ContainerItem)e.Parameter;
                        QueryPropertiesResponsePacket properties = _SpyHelper.FindFirstPacket(item.Serial, typeof(QueryPropertiesResponsePacket)) as QueryPropertiesResponsePacket;

                        using (FileStream stream = File.Open(_SaveFileDialog.FileName, FileMode.Create, FileAccess.Write, FileShare.None))
                        {
                            UltimaItemGenerator.Generate(stream, item.ItemID, item.Hue, item.Amount, properties);
                        }
                    }
                    else if (e.Parameter is MobileIncommingPacket)
                    {
                        MobileIncommingPacket mobile = (MobileIncommingPacket)e.Parameter;
                        MobileNamePacket      name   = _SpyHelper.FindFirstPacket(mobile.Serial, typeof(MobileNamePacket)) as MobileNamePacket;

                        using (FileStream stream = File.Open(_SaveFileDialog.FileName, FileMode.Create, FileAccess.Write, FileShare.None))
                        {
                            UltimaMobileGenerator.Generate(stream, mobile, name);
                        }
                    }
                }
                catch (Exception ex)
                {
                    ShowNotification(NotificationType.Error, ex);
                }
                finally
                {
                    HideLoading();
                }
            }
        }