Exemple #1
0
 /// <summary>
 /// If automatic update checking is enabled, checks if there are any updates available.
 /// Returns the download URL if an update is available.
 /// Returns null if no update is available, or if no check was performed.
 /// </summary>
 public static Task<string> CheckForUpdatesIfEnabledAsync(ILSpySettings spySettings)
 {
     var tcs = new TaskCompletionSource<string>();
     UpdateSettings s = new UpdateSettings(spySettings);
     if (checkForUpdateCode && s.AutomaticUpdateCheckEnabled) {
         // perform update check if we never did one before;
         // or if the last check wasn't in the past 7 days
         if (s.LastSuccessfulUpdateCheck == null
             || s.LastSuccessfulUpdateCheck < DateTime.UtcNow.AddDays(-7)
             || s.LastSuccessfulUpdateCheck > DateTime.UtcNow)
         {
             GetLatestVersionAsync().ContinueWith(
                 delegate (Task<AvailableVersionInfo> task) {
                     try {
                         s.LastSuccessfulUpdateCheck = DateTime.UtcNow;
                         AvailableVersionInfo v = task.Result;
                         if (v.Version > currentVersion)
                             tcs.SetResult(v.DownloadUrl);
                         else
                             tcs.SetResult(null);
                     } catch (AggregateException) {
                         // ignore errors getting the version info
                         tcs.SetResult(null);
                     }
                 });
         } else {
             tcs.SetResult(null);
         }
     } else {
         tcs.SetResult(null);
     }
     return tcs.Task;
 }
		public MainWindow()
		{
			instance = this;
			spySettings = ILSpySettings.Load();
			this.sessionSettings = new SessionSettings(spySettings);
			this.assemblyListManager = new AssemblyListManager(spySettings);
			
			this.Icon = new BitmapImage(new Uri("pack://application:,,,/ILSpy;component/images/ILSpy.ico"));
			
			this.DataContext = sessionSettings;
			this.Left = sessionSettings.WindowBounds.Left;
			this.Top = sessionSettings.WindowBounds.Top;
			this.Width = sessionSettings.WindowBounds.Width;
			this.Height = sessionSettings.WindowBounds.Height;
			// TODO: validate bounds (maybe a monitor was removed...)
			this.WindowState = sessionSettings.WindowState;
			
			InitializeComponent();
			App.CompositionContainer.ComposeParts(this);
			Grid.SetRow(decompilerTextView, 1);
			rightPane.Children.Add(decompilerTextView);
			
			if (sessionSettings.SplitterPosition > 0 && sessionSettings.SplitterPosition < 1) {
				leftColumn.Width = new GridLength(sessionSettings.SplitterPosition, GridUnitType.Star);
				rightColumn.Width = new GridLength(1 - sessionSettings.SplitterPosition, GridUnitType.Star);
			}
			sessionSettings.FilterSettings.PropertyChanged += filterSettings_PropertyChanged;
			
			InitMainMenu();
			InitToolbar();
			ContextMenuProvider.Add(treeView);
			ContextMenuProvider.Add(analyzerTree);
			
			this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
		}
Exemple #3
0
		public MainWindow()
		{
			instance = this;
			spySettings = ILSpySettings.Load();
			this.sessionSettings = new SessionSettings(spySettings);
			this.assemblyListManager = new AssemblyListManager(spySettings);
			
			this.Icon = new BitmapImage(new Uri("pack://application:,,,/ILSpy;component/images/ILSpy.ico"));
			
			this.DataContext = sessionSettings;
			
			InitializeComponent();
			App.CompositionContainer.ComposeParts(this);
			mainPane.Content = decompilerTextView;
			
			if (sessionSettings.SplitterPosition > 0 && sessionSettings.SplitterPosition < 1) {
				leftColumn.Width = new GridLength(sessionSettings.SplitterPosition, GridUnitType.Star);
				rightColumn.Width = new GridLength(1 - sessionSettings.SplitterPosition, GridUnitType.Star);
			}
			sessionSettings.FilterSettings.PropertyChanged += filterSettings_PropertyChanged;
			
			InitMainMenu();
			InitToolbar();
			ContextMenuProvider.Add(treeView, decompilerTextView);
			
			this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
		}
Exemple #4
0
        public MainWindow()
        {
            spySettings = ILSpySettings.Load();
            this.sessionSettings = new SessionSettings(spySettings);
            this.assemblyListManager = new AssemblyListManager(spySettings);

            this.DataContext = sessionSettings;
            this.Left = sessionSettings.WindowBounds.Left;
            this.Top = sessionSettings.WindowBounds.Top;
            this.Width = sessionSettings.WindowBounds.Width;
            this.Height = sessionSettings.WindowBounds.Height;
            // TODO: validate bounds (maybe a monitor was removed...)
            this.WindowState = sessionSettings.WindowState;

            InitializeComponent();
            decompilerTextView.mainWindow = this;

            if (sessionSettings.SplitterPosition > 0 && sessionSettings.SplitterPosition < 1) {
                leftColumn.Width = new GridLength(sessionSettings.SplitterPosition, GridUnitType.Star);
                rightColumn.Width = new GridLength(1 - sessionSettings.SplitterPosition, GridUnitType.Star);
            }
            sessionSettings.FilterSettings.PropertyChanged += filterSettings_PropertyChanged;

            #if DEBUG
            AddDebugItemsToToolbar();
            #endif
            this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
        }
Exemple #5
0
		public MainWindow()
		{
			instance = this;
			spySettings = ILSpySettings.Load();
			this.sessionSettings = new SessionSettings(spySettings);
			this.assemblyListManager = new AssemblyListManager(spySettings);
			
			if (Environment.OSVersion.Version.Major >= 6)
				this.Icon = new BitmapImage(new Uri("pack://application:,,,/ILSpy;component/images/ILSpy.ico"));
			else
				this.Icon = Images.AssemblyLoading;
			
			this.DataContext = sessionSettings;
			this.Left = sessionSettings.WindowBounds.Left;
			this.Top = sessionSettings.WindowBounds.Top;
			this.Width = sessionSettings.WindowBounds.Width;
			this.Height = sessionSettings.WindowBounds.Height;
			// TODO: validate bounds (maybe a monitor was removed...)
			this.WindowState = sessionSettings.WindowState;
			
			InitializeComponent();
			decompilerTextView.mainWindow = this;
			
			if (sessionSettings.SplitterPosition > 0 && sessionSettings.SplitterPosition < 1) {
				leftColumn.Width = new GridLength(sessionSettings.SplitterPosition, GridUnitType.Star);
				rightColumn.Width = new GridLength(1 - sessionSettings.SplitterPosition, GridUnitType.Star);
			}
			sessionSettings.FilterSettings.PropertyChanged += filterSettings_PropertyChanged;
			
			this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
		}
Exemple #6
0
		public AssemblyListManager(ILSpySettings spySettings)
		{
			XElement doc = spySettings["AssemblyLists"];
			foreach (var list in doc.Elements("List")) {
				AssemblyLists.Add(SessionSettings.Unescape((string)list.Attribute("name")));
			}
		}
Exemple #7
0
 public static Task<string> CheckForUpdatesAsync(ILSpySettings spySettings)
 {
     var tcs = new TaskCompletionSource<string>();
     UpdateSettings s = new UpdateSettings(spySettings);
     CheckForUpdateInternal(tcs, s);
     return tcs.Task;
 }
Exemple #8
0
		/// <summary>
		/// Loads an assembly list from the ILSpySettings.
		/// If no list with the specified name is found, the default list is loaded instead.
		/// </summary>
		public AssemblyList LoadList(ILSpySettings spySettings, string listName)
		{
			AssemblyList list = DoLoadList(spySettings, listName);
			if (!AssemblyLists.Contains(list.ListName))
				AssemblyLists.Add(list.ListName);
			return list;
		}
		public static DecompilerSettings LoadDecompilerSettings(ILSpySettings settings)
		{
			XElement e = settings["DecompilerSettings"];
			DecompilerSettings s = new DecompilerSettings();
			s.AnonymousMethods = (bool?)e.Attribute("anonymousMethods") ?? s.AnonymousMethods;
			s.YieldReturn = (bool?)e.Attribute("yieldReturn") ?? s.YieldReturn;
			return s;
		}
		public static DecompilerSettings LoadDecompilerSettings(ILSpySettings settings)
		{
			XElement e = settings["DecompilerSettings"];
			DecompilerSettings s = new DecompilerSettings();
			s.AnonymousMethods = (bool?)e.Attribute("anonymousMethods") ?? s.AnonymousMethods;
			s.YieldReturn = (bool?)e.Attribute("yieldReturn") ?? s.YieldReturn;
			s.QueryExpressions = (bool?)e.Attribute("queryExpressions") ?? s.QueryExpressions;
			s.UseDebugSymbols = (bool?)e.Attribute("useDebugSymbols") ?? s.UseDebugSymbols;
			return s;
		}
        public void Load(ILSpySettings settings)
        {
            //Creates the viewmodel
            var vm = new ILEditOptionPageViewModel();

            //Initializes the viewmodel
            vm.Load();

            //Sets the data context
            this.DataContext = vm;
        }
Exemple #12
0
		public override void Load(ILSpySettings settings)
		{
			// For loading options, use ILSpySetting's indexer.
			// If the specified section does exist, the indexer will return a new empty element.
			XElement e = settings[ns + "CustomOptions"];
			// Now load the options from the XML document:
			Options s = new Options();
			s.UselessOption1 = (bool?)e.Attribute("useless1") ?? s.UselessOption1;
			s.UselessOption2 = (double?)e.Attribute("useless2") ?? s.UselessOption2;
			this.options = s;
		}
Exemple #13
0
        async void downloadOrCheckUpdateButtonClick(object sender, RoutedEventArgs e)
        {
            if (updateAvailableDownloadUrl != null)
            {
                MainWindow.OpenLink(updateAvailableDownloadUrl);
            }
            else
            {
                updatePanel.Visibility = Visibility.Collapsed;
                string downloadUrl = await AboutPage.CheckForUpdatesAsync(ILSpySettings.Load());

                AdjustUpdateUIAfterCheck(downloadUrl, true);
            }
        }
Exemple #14
0
        public void ShowMessageIfUpdatesAvailableAsync(ILSpySettings spySettings, bool forceCheck = false)
        {
            Task <string> result;

            if (forceCheck)
            {
                result = AboutPage.CheckForUpdatesAsync(spySettings);
            }
            else
            {
                result = AboutPage.CheckForUpdatesIfEnabledAsync(spySettings);
            }
            result.ContinueWith(task => AdjustUpdateUIAfterCheck(task, forceCheck), TaskScheduler.FromCurrentSynchronizationContext());
        }
Exemple #15
0
 void ShowMessageIfUpdatesAvailableAsync(ILSpySettings spySettings)
 {
     AboutPage.CheckForUpdatesIfEnabledAsync(spySettings).ContinueWith(
         delegate(Task <string> task)
     {
         if (task.Result != null)
         {
             updateAvailableDownloadUrl      = task.Result;
             updateAvailablePanel.Visibility = Visibility.Visible;
         }
     },
         TaskScheduler.FromCurrentSynchronizationContext()
         );
 }
Exemple #16
0
            public UpdateSettings(ILSpySettings spySettings)
            {
                XElement s = spySettings["UpdateSettings"];

                this.automaticUpdateCheckEnabled = (bool?)s.Element("AutomaticUpdateCheckEnabled") ?? true;
                try
                {
                    this.lastSuccessfulUpdateCheck = (DateTime?)s.Element("LastSuccessfulUpdateCheck");
                }
                catch (FormatException)
                {
                    // avoid crashing on settings files invalid due to
                    // https://github.com/icsharpcode/ILSpy/issues/closed/#issue/2
                }
            }
        public LinqPadSpyContainer(Application currentApplication, Language decompiledLanguage)
        {
            if (currentApplication == null)
            {
                throw new ArgumentNullException("currentApplication");
            }
            if (decompiledLanguage == null)
            {
                throw new ArgumentNullException("decompiledLanguage");
            }

            this.decompiledLanguage = decompiledLanguage;

            this.currentApplication = currentApplication;

            // Initialize supported ILSpy languages. Values used for the combobox.
            Languages.Initialize(CompositionContainerBuilder.Container);

            this.CurrentAssemblyList = new AssemblyList("LINQPadAssemblyList", this.currentApplication);

            ICSharpCode.ILSpy.App.CompositionContainer = CompositionContainerBuilder.Container;

            CompositionContainerBuilder.Container.ComposeParts(this);

            // A hack to get around the global shared state of the Window object throughout ILSpy.
            ICSharpCode.ILSpy.MainWindow.SpyWindow = this;

            this.spySettings = ILSpySettings.Load();

            this.sessionSettings = new SessionSettings(this.spySettings)
            {
                ActiveAssemblyList = this.CurrentAssemblyList.ListName
            };

            SetUpDataContext();

            this.assemblyPath = LinqPadUtil.GetLastLinqPadQueryAssembly();

            this.decompilerTextView = GetDecompilerTextView();

            InitializeComponent();

            this.mainPane.Content = this.decompilerTextView;

            this.InitToolbar();

            this.Loaded += new RoutedEventHandler(this.MainWindowLoaded);
        }
Exemple #18
0
        AssemblyList DoLoadList(ILSpySettings spySettings, string listName)
        {
            XElement doc = spySettings["AssemblyLists"];

            if (listName != null)
            {
                foreach (var list in doc.Elements("List"))
                {
                    if ((string)list.Attribute("name") == listName)
                    {
                        return(new AssemblyList(list));
                    }
                }
            }
            return(new AssemblyList(listName ?? DefaultListName));
        }
Exemple #19
0
        public void ShowAssemblyList(string name)
        {
            ILSpySettings settings = this.spySettings;

            if (settings == null)
            {
                settings = ILSpySettings.Load();
            }
            AssemblyList list = this.assemblyListManager.LoadList(settings, name);

            //Only load a new list when it is a different one
            if (list.ListName != CurrentAssemblyList.ListName)
            {
                ShowAssemblyList(list);
            }
        }
Exemple #20
0
 void OKButton_Click(object sender, RoutedEventArgs e)
 {
     ILSpySettings.Update(
         delegate(XElement root) {
         foreach (var optionPage in optionPages)
         {
             IOptionPage page = optionPage.Value as IOptionPage;
             if (page != null)
             {
                 page.Save(root);
             }
         }
     });
     this.DialogResult = true;
     Close();
 }
Exemple #21
0
		AssemblyList DoLoadList(ILSpySettings spySettings, string listName)
		{
			XElement doc = spySettings["AssemblyLists"];
			if (listName != null) {
				foreach (var list in doc.Elements("List")) {
					if (SessionSettings.Unescape((string)list.Attribute("name")) == listName) {
						return new AssemblyList(list);
					}
				}
			}
			XElement firstList = doc.Elements("List").FirstOrDefault();
			if (firstList != null)
				return new AssemblyList(firstList);
			else
				return new AssemblyList(listName ?? DefaultListName);
		}
Exemple #22
0
        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            ILSpySettings spySettings = this.spySettings;

            this.spySettings = null;

            // Load AssemblyList only in Loaded event so that WPF is initialized before we start the CPU-heavy stuff.
            // This makes the UI come up a bit faster.
            this.assemblyList = assemblyListManager.LoadList(spySettings, sessionSettings.ActiveAssemblyList);

            HandleCommandLineArguments(App.CommandLineArguments);

            if (assemblyList.GetAssemblies().Length == 0 &&
                assemblyList.ListName == AssemblyListManager.DefaultListName)
            {
                LoadInitialAssemblies();
            }

            ShowAssemblyList(this.assemblyList);

            HandleCommandLineArgumentsAfterShowList(App.CommandLineArguments);
            if (App.CommandLineArguments.NavigateTo == null && App.CommandLineArguments.AssembliesToLoad.Count != 1)
            {
                SharpTreeNode node = FindNodeByPath(sessionSettings.ActiveTreeViewPath, true);
                if (node != null)
                {
                    SelectNode(node);

                    // only if not showing the about page, perform the update check:
                    ShowMessageIfUpdatesAvailableAsync(spySettings);
                }
                else
                {
                    AboutPage.Display(decompilerTextView);
                }
            }

            NavigationCommands.Search.InputGestures.Add(new KeyGesture(Key.E, ModifierKeys.Control));

            AvalonEditTextOutput output = new AvalonEditTextOutput();

            if (FormatExceptions(App.StartupExceptions.ToArray(), output))
            {
                decompilerTextView.ShowText(output);
            }
        }
Exemple #23
0
        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            DockWorkspace.Instance.Documents.Add(new DecompiledDocumentModel()
            {
                IsCloseable     = false,
                Language        = CurrentLanguage,
                LanguageVersion = CurrentLanguageVersion
            });
            DockWorkspace.Instance.ActiveDocument = DockWorkspace.Instance.Documents.First();

            ILSpySettings spySettings = this.spySettingsForMainWindow_Loaded;

            this.spySettingsForMainWindow_Loaded = null;
            var loadPreviousAssemblies = Options.MiscSettingsPanel.CurrentMiscSettings.LoadPreviousAssemblies;

            if (loadPreviousAssemblies)
            {
                // Load AssemblyList only in Loaded event so that WPF is initialized before we start the CPU-heavy stuff.
                // This makes the UI come up a bit faster.
                this.assemblyList = assemblyListManager.LoadList(spySettings, sessionSettings.ActiveAssemblyList);
            }
            else
            {
                this.assemblyList = new AssemblyList(AssemblyListManager.DefaultListName);
                assemblyListManager.ClearAll();
            }

            HandleCommandLineArguments(App.CommandLineArguments);

            if (assemblyList.GetAssemblies().Length == 0 &&
                assemblyList.ListName == AssemblyListManager.DefaultListName &&
                loadPreviousAssemblies)
            {
                LoadInitialAssemblies();
            }

            ShowAssemblyList(this.assemblyList);

            if (sessionSettings.ActiveAutoLoadedAssembly != null)
            {
                this.assemblyList.Open(sessionSettings.ActiveAutoLoadedAssembly, true);
            }

            Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(() => OpenAssemblies(spySettings)));
        }
Exemple #24
0
        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            ILSpySettings spySettings = this.spySettings;

            this.spySettings = null;

            // Load AssemblyList only in Loaded event so that WPF is initialized before we start the CPU-heavy stuff.
            // This makes the UI come up a bit faster.
            this.assemblyList = assemblyListManager.LoadList(spySettings, sessionSettings.ActiveAssemblyList);

            HandleCommandLineArguments(App.CommandLineArguments);

            if (assemblyList.GetAssemblies().Length == 0 &&
                assemblyList.ListName == AssemblyListManager.DefaultListName)
            {
                LoadInitialAssemblies();
            }

            ShowAssemblyList(this.assemblyList);

            HandleCommandLineArgumentsAfterShowList(App.CommandLineArguments);

            if (App.CommandLineArguments.NavigateTo == null)
            {
                SharpTreeNode node = FindNodeByPath(sessionSettings.ActiveTreeViewPath, true);
                if (node != null)
                {
                    SelectNode(node);

                    // only if not showing the about page, perform the update check:
                    ShowMessageIfUpdatesAvailableAsync(spySettings);
                }
                else
                {
                    AboutPage.Display(decompilerTextView);
                }
            }

            //Fires the OnLoaded notification to the plugins
            foreach (var x in applicationLifeCycleInterceptors)
            {
                x.Value.OnLoaded();
            }
        }
Exemple #25
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.ExportProvider.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"));
			output.AddVisualLineElementGenerator(new MyLinkElementGenerator("MS-PL", "resource:MS-PL.txt"));
			textView.ShowText(output);
		}
Exemple #26
0
		/// <summary>
		/// If automatic update checking is enabled, checks if there are any updates available.
		/// Returns the download URL if an update is available.
		/// Returns null if no update is available, or if no check was performed.
		/// </summary>
		public static Task<string> CheckForUpdatesIfEnabledAsync(ILSpySettings spySettings)
		{
			var tcs = new TaskCompletionSource<string>();
			UpdateSettings s = new UpdateSettings(spySettings);
			if (s.AutomaticUpdateCheckEnabled) {
				// perform update check if we never did one before;
				// or if the last check wasn't in the past 7 days
				if (s.LastSuccessfulUpdateCheck == null
					|| s.LastSuccessfulUpdateCheck < DateTime.UtcNow.AddDays(-7)
					|| s.LastSuccessfulUpdateCheck > DateTime.UtcNow) {
					CheckForUpdateInternal(tcs, s);
				} else {
					tcs.SetResult(null);
				}
			} else {
				tcs.SetResult(null);
			}
			return tcs.Task;
		}
Exemple #27
0
        public MainWindow()
        {
            instance                 = this;
            spySettings              = ILSpySettings.Load();
            this.sessionSettings     = new SessionSettings(spySettings);
            this.assemblyListManager = new AssemblyListManager(spySettings);

            if (Environment.OSVersion.Version.Major >= 6)
            {
                this.Icon = new BitmapImage(new Uri("pack://application:,,,/ILSpy;component/images/ILSpy.ico"));
            }
            else
            {
                this.Icon = Images.AssemblyLoading;
            }

            this.DataContext = sessionSettings;
            this.Left        = sessionSettings.WindowBounds.Left;
            this.Top         = sessionSettings.WindowBounds.Top;
            this.Width       = sessionSettings.WindowBounds.Width;
            this.Height      = sessionSettings.WindowBounds.Height;
            // TODO: validate bounds (maybe a monitor was removed...)
            this.WindowState = sessionSettings.WindowState;

            InitializeComponent();
            App.CompositionContainer.ComposeParts(this);
            Grid.SetRow(decompilerTextView, 1);
            rightPane.Children.Add(decompilerTextView);

            if (sessionSettings.SplitterPosition > 0 && sessionSettings.SplitterPosition < 1)
            {
                leftColumn.Width  = new GridLength(sessionSettings.SplitterPosition, GridUnitType.Star);
                rightColumn.Width = new GridLength(1 - sessionSettings.SplitterPosition, GridUnitType.Star);
            }
            sessionSettings.FilterSettings.PropertyChanged += filterSettings_PropertyChanged;

            InitMainMenu();
            InitToolbar();
            ContextMenuProvider.Add(treeView);
            ContextMenuProvider.Add(analyzerTree);

            this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
        }
Exemple #28
0
        /// <summary>
        /// If automatic update checking is enabled, checks if there are any updates available.
        /// Returns the download URL if an update is available.
        /// Returns null if no update is available, or if no check was performed.
        /// </summary>
        public static Task <string> CheckForUpdatesIfEnabledAsync(ILSpySettings spySettings)
        {
            var            tcs = new TaskCompletionSource <string>();
            UpdateSettings s   = new UpdateSettings(spySettings);

            if (s.AutomaticUpdateCheckEnabled)
            {
                // perform update check if we never did one before;
                // or if the last check wasn't in the past 7 days
                if (s.LastSuccessfulUpdateCheck == null ||
                    s.LastSuccessfulUpdateCheck < DateTime.UtcNow.AddDays(-7) ||
                    s.LastSuccessfulUpdateCheck > DateTime.UtcNow)
                {
                    GetLatestVersionAsync().ContinueWith(
                        delegate(Task <AvailableVersionInfo> task) {
                        try {
                            s.LastSuccessfulUpdateCheck = DateTime.UtcNow;
                            AvailableVersionInfo v      = task.Result;
                            if (v.Version > currentVersion)
                            {
                                tcs.SetResult(v.DownloadUrl);
                            }
                            else
                            {
                                tcs.SetResult(null);
                            }
                        } catch (AggregateException) {
                            // ignore errors getting the version info
                            tcs.SetResult(null);
                        }
                    });
                }
                else
                {
                    tcs.SetResult(null);
                }
            }
            else
            {
                tcs.SetResult(null);
            }
            return(tcs.Task);
        }
Exemple #29
0
        /// <summary>
        /// Called on startup or when passed arguments via WndProc from a second instance.
        /// In the format case, spySettings is non-null; in the latter it is null.
        /// </summary>
        void HandleCommandLineArgumentsAfterShowList(CommandLineArguments args, ILSpySettings spySettings = null)
        {
            if (nugetPackagesToLoad.Count > 0)
            {
                var relevantPackages = nugetPackagesToLoad.ToArray();
                nugetPackagesToLoad.Clear();
                // Show the nuget package open dialog after the command line/window message was processed.
                Dispatcher.BeginInvoke(new Action(() => LoadAssemblies(relevantPackages, commandLineLoadedAssemblies, focusNode: false)), DispatcherPriority.Normal);
            }
            var relevantAssemblies = commandLineLoadedAssemblies.ToList();

            commandLineLoadedAssemblies.Clear();             // clear references once we don't need them anymore
            NavigateOnLaunch(args.NavigateTo, sessionSettings.ActiveTreeViewPath, spySettings, relevantAssemblies);
            if (args.Search != null)
            {
                SearchPane.Instance.SearchTerm = args.Search;
                SearchPane.Instance.Show();
            }
        }
Exemple #30
0
        public void Save()
        {
            XElement doc = new XElement("SessionSettings");

            doc.Add(this.FilterSettings.SaveAsXml());
            if (this.ActiveAssemblyList != null)
            {
                doc.Add(new XElement("ActiveAssemblyList", this.ActiveAssemblyList));
            }
            if (this.ActiveTreeViewPath != null)
            {
                doc.Add(new XElement("ActiveTreeViewPath", ActiveTreeViewPath.Select(p => new XElement("Node", p))));
            }
            doc.Add(new XElement("WindowState", ToString(this.WindowState)));
            doc.Add(new XElement("WindowBounds", ToString(this.WindowBounds)));
            doc.Add(new XElement("SplitterPosition", ToString(this.SplitterPosition)));
            doc.Add(new XElement("AnalyzerSplitterPosition", ToString(this.AnalyzerSplitterPosition)));

            ILSpySettings.SaveSettings(doc);
        }
Exemple #31
0
        public OptionsDialog()
        {
            InitializeComponent();
            App.CompositionContainer.ComposeParts(this);
            ILSpySettings settings = ILSpySettings.Load();

            foreach (var optionPage in optionPages)
            {
                TabItem tabItem = new TabItem();
                tabItem.Header  = optionPage.Metadata.Title;
                tabItem.Content = optionPage.Value;
                tabControl.Items.Add(tabItem);

                IOptionPage page = optionPage.Value as IOptionPage;
                if (page != null)
                {
                    page.Load(settings);
                }
            }
        }
Exemple #32
0
        public async Task ShowMessageIfUpdatesAvailableAsync(ILSpySettings spySettings, bool forceCheck = false)
        {
            // Don't check for updates if we're in an MSIX since they work differently
            if (WindowsVersionHelper.HasPackageIdentity)
            {
                return;
            }

            string downloadUrl;

            if (forceCheck)
            {
                downloadUrl = await AboutPage.CheckForUpdatesAsync(spySettings);
            }
            else
            {
                downloadUrl = await AboutPage.CheckForUpdatesIfEnabledAsync(spySettings);
            }

            AdjustUpdateUIAfterCheck(downloadUrl, forceCheck);
        }
Exemple #33
0
 public bool DeleteList(string Name)
 {
     if (AssemblyLists.Remove(Name))
     {
         ILSpySettings.Update(
             delegate(XElement root) {
             XElement doc = root.Element("AssemblyLists");
             if (doc == null)
             {
                 return;
             }
             XElement listElement = doc.Elements("List").FirstOrDefault(e => (string)e.Attribute("name") == Name);
             if (listElement != null)
             {
                 listElement.Remove();
             }
         });
         return(true);
     }
     return(false);
 }
 /// <summary>
 /// Saves the specifies assembly list into the config file.
 /// </summary>
 public static void SaveList(AssemblyList list)
 {
     ILSpySettings.Update(
         delegate(XElement root) {
         XElement doc = root.Element("AssemblyLists");
         if (doc == null)
         {
             doc = new XElement("AssemblyLists");
             root.Add(doc);
         }
         XElement listElement = doc.Elements("List").FirstOrDefault(e => (string)e.Attribute("name") == list.ListName);
         if (listElement != null)
         {
             listElement.ReplaceWith(list.SaveAsXml());
         }
         else
         {
             doc.Add(list.SaveAsXml());
         }
     });
 }
Exemple #35
0
        public MainWindow()
        {
            instance = this;
            var spySettings = ILSpySettings.Load();

            this.spySettingsForMainWindow_Loaded = spySettings;
            this.sessionSettings     = new SessionSettings(spySettings);
            this.assemblyListManager = new AssemblyListManager(spySettings);

            this.Icon = new BitmapImage(new Uri("pack://application:,,,/ILSpy;component/images/ILSpy.ico"));

            this.DataContext = new MainWindowDataContext {
                Workspace       = DockWorkspace.Instance,
                SessionSettings = sessionSettings
            };

            DockWorkspace.Instance.LoadSettings(sessionSettings);

            InitializeComponent();

            XmlLayoutSerializer serializer = new XmlLayoutSerializer(DockManager);

            serializer.LayoutSerializationCallback += DockWorkspace.Instance.LayoutSerializationCallback;
            try {
                sessionSettings.DockLayout.Deserialize(serializer);
            } finally {
                serializer.LayoutSerializationCallback -= DockWorkspace.Instance.LayoutSerializationCallback;
            }

            DockWorkspace.Instance.EnsureUnclosablePanes();

            sessionSettings.FilterSettings.PropertyChanged += filterSettings_PropertyChanged;

            InitMainMenu();
            InitToolbar();
            ContextMenuProvider.Add(treeView);

            this.Loaded += MainWindow_Loaded;
        }
Exemple #36
0
        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            ILSpySettings spySettings = this.spySettings;

            this.spySettings = null;

            // Load AssemblyList only in Loaded event so that WPF is initialized before we start the CPU-heavy stuff.
            // This makes the UI come up a bit faster.
            this.assemblyList = assemblyListManager.LoadList(spySettings, sessionSettings.ActiveAssemblyList);

            HandleCommandLineArguments(App.CommandLineArguments);

            if (assemblyList.GetAssemblies().Length == 0 &&
                assemblyList.ListName == AssemblyListManager.DefaultListName)
            {
                LoadInitialAssemblies();
            }

            ShowAssemblyList(this.assemblyList);

            Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(() => OpenAssemblies(spySettings)));
        }
Exemple #37
0
        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            ILSpySettings spySettings = this.spySettings;

            this.spySettings = null;

            // Load AssemblyList only in Loaded event so that WPF is initialized before we start the CPU-heavy stuff.
            // This makes the UI come up a bit faster.
            this.assemblyList = assemblyListManager.LoadList(spySettings, sessionSettings.ActiveAssemblyList);

            ShowAssemblyList(this.assemblyList);

            string[] args = Environment.GetCommandLineArgs();
            for (int i = 1; i < args.Length; i++)
            {
                assemblyList.OpenAssembly(args[i]);
            }
            if (assemblyList.GetAssemblies().Length == 0)
            {
                LoadInitialAssemblies();
            }

            SharpTreeNode node = FindNodeByPath(sessionSettings.ActiveTreeViewPath, true);

            if (node != null)
            {
                SelectNode(node);

                // only if not showing the about page, perform the update check:
                ShowMessageIfUpdatesAvailableAsync(spySettings);
            }
            else
            {
                AboutPage.Display(decompilerTextView);
            }
        }
Exemple #38
0
        public SessionSettings(ILSpySettings spySettings)
        {
            XElement doc = spySettings["SessionSettings"];

            XElement filterSettings = doc.Element("FilterSettings");

            if (filterSettings == null)
            {
                filterSettings = new XElement("FilterSettings");
            }

            this.FilterSettings = new FilterSettings(filterSettings);

            this.ActiveAssemblyList = (string)doc.Element("ActiveAssemblyList");

            XElement activeTreeViewPath = doc.Element("ActiveTreeViewPath");

            if (activeTreeViewPath != null)
            {
                this.ActiveTreeViewPath = activeTreeViewPath.Elements().Select(e => Unescape((string)e)).ToArray();
            }
            this.ActiveAutoLoadedAssembly = (string)doc.Element("ActiveAutoLoadedAssembly");

            this.WindowState                = FromString((string)doc.Element("WindowState"), WindowState.Normal);
            this.WindowBounds               = FromString((string)doc.Element("WindowBounds"), DefaultWindowBounds);
            this.SplitterPosition           = FromString((string)doc.Element("SplitterPosition"), 0.4);
            this.TopPaneSplitterPosition    = FromString((string)doc.Element("TopPaneSplitterPosition"), 0.3);
            this.BottomPaneSplitterPosition = FromString((string)doc.Element("BottomPaneSplitterPosition"), 0.3);
            this.SelectedSearchMode         = FromString((string)doc.Element("SelectedSearchMode"), SearchMode.TypeAndMember);
            this.IsDarkMode = FromString((string)doc.Element(nameof(IsDarkMode)), false);
            string currentCulture = (string)doc.Element(nameof(CurrentCulture));

            this.CurrentCulture = string.IsNullOrEmpty(currentCulture) ? null : currentCulture;

            this.DockLayout = new DockLayoutSettings(doc.Element("DockLayout"));
        }
Exemple #39
0
 public void ShowMessageIfUpdatesAvailableAsync(ILSpySettings spySettings, bool forceCheck = false)
 {
     Task<string> result;
     if (forceCheck) {
         result = AboutPage.CheckForUpdatesAsync(spySettings);
     } else {
         result = AboutPage.CheckForUpdatesIfEnabledAsync(spySettings);
     }
     result.ContinueWith(task => AdjustUpdateUIAfterCheck(task, forceCheck), TaskScheduler.FromCurrentSynchronizationContext());
 }
Exemple #40
0
			public UpdateSettings(ILSpySettings spySettings)
			{
				XElement s = spySettings["UpdateSettings"];
				this.automaticUpdateCheckEnabled = (bool?)s.Element("AutomaticUpdateCheckEnabled") ?? true;
				try {
					this.lastSuccessfulUpdateCheck = (DateTime?)s.Element("LastSuccessfulUpdateCheck");
				} catch (FormatException) {
					// avoid crashing on settings files invalid due to
					// https://github.com/icsharpcode/ILSpy/issues/closed/#issue/2
				}
			}
Exemple #41
0
        public static void Display(DecompilerTextView textView)
        {
            AvalonEditTextOutput output = new AvalonEditTextOutput()
            {
                Title = Resources.About, EnableHyperlinks = true
            };

            output.WriteLine(Resources.ILSpyVersion + RevisionClass.FullVersion);
            if (WindowsVersionHelper.HasPackageIdentity)
            {
                output.WriteLine($"Package Name: {WindowsVersionHelper.GetPackageFamilyName()}");
            }
            else                // if we're running in an MSIX, updates work differently
            {
                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        = Resources.AutomaticallyCheckUpdatesEveryWeek;
                    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.ExportProvider.GetExportedValues <IAboutPageAddition>())
            {
                plugin.Write(output);
            }
            output.WriteLine();
            output.Address = new Uri("resource://AboutPage");
            using (Stream s = typeof(AboutPage).Assembly.GetManifestResourceStream(typeof(AboutPage), Resources.ILSpyAboutPageTxt)) {
                using (StreamReader r = new StreamReader(s)) {
                    string line;
                    while ((line = r.ReadLine()) != null)
                    {
                        output.WriteLine(line);
                    }
                }
            }
            output.AddVisualLineElementGenerator(new MyLinkElementGenerator("MIT License", "resource:license.txt"));
            output.AddVisualLineElementGenerator(new MyLinkElementGenerator("third-party notices", "resource:third-party-notices.txt"));
            textView.ShowText(output);
        }
Exemple #42
0
        public static Task <string> CheckForUpdatesAsync(ILSpySettings spySettings)
        {
            UpdateSettings s = new UpdateSettings(spySettings);

            return(CheckForUpdateInternal(s));
        }
Exemple #43
0
		public override void Load(ILSpySettings settings) {
			this.settings = DebuggerSettings.Instance.Clone();
			this.BreakProcessType = this.settings.BreakProcessType;
		}
Exemple #44
0
		public override void Load(ILSpySettings settings) {
			var xelem = settings[SETTINGS_SECTION_NAME];
			this.UseMemoryMappedIO = (bool?)xelem.Attribute("UseMemoryMappedIO") ?? true;
			this.DeserializeResources = (bool?)xelem.Attribute("DeserializeResources") ?? true;
		}
Exemple #45
0
        void LoadingHandler(int i)
        {
            switch (i) {
            case 0:
                this.CommandBindings.Add(new CommandBinding(ILSpyTreeNode.TreeNodeActivatedEvent, TreeNodeActivatedExecuted));

                ContextMenuProvider.Add(treeView);

                ILSpySettings spySettings = this.spySettings;
                this.spySettings = null;

                this.assemblyList = assemblyListManager.LoadList(spySettings, sessionSettings.ActiveAssemblyList);
                break;

            case 1:
                HandleCommandLineArguments(App.CommandLineArguments);

                if (assemblyList.GetAssemblies().Length == 0
                    && assemblyList.ListName == AssemblyListManager.DefaultListName) {
                    LoadInitialAssemblies();
                }

                ShowAssemblyListDontAskUser(this.assemblyList);
                break;

            case 2:
                HandleCommandLineArgumentsAfterShowList(App.CommandLineArguments);
                if (App.CommandLineArguments.NavigateTo == null && App.CommandLineArguments.AssembliesToLoad.Count != 1) {
                    if (ICSharpCode.ILSpy.Options.DisplaySettingsPanel.CurrentDisplaySettings.RestoreTabsAtStartup) {
                        RestoreTabGroups(sessionSettings.SavedTabGroupsState);
                        if (!sessionSettings.TabsFound)
                            AboutPage.Display(SafeActiveTextView);
                    }
                    else {
                        AboutPage.Display(SafeActiveTextView);
                    }
                }
                break;

            case 3:
                AvalonEditTextOutput output = new AvalonEditTextOutput();
                if (FormatExceptions(App.StartupExceptions.ToArray(), output))
                    SafeActiveTextView.ShowText(output);

                if (topPane.Content == null) {
                    var pane = GetPane(topPane, sessionSettings.TopPaneSettings.Name);
                    if (pane != null)
                        ShowInTopPane(pane.PaneTitle, pane);
                }
                if (bottomPane.Content == null) {
                    var pane = GetPane(bottomPane, sessionSettings.BottomPaneSettings.Name);
                    if (pane != null)
                        ShowInBottomPane(pane.PaneTitle, pane);
                }
                break;

            case 4:
                foreach (var plugin in plugins)
                    plugin.OnLoaded();

                var list = callWhenLoaded;
                callWhenLoaded = null;
                foreach (var func in list)
                    func();

                break;

            case 5:
                this.IsEnabled = true;

                // Make sure that when no tabs are created that we have focus. If we don't do this we
                // can't press Ctrl+K and open the asm search.
                this.Focus();

                // Sometimes we get keyboard focus when it's better that the text editor gets the focus instead
                this.GotKeyboardFocus += MainWindow_GotKeyboardFocus;

                loadingControl.Visibility = Visibility.Collapsed;
                mainGrid.Visibility = Visibility.Visible;

                // In case a plugin has added their own bindings
                UninstallTabCommandBindings(ActiveTabState);
                InstallTabCommandBindings(ActiveTabState);

                // Flickering workaround fix. Could reproduce it when using VMWare + WinXP
                loadingProgressBar.IsIndeterminate = false;
                return;
            default:
                return;
            }
            StartLoadingHandler(i + 1);
        }
Exemple #46
0
		void ShowMessageIfUpdatesAvailableAsync(ILSpySettings spySettings)
		{
			AboutPage.CheckForUpdatesIfEnabledAsync(spySettings).ContinueWith(
				delegate (Task<string> task) {
					if (task.Result != null) {
						updateAvailableDownloadUrl = task.Result;
						updateAvailablePanel.Visibility = Visibility.Visible;
					}
				},
				TaskScheduler.FromCurrentSynchronizationContext()
			);
		}
Exemple #47
0
		void MainWindow_Loaded(object sender, RoutedEventArgs e)
		{
			ILSpySettings spySettings = this.spySettings;
			this.spySettings = null;
			
			// Load AssemblyList only in Loaded event so that WPF is initialized before we start the CPU-heavy stuff.
			// This makes the UI come up a bit faster.
			this.assemblyList = assemblyListManager.LoadList(spySettings, sessionSettings.ActiveAssemblyList);
			
			HandleCommandLineArguments(App.CommandLineArguments);
			
			if (assemblyList.GetAssemblies().Length == 0
			    && assemblyList.ListName == AssemblyListManager.DefaultListName)
			{
				LoadInitialAssemblies();
			}
			
			ShowAssemblyList(this.assemblyList);
			
			HandleCommandLineArgumentsAfterShowList(App.CommandLineArguments);
			
			if (App.CommandLineArguments.NavigateTo == null) {
				SharpTreeNode node = FindNodeByPath(sessionSettings.ActiveTreeViewPath, true);
				if (node != null) {
					SelectNode(node);
					
					// only if not showing the about page, perform the update check:
					ShowMessageIfUpdatesAvailableAsync(spySettings);
				} else {
					AboutPage.Display(decompilerTextView);
				}
			}

            //Fires the OnLoaded notification to the plugins
            foreach (var x in applicationLifeCycleInterceptors)
                x.Value.OnLoaded();
		}
Exemple #48
0
		void MainWindow_Loaded(object sender, RoutedEventArgs e)
		{
			ILSpySettings spySettings = this.spySettings;
			this.spySettings = null;
			
			// Load AssemblyList only in Loaded event so that WPF is initialized before we start the CPU-heavy stuff.
			// This makes the UI come up a bit faster.
			this.assemblyList = assemblyListManager.LoadList(spySettings, sessionSettings.ActiveAssemblyList);
			
			HandleCommandLineArguments(App.CommandLineArguments);
			
			ShowAssemblyList(this.assemblyList);
			
			HandleCommandLineArgumentsAfterShowList(App.CommandLineArguments);
			if (App.CommandLineArguments.NavigateTo == null && App.CommandLineArguments.AssembliesToLoad.Count != 1) {
				SharpTreeNode node = FindNodeByPath(sessionSettings.ActiveTreeViewPath, true);
				if (node != null) {
					SelectNode(node);
					
					// only if not showing the about page, perform the update check:
					ShowMessageIfUpdatesAvailableAsync(spySettings);
				} else {
					AboutPage.Display(decompilerTextView);
				}
			}
			
			NavigationCommands.Search.InputGestures.Add(new KeyGesture(Key.E, ModifierKeys.Control));
			
			AvalonEditTextOutput output = new AvalonEditTextOutput();
			if (FormatExceptions(App.StartupExceptions.ToArray(), output))
				decompilerTextView.ShowText(output);
		}
Exemple #49
0
 public UpdateSettings(ILSpySettings spySettings)
 {
     XElement xElement = spySettings["UpdateSettings"];
     this.automaticUpdateCheckEnabled = (((bool?)xElement.Element("AutomaticUpdateCheckEnabled")) ?? true);
     try
     {
         this.lastSuccessfulUpdateCheck = (DateTime?)xElement.Element("LastSuccessfulUpdateCheck");
     }
     catch (FormatException)
     {
     }
 }
 public void Load(ILSpySettings settings)
 {
     this.DataContext = LoadDecompilerSettings(settings);
 }
Exemple #51
0
 public override async void Execute(object parameter)
 {
     await MainWindow.Instance.ShowMessageIfUpdatesAvailableAsync(ILSpySettings.Load(), forceCheck : true);
 }
		public void Load(ILSpySettings settings)
		{
			this.DataContext = LoadDecompilerSettings(settings);
		}
Exemple #53
0
		void MainWindow_Loaded(object sender, RoutedEventArgs e)
		{
			ILSpySettings spySettings = this.spySettings;
			this.spySettings = null;
			
			// Load AssemblyList only in Loaded event so that WPF is initialized before we start the CPU-heavy stuff.
			// This makes the UI come up a bit faster.
			this.assemblyList = assemblyListManager.LoadList(spySettings, sessionSettings.ActiveAssemblyList);
			
			HandleCommandLineArguments(App.CommandLineArguments);
			
			if (assemblyList.GetAssemblies().Length == 0
				&& assemblyList.ListName == AssemblyListManager.DefaultListName)
			{
				LoadInitialAssemblies();
			}
			
			ShowAssemblyList(this.assemblyList);
			
			HandleCommandLineArgumentsAfterShowList(App.CommandLineArguments);
			if (App.CommandLineArguments.NavigateTo == null && App.CommandLineArguments.AssembliesToLoad.Count != 1) {
				SharpTreeNode node = null;
				if (sessionSettings.ActiveTreeViewPath != null) {
					node = FindNodeByPath(sessionSettings.ActiveTreeViewPath, true);
					if (node == this.assemblyListTreeNode & sessionSettings.ActiveAutoLoadedAssembly != null) {
						this.assemblyList.OpenAssembly(sessionSettings.ActiveAutoLoadedAssembly, true);
						node = FindNodeByPath(sessionSettings.ActiveTreeViewPath, true);
					}
				}
				if (node != null) {
					SelectNode(node);
					
					// only if not showing the about page, perform the update check:
					ShowMessageIfUpdatesAvailableAsync(spySettings);
				} else {
					AboutPage.Display(decompilerTextView);
				}
			}
			
			AvalonEditTextOutput output = new AvalonEditTextOutput();
			if (FormatExceptions(App.StartupExceptions.ToArray(), output))
				decompilerTextView.ShowText(output);
		}
Exemple #54
0
		void MainWindow_Loaded(object sender, RoutedEventArgs e)
		{
		    this.Opacity = 0;

			ILSpySettings spySettings = this.spySettings;
			this.spySettings = null;
			
			// Load AssemblyList only in Loaded event so that WPF is initialized before we start the CPU-heavy stuff.
			// This makes the UI come up a bit faster.
			this.assemblyList = assemblyListManager.LoadList(spySettings, sessionSettings.ActiveAssemblyList);
			
			HandleCommandLineArguments(App.CommandLineArguments);
			
			if (assemblyList.GetAssemblies().Length == 0
			    && assemblyList.ListName == AssemblyListManager.DefaultListName)
			{
				LoadInitialAssemblies();
			}
			
			ShowAssemblyList(this.assemblyList);
			
			HandleCommandLineArgumentsAfterShowList(App.CommandLineArguments);
			
			if (App.CommandLineArguments.NavigateTo == null) {
				SharpTreeNode node = FindNodeByPath(sessionSettings.ActiveTreeViewPath, true);
				if (node != null) {
					SelectNode(node);
					
					// only if not showing the about page, perform the update check:
					ShowMessageIfUpdatesAvailableAsync(spySettings);
				} else {
					AboutPage.Display(decompilerTextView);
				}
			}

		    searchBox.DataContext = SearchPane.Instance;

            // setting the opacity to 0 and then using this code to set it back to 1 is kind of a hack to get 
            // around a problem where the window doesn't render properly when using the shell integration library
            // but it works, and it looks nice
		    Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => this.Opacity = 1));
		}
Exemple #55
0
        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            ILSpySettings spySettings = this.spySettings;
            this.spySettings = null;

            // Load AssemblyList only in Loaded event so that WPF is initialized before we start the CPU-heavy stuff.
            // This makes the UI come up a bit faster.
            this.assemblyList = assemblyListManager.LoadList(spySettings, sessionSettings.ActiveAssemblyList);

            ShowAssemblyList(this.assemblyList);

            string[] args = Environment.GetCommandLineArgs();
            for (int i = 1; i < args.Length; i++) {
                assemblyList.OpenAssembly(args[i]);
            }
            if (assemblyList.GetAssemblies().Length == 0)
                LoadInitialAssemblies();

            SharpTreeNode node = FindNodeByPath(sessionSettings.ActiveTreeViewPath, true);
            if (node != null) {
                SelectNode(node);

                // only if not showing the about page, perform the update check:
                ShowMessageIfUpdatesAvailableAsync(spySettings);
            } else {
                AboutPage.Display(decompilerTextView);
            }
        }
Exemple #56
0
 public static Task<string> CheckForUpdatesIfEnabledAsync(ILSpySettings spySettings)
 {
     TaskCompletionSource<string> tcs = new TaskCompletionSource<string>();
     AboutPage.UpdateSettings s = new AboutPage.UpdateSettings(spySettings);
     if (s.AutomaticUpdateCheckEnabled)
     {
         if (!s.LastSuccessfulUpdateCheck.HasValue || s.LastSuccessfulUpdateCheck < DateTime.UtcNow.AddDays(-7.0) || s.LastSuccessfulUpdateCheck > DateTime.UtcNow)
         {
             AboutPage.GetLatestVersionAsync().ContinueWith(delegate(Task<AboutPage.AvailableVersionInfo> task)
             {
                 try
                 {
                     s.LastSuccessfulUpdateCheck = new DateTime?(DateTime.UtcNow);
                     AboutPage.AvailableVersionInfo result = task.Result;
                     if (result.Version > AboutPage.currentVersion)
                     {
                         tcs.SetResult(result.DownloadUrl);
                     }
                     else
                     {
                         tcs.SetResult(null);
                     }
                 }
                 catch (AggregateException)
                 {
                     tcs.SetResult(null);
                 }
             });
         }
         else
         {
             tcs.SetResult(null);
         }
     }
     else
     {
         tcs.SetResult(null);
     }
     return tcs.Task;
 }
Exemple #57
0
        async void NavigateOnLaunch(string navigateTo, string[] activeTreeViewPath, ILSpySettings spySettings, List <LoadedAssembly> relevantAssemblies)
        {
            var initialSelection = treeView.SelectedItem;

            if (navigateTo != null)
            {
                bool found = false;
                if (navigateTo.StartsWith("N:", StringComparison.Ordinal))
                {
                    string namespaceName = navigateTo.Substring(2);
                    foreach (LoadedAssembly asm in relevantAssemblies)
                    {
                        AssemblyTreeNode asmNode = assemblyListTreeNode.FindAssemblyNode(asm);
                        if (asmNode != null)
                        {
                            // FindNamespaceNode() blocks the UI if the assembly is not yet loaded,
                            // so use an async wait instead.
                            await asm.GetPEFileAsync().Catch <Exception>(ex => { });

                            NamespaceTreeNode nsNode = asmNode.FindNamespaceNode(namespaceName);
                            if (nsNode != null)
                            {
                                found = true;
                                if (treeView.SelectedItem == initialSelection)
                                {
                                    SelectNode(nsNode);
                                }
                                break;
                            }
                        }
                    }
                }
                else if (navigateTo == "none")
                {
                    // Don't navigate anywhere; start empty.
                    // Used by ILSpy VS addin, it'll send us the real location to navigate to via IPC.
                    found = true;
                }
                else
                {
                    IEntity mr = await Task.Run(() => FindEntityInRelevantAssemblies(navigateTo, relevantAssemblies));

                    if (mr != null && mr.ParentModule.PEFile != null)
                    {
                        found = true;
                        if (treeView.SelectedItem == initialSelection)
                        {
                            JumpToReference(mr);
                        }
                    }
                }
                if (!found && treeView.SelectedItem == initialSelection)
                {
                    AvalonEditTextOutput output = new AvalonEditTextOutput();
                    output.Write(string.Format("Cannot find '{0}' in command line specified assemblies.", navigateTo));
                    decompilerTextView.ShowText(output);
                }
            }
            else if (relevantAssemblies.Count == 1)
            {
                // NavigateTo == null and an assembly was given on the command-line:
                // Select the newly loaded assembly
                AssemblyTreeNode asmNode = assemblyListTreeNode.FindAssemblyNode(relevantAssemblies[0]);
                if (asmNode != null && treeView.SelectedItem == initialSelection)
                {
                    SelectNode(asmNode);
                }
            }
            else if (spySettings != null)
            {
                SharpTreeNode node = null;
                if (activeTreeViewPath?.Length > 0)
                {
                    foreach (var asm in assemblyList.GetAssemblies())
                    {
                        if (asm.FileName == activeTreeViewPath[0])
                        {
                            // FindNodeByPath() blocks the UI if the assembly is not yet loaded,
                            // so use an async wait instead.
                            await asm.GetPEFileAsync().Catch <Exception>(ex => { });
                        }
                    }
                    node = FindNodeByPath(activeTreeViewPath, true);
                }
                if (treeView.SelectedItem == initialSelection)
                {
                    if (node != null)
                    {
                        SelectNode(node);

                        // only if not showing the about page, perform the update check:
                        await ShowMessageIfUpdatesAvailableAsync(spySettings);
                    }
                    else
                    {
                        AboutPage.Display(decompilerTextView);
                    }
                }
            }
        }
Exemple #58
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(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 }
                    });
                });
            }
            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(AboutPage), "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");

            //reset icon bar
            textView.manager.Bookmarks.Clear();
        }
Exemple #59
0
 void Load(ILSpySettings settings)
 {
     var csx = settings[SETTINGS_NAME];
     UseHexadecimal = (bool?)csx.Attribute("UseHexadecimal") ?? true;
     SyntaxHighlightCallStack = (bool?)csx.Attribute("SyntaxHighlightCallStack") ?? true;
     SyntaxHighlightBreakpoints = (bool?)csx.Attribute("SyntaxHighlightBreakpoints") ?? true;
     SyntaxHighlightThreads = (bool?)csx.Attribute("SyntaxHighlightThreads") ?? true;
     SyntaxHighlightModules = (bool?)csx.Attribute("SyntaxHighlightModules") ?? true;
     SyntaxHighlightLocals = (bool?)csx.Attribute("SyntaxHighlightLocals") ?? true;
     SyntaxHighlightAttach = (bool?)csx.Attribute("SyntaxHighlightAttach") ?? true;
     SyntaxHighlightExceptions = (bool?)csx.Attribute("SyntaxHighlightExceptions") ?? true;
     BreakProcessType = (BreakProcessType)((int?)csx.Attribute("BreakProcessType") ?? (int)BreakProcessType.ModuleCctorOrEntryPoint);
     PropertyEvalAndFunctionCalls = (bool?)csx.Attribute("PropertyEvalAndFunctionCalls") ?? true;
     UseStringConversionFunction = (bool?)csx.Attribute("UseStringConversionFunction") ?? true;
     DebuggerBrowsableAttributesCanHidePropsFields = (bool?)csx.Attribute("DebuggerBrowsableAttributesCanHidePropsFields") ?? true;
     CompilerGeneratedAttributesCanHideFields = (bool?)csx.Attribute("CompilerGeneratedAttributesCanHideFields") ?? true;
     DisableManagedDebuggerDetection = (bool?)csx.Attribute("DisableManagedDebuggerDetection") ?? true;
     IgnoreBreakInstructions = (bool?)csx.Attribute("IgnoreBreakInstructions") ?? false;
     CoreCLRDbgShimFilename = SessionSettings.Unescape((string)csx.Attribute("CoreCLRDbgShimFilename") ?? string.Empty);
 }
Exemple #60
0
        public MainWindow()
        {
            instance = this;
            mainMenu = new Menu();
            spySettings = ILSpySettings.Load();
            this.sessionSettings = new SessionSettings(spySettings);
            this.sessionSettings.PropertyChanged += sessionSettings_PropertyChanged;
            this.assemblyListManager = new AssemblyListManager(spySettings);
            Themes.ThemeChanged += Themes_ThemeChanged;
            Themes.IsHighContrastChanged += (s, e) => Themes.SwitchThemeIfNecessary();
            Options.DisplaySettingsPanel.CurrentDisplaySettings.PropertyChanged += CurrentDisplaySettings_PropertyChanged;
            OtherSettings.Instance.PropertyChanged += OtherSettings_PropertyChanged;
            InitializeTextEditorFontResource();

            languageComboBox = new ComboBox() {
                DisplayMemberPath = "Name",
                Width = 100,
                ItemsSource = Languages.AllLanguages,
            };
            languageComboBox.SetBinding(ComboBox.SelectedItemProperty, new Binding("FilterSettings.Language") {
                Source = sessionSettings,
            });

            InitializeComponent();
            AddTitleInfo(IntPtr.Size == 4 ? "x86" : "x64");
            App.CompositionContainer.ComposeParts(this);

            if (sessionSettings.LeftColumnWidth > 0)
                leftColumn.Width = new GridLength(sessionSettings.LeftColumnWidth, GridUnitType.Pixel);
            sessionSettings.FilterSettings.PropertyChanged += filterSettings_PropertyChanged;

            InstallCommands();

            tabGroupsManager = new TabGroupsManager<TabState>(tabGroupsContentPresenter, tabManager_OnSelectionChanged, tabManager_OnAddRemoveTabState);
            tabGroupsManager.OnTabGroupSelected += tabGroupsManager_OnTabGroupSelected;
            var theme = Themes.GetThemeOrDefault(sessionSettings.ThemeName);
            if (theme.IsHighContrast != Themes.IsHighContrast)
                theme = Themes.GetThemeOrDefault(Themes.CurrentDefaultThemeName) ?? theme;
            Themes.Theme = theme;
            InitializeAssemblyTreeView(treeView);

            InitMainMenu();
            InitToolbar();
            loadingImage.Source = ImageCache.Instance.GetImage("dnSpy-Big", theme.GetColor(ColorType.EnvironmentBackground).InheritedColor.Background.GetColor(null).Value);

            this.Activated += (s, e) => UpdateSystemMenuImage();
            this.Deactivated += (s, e) => UpdateSystemMenuImage();
            this.ContentRendered += MainWindow_ContentRendered;
            this.IsEnabled = false;
        }