public override bool View(TabPageModel tabPage)
 {
     try
     {
         AvalonEditTextOutput output = new AvalonEditTextOutput();
         BitmapImage          image  = new BitmapImage();
         image.BeginInit();
         image.StreamSource = OpenStream();
         image.EndInit();
         output.AddUIElement(() => new Image {
             Source = image
         });
         output.WriteLine();
         output.AddButton(Images.Save, Resources.Save, delegate {
             Save(null);
         });
         tabPage.ShowTextView(textView => textView.ShowNode(output, this));
         tabPage.SupportsLanguageSwitching = false;
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
示例#2
0
        public override bool View(TabPageModel tabPage)
        {
            Stream s = Resource.TryOpenStream();

            if (s != null && s.Length < DecompilerTextView.DefaultOutputLengthLimit)
            {
                s.Position = 0;
                FileType type = GuessFileType.DetectFileType(s);
                if (type != FileType.Binary)
                {
                    s.Position = 0;
                    AvalonEditTextOutput output = new AvalonEditTextOutput();
                    output.Title = Resource.Name;
                    output.Write(FileReader.OpenStream(s, Encoding.UTF8).ReadToEnd());
                    string ext;
                    if (type == FileType.Xml)
                    {
                        ext = ".xml";
                    }
                    else
                    {
                        ext = Path.GetExtension(DecompilerTextView.CleanUpName(Resource.Name));
                    }
                    tabPage.ShowTextView(textView => textView.ShowNode(output, this, HighlightingManager.Instance.GetDefinitionByExtension(ext)));
                    tabPage.SupportsLanguageSwitching = false;
                    return(true);
                }
            }
            return(false);
        }
示例#3
0
 public override bool View(TabPageModel tabPage)
 {
     try
     {
         AvalonEditTextOutput output = new AvalonEditTextOutput();
         using var data = OpenStream();
         if (data == null)
         {
             return(false);
         }
         IconBitmapDecoder decoder = new IconBitmapDecoder(data, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
         foreach (var frame in decoder.Frames)
         {
             output.Write(String.Format("{0}x{1}, {2} bit: ", frame.PixelHeight, frame.PixelWidth, frame.Thumbnail.Format.BitsPerPixel));
             AddIcon(output, frame);
             output.WriteLine();
         }
         output.AddButton(Images.Save, Resources.Save, delegate {
             Save(null);
         });
         tabPage.ShowTextView(textView => textView.ShowNode(output, this));
         tabPage.SupportsLanguageSwitching = false;
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
示例#4
0
        public override bool View(TabPageModel tabPage)
        {
            AvalonEditTextOutput    output       = new AvalonEditTextOutput();
            IHighlightingDefinition highlighting = null;

            tabPage.ShowTextView(textView => textView.RunWithCancellation(
                                     token => Task.Factory.StartNew(
                                         () => {
                try {
                    // cache read text because stream will be closed after first read
                    if (text == null)
                    {
                        using (var reader = new StreamReader(Data)) {
                            text = reader.ReadToEnd();
                        }
                    }
                    output.Write(text);
                    highlighting = null;
                }
                catch (Exception ex) {
                    output.Write(ex.ToString());
                }
                return(output);
            }, token)
                                     ).Then(t => textView.ShowNode(t, this, highlighting))
                                 .HandleExceptions());
            tabPage.SupportsLanguageSwitching = false;
            return(true);
        }
示例#5
0
        public override bool View(TabPageModel tabPage)
        {
            IHighlightingDefinition highlighting = null;

            tabPage.SupportsLanguageSwitching = false;
            tabPage.ShowTextView(textView => textView.RunWithCancellation(
                                     token => Task.Factory.StartNew(
                                         () => {
                AvalonEditTextOutput output = new AvalonEditTextOutput();
                try
                {
                    if (LoadBaml(output, token))
                    {
                        highlighting = HighlightingManager.Instance.GetDefinitionByExtension(".xml");
                    }
                }
                catch (Exception ex)
                {
                    output.Write(ex.ToString());
                }
                return(output);
            }, token))
                                 .Then(output => textView.ShowNode(output, this, highlighting))
                                 .HandleExceptions());
            return(true);
        }
示例#6
0
        public override bool View(TabPageModel tabPage)
        {
            try
            {
                AvalonEditTextOutput output = new AvalonEditTextOutput();
                BitmapImage          image  = new BitmapImage();
                byte[] curData;
                using (var data = OpenStream())
                {
                    if (data == null)
                    {
                        return(false);
                    }
                    //HACK: windows imaging does not understand that .cur files have the same layout as .ico
                    // so load to data, and modify the ResourceType in the header to make look like an icon...
                    MemoryStream s = data as MemoryStream;
                    if (s == null)
                    {
                        // data was stored in another stream type (e.g. PinnedBufferedMemoryStream)
                        s = new MemoryStream();
                        data.CopyTo(s);
                    }
                    curData = s.ToArray();
                }
                curData[2] = 1;
                using (Stream stream = new MemoryStream(curData))
                {
                    image.BeginInit();
                    image.StreamSource = stream;
                    image.EndInit();
                }

                output.AddUIElement(() => new Image {
                    Source = image
                });
                output.WriteLine();
                output.AddButton(Images.Save, Resources.Save, delegate {
                    Save(null);
                });
                tabPage.ShowTextView(textView => textView.ShowNode(output, this));
                tabPage.SupportsLanguageSwitching = false;
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
示例#7
0
        public override bool Save(TabPageModel tabPage)
        {
            Language language = this.Language;

            if (string.IsNullOrEmpty(language.ProjectFileExtension))
            {
                return(false);
            }
            SaveFileDialog dlg = new SaveFileDialog();

            dlg.FileName = DecompilerTextView.CleanUpName(LoadedAssembly.ShortName) + language.ProjectFileExtension;
            dlg.Filter   = language.Name + " project|*" + language.ProjectFileExtension + "|" + language.Name + " single file|*" + language.FileExtension + "|All files|*.*";
            if (dlg.ShowDialog() == true)
            {
                DecompilationOptions options = new DecompilationOptions();
                options.FullDecompilation = true;
                if (dlg.FilterIndex == 1)
                {
                    options.SaveAsProjectDirectory = Path.GetDirectoryName(dlg.FileName);
                    foreach (string entry in Directory.GetFileSystemEntries(options.SaveAsProjectDirectory))
                    {
                        if (!string.Equals(entry, dlg.FileName, StringComparison.OrdinalIgnoreCase))
                        {
                            var result = MessageBox.Show(
                                Resources.AssemblySaveCodeDirectoryNotEmpty,
                                Resources.AssemblySaveCodeDirectoryNotEmptyTitle,
                                MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No);
                            if (result == MessageBoxResult.No)
                            {
                                return(true);                                // don't save, but mark the Save operation as handled
                            }
                            break;
                        }
                    }
                }
                tabPage.ShowTextView(textView => textView.SaveToDisk(language, new[] { this }, options, dlg.FileName));
            }
            return(true);
        }