public MainClass(string [] args) { Ticker.Tick(); // required for the MS .NET runtime that doesn't initialize glib automatically if (!GLib.Thread.Supported) { GLib.Thread.Init(); } // Connect to dbus DBusInstance DBusInstance = ServiceManager.Get <DBusInstance> (); DBusInstance.Initialise(); if (DBusInstance.AlreadyRunning) { Console.WriteLine("Already running"); DBusInstance.CommandParser.ParseCommands(args); return; } DBusInstance.CommandParser.RunCommand += HandleCommand; Ticker.Tick(); CheckDataFolders(); Ticker.Tock("Checking folders"); foreach (string arg in args) { HandleCommand(arg); } Ticker.Tick(); if (DebugEnabled) { BuildNlogConfig(); } logger = DebugEnabled ? NLog.LogManager.GetCurrentClassLogger() : new EmptyLogger(); Ticker.Tock("NLog"); logger.Info("Starting Monsoon"); Ticker.Tick(); SetProcessName("monsoon"); Ticker.Tock("Setting process name"); string localeDir = Path.Combine(Defines.ApplicationDirectory, "locale"); if (!Directory.Exists(localeDir)) { localeDir = Path.Combine(Defines.InstallPrefix, "share"); localeDir = Path.Combine(localeDir, "locale"); } Ticker.Tick(); Mono.Unix.Catalog.Init("monsoon", localeDir); logger.Debug("Using locale data from: {0}", localeDir); Application.Init("monsoon", ref args); Ticker.Tock("Locale"); try { SettingsManager.Restore <EngineSettings> (SettingsManager.EngineSettings); SettingsManager.Restore <PreferencesSettings> (SettingsManager.Preferences); SettingsManager.Restore <TorrentSettings> (SettingsManager.DefaultTorrentSettings); } catch (Exception ex) { logger.Error("Couldn't restore old settings: {0}", ex.Message); } try { Ticker.Tick(); mainWindow = new MainWindow(); Ticker.Tock("Instantiating window"); } catch (Exception e) { logger.ErrorException(e.Message, e); Environment.Exit(0); } LoadAddins(); GLib.ExceptionManager.UnhandledException += new GLib.UnhandledExceptionHandler(OnUnhandledException); Ticker.Tock("Total time:"); Application.Run(); try { SettingsManager.Store <EngineSettings> (SettingsManager.EngineSettings); SettingsManager.Store <PreferencesSettings> (SettingsManager.Preferences); SettingsManager.Store <TorrentSettings> (SettingsManager.DefaultTorrentSettings); } catch (Exception ex) { logger.Error("Could save engine settings: {0}", ex.Message); } ServiceManager.Get <ListenPortController> ().Stop(); mainWindow.Destroy(); }