WriteLine() публичный Метод

public WriteLine ( ) : void
Результат void
Пример #1
0
        Task <AvalonEditTextOutput> SaveToDiskAsync(DecompilationContext context, string fileName)
        {
            TaskCompletionSource <AvalonEditTextOutput> tcs = new TaskCompletionSource <AvalonEditTextOutput>();
            Thread thread = new Thread(new ThreadStart(
                                           delegate {
                try {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    using (StreamWriter w = new StreamWriter(fileName)) {
                        try {
                            DecompileNodes(context, new PlainTextOutput(w));
                        } catch (OperationCanceledException) {
                            w.WriteLine();
                            w.WriteLine("Decompiled was cancelled.");
                            throw;
                        }
                    }
                    stopwatch.Stop();
                    AvalonEditTextOutput output = new AvalonEditTextOutput();
                    output.WriteLine("Decompilation complete in " + stopwatch.Elapsed.TotalSeconds.ToString("F1") + " seconds.");
                    output.WriteLine();
                    output.AddButton(null, Properties.Resources.OpenExplorer, delegate { Process.Start("explorer", "/select,\"" + fileName + "\""); });
                    output.WriteLine();
                    tcs.SetResult(output);
                } catch (OperationCanceledException) {
                    tcs.SetCanceled();
                } catch (Exception ex) {
                    tcs.SetException(ex);
                }
            }));

            thread.Start();
            return(tcs.Task);
        }
Пример #2
0
		public static void Display(DecompilerTextView textView) {
			AvalonEditTextOutput output = new AvalonEditTextOutput();
			output.WriteLine(string.Format("dnSpy version {0}", currentVersion.ToString()), TextTokenType.Text);
			var decVer = typeof(ICSharpCode.Decompiler.Ast.AstBuilder).Assembly.GetName().Version;
			output.WriteLine(string.Format("ILSpy Decompiler version {0}.{1}.{2}", decVer.Major, decVer.Minor, decVer.Build), TextTokenType.Text);
			if (checkForUpdateCode)
				output.AddUIElement(
					delegate {
						StackPanel stackPanel = new StackPanel();
						stackPanel.HorizontalAlignment = HorizontalAlignment.Center;
						stackPanel.Orientation = Orientation.Horizontal;
						if (latestAvailableVersion == null) {
							AddUpdateCheckButton(stackPanel, textView);
						}
						else {
						// we already retrieved the latest version sometime earlier
						ShowAvailableVersion(latestAvailableVersion, stackPanel);
						}
						CheckBox checkBox = new CheckBox();
						checkBox.Margin = new Thickness(4);
						checkBox.Content = "Automatically check for updates every week";
						UpdateSettings settings = new UpdateSettings(DNSpySettings.Load());
						checkBox.SetBinding(CheckBox.IsCheckedProperty, new Binding("AutomaticUpdateCheckEnabled") { Source = settings });
						return new StackPanel {
							Margin = new Thickness(0, 4, 0, 0),
							Cursor = Cursors.Arrow,
							Children = { stackPanel, checkBox }
						};
					});
			if (checkForUpdateCode)
				output.WriteLine();
			foreach (var plugin in App.CompositionContainer.GetExportedValues<IAboutPageAddition>())
				plugin.Write(output);
			output.WriteLine();
			using (Stream s = typeof(AboutPage).Assembly.GetManifestResourceStream(typeof(dnSpy.StartUpClass), "README.txt")) {
				using (StreamReader r = new StreamReader(s)) {
					string line;
					while ((line = r.ReadLine()) != null) {
						output.WriteLine(line, TextTokenType.Text);
					}
				}
			}
			output.AddVisualLineElementGenerator(new MyLinkElementGenerator("SharpDevelop", "http://www.icsharpcode.net/opensource/sd/"));
			output.AddVisualLineElementGenerator(new MyLinkElementGenerator("MIT License", "resource:license.txt"));
			output.AddVisualLineElementGenerator(new MyLinkElementGenerator("LGPL", "resource:LGPL.txt"));
			output.AddVisualLineElementGenerator(new MyLinkElementGenerator("COPYING", "resource:COPYING"));
			textView.ShowText(output);
			MainWindow.Instance.SetTitle(textView, "About");
		}
Пример #3
0
 Task DoDecompile(DecompilationContext context, int outputLengthLimit)
 {
     return(RunWithCancellation(
                delegate(CancellationToken ct) {           // creation of the background task
         context.Options.CancellationToken = ct;
         return DecompileAsync(context, outputLengthLimit);
     })
            .Then(
                delegate(AvalonEditTextOutput textOutput) {           // handling the result
         ShowOutput(textOutput, context.Language.SyntaxHighlighting, context.Options.TextViewState);
         decompiledNodes = context.TreeNodes;
     })
            .Catch <Exception>(exception => {
         textEditor.SyntaxHighlighting = null;
         Debug.WriteLine("Decompiler crashed: " + exception.ToString());
         AvalonEditTextOutput output = new AvalonEditTextOutput();
         if (exception is OutputLengthExceededException)
         {
             WriteOutputLengthExceededMessage(output, context, outputLengthLimit == DefaultOutputLengthLimit);
         }
         else
         {
             output.WriteLine(exception.ToString());
         }
         ShowOutput(output);
         decompiledNodes = context.TreeNodes;
     }));
 }
Пример #4
0
 /// <summary>
 /// Starts the decompilation of the given nodes.
 /// The result will be saved to the given file name.
 /// </summary>
 void SaveToDisk(DecompilationContext context, string fileName)
 {
     RunWithCancellation(
         delegate(CancellationToken ct) {
         context.Options.CancellationToken = ct;
         return(SaveToDiskAsync(context, fileName));
     },
         delegate(Task <AvalonEditTextOutput> task) {
         try {
             ShowOutput(task.Result);
         } catch (AggregateException aggregateException) {
             textEditor.SyntaxHighlighting = null;
             Debug.WriteLine("Decompiler crashed: " + aggregateException.ToString());
             // Unpack aggregate exceptions as long as there's only a single exception:
             // (assembly load errors might produce nested aggregate exceptions)
             Exception ex = aggregateException;
             while (ex is AggregateException && (ex as AggregateException).InnerExceptions.Count == 1)
             {
                 ex = ex.InnerException;
             }
             AvalonEditTextOutput output = new AvalonEditTextOutput();
             output.WriteLine(ex.ToString());
             ShowOutput(output);
         }
         decompiledNodes = context.TreeNodes;
     });
 }
Пример #5
0
		public override bool View(DecompilerTextView textView)
		{
			try {
				AvalonEditTextOutput output = new AvalonEditTextOutput();
				Data.Position = 0;
				BitmapImage image = new BitmapImage();

				//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...
				byte[] curData = ((MemoryStream)Data).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, "Save", delegate {
					Save(null);
				});
				textView.ShowNode(output, this, null);
				return true;
			}
			catch (Exception) {
				return false;
			}
		}
Пример #6
0
 public override bool View(DecompilerTextView textView)
 {
   try
   {
     AvalonEditTextOutput output = new AvalonEditTextOutput();
     Data.Position = 0;
     IconBitmapDecoder decoder = new IconBitmapDecoder(Data, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.None);
     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, "Save", delegate
     {
       Save(null);
     });
     textView.ShowNode(output, this);
     return true;
   }
   catch (Exception)
   {
     return false;
   }
 }
Пример #7
0
 void DoDecompile(DecompilationContext context, int outputLengthLimit)
 {
     RunWithCancellation(
         delegate(CancellationToken ct) {                  // creation of the background task
         context.Options.CancellationToken = ct;
         return(DecompileAsync(context, outputLengthLimit));
     },
         delegate(Task <AvalonEditTextOutput> task) {                 // handling the result
         try {
             AvalonEditTextOutput textOutput = task.Result;
             ShowOutput(textOutput, context.Language.SyntaxHighlighting, context.Options.TextViewState);
         } catch (AggregateException aggregateException) {
             textEditor.SyntaxHighlighting = null;
             Debug.WriteLine("Decompiler crashed: " + aggregateException.ToString());
             // Unpack aggregate exceptions as long as there's only a single exception:
             // (assembly load errors might produce nested aggregate exceptions)
             Exception ex = aggregateException;
             while (ex is AggregateException && (ex as AggregateException).InnerExceptions.Count == 1)
             {
                 ex = ex.InnerException;
             }
             AvalonEditTextOutput output = new AvalonEditTextOutput();
             if (ex is OutputLengthExceededException)
             {
                 WriteOutputLengthExceededMessage(output, context, outputLengthLimit == DefaultOutputLengthLimit);
             }
             else
             {
                 output.WriteLine(ex.ToString());
             }
             ShowOutput(output);
         }
     });
 }
Пример #8
0
 public override void Execute(object parameter)
 {
     MainWindow.Instance.TextView.RunWithCancellation(ct => Task<AvalonEditTextOutput>.Factory.StartNew(() => {
         AvalonEditTextOutput output = new AvalonEditTextOutput();
         Parallel.ForEach(MainWindow.Instance.CurrentAssemblyList.GetAssemblies(), new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount, CancellationToken = ct }, delegate(LoadedAssembly asm) {
             if (!asm.HasLoadError) {
                 Stopwatch w = Stopwatch.StartNew();
                 Exception exception = null;
                 using (var writer = new System.IO.StreamWriter("c:\\temp\\decompiled\\" + asm.ShortName + ".cs")) {
                     try {
                         new CSharpLanguage().DecompileAssembly(asm, new Decompiler.PlainTextOutput(writer), new DecompilationOptions { FullDecompilation = true, CancellationToken = ct });
                     }
                     catch (Exception ex) {
                         writer.WriteLine(ex.ToString());
                         exception = ex;
                     }
                 }
                 lock (output) {
                     output.Write(asm.ShortName + " - " + w.Elapsed);
                     if (exception != null) {
                         output.Write(" - ");
                         output.Write(exception.GetType().Name);
                     }
                     output.WriteLine();
                 }
             }
         });
         return output;
     }, ct), task => MainWindow.Instance.TextView.ShowText(task.Result));
 }
Пример #9
0
		public static void Display(DecompilerTextView textView)
		{
			AvalonEditTextOutput output = new AvalonEditTextOutput();
			output.WriteLine("ILSpy version " + RevisionClass.FullVersion);
			output.AddUIElement(
				delegate {
					StackPanel stackPanel = new StackPanel();
					stackPanel.HorizontalAlignment = HorizontalAlignment.Center;
					stackPanel.Orientation = Orientation.Horizontal;
					if (latestAvailableVersion == null) {
						AddUpdateCheckButton(stackPanel, textView);
					} else {
						// we already retrieved the latest version sometime earlier
						ShowAvailableVersion(latestAvailableVersion, stackPanel);
					}
					CheckBox checkBox = new CheckBox();
					checkBox.Margin = new Thickness(4);
					checkBox.Content = "Automatically check for updates every week";
					UpdateSettings settings = new UpdateSettings(ILSpySettings.Load());
					checkBox.SetBinding(CheckBox.IsCheckedProperty, new Binding("AutomaticUpdateCheckEnabled") { Source = settings });
					return new StackPanel {
						Margin = new Thickness(0, 4, 0, 0),
						Cursor = Cursors.Arrow,
						Children = { stackPanel, checkBox }
					};
				});
			output.WriteLine();
			foreach (var plugin in App.CompositionContainer.GetExportedValues<IAboutPageAddition>())
				plugin.Write(output);
			output.WriteLine();
			using (Stream s = typeof(AboutPage).Assembly.GetManifestResourceStream(typeof(AboutPage), "README.txt")) {
				using (StreamReader r = new StreamReader(s)) {
					string line;
					while ((line = r.ReadLine()) != null) {
						output.WriteLine(line);
					}
				}
			}
			output.AddVisualLineElementGenerator(new MyLinkElementGenerator("SharpDevelop", "http://www.icsharpcode.net/opensource/sd/"));
			output.AddVisualLineElementGenerator(new MyLinkElementGenerator("MIT License", "resource:license.txt"));
			output.AddVisualLineElementGenerator(new MyLinkElementGenerator("LGPL", "resource:LGPL.txt"));
			textView.ShowText(output);
			
			//reset icon bar
			textView.manager.Bookmarks.Clear();
		}
Пример #10
0
		/// <summary>
		/// Switches the GUI into "waiting" mode, then calls <paramref name="taskCreation"/> to create
		/// the task.
		/// If another task is started before the previous task finishes running, the previous task is cancelled.
		/// </summary>
		public Task<T> RunWithCancellation<T>(Func<CancellationToken, Task<T>> taskCreation)
		{
			if (waitAdorner.Visibility != Visibility.Visible) {
				waitAdorner.Visibility = Visibility.Visible;
				// Work around a WPF bug by setting IsIndeterminate only while the progress bar is visible.
				// https://github.com/icsharpcode/ILSpy/issues/593
				progressBar.IsIndeterminate = true;
				waitAdorner.BeginAnimation(OpacityProperty, new DoubleAnimation(0, 1, new Duration(TimeSpan.FromSeconds(0.5)), FillBehavior.Stop));
				var taskBar = MainWindow.Instance.TaskbarItemInfo;
				if (taskBar != null) {
					taskBar.ProgressState = System.Windows.Shell.TaskbarItemProgressState.Indeterminate;
				}
			}
			CancellationTokenSource previousCancellationTokenSource = currentCancellationTokenSource;
			var myCancellationTokenSource = new CancellationTokenSource();
			currentCancellationTokenSource = myCancellationTokenSource;
			// cancel the previous only after current was set to the new one (avoid that the old one still finishes successfully)
			if (previousCancellationTokenSource != null)
				previousCancellationTokenSource.Cancel();
			
			var tcs = new TaskCompletionSource<T>();
			Task<T> task;
			try {
				task = taskCreation(myCancellationTokenSource.Token);
			} catch (OperationCanceledException) {
				task = TaskHelper.FromCancellation<T>();
			} catch (Exception ex) {
				task = TaskHelper.FromException<T>(ex);
			}
			Action continuation = delegate {
				try {
					if (currentCancellationTokenSource == myCancellationTokenSource) {
						currentCancellationTokenSource = null;
						waitAdorner.Visibility = Visibility.Collapsed;
						progressBar.IsIndeterminate = false;
						var taskBar = MainWindow.Instance.TaskbarItemInfo;
						if (taskBar != null) {
							taskBar.ProgressState = System.Windows.Shell.TaskbarItemProgressState.None;
						}
						if (task.IsCanceled) {
							AvalonEditTextOutput output = new AvalonEditTextOutput();
							output.WriteLine("The operation was canceled.");
							ShowOutput(output);
						}
						tcs.SetFromTask(task);
					} else {
						tcs.SetCanceled();
					}
				} finally {
					myCancellationTokenSource.Dispose();
				}
			};
			task.ContinueWith(delegate { Dispatcher.BeginInvoke(DispatcherPriority.Normal, continuation); });
			return tcs.Task;
		}
Пример #11
0
        /// <summary>
        /// Switches the GUI into "waiting" mode, then calls <paramref name="taskCreation"/> to create
        /// the task.
        /// When the task completes without being cancelled, the <paramref name="taskCompleted"/>
        /// callback is called on the GUI thread.
        /// When the task is cancelled before completing, the callback is not called; and any result
        /// of the task (including exceptions) are ignored.
        /// </summary>
        public void RunWithCancellation <T>(Func <CancellationToken, Task <T> > taskCreation, Action <Task <T> > taskCompleted)
        {
            if (waitAdorner.Visibility != Visibility.Visible)
            {
                waitAdorner.Visibility = Visibility.Visible;
                waitAdorner.BeginAnimation(OpacityProperty, new DoubleAnimation(0, 1, new Duration(TimeSpan.FromSeconds(0.5)), FillBehavior.Stop));
            }
            CancellationTokenSource previousCancellationTokenSource = currentCancellationTokenSource;
            var myCancellationTokenSource = new CancellationTokenSource();

            currentCancellationTokenSource = myCancellationTokenSource;
            // cancel the previous only after current was set to the new one (avoid that the old one still finishes successfully)
            if (previousCancellationTokenSource != null)
            {
                previousCancellationTokenSource.Cancel();
            }

            var    task         = taskCreation(myCancellationTokenSource.Token);
            Action continuation = delegate {
                try {
                    if (currentCancellationTokenSource == myCancellationTokenSource)
                    {
                        currentCancellationTokenSource = null;
                        waitAdorner.Visibility         = Visibility.Collapsed;
                        if (task.IsCanceled)
                        {
                            AvalonEditTextOutput output = new AvalonEditTextOutput();
                            output.WriteLine("The operation was canceled.");
                            ShowOutput(output);
                        }
                        else
                        {
                            taskCompleted(task);
                        }
                    }
                    else
                    {
                        try {
                            task.Wait();
                        } catch (AggregateException) {
                            // observe the exception (otherwise the task's finalizer will shut down the AppDomain)
                        }
                    }
                } finally {
                    myCancellationTokenSource.Dispose();
                }
            };

            task.ContinueWith(delegate { Dispatcher.BeginInvoke(DispatcherPriority.Normal, continuation); });
        }
Пример #12
0
        /// <summary>
        /// Starts the decompilation of the given nodes.
        /// The result will be saved to the given file name.
        /// </summary>
        void SaveToDisk(DecompilationContext context, string fileName)
        {
            textEditor.Clear();

            TaskCompletionSource <AvalonEditTextOutput> tcs = new TaskCompletionSource <AvalonEditTextOutput>();

            RunWithCancellation(
                delegate(CancellationToken ct) {
                context.Options.CancellationToken = ct;

                try {
                    var language = context.Language;
                    var options  = context.Options;

                    AvalonEditTextOutput output = new AvalonEditTextOutput();

                    string path = Path.GetDirectoryName(fileName);

                    char[] invalidPathCharacters = Path.GetInvalidPathChars().Concat(Path.GetInvalidFileNameChars()).Distinct().ToArray();

                    foreach (ILSpyTreeNode node in context.TreeNodes)
                    {
                        string sanitized = new string(node.Text.ToString().Replace("<", "-").Replace(">", "-").Where(c => !invalidPathCharacters.Contains(c)).ToArray());

                        string fn = Path.Combine(path, $"{sanitized}.cs");

                        AvalonEditTextOutput saveOutput = SaveToDiskAsync(new DecompilationContext(language, new ILSpyTreeNode[] { node }, options), fn).Result;

                        output.WriteLine(saveOutput.GetDocument().Text);
                    }

                    tcs.SetResult(output);
                } catch (OperationCanceledException) {
                    tcs.SetCanceled();
                }
                return(tcs.Task);
            })
            .Then(output => ShowOutput(output))
            .Catch((Exception ex) => {
                textEditor.SyntaxHighlighting = null;
                Debug.WriteLine("Decompiler crashed: " + ex.ToString());
                // Unpack aggregate exceptions as long as there's only a single exception:
                // (assembly load errors might produce nested aggregate exceptions)
                AvalonEditTextOutput output = new AvalonEditTextOutput();
                output.WriteLine(ex.ToString());
                ShowOutput(output);
            }).HandleExceptions();
        }
Пример #13
0
 /// <summary>
 /// Starts the decompilation of the given nodes.
 /// The result will be saved to the given file name.
 /// </summary>
 void SaveToDisk(DecompilationContext context, string fileName)
 {
     RunWithCancellation(
         delegate(CancellationToken ct) {
         context.Options.CancellationToken = ct;
         return(SaveToDiskAsync(context, fileName));
     })
     .Then(output => ShowOutput(output))
     .Catch((Exception ex) => {
         textEditor.SyntaxHighlighting = null;
         Debug.WriteLine("Decompiler crashed: " + ex.ToString());
         // Unpack aggregate exceptions as long as there's only a single exception:
         // (assembly load errors might produce nested aggregate exceptions)
         AvalonEditTextOutput output = new AvalonEditTextOutput();
         output.WriteLine(ex.ToString());
         ShowOutput(output);
     }).HandleExceptions();
 }
Пример #14
0
 public override bool View(DecompilerTextView textView)
 {
     try {
         AvalonEditTextOutput output = new AvalonEditTextOutput();
         Data.Position = 0;
         BitmapImage image = new BitmapImage();
         image.BeginInit();
         image.StreamSource = Data;
         image.EndInit();
         output.AddUIElement(() => new Image { Source = image });
         output.WriteLine();
         output.AddButton(ImageCache.Instance.GetImage("Save", BackgroundType.Button), "Save", delegate {
             Save(null);
         });
         textView.ShowNode(output, this);
         return true;
     }
     catch (Exception) {
         return false;
     }
 }
Пример #15
0
 public static void Display(DecompilerTextView textView)
 {
     AvalonEditTextOutput output = new AvalonEditTextOutput();
     output.WriteLine("ILSpy version " + RevisionClass.FullVersion);
     output.AddUIElement(
         delegate {
             StackPanel stackPanel = new StackPanel();
             stackPanel.HorizontalAlignment = HorizontalAlignment.Center;
             stackPanel.Orientation = Orientation.Horizontal;
             if (latestAvailableVersion == null) {
                 AddUpdateCheckButton(stackPanel, textView);
             } else {
                 // we already retrieved the latest version sometime earlier
                 ShowAvailableVersion(latestAvailableVersion, stackPanel);
             }
             CheckBox checkBox = new CheckBox();
             checkBox.Margin = new Thickness(4);
             checkBox.Content = "Automatically check for updates every week";
             UpdateSettings settings = new UpdateSettings(ILSpySettings.Load());
             checkBox.SetBinding(CheckBox.IsCheckedProperty, new Binding("AutomaticUpdateCheckEnabled") { Source = settings });
             return new StackPanel {
                 Margin = new Thickness(0, 4, 0, 0),
                 Cursor = Cursors.Arrow,
                 Children = { stackPanel, checkBox }
             };
         });
     output.WriteLine();
     output.WriteLine();
     using (Stream s = typeof(AboutPage).Assembly.GetManifestResourceStream(typeof(AboutPage), "README.txt")) {
         using (StreamReader r = new StreamReader(s)) {
             string line;
             while ((line = r.ReadLine()) != null)
                 output.WriteLine(line);
         }
     }
     textView.Show(output);
 }
Пример #16
0
 private static void AddUpdateCheckButton(StackPanel stackPanel, DecompilerTextView textView)
 {
     Button button = new Button();
     button.Content = "检查更新";
     button.Cursor = Cursors.Arrow;
     stackPanel.Children.Add(button);
     button.Click += delegate(object param0, RoutedEventArgs param1)
     {
         button.Content = "检查更新中...";
         button.IsEnabled = false;
         AboutPage.GetLatestVersionAsync().ContinueWith(delegate(Task<AboutPage.AvailableVersionInfo> task)
         {
             try
             {
                 stackPanel.Children.Clear();
                 AboutPage.ShowAvailableVersion(task.Result, stackPanel);
             }
             catch (Exception ex)
             {
                 AvalonEditTextOutput avalonEditTextOutput = new AvalonEditTextOutput();
                 avalonEditTextOutput.WriteLine(ex.ToString());
                 textView.ShowText(avalonEditTextOutput);
             }
         }, TaskScheduler.FromCurrentSynchronizationContext());
     };
 }
Пример #17
0
 bool LoadImage(AvalonEditTextOutput output)
 {
     try {
         value.Position = 0;
         BitmapImage image = new BitmapImage();
         image.BeginInit();
         image.StreamSource = value;
         image.EndInit();
         output.AddUIElement(() => new Image { Source = image });
         output.WriteLine();
         output.AddButton(Images.Save, "Save", delegate { Save(null); });
     } catch (Exception) {
         return false;
     }
     return true;
 }
Пример #18
0
		static void AddUpdateCheckButton(StackPanel stackPanel, DecompilerTextView textView) {
			Button button = new Button();
			button.Content = "Check for updates";
			button.Cursor = Cursors.Arrow;
			stackPanel.Children.Add(button);

			button.Click += delegate {
				button.Content = "Checking...";
				button.IsEnabled = false;
				GetLatestVersionAsync().ContinueWith(
					delegate (Task<AvailableVersionInfo> task) {
						try {
							stackPanel.Children.Clear();
							ShowAvailableVersion(task.Result, stackPanel);
						}
						catch (Exception ex) {
							AvalonEditTextOutput exceptionOutput = new AvalonEditTextOutput();
							exceptionOutput.WriteLine(ex.ToString(), TextTokenType.Text);
							textView.ShowText(exceptionOutput);
						}
					}, TaskScheduler.FromCurrentSynchronizationContext());
			};
		}
Пример #19
0
		internal override bool View(DecompilerTextView textView)
		{
			try {
				AvalonEditTextOutput output = new AvalonEditTextOutput();
				data.Position = 0;
				BitmapImage image = new BitmapImage();
				image.BeginInit();
				image.StreamSource = data;
				image.EndInit();
				output.AddUIElement(() => new Image { Source = image });
				output.WriteLine();
				output.AddButton(Images.Save, "Save", delegate { Save(null); });
				textView.Show(output, null);
				return true;
			} catch (Exception) {
				return false;
			}
		}
Пример #20
0
 public static void Display(DecompilerTextView textView)
 {
     AvalonEditTextOutput avalonEditTextOutput = new AvalonEditTextOutput();
     avalonEditTextOutput.WriteLine("ILSpy 版本 2.1.0.1603");
     avalonEditTextOutput.AddUIElement(delegate
     {
         StackPanel stackPanel = new StackPanel();
         stackPanel.HorizontalAlignment = HorizontalAlignment.Center;
         stackPanel.Orientation = Orientation.Horizontal;
         if (AboutPage.latestAvailableVersion == null)
         {
             AboutPage.AddUpdateCheckButton(stackPanel, textView);
         }
         else
         {
             AboutPage.ShowAvailableVersion(AboutPage.latestAvailableVersion, stackPanel);
         }
         CheckBox checkBox = new CheckBox();
         checkBox.Margin = new Thickness(4.0);
         checkBox.Content = "每周自动检查更新";
         AboutPage.UpdateSettings source = new AboutPage.UpdateSettings(ILSpySettings.Load());
         checkBox.SetBinding(ToggleButton.IsCheckedProperty, new Binding("AutomaticUpdateCheckEnabled")
         {
             Source = source
         });
         return new StackPanel
         {
             Margin = new Thickness(0.0, 4.0, 0.0, 0.0),
             Cursor = Cursors.Arrow,
             Children =
             {
                 stackPanel,
                 checkBox
             }
         };
     });
     avalonEditTextOutput.WriteLine();
     foreach (IAboutPageAddition current in App.CompositionContainer.GetExportedValues<IAboutPageAddition>())
     {
         current.Write(avalonEditTextOutput);
     }
     avalonEditTextOutput.WriteLine();
     using (Stream manifestResourceStream = typeof(AboutPage).Assembly.GetManifestResourceStream(typeof(AboutPage), "README.txt"))
     {
         using (StreamReader streamReader = new StreamReader(manifestResourceStream))
         {
             string text;
             while ((text = streamReader.ReadLine()) != null)
             {
                 avalonEditTextOutput.WriteLine(text);
             }
         }
     }
     avalonEditTextOutput.AddVisualLineElementGenerator(new AboutPage.MyLinkElementGenerator("SharpDevelop", "http://www.icsharpcode.net/opensource/sd/"));
     avalonEditTextOutput.AddVisualLineElementGenerator(new AboutPage.MyLinkElementGenerator("MIT License", "resource:license.txt"));
     avalonEditTextOutput.AddVisualLineElementGenerator(new AboutPage.MyLinkElementGenerator("LGPL", "resource:LGPL.txt"));
     avalonEditTextOutput.AddVisualLineElementGenerator(new AboutPage.MyLinkElementGenerator("iFish(木鱼)", "http://www.fishlee.net/about/"));
     textView.ShowText(avalonEditTextOutput);
     textView.manager.Bookmarks.Clear();
 }
Пример #21
0
		void Window_RequestNavigate(object sender, RequestNavigateEventArgs e)
		{
			if (e.Uri.Scheme == "resource") {
				AvalonEditTextOutput output = new AvalonEditTextOutput();
				using (Stream s = typeof(App).Assembly.GetManifestResourceStream(typeof(dnSpy.StartUpClass), e.Uri.AbsolutePath)) {
					using (StreamReader r = new StreamReader(s)) {
						string line;
						while ((line = r.ReadLine()) != null) {
							output.Write(line, TextTokenType.Text);
							output.WriteLine();
						}
					}
				}
				var textView = ILSpy.MainWindow.Instance.SafeActiveTextView;
				textView.ShowText(output);
				ILSpy.MainWindow.Instance.SetTitle(textView, e.Uri.AbsolutePath);
				e.Handled = true;
			}
		}
Пример #22
0
        public override bool View(DecompilerTextView textView)
        {
            try {
                AvalonEditTextOutput output = new AvalonEditTextOutput();
                Data.Position = 0;
                BitmapImage image = new BitmapImage();

                //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 (null == s)
                {
                    // data was stored in another stream type (e.g. PinnedBufferedMemoryStream)
                    s = new MemoryStream();
                    Data.CopyTo(s);
                }
                byte[] 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(ImageCache.Instance.GetImage("Save", BackgroundType.Button), "Save", delegate {
                    Save(null);
                });
                textView.ShowNode(output, this);
                return true;
            }
            catch (Exception) {
                return false;
            }
        }
Пример #23
0
		void Window_RequestNavigate(object sender, RequestNavigateEventArgs e)
		{
			if (e.Uri.Scheme == "resource") {
				AvalonEditTextOutput output = new AvalonEditTextOutput();
				using (Stream s = typeof(App).Assembly.GetManifestResourceStream(typeof(App), e.Uri.AbsolutePath)) {
					using (StreamReader r = new StreamReader(s)) {
						string line;
						while ((line = r.ReadLine()) != null) {
							output.Write(line);
							output.WriteLine();
						}
					}
				}
				ILSpy.MainWindow.Instance.TextView.Show(output);
			} else {
				Process.Start(e.Uri.ToString());
			}
		}
Пример #24
0
 public void WriteNewLine()
 {
     output.WriteLine();
     needsNewLine = false;
 }