~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Ide/MonoDevelop.Ide/IdeStartup.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
80
80
                                LoggingService.LogInfo ("Logging instrumentation service data to file: " + logFile);
81
81
                                InstrumentationService.StartAutoSave (logFile, 1000);
82
82
                        }
 
83
 
 
84
                        //ensure native libs initialized before we hit anything that p/invokes
 
85
                        Platform.Initialize ();
83
86
                        
84
87
                        Counters.Initialization.Trace ("Initializing GTK");
 
88
                        if (Platform.IsWindows) {
 
89
                                CheckWindowsGtk ();
 
90
                        }
85
91
                        SetupExceptionManager ();
86
92
                        
87
93
                        try {
89
95
                        } catch (Exception ex) {
90
96
                                LoggingService.LogError ("Error initialising GLib logging.", ex);
91
97
                        }
92
 
                        
93
 
                        //OSXFIXME
 
98
 
 
99
                        SetupTheme ();
 
100
 
94
101
                        var args = options.RemainingArgs.ToArray ();
95
 
                        Gtk.Application.Init ("monodevelop", ref args);
96
 
                        
 
102
                        Gtk.Application.Init (BrandingService.ApplicationName, ref args);
 
103
 
 
104
                        FilePath p = typeof(IdeStartup).Assembly.Location;
 
105
                        Assembly.LoadFrom (p.ParentDirectory.Combine ("Xwt.Gtk.dll"));
 
106
                        Xwt.Application.Initialize (Xwt.ToolkitType.Gtk);
 
107
                        Xwt.Engine.Toolkit.ExitUserCode (null);
 
108
 
97
109
                        //default to Windows IME on Windows
98
110
                        if (Platform.IsWindows && Mono.TextEditor.GtkWorkarounds.GtkMinorVersion >= 16) {
99
111
                                var settings = Gtk.Settings.Default;
128
140
                                }
129
141
                        }
130
142
                        
 
143
                        Counters.Initialization.Trace ("Initializing Runtime");
 
144
                        Runtime.Initialize (true);
 
145
 
 
146
                        Counters.Initialization.Trace ("Initializing theme and splash window");
 
147
 
131
148
                        DefaultTheme = Gtk.Settings.Default.ThemeName;
132
 
                        if (!string.IsNullOrEmpty (IdeApp.Preferences.UserInterfaceTheme))
133
 
                                Gtk.Settings.Default.ThemeName = IdeApp.Preferences.UserInterfaceTheme;
 
149
                        if (!string.IsNullOrEmpty (IdeApp.Preferences.UserInterfaceTheme)) {
 
150
                                string theme;
 
151
                                if (!ValidateGtkTheme (IdeApp.Preferences.UserInterfaceTheme, out theme))
 
152
                                        return 1;
 
153
                                Gtk.Settings.Default.ThemeName = theme;
 
154
                        }
134
155
                        
135
156
                        //don't show the splash screen on the Mac, so instead we get the expected "Dock bounce" effect
136
157
                        //this also enables the Mac platform service to subscribe to open document events before the GUI loop starts.
137
158
                        if (Platform.IsMac)
138
159
                                options.NoSplash = true;
139
160
                        
140
 
                        IProgressMonitor monitor;
141
 
                        
142
 
                        if (options.NoSplash) {
 
161
                        IProgressMonitor monitor = null;
 
162
                        if (!options.NoSplash) {
 
163
                                try {
 
164
                                        monitor = new SplashScreenForm ();
 
165
                                        ((SplashScreenForm)monitor).ShowAll ();
 
166
                                } catch (Exception ex) {
 
167
                                        LoggingService.LogError ("Failed to create splash screen", ex);
 
168
                                }
 
169
                        }
 
170
                        if (monitor == null) {
143
171
                                monitor = new MonoDevelop.Core.ProgressMonitoring.ConsoleProgressMonitor ();
144
 
                        } else {
145
 
                                monitor = SplashScreenForm.SplashScreen;
146
 
                                SplashScreenForm.SplashScreen.ShowAll ();
147
172
                        }
148
173
                        
149
 
                        Counters.Initialization.Trace ("Initializing Runtime");
150
 
                        monitor.BeginTask (GettextCatalog.GetString ("Starting {0}", BrandingService.ApplicationName), 3);
151
 
                        monitor.Step (1);
152
 
                        Runtime.Initialize (true);
153
 
                        
 
174
                        monitor.BeginTask (GettextCatalog.GetString ("Starting {0}", BrandingService.ApplicationName), 2);
 
175
 
154
176
                        //make sure that the platform service is initialised so that the Mac platform can subscribe to open-document events
155
177
                        Counters.Initialization.Trace ("Initializing Platform Service");
156
178
                        DesktopService.Initialize ();
190
212
                                version += "." + Assembly.GetEntryAssembly ().GetName ().Version.Build;
191
213
                        if (Assembly.GetEntryAssembly ().GetName ().Version.Revision != 0)
192
214
                                version += "." + Assembly.GetEntryAssembly ().GetName ().Version.Revision;
193
 
                        
194
 
                        // System checks
195
 
                        if (!CheckBug77135 ())
196
 
                                return 1;
197
 
                        
198
 
                        if (!CheckQtCurve ())
199
 
                                return 1;
200
215
 
201
216
                        CheckFileWatcher ();
202
217
                        
210
225
                                
211
226
                                if (errorsList.Count > 0) {
212
227
                                        if (monitor is SplashScreenForm)
213
 
                                                SplashScreenForm.SplashScreen.Hide ();
 
228
                                                ((SplashScreenForm)monitor).Hide ();
214
229
                                        AddinLoadErrorDialog dlg = new AddinLoadErrorDialog ((AddinError[]) errorsList.ToArray (typeof(AddinError)), false);
215
230
                                        if (!dlg.Run ())
216
231
                                                return 1;
217
232
                                        if (monitor is SplashScreenForm)
218
 
                                                SplashScreenForm.SplashScreen.Show ();
 
233
                                                ((SplashScreenForm)monitor).Show ();
219
234
                                        reportedFailures = errorsList.Count;
220
235
                                }
221
236
                                
240
255
                        if (error != null) {
241
256
                                LoggingService.LogFatalError (null, error);
242
257
                                MessageService.ShowException (error,
243
 
                                                              GettextCatalog.GetString ("MonoDevelop failed to start. The following error has been reported: ") + error.Message);
 
258
                                                              BrandingService.BrandApplicationName (GettextCatalog.GetString ("MonoDevelop failed to start. The following error has been reported: ") + error.Message));
244
259
                                return 1;
245
260
                        }
246
261
 
280
295
                        
281
296
                        return 0;
282
297
                }
 
298
 
 
299
                void SetupTheme ()
 
300
                {
 
301
                        // Use the bundled gtkrc only if the Xamarin theme is installed
 
302
                        if (File.Exists (Path.Combine (Gtk.Rc.ModuleDir, "libxamarin.so")) || File.Exists (Path.Combine (Gtk.Rc.ModuleDir, "libxamarin.dll"))) {
 
303
                                var gtkrc = "gtkrc";
 
304
                                if (Platform.IsWindows) {
 
305
                                        gtkrc += ".win32";
 
306
                                } else if (Platform.IsMac) {
 
307
                                        gtkrc += ".mac";
 
308
                                }
 
309
                                Environment.SetEnvironmentVariable ("GTK2_RC_FILES", PropertyService.EntryAssemblyPath.Combine (gtkrc));
 
310
                        }
 
311
                }
 
312
 
 
313
                [System.Runtime.InteropServices.DllImport("kernel32.dll", CharSet = System.Runtime.InteropServices.CharSet.Unicode, SetLastError = true)]
 
314
                [return: System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)]
 
315
                static extern bool SetDllDirectory (string lpPathName);
 
316
 
 
317
                static void CheckWindowsGtk ()
 
318
                {
 
319
                        string location = null;
 
320
                        using (var key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Xamarin\GtkSharp\InstallFolder")) {
 
321
                                if (key != null) {
 
322
                                        location = key.GetValue (null) as string;
 
323
                                }
 
324
                        }
 
325
                        if (location == null || !File.Exists (Path.Combine (location, "bin", "libgtk-win32-2.0-0.dll"))) {
 
326
                                LoggingService.LogError ("Did not find registered GTK# installation");
 
327
                                return;
 
328
                        }
 
329
                        var path = Path.Combine (location, @"bin");
 
330
                        try {
 
331
                                if (SetDllDirectory (path)) {
 
332
                                        return;
 
333
                                }
 
334
                        } catch (EntryPointNotFoundException) {
 
335
                        }
 
336
                        LoggingService.LogError ("Unable to set GTK# dll directory");
 
337
                }
283
338
                
284
339
                public bool Initialized {
285
340
                        get { return initialized; }
355
410
                        IdeApp.Workbench.Present ();
356
411
                        return false;
357
412
                }
358
 
                
359
 
                bool CheckQtCurve ()
 
413
 
 
414
                internal readonly static string[] FailingGtkThemes = new string[] {
 
415
                        "QtCurve",
 
416
                        "oxygen-gtk"
 
417
                };
 
418
 
 
419
                internal static string[] gtkThemeFallbacks = new string[] {
 
420
                        "Gilouche", // SUSE
 
421
                        "Mint-X", // MINT
 
422
                        "Radiance", // Ubuntu 'light' theme (MD looks better with the light theme in 4.0 - if that changes switch this one)
 
423
                        "Clearlooks" // GTK theme
 
424
                };
 
425
 
 
426
                bool ValidateGtkTheme (string requestedTheme, out string validTheme)
360
427
                {
361
 
                        if (Gtk.Settings.Default.ThemeName == "QtCurve") {
362
 
                                string msg = "QtCurve theme not supported";
363
 
                                string desc = "Your system is using the QtCurve GTK+ theme. This theme is known to cause stability issues in MonoDevelop. Please select another theme in the GTK+ Theme Selector.\n\nIf you click on Proceed, MonoDevelop will switch to the default GTK+ theme.";
364
 
                                AlertButton res = MessageService.GenericAlert (Gtk.Stock.DialogWarning, msg, desc, AlertButton.Cancel, AlertButton.Proceed);
365
 
                                if (res == AlertButton.Cancel)
366
 
                                        return false;
367
 
                                Gtk.Settings.Default.ThemeName = "Gilouche";
 
428
                        foreach (var theme in FailingGtkThemes) {
 
429
                                if (requestedTheme == theme) {
 
430
                                        string msg = theme +" theme not supported";
 
431
                                        string desc = "Your system is using the " + theme + " GTK+ theme. This theme is known to cause stability issues in MonoDevelop. Please select another theme in the GTK+ Theme Selector.\n\nIf you click on Proceed, MonoDevelop will switch to the default GTK+ theme.";
 
432
                                        AlertButton res = MessageService.GenericAlert (Gtk.Stock.DialogWarning, msg, desc, AlertButton.Cancel, AlertButton.Proceed);
 
433
                                        if (res == AlertButton.Cancel) {
 
434
                                                validTheme = null;
 
435
                                                return false;
 
436
                                        }
 
437
                                        var themes = MonoDevelop.Ide.Gui.OptionPanels.IDEStyleOptionsPanelWidget.InstalledThemes;
 
438
                                        string fallback = null;
 
439
                                        foreach (string fb in gtkThemeFallbacks) {
 
440
                                                var foundTheme = themes.FirstOrDefault (t => string.Compare (fb, t, StringComparison.OrdinalIgnoreCase) == 0);
 
441
                                                if (foundTheme != null) {
 
442
                                                        fallback = foundTheme;
 
443
                                                        break;
 
444
                                                }
 
445
                                        }
 
446
 
 
447
                                        validTheme = fallback ?? themes.FirstOrDefault () ?? requestedTheme;
 
448
                                        return validTheme != null;
 
449
                                }
368
450
                        }
 
451
 
 
452
                        validTheme = requestedTheme;
369
453
                        return true;
370
454
                }
371
455
                
380
464
                                                string msg = "Inotify watch limit is too low (" + n + ").\n";
381
465
                                                msg += "MonoDevelop will switch to managed file watching.\n";
382
466
                                                msg += "See http://monodevelop.com/Inotify_Watches_Limit for more info.";
383
 
                                                LoggingService.LogWarning (msg);
 
467
                                                LoggingService.LogWarning (BrandingService.BrandApplicationName (msg));
384
468
                                                Runtime.ProcessService.EnvironmentVariableOverrides["MONO_MANAGED_WATCHER"] = 
385
469
                                                        Environment.GetEnvironmentVariable ("MONO_MANAGED_WATCHER");
386
470
                                                Environment.SetEnvironmentVariable ("MONO_MANAGED_WATCHER", "1");
390
474
                                LoggingService.LogWarning ("There was a problem checking whether to use managed file watching", e);
391
475
                        }
392
476
                }
393
 
                
394
 
                bool CheckBug77135 ()
395
 
                {
396
 
                        try {
397
 
                                // Check for bug 77135. Some versions of gnome-vfs2 and libgda
398
 
                                // make MD crash in the file open dialog or in FileIconLoader.
399
 
                                // Only in Suse.
400
 
                                
401
 
                                string path = "/etc/SuSE-release";
402
 
                                if (!File.Exists (path))
403
 
                                        return true;
404
 
                                        
405
 
                                // Only run the check for SUSE 10
406
 
                                StreamReader sr = File.OpenText (path);
407
 
                                string txt = sr.ReadToEnd ();
408
 
                                sr.Close ();
409
 
                                
410
 
                                if (txt.IndexOf ("SUSE LINUX 10") == -1)
411
 
                                        return true;
412
 
                                        
413
 
                                string current_libgda;
414
 
                                string current_gnomevfs;
415
 
                                string required_libgda = "1.3.91.5.4";
416
 
                                string required_gnomevfs = "2.12.0.9.2";
417
 
                                
418
 
                                StringWriter sw = new StringWriter ();
419
 
                                ProcessWrapper pw = Runtime.ProcessService.StartProcess ("rpm", "--qf %{version}.%{release} -q libgda", null, sw, null, null);
420
 
                                pw.WaitForOutput ();
421
 
                                current_libgda = sw.ToString ().Trim (' ','\n');
422
 
                                
423
 
                                sw = new StringWriter ();
424
 
                                pw = Runtime.ProcessService.StartProcess ("rpm", "--qf %{version}.%{release} -q gnome-vfs2", null, sw, null, null);
425
 
                                pw.WaitForOutput ();
426
 
                                current_gnomevfs = sw.ToString ().Trim (' ','\n');
427
 
                                
428
 
                                bool fail1 = Addin.CompareVersions (current_libgda, required_libgda) == 1;
429
 
                                bool fail2 = Addin.CompareVersions (current_gnomevfs, required_gnomevfs) == 1;
430
 
                                
431
 
                                if (fail1 || fail2) {
432
 
                                        string msg = GettextCatalog.GetString ("Some packages installed in your system are not compatible with MonoDevelop:\n");
433
 
                                        if (fail1)
434
 
                                                msg += "\nlibgda " + current_libgda + " ("+ GettextCatalog.GetString ("version required: {0}", required_libgda) + ")";
435
 
                                        if (fail2)
436
 
                                                msg += "\ngnome-vfs2 " + current_gnomevfs + " ("+ GettextCatalog.GetString ("version required: {0}", required_gnomevfs) + ")";
437
 
                                        msg += "\n\n";
438
 
                                        msg += GettextCatalog.GetString ("You need to upgrade the previous packages to start using MonoDevelop.");
439
 
                                        
440
 
                                        SplashScreenForm.SplashScreen.Hide ();
441
 
                                        Gtk.MessageDialog dlg = new Gtk.MessageDialog (null, Gtk.DialogFlags.Modal, Gtk.MessageType.Error, Gtk.ButtonsType.Ok, msg);
442
 
                                        dlg.Run ();
443
 
                                        dlg.Destroy ();
444
 
                                        
445
 
                                        return false;
446
 
                                } else
447
 
                                        return true;
448
 
                        }
449
 
                        catch (Exception ex)
450
 
                        {
451
 
                                // Just ignore for now.
452
 
                                Console.WriteLine (ex);
453
 
                                return true;
454
 
                        }
455
 
                }
456
 
                
 
477
 
457
478
                void SetupExceptionManager ()
458
479
                {
 
480
                        System.Threading.Tasks.TaskScheduler.UnobservedTaskException += (sender, e) => {
 
481
                                HandleException (e.Exception.Flatten (), false);
 
482
                                e.SetObserved ();
 
483
                        };
459
484
                        GLib.ExceptionManager.UnhandledException += delegate (GLib.UnhandledExceptionArgs args) {
460
485
                                HandleException ((Exception)args.ExceptionObject, args.IsTerminating);
461
486
                        };
462
487
                        AppDomain.CurrentDomain.UnhandledException += delegate (object sender, UnhandledExceptionEventArgs args) {
463
488
                                HandleException ((Exception)args.ExceptionObject, args.IsTerminating);
464
489
                        };
 
490
                        Xwt.Application.UnhandledException += (sender, e) => {
 
491
                                HandleException (e.ErrorException, false);
 
492
                        };
465
493
                }
466
494
                
467
495
                void HandleException (Exception ex, bool willShutdown)
498
526
                        bool retry = false;
499
527
                        do {
500
528
                                try {
501
 
                                        Runtime.SetProcessName (BrandingService.ApplicationName);
 
529
                                        var exename = Path.GetFileNameWithoutExtension (Assembly.GetEntryAssembly ().Location);
 
530
                                        if (!Platform.IsMac && !Platform.IsWindows)
 
531
                                                exename = exename.ToLower ();
 
532
                                        Runtime.SetProcessName (exename);
502
533
                                        var app = new IdeStartup ();
503
534
                                        ret = app.Run (options);
504
535
                                        break;
505
536
                                } catch (Exception ex) {
506
537
                                        if (!retry && AddinManager.IsInitialized) {
507
 
                                                LoggingService.LogWarning (BrandingService.ApplicationName + " failed to start. Rebuilding addins registry.");
 
538
                                                LoggingService.LogWarning (BrandingService.ApplicationName + " failed to start. Rebuilding addins registry.", ex);
508
539
                                                AddinManager.Registry.Rebuild (new Mono.Addins.ConsoleProgressStatus (true));
509
 
                                                LoggingService.LogInfo ("Addin registry rebuilt. Restarting MonoDevelop.");
 
540
                                                LoggingService.LogInfo ("Addin registry rebuilt. Restarting {0}.", BrandingService.ApplicationName);
510
541
                                                retry = true;
511
542
                                        } else {
512
 
                                                LoggingService.LogFatalError (BrandingService.ApplicationName + " failed to start. Some of the assemblies required to run MonoDevelop (for example gtk-sharp, gnome-sharp or gtkhtml-sharp) may not be properly installed in the GAC.", ex);
 
543
                                                LoggingService.LogFatalError (
 
544
                                                        string.Format (
 
545
                                                                "{0} failed to start. Some of the assemblies required to run {0} (for example gtk-sharp)" +
 
546
                                                                "may not be properly installed in the GAC.",
 
547
                                                                BrandingService.ApplicationName
 
548
                                                        ), ex);
513
549
                                                retry = false;
514
550
                                        }
515
551
                                } finally {