Exemple #1
0
        public object GetView(string extension, System.IO.Stream stream)
        {
            stream = StreamUtility.MakeSeekable(stream);

            // don't display file bigger than 1MB
            if (stream.Length > 1024 * 1024)
            {
                return("** This file is too big to view inline. ***");
            }

            var rtf = new RichTextBox
            {
                IsReadOnly                    = true,
                BorderThickness               = new System.Windows.Thickness(0),
                VerticalScrollBarVisibility   = ScrollBarVisibility.Auto,
                HorizontalScrollBarVisibility = ScrollBarVisibility.Auto
            };

            rtf.Document.MinPageWidth = 800;

            var range = new TextRange(rtf.Document.ContentStart, rtf.Document.ContentEnd);

            range.Load(stream, System.Windows.DataFormats.Rtf);

            return(rtf);
        }
Exemple #2
0
        public object GetView(IPackageContent selectedFile, IReadOnlyList <IPackageContent> peerFiles)
        {
            using (var stream = StreamUtility.MakeSeekable(selectedFile.GetStream(), true))
            {
                // don't display file bigger than 1MB
                if (stream.Length > 1024 * 1024)
                {
                    return("** This file is too big to view inline. ***");
                }

                var rtf = new RichTextBox
                {
                    IsReadOnly                    = true,
                    BorderThickness               = new System.Windows.Thickness(0),
                    VerticalScrollBarVisibility   = ScrollBarVisibility.Auto,
                    HorizontalScrollBarVisibility = ScrollBarVisibility.Auto
                };
                rtf.Document.MinPageWidth = 800;

                var range = new TextRange(rtf.Document.ContentStart, rtf.Document.ContentEnd);
                range.Load(stream, System.Windows.DataFormats.Rtf);

                return(rtf);
            }
        }
Exemple #3
0
        public object GetView(string extension, Stream stream)
        {
            AssemblyDebugDataViewModel data = null;

            try
            {
                using (var str = StreamUtility.MakeSeekable(stream))
                {
                    data = new AssemblyDebugDataViewModel(AssemblyMetadataReader.ReadDebugData(str));
                }

                return(new ScrollViewer
                {
                    HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                    VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
                    Content = new Controls.PdbFileViewer
                    {
                        DataContext = data
                    }
                });
            }
            catch
            {
                return(new TextBlock()
                {
                    Text = "Full PDB's are not supported yet. Portable and Embedded are currently supported.",
                    Margin = new Thickness(3)
                });
            }
        }
Exemple #4
0
        public object GetView(IPackageContent selectedFile, IReadOnlyList <IPackageContent> peerFiles)
        {
            DiagnosticsClient.TrackEvent("ImageFileViewer");

            using (var stream = StreamUtility.MakeSeekable(selectedFile.GetStream(), true))
            {
                var source = new BitmapImage();
                source.BeginInit();
                source.CacheOption  = BitmapCacheOption.OnLoad;
                source.StreamSource = stream;
                source.EndInit();

                var image = new Image
                {
                    Source = source,
                    Width  = source.Width,
                    Height = source.Height,
                };

                return(new ScrollViewer
                {
                    HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                    VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
                    Content = image
                });
            }
        }
Exemple #5
0
        public object GetView(string extension, Stream stream)
        {
            stream = StreamUtility.MakeSeekable(stream);

            var source = new BitmapImage();

            source.BeginInit();
            source.CacheOption  = BitmapCacheOption.OnLoad;
            source.StreamSource = stream;
            source.EndInit();

            var image = new Image
            {
                Source = source,
                Width  = source.Width,
                Height = source.Height,
            };

            return(new ScrollViewer
            {
                HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
                Content = image
            });
        }
        public object GetView(IPackageContent selectedFile, IReadOnlyList <IPackageContent> peerFiles)
        {
            DiagnosticsClient.TrackEvent("PdbFileViewer");

            AssemblyDebugDataViewModel?data = null;

            // Get the PE file, exe or dll that matches
            var filename = Path.GetFileNameWithoutExtension(selectedFile.Name);
            var pe       = peerFiles.FirstOrDefault(pc => pc.Path != selectedFile.Path &&
                                                    Path.GetFileNameWithoutExtension(pc.Name) !.Equals(filename, StringComparison.OrdinalIgnoreCase) &&
                                                    (".dll".Equals(Path.GetExtension(pc.Name), StringComparison.OrdinalIgnoreCase) ||
                                                     ".exe".Equals(Path.GetExtension(pc.Name), StringComparison.OrdinalIgnoreCase)));

            Stream?peStream = null;

            try
            {
                if (pe != null) // we have a matching file
                {
                    peStream = StreamUtility.MakeSeekable(pe.GetStream(), true);
                }


                // This might throw an exception because we don't know if it's a full PDB or portable
                // Try anyway in case it succeeds as a ppdb
                try
                {
                    using (var stream = StreamUtility.MakeSeekable(selectedFile.GetStream(), true))
                    {
                        data = new AssemblyDebugDataViewModel(AssemblyMetadataReader.ReadDebugData(peStream, stream));
                    }

                    return(new ScrollViewer
                    {
                        HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                        VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
                        Content = new Controls.PdbFileViewer
                        {
                            DataContext = data
                        }
                    });
                }
                catch (ArgumentNullException)
                {
                }
            }
            finally
            {
                peStream?.Dispose();
            }

            return(new TextBlock()
            {
                Text = "Full PDB files rquired the EXE or DLL to be alongside."
            });
        }
Exemple #7
0
 private void UserControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
 {
     if (e.NewValue is FileEditorViewModel viewModel && viewModel.FileInEdit != null)
     {
         SyntaxDefinitions.SelectedItem = SyntaxHighlightingHelper.GuessHighligtingDefinition(viewModel.FileInEdit.Path);
         var stream = viewModel.FileInEdit.GetStream();
         stream = StreamUtility.MakeSeekable(stream);
         Editor.Load(stream);
     }
 }
Exemple #8
0
        private void UserControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            var info = (FileContentInfo)DataContext;

            if (info != null && info.IsTextFile)
            {
                LanguageBox.SelectedItem = SyntaxHighlightingHelper.GuessHighligtingDefinition(info.File.Name);
                contentBox.ScrollToHome();
                contentBox.Load(StreamUtility.ToStream((string)info.Content));
            }
            else
            {
                contentBox.Clear();
            }
        }
Exemple #9
0
        public object GetView(IPackageContent selectedFile, IReadOnlyList <IPackageContent> peerFiles)
        {
            DiagnosticsClient.TrackEvent("PdbFileViewer");

            AssemblyDebugDataViewModel?data = null;

            // Get the PE file, exe or dll that matches
            var pe = peerFiles.FirstOrDefault(pc => ".dll".Equals(Path.GetExtension(pc.Name), StringComparison.OrdinalIgnoreCase) ||
                                              ".exe".Equals(Path.GetExtension(pc.Name), StringComparison.OrdinalIgnoreCase) ||
                                              ".winmd".Equals(Path.GetExtension(pc.Name), StringComparison.OrdinalIgnoreCase));

#pragma warning disable CA2000 // Dispose objects before losing scope -- ReadDebugData will dispose
            Stream?peStream = null;

            if (pe != null) // we have a matching file
            {
                peStream = StreamUtility.MakeSeekable(pe.GetStream(), true);
            }


            // This might throw an exception because we don't know if it's a full PDB or portable
            // Try anyway in case it succeeds as a ppdb
            try
            {
                var stream = StreamUtility.MakeSeekable(selectedFile.GetStream(), true);
                data = new AssemblyDebugDataViewModel(AssemblyMetadataReader.ReadDebugData(peStream, stream));


                return(new ScrollViewer
                {
                    HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                    VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
                    Content = new Controls.PdbFileViewer
                    {
                        DataContext = data
                    }
                });
            }
            catch (ArgumentNullException)
            {
            }
#pragma warning restore CA2000 // Dispose objects before losing scope
            return(new TextBlock()
            {
                Text = "Full PDB files requires the EXE or DLL to be alongside."
            });
        }
        public object GetView(string extension, Stream stream)
        {
            stream = StreamUtility.MakeSeekable(stream);

            var source = new BitmapImage();

            source.BeginInit();
            source.CacheOption  = BitmapCacheOption.OnLoad;
            source.StreamSource = stream;
            source.EndInit();

            return(new Image
            {
                Source = source,
                Width = source.Width,
                Height = source.Height
            });
        }
        private void UserControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (e.NewValue is FileEditorViewModel viewModel && viewModel.FileInEdit != null)
            {
                DiagnosticsClient.TrackEvent("FileEditor_Load");

                SyntaxDefinitions.SelectedItem = SyntaxHighlightingHelper.GuessHighligtingDefinition(viewModel.FileInEdit.Path);
                try
                {
                    var stream = viewModel.FileInEdit.GetStream();
                    stream = StreamUtility.MakeSeekable(stream);
                    Editor.Load(stream);
                }
                catch (Exception ex)
                {
                    _uIServices.Show(ex.Message, MessageLevel.Error);
                }
            }
        }
Exemple #12
0
        public static object?ConvertToImage(PackageViewModel package, string iconOrIconUrl)
        {
            // note: unused `iconOrIconUrl` is used as a refresh trigger
            if (package?.IsDisposed == false && !string.IsNullOrEmpty(iconOrIconUrl))
            {
                var metadata = package.PackageMetadata;

                if (!string.IsNullOrEmpty(metadata.Icon))
                {
                    // Normalize any directories to match what's the package
                    // We do this here instead of the metadata so that we round-trip
                    // whatever the user originally had when in edit view
                    var iconPath = metadata.Icon.Replace('/', '\\');
                    foreach (var file in package.RootFolder.GetFiles())
                    {
                        if (string.Equals(file.Path, iconPath, StringComparison.OrdinalIgnoreCase))
                        {
                            try
                            {
                                using var stream = StreamUtility.MakeSeekable(file.GetStream(), true);

                                var image = new BitmapImage();
                                image.SetSource(stream);

                                return(image);
                            }
                            catch (Exception e)
                            {
                                typeof(PackageIconConverterHelper).Log().Error($"failed to open icon file: {metadata.Icon}", e);
                            }
                        }
                    }
                }

                if (metadata.IconUrl != null)
                {
                    return(IconUrlConverter.ConvertToBitmapSource(metadata.IconUrl?.ToString() !, PackageImages.DefaultPackageIcon));
                }
            }

            return(PackageImages.DefaultPackageIcon);
        }
        public object GetView(IPackageContent selectedFile, IReadOnlyList <IPackageContent> peerFiles)
        {
            DiagnosticsClient.TrackEvent("PdbFileViewer");

            // Get the PE file, exe or dll that matches
            var pe = peerFiles.FirstOrDefault(pc => ".dll".Equals(Path.GetExtension(pc.Name), StringComparison.OrdinalIgnoreCase) ||
                                              ".exe".Equals(Path.GetExtension(pc.Name), StringComparison.OrdinalIgnoreCase) ||
                                              ".winmd".Equals(Path.GetExtension(pc.Name), StringComparison.OrdinalIgnoreCase));

#pragma warning disable CA2000 // Dispose objects before losing scope -- ReadDebugData will dispose
            var peStream = pe != null
                ? StreamUtility.MakeSeekable(pe.GetStream(), true)
                : null;

            // This might throw an exception because we don't know if it's a full PDB or portable
            // Try anyway in case it succeeds as a ppdb
            try
            {
                var stream = StreamUtility.MakeSeekable(selectedFile.GetStream(), true);
                var data   = new AssemblyDebugDataViewModel(AssemblyMetadataReader.ReadDebugData(peStream, stream));

#if !HAS_UNO
                // Tab control with two pages
                var tc = new TabControl()
                {
                    Items =
                    {
                        new TabItem
                        {
                            Header  = "PDB Info",
                            Content = new ScrollViewer
                            {
                                HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                                VerticalScrollBarVisibility   = ScrollBarVisibility.Auto,
                                Content = new Controls.PdbInfoViewer
                                {
                                    DataContext = data
                                }
                            }
                        },
                        new TabItem
                        {
                            Header  = "PDB Sources",
                            Content = new ScrollViewer
                            {
                                HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                                VerticalScrollBarVisibility   = ScrollBarVisibility.Auto,
                                Content = new Controls.PdbSourcesViewer
                                {
                                    DataContext = data
                                }
                            }
                        }
                    }
                };

                return(tc);
#else
                // returning UIElement from here works.
                // however due to performance issues, we are just
                // returning the datacontext and letting the xaml to handle the view.
                // also, the ui layout is vastely different compared to the #if-block above
                return(new AssemblyFileViewer.AssemblyFileContent()
                {
                    Metadata = null,
                    DebugData = data,
                });
#endif
            }
            catch (ArgumentNullException)
            {
            }
            catch (Exception e)
            {
#if HAS_UNO
                this.Log().Error("Failed to generate view", e);
#endif
            }

#pragma warning restore CA2000 // Dispose objects before losing scope
            return(new TextBlock()
            {
                Text = "Full PDB files requires the EXE or DLL to be alongside."
            });
        }