コード例 #1
0
ファイル: DataAsset.cs プロジェクト: layshua/Alexandria
        /// <summary>
        /// Fill out a context menu.
        /// </summary>
        /// <param name="strip"></param>
        public override void FillContextMenu(ContextMenuStrip strip)
        {
            ToolStripMenuItem saveBinary;

            strip.Items.Add(saveBinary = new ToolStripMenuItem("Save binary to file...")
            {
            });

            saveBinary.Click += (sender, args) => {
                var dialog = new SaveFileDialog()
                {
                    Title           = "Select filename for " + Name,
                    FileName        = Name,
                    OverwritePrompt = true,
                };

                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    using (Stream file = File.Open(dialog.FileName, FileMode.Create))
                        using (Stream source = Open())
                            source.CopyTo(file);
                }
            };

            try {
                Contents.FillContextMenu(strip);
            } catch (Exception) {
                ToolStripMenuItem debugException = new ToolStripMenuItem("Debug exception thrown when reading...")
                {
                };

                debugException.Click += (sender, args) => {
                    try {
                        var thread = new Thread(() => Contents.FillContextMenu(strip));
                        thread.Start();
                        while (thread.ThreadState == System.Threading.ThreadState.Running)
                        {
                            Thread.SpinWait(1);
                        }
                    } catch (Exception exception) {
                        exception.ToString();
                        Debugger.Break();
                    }
                };

                strip.Items.Add(debugException);
            }
        }