Exemplo n.º 1
0
        DecompileContext CreateDecompileContext(IShowContext ctx)
        {
            var decompileContext     = new DecompileContext();
            var decompilationContext = new DecompilationContext();

            decompilationContext.CalculateBinSpans      = true;
            decompilationContext.GetDisableAssemblyLoad = () => decompileFileTabContentFactory.FileManager.DisableAssemblyLoad();
            decompilationContext.IsBodyModified         = m => decompileFileTabContentFactory.MethodAnnotations.IsBodyModified(m);
            var output     = new DocumentViewerOutput();
            var dispatcher = Dispatcher.CurrentDispatcher;

            decompileContext.DecompileNodeContext = new DecompileNodeContext(decompilationContext, Language, output, dispatcher);
            if (ctx.IsRefresh)
            {
                decompileContext.SavedRefPos = ((IDocumentViewer)ctx.UIContext).SaveReferencePosition();
                if (decompileContext.SavedRefPos != null)
                {
                    ctx.OnShown = e => {
                        if (e.Success && !e.HasMovedCaret)
                        {
                            e.HasMovedCaret = ((IDocumentViewer)ctx.UIContext).RestoreReferencePosition(decompileContext.SavedRefPos);
                            if (!e.HasMovedCaret)
                            {
                                ((IDocumentViewer)ctx.UIContext).MoveCaretToPosition(0);
                                e.HasMovedCaret = true;
                            }
                        }
                    };
                }
            }
            return(decompileContext);
        }
Exemplo n.º 2
0
 DocumentViewerContent CreateContent(IDocumentViewer documentViewer, DocumentViewerOutput docViewerOutput)
 {
     using (var context = new DocumentViewerCustomDataContext(documentViewer, docViewerOutput.GetCachedText(), docViewerOutput.GetCustomDataDictionary())) {
         foreach (var lazy in decompileFileTabContentFactory.DocumentViewerCustomDataProviders)
         {
             lazy.Value.OnCustomData(context);
         }
         return(docViewerOutput.CreateResult(context.GetResultDictionary()));
     }
 }
Exemplo n.º 3
0
        public void EndAsyncShow(IShowContext ctx, IAsyncShowResult result)
        {
            var decompileContext = (DecompileContext)ctx.UserData;
            var documentViewer   = (IDocumentViewer)ctx.UIContext;

            var contentType = decompileContext.DecompileNodeContext.ContentType;

            if (contentType == null)
            {
                var contentTypeString = decompileContext.DecompileNodeContext.ContentTypeString;
                if (contentTypeString == null)
                {
                    contentTypeString = ContentTypes.TryGetContentTypeStringByExtension(decompileContext.DecompileNodeContext.Language.FileExtension) ?? ContentTypes.PlainText;
                }
                contentType = decompileFileTabContentFactory.ContentTypeRegistryService.GetContentType(contentTypeString);
                Debug.Assert(contentType != null);
            }

            DocumentViewerContent content;

            if (result.IsCanceled)
            {
                var docViewerOutput = new DocumentViewerOutput();
                docViewerOutput.Write(dnSpy_Resources.DecompilationCanceled, BoxedTextColor.Error);
                content = CreateContent(documentViewer, docViewerOutput);
            }
            else if (result.Exception != null)
            {
                var docViewerOutput = new DocumentViewerOutput();
                docViewerOutput.Write(dnSpy_Resources.DecompilationException, BoxedTextColor.Error);
                docViewerOutput.WriteLine();
                docViewerOutput.Write(result.Exception.ToString(), BoxedTextColor.Text);
                content = CreateContent(documentViewer, docViewerOutput);
            }
            else
            {
                content = decompileContext.CachedContent;
                if (content == null)
                {
                    var docViewerOutput = (DocumentViewerOutput)decompileContext.DecompileNodeContext.Output;
                    content = CreateContent(documentViewer, docViewerOutput);
                    if (docViewerOutput.CanBeCached)
                    {
                        decompileFileTabContentFactory.DecompilationCache.Cache(decompileContext.DecompileNodeContext.Language, nodes, content, contentType);
                    }
                }
            }

            if (result.CanShowOutput)
            {
                documentViewer.SetContent(content, contentType);
            }
        }