コード例 #1
0
ファイル: ResourceTreeNode.cs プロジェクト: quitec/ilspy
        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);
        }
コード例 #2
0
        public override bool View(DecompilerTextView textView)
        {
            EmbeddedResource er = r as EmbeddedResource;

            if (er != null)
            {
                Stream s = er.GetResourceStream();
                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.Write(FileReader.OpenStream(s, Encoding.UTF8).ReadToEnd());
                        string ext;
                        if (type == FileType.Xml)
                        {
                            ext = ".xml";
                        }
                        else
                        {
                            ext = Path.GetExtension(DecompilerTextView.CleanUpName(er.Name));
                        }
                        textView.ShowNode(output, this, HighlightingManager.Instance.GetDefinitionByExtension(ext));
                        return(true);
                    }
                }
            }
            return(false);
        }
コード例 #3
0
        internal static string GetStringContents(Stream stream)
        {
            if (stream == null)
            {
                return(null);
            }

            stream.Position = 0;
            if (GuessFileType.DetectFileType(stream) == FileType.Binary)
            {
                return(null);
            }

            stream.Position = 0;
            return(FileReader.OpenStream(stream, Encoding.UTF8).ReadToEnd());
        }
コード例 #4
0
        internal static bool View(ILSpyTreeNode node, DecompilerTextView textView, Stream stream, string name)
        {
            if (stream == null || stream.Length >= DecompilerTextView.DefaultOutputLengthLimit)
            {
                return(false);
            }

            stream.Position = 0;
            FileType type = GuessFileType.DetectFileType(stream);

            if (type == FileType.Binary)
            {
                return(false);
            }

            stream.Position = 0;
            AvalonEditTextOutput output = new AvalonEditTextOutput();

            output.Write(FileReader.OpenStream(stream, Encoding.UTF8).ReadToEnd(), TextTokenType.Text);
            string ext;

            if (type == FileType.Xml)
            {
                ext = ".xml";
            }
            else
            {
                try {
                    ext = Path.GetExtension(DecompilerTextView.CleanUpName(name));
                }
                catch (ArgumentException) {
                    ext = ".txt";
                }
            }
            textView.ShowNode(output, node, HighlightingManager.Instance.GetDefinitionByExtension(ext));
            return(true);
        }