Пример #1
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            // allow long term logging (for report box)
            Log.Singleton.EnableLongTermStore();

            // catch unhandled exceptions
            SetupExceptionHandling();

            // Build up of options
            Log.Singleton.Info("Application startup.");

            var exePath = System.Reflection.Assembly.GetEntryAssembly()?.Location;

            Options.ReplaceCurr(InferOptions(exePath, e.Args));

            // search for plugins?
            if (Options.Curr.PluginDir != null)
            {
                var searchDir = System.IO.Path.Combine(
                    System.IO.Path.GetDirectoryName(exePath),
                    Options.Curr.PluginDir);

                Log.Singleton.Info(
                    "Searching for the plugins in the plugin directory: {0}", searchDir);

                var pluginDllInfos = Plugins.TrySearchPlugins(searchDir);

                Log.Singleton.Info(
                    $"Found {pluginDllInfos.Count} plugin(s) in the plugin directory: {searchDir}");

                Options.Curr.PluginDll.AddRange(pluginDllInfos);
            }

            Log.Singleton.Info(
                $"Loading and activating {Options.Curr.PluginDll.Count} plugin(s)...");

            Plugins.LoadedPlugins = LoadAndActivatePlugins(Options.Curr.PluginDll);

            // at end, write all default options to JSON?
            if (Options.Curr.WriteDefaultOptionsFN != null)
            {
                // info
                var fullFilename = System.IO.Path.GetFullPath(Options.Curr.WriteDefaultOptionsFN);
                Log.Singleton.Info($"Writing resulting options to a JSON file: {fullFilename}");

                // retrieve
                Plugins.TryGetDefaultOptionsForPlugins(Options.Curr.PluginDll, Plugins.LoadedPlugins);
                OptionsInformation.WriteJson(Options.Curr, fullFilename);
            }

            // colors
            if (true)
            {
                var resNames = new[] {
                    "LightAccentColor", "DarkAccentColor", "DarkestAccentColor", "FocusErrorBrush"
                };
                for (int i = 0; i < resNames.Length; i++)
                {
                    var x = this.FindResource(resNames[i]);
                    if (x != null &&
                        x is System.Windows.Media.SolidColorBrush &&
                        Options.Curr.AccentColors.ContainsKey((OptionsInformation.ColorNames)i))
                    {
                        this.Resources[resNames[i]] = AnyUiDisplayContextWpf.GetWpfBrush(
                            Options.Curr.GetColor((OptionsInformation.ColorNames)i));
                    }
                }
                resNames = new[] { "FocusErrorColor" };
                for (int i = 0; i < resNames.Length; i++)
                {
                    var x = this.FindResource(resNames[i]);
                    if (x != null &&
                        x is System.Windows.Media.Color &&
                        Options.Curr.AccentColors.ContainsKey((OptionsInformation.ColorNames)(3 + i)))
                    {
                        this.Resources[resNames[i]] = AnyUiDisplayContextWpf.GetWpfColor(
                            Options.Curr.GetColor((OptionsInformation.ColorNames)(3 + i)));
                    }
                }
            }

            Pref pref = Pref.Read();

            // show splash (required for licenses of open source)
            if (Options.Curr.SplashTime != 0)
            {
                var splash = new CustomSplashScreenNew(pref);
                splash.Show();
            }

            // show main window
            MainWindow wnd = new MainWindow(pref);

            wnd.Show();
        }
Пример #2
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            // allow long term logging (for report box)
            Log.LogInstance.EnableLongTermStore();

            // Build up of options
            Log.Info("Application startup.");

            // there is a special case for having "no" command line options ..
            string directAasx = null;

            if (e.Args.Length == 1 && !e.Args[0].StartsWith("-"))
            {
                directAasx = e.Args[0];
                Log.Info("Direct request to load AASX {0} ..", directAasx);
            }

            // If no command line args given, read options via default filename
            if (directAasx != null || e.Args.Length < 1)
            {
                var exePath = System.Reflection.Assembly.GetEntryAssembly()?.Location;
                var defFn   = System.IO.Path.Combine(
                    System.IO.Path.GetDirectoryName("" + exePath),
                    System.IO.Path.GetFileNameWithoutExtension("" + exePath) + ".options.json");

                Log.Info("Check {0} for default options in JSON ..", defFn);
                if (File.Exists(defFn))
                {
                    Options.Curr.ReadJson(defFn);
                }

                // overrule
                if (directAasx != null)
                {
                    Options.Curr.AasxToLoad = directAasx;
                }
            }
            else
            {
                // 2nd parse options
                Log.Info("Parsing commandline options ..");
                foreach (var a in e.Args)
                {
                    Log.Info("argument {0}", a);
                }
                Options.Curr.ParseArgs(e.Args);
            }

            // 3rd further commandline options in extra file
            if (Options.Curr.OptionsTextFn != null)
            {
                Log.Info("Parsing options from distinct file {0} ..", Options.Curr.OptionsTextFn);
                var fullfn = System.IO.Path.GetFullPath(Options.Curr.OptionsTextFn);
                Options.Curr.TryReadOptionsFile(fullfn);
            }

            // search for plugins?
            if (Options.Curr.PluginDir != null)
            {
                var searchDir = System.IO.Path.Combine(
                    System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly()?.Location),
                    Options.Curr.PluginDir);
                Log.Info("Searching for plug-ins in {0} ..", searchDir);
                Plugins.TrySearchPlugins(searchDir, Options.Curr.PluginDll);
            }

            // Plugins to be loaded
            Log.Info("Try load and activate plug-ins ..");
            Plugins.TryActivatePlugins(Options.Curr.PluginDll);
            Plugins.TrySetOptionsForPlugins(Options.Curr);

            // at end, write all default options to JSON?
            if (Options.Curr.WriteDefaultOptionsFN != null)
            {
                // info
                var fullfn = System.IO.Path.GetFullPath(Options.Curr.WriteDefaultOptionsFN);
                Log.Info("Writing resulting options into JSOnN {0}", fullfn);

                // retrieve
                Plugins.TrGetDefaultOptionsForPlugins(Options.Curr);
                Options.Curr.WriteJson(fullfn);
            }

            // colors
            if (true)
            {
                var resNames = new[] {
                    "LightAccentColor", "DarkAccentColor", "DarkestAccentColor", "FocusErrorBrush"
                };
                for (int i = 0; i < resNames.Length; i++)
                {
                    var x = this.FindResource(resNames[i]);
                    if (x != null &&
                        x is System.Windows.Media.SolidColorBrush && Options.Curr.AccentColors.ContainsKey(i))
                    {
                        this.Resources[resNames[i]] = new System.Windows.Media.SolidColorBrush(
                            Options.Curr.AccentColors[i]);
                    }
                }
                resNames = new[] { "FocusErrorColor" };
                for (int i = 0; i < resNames.Length; i++)
                {
                    var x = this.FindResource(resNames[i]);
                    if (x != null && x is System.Windows.Media.Color && Options.Curr.AccentColors.ContainsKey(3 + i))
                    {
                        this.Resources[resNames[i]] = Options.Curr.AccentColors[3 + i];
                    }
                }
            }

            // show splash (required for licenses of open source)
            var splash = new CustomSplashScreenNew();

            splash.Show();

            // show main window
            MainWindow wnd = new MainWindow();

            wnd.Show();
        }