Пример #1
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            try
            {
                LogDir = Path.Combine(Utils.GetDataFolderPath(), "logs");
                GlobalDiagnosticsContext.Set("logDir", LogDir);

                Assembly thisAssembly = Assembly.GetAssembly(typeof(App));
                var      path         = Path.GetDirectoryName(thisAssembly.Location);
                if (Environment.Is64BitProcess)
                {
                    SevenZip.SevenZipBase.SetLibraryPath(Path.Combine(path, @"7z64.dll"));
                }
                else
                {
                    SevenZip.SevenZipBase.SetLibraryPath(Path.Combine(path, @"7z.dll"));
                }

                ResourceManagerEx.Initialize();
                TranslationSource.Instance.SetCulture(GrepSettings.Instance.Get <string>(GrepSettings.Key.CurrentCulture));
                AppTheme.Instance.Initialize();

                AppArgs = new CommandLineArgs(Environment.CommandLine);

                if (AppArgs.WarmUp)
                {
                    MainWindow         = new MainForm(false);
                    MainWindow.Loaded += MainWindow_Loaded;
                }
                else if (AppArgs.ShowHelp)
                {
                    MainWindow = new HelpWindow(AppArgs.GetHelpString(), AppArgs.InvalidArgument);
                }
                else
                {
                    AppArgs.ApplyArgs();
                }

                if (MainWindow == null)
                {
                    MainWindow = new MainForm();
                    Utils.DeleteTempFolder();
                }

                MainWindow.Show();
                if (AppArgs.ExecuteSearch && MainWindow.DataContext != null)
                {
                    if (MainWindow is MainForm mainView)
                    {
                        mainView.ViewModel.SearchCommand.Execute(null);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Failure in application startup");
                MessageBox.Show(Localization.Properties.Resources.MessageBox_SomethingBrokeDownInDnGrep + LogDir,
                                Localization.Properties.Resources.MessageBox_DnGrep,
                                MessageBoxButton.OK, MessageBoxImage.Error,
                                MessageBoxResult.OK, TranslationSource.Instance.FlowDirection);
            }
        }