示例#1
0
        private void AlephNote_Startup()
        {
            DispatcherUnhandledException         += AppDispatcherUnhandledException;
            Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;

            AlephAppContext.Init(new AlephWPFContext());

            LoggerSingleton.Register(new EventLogger());
            PluginManagerSingleton.Register(PluginMan);
            ThemeManager.Register(Themes);

            Args = new CommandLineArguments(Environment.GetCommandLineArgs(), false);

            if (Args.Contains("debug"))
            {
                DebugMode = true;
            }

            UpdateMigrationFrom = Args.GetVersionDefault("migration_from", default(Version));
            UpdateMigrationTo   = Args.GetVersionDefault("migration_to", default(Version));

            IsUpdateMigration = (UpdateMigrationFrom != default(Version)) && (UpdateMigrationTo != default(Version)) && Args.Contains("updated");

#if DEBUG
            DebugMode = true;
#endif
            PluginManager.Inst.LoadPlugins(AppDomain.CurrentDomain.BaseDirectory);
            App.Themes.Init(Args.GetStringDefault("themes", Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "themes")));

            AppSettings settings;
            try
            {
                if (File.Exists(AppSettings.PATH_SETTINGS))
                {
                    settings = AppSettings.Load(AppSettings.PATH_SETTINGS);
                    if (IsUpdateMigration)
                    {
                        settings.Migrate(UpdateMigrationFrom, UpdateMigrationTo);
                        settings.Save();
                    }
                }
                else
                {
                    settings = AppSettings.CreateEmpty(AppSettings.PATH_SETTINGS);
                    settings.Save();

                    IsFirstLaunch = true;
                }
            }
            catch (Exception e)
            {
                ExceptionDialog.Show(null, "Could not load settings", "Could not load settings from " + AppSettings.PATH_SETTINGS, e);
                settings = AppSettings.CreateEmpty(AppSettings.PATH_SETTINGS);
            }

            AlephAppContext.SetFallbackSettings(settings);             // [HACK] used if someone accesses Context.Settings before there is an context ...

            if (settings.LockOnStartup && !settings.IsReadOnlyMode)
            {
                settings.IsReadOnlyMode = true;
            }
            if (settings.ForceDebugMode)
            {
                DebugMode = true;
            }
            if (settings.DisableLogger)
            {
                LoggerSingleton.Swap(new VoidLogger());
            }

            ThemeManager.Inst.LoadWithErrorDialog(settings);

            if (settings.SingleInstanceMode)
            {
                var mtx = new Mutex(true, "AlephNoteApp_" + settings.ClientID);
                if (!mtx.WaitOne(TimeSpan.Zero, true))
                {
                    NativeMethods.PostMessage(
                        (IntPtr)NativeMethods.HWND_BROADCAST,
                        NativeMethods.WM_SHOWME,
                        IntPtr.Zero,
                        IntPtr.Zero);

                    return;
                }
            }

            var mw = new MainWindow(settings);

            if (!(settings.MinimizeToTray && settings.StartupState == ExtendedWindowState.Minimized))
            {
                mw.Show();
            }
        }
示例#2
0
        private void Application_Startup(object sender, StartupEventArgs suea)
        {
            DispatcherUnhandledException         += AppDispatcherUnhandledException;
            Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;

            LoggerSingleton.Register(Logger);
            PluginManagerSingleton.Register(PluginMan);
            ThemeManager.Register(Themes);

            Args = new CommandLineArguments(Environment.GetCommandLineArgs(), false);

            if (Args.Contains("debug"))
            {
                DebugMode = true;
            }

            UpdateMigrationFrom = Args.GetVersionDefault("migration_from", default(Version));
            UpdateMigrationTo   = Args.GetVersionDefault("migration_to", default(Version));

            IsUpdateMigration = (UpdateMigrationFrom != default(Version)) && (UpdateMigrationTo != default(Version)) && Args.Contains("updated");

#if DEBUG
            DebugMode = true;
#endif
            Logger.DebugEnabled = DebugMode;

            PluginManager.Inst.LoadPlugins(AppDomain.CurrentDomain.BaseDirectory);
            App.Themes.Init(Args.GetStringDefault("themes", Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "themes")));

            AppSettings settings;
            try
            {
                if (File.Exists(PATH_SETTINGS))
                {
                    settings = AppSettings.Load(PATH_SETTINGS);
                    if (IsUpdateMigration)
                    {
                        settings.Migrate(UpdateMigrationFrom, UpdateMigrationTo);
                        settings.Save();
                    }
                }
                else
                {
                    settings = AppSettings.CreateEmpty(PATH_SETTINGS);
                    settings.Save();

                    IsFirstLaunch = true;
                }
            }
            catch (Exception e)
            {
                ExceptionDialog.Show(null, "Could not load settings", "Could not load settings from " + PATH_SETTINGS, e);
                settings = AppSettings.CreateEmpty(App.PATH_SETTINGS);
            }

            if (settings.LockOnStartup && !settings.IsReadOnlyMode)
            {
                settings.IsReadOnlyMode = true;
            }

            ThemeManager.Inst.LoadWithErrorDialog(settings);

            var mw = new MainWindow(settings);

            if (!(settings.MinimizeToTray && settings.StartupState == ExtendedWindowState.Minimized))
            {
                mw.Show();
            }
        }