Example #1
0
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            FinalizeDatabaseTransaction();
            if (e.IsTerminating)
            {
                Logger.Fatal(L(nameof(Resources.Application_UnhandledException)), e.ExceptionObject as Exception);
                if (IsExiting)
                {
                    return;
                }

                var message = L(nameof(Resources.Bootstrapper_UnhandledException));

                ChocolateyMessageBox.Show(
                    e.ExceptionObject.ToString(),
                    message,
                    MessageBoxButton.OK,
                    MessageBoxImage.Error,
                    MessageBoxResult.OK,
                    MessageBoxOptions.ServiceNotification);
            }
            else
            {
                Logger.Error(L(nameof(Resources.Application_UnhandledException)), e.ExceptionObject as Exception);
            }
        }
Example #2
0
        protected override async void OnStartup(object sender, StartupEventArgs e)
        {
            try
            {
                // Do not remove! Load Chocolatey once so all config gets set
                // properly for future calls
                var choco = Lets.GetChocolatey(initializeLogging: false);

                Mapper.Initialize(config =>
                {
                    config.CreateMap <Package, IPackageViewModel>().ConstructUsing(rc => Container.Resolve <IPackageViewModel>());
                });

                var packageService = Container.Resolve <IChocolateyService>();
                var features       = await packageService.GetFeatures();

                var backgroundFeature = features.FirstOrDefault(feature => string.Equals(feature.Name, "useBackgroundService", StringComparison.OrdinalIgnoreCase));
                var elevationProvider = Elevation.Instance;
                elevationProvider.IsBackgroundRunning = backgroundFeature?.Enabled ?? false;

                var splashScreen = Container.Resolve <ISplashScreenService>();
                splashScreen.Close(TimeSpan.FromMilliseconds(300));

                DisplayRootViewFor <ShellViewModel>();
            }
            catch (Exception ex)
            {
                var messageFormat = L(nameof(Resources.Fatal_Startup_Error_Formatted), ex.Message);

                ChocolateyMessageBox.Show(messageFormat);
                Logger.Fatal(ex, L(nameof(Resources.Fatal_Startup_Error)));
                await OnExitAsync();
            }
        }
Example #3
0
        public void CheckOperatingSystemCompatibility()
        {
            var operatingSystemVersion = Environment.OSVersion;

            if (operatingSystemVersion.Version.Major == 10 &&
                !_chocolateyConfigurationProvider.IsChocolateyExecutableBeingUsed)
            {
                // TODO: Possibly make these values translatable, do not use Resources directly, instead Use TranslationSource.Instance["KEY_NAME"];
                ChocolateyMessageBox.Show(
                    "Usage of the PowerShell Version of Chocolatey (i.e. <= 0.9.8.33) has been detected.  Chocolatey GUI does not support using this version of Chocolatey on Windows 10.  Please update Chocolatey to the new C# Version (i.e. > 0.9.9.0) and restart Chocolatey GUI.  This application will now close.",
                    "Incompatible Operating System Version",
                    MessageBoxButton.OK,
                    MessageBoxImage.Error,
                    MessageBoxResult.OK,
                    MessageBoxOptions.ServiceNotification);

                Application.Current.Shutdown();
            }
        }
Example #4
0
        /// <inheritdoc />
        public async Task <MessageDialogResult> ShowMessageAsync(string title, string message)
        {
            using (await _lock.EnterAsync())
            {
                if (ShellView != null)
                {
                    var dialogSettings = new MetroDialogSettings
                    {
                        AffirmativeButtonText = L(nameof(Resources.ChocolateyDialog_OK))
                    };

                    return(await ShellView.ShowMessageAsync(title, message, MessageDialogStyle.Affirmative, dialogSettings));
                }

                return(ChocolateyMessageBox.Show(message, title) == MessageBoxResult.OK
                    ? MessageDialogResult.Affirmative
                    : MessageDialogResult.Negative);
            }
        }
        protected override void OnInitialize()
        {
            try
            {
                ListViewMode = _configService.GetEffectiveConfiguration().DefaultToTileViewForRemoteSource ?? true ? ListViewMode.Tile : ListViewMode.Standard;
                ShowAdditionalPackageInformation = _configService.GetEffectiveConfiguration().ShowAdditionalPackageInformation ?? false;

                Observable.FromEventPattern <EventArgs>(_configService, "SettingsChanged")
                .ObserveOnDispatcher()
                .Subscribe(eventPattern =>
                {
                    var appConfig = (AppConfiguration)eventPattern.Sender;

                    _searchQuerySubscription?.Dispose();
                    if (appConfig.UseDelayedSearch ?? false)
                    {
                        SubscribeToLoadPackagesOnSearchQueryChange();
                    }

                    ListViewMode = appConfig.DefaultToTileViewForRemoteSource ?? false ? ListViewMode.Tile : ListViewMode.Standard;
                    ShowAdditionalPackageInformation = appConfig.ShowAdditionalPackageInformation ?? false;
                });

                var immediateProperties = new[]
                {
                    "IncludeAllVersions", "IncludePrerelease", "MatchWord", "SortSelection"
                };

                if (_configService.GetEffectiveConfiguration().UseDelayedSearch ?? false)
                {
                    SubscribeToLoadPackagesOnSearchQueryChange();
                }

                Observable.FromEventPattern <PropertyChangedEventArgs>(this, "PropertyChanged")
                .Where(e => immediateProperties.Contains(e.EventArgs.PropertyName))
                .ObserveOnDispatcher()
#pragma warning disable 4014
                .Subscribe(e => LoadPackages(false));
#pragma warning restore 4014

                Observable.FromEventPattern <PropertyChangedEventArgs>(this, "PropertyChanged")
                .Where(e => e.EventArgs.PropertyName == "CurrentPage")
                .Throttle(TimeSpan.FromMilliseconds(300))
                .DistinctUntilChanged()
                .ObserveOnDispatcher()
#pragma warning disable 4014
                .Subscribe(e => LoadPackages(false));
#pragma warning restore 4014
            }
            catch (InvalidOperationException ex)
            {
                Logger.Error(ex, "Failed to initialize remote source view model.");
                var message = L(nameof(Resources.RemoteSourceViewModel_UnableToConnectToFeed));
                var caption = L(nameof(Resources.RemoteSourceViewModel_FeedSearchError));
                ChocolateyMessageBox.Show(
                    string.Format(
                        CultureInfo.InvariantCulture,
                        message,
                        Source.Value),
                    caption,
                    MessageBoxButton.OK,
                    MessageBoxImage.Error,
                    MessageBoxResult.OK,
                    MessageBoxOptions.ServiceNotification);
            }
        }
Example #6
0
        public App()
        {
            AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
            {
                var requestedAssembly = new AssemblyName(args.Name);

                try
                {
                    if (string.Equals(requestedAssembly.Name, "chocolatey", StringComparison.OrdinalIgnoreCase))
                    {
                        var installDir = Environment.GetEnvironmentVariable("ChocolateyInstall");
                        if (string.IsNullOrEmpty(installDir))
                        {
                            var rootDrive = Path.GetPathRoot(Assembly.GetExecutingAssembly().Location);
                            if (string.IsNullOrEmpty(rootDrive))
                            {
                                return(null); // TODO: Maybe return the chocolatey.dll file instead?
                            }

                            installDir = Path.Combine(rootDrive, "ProgramData", "chocolatey");
                        }

                        var assemblyLocation = Path.Combine(installDir, "choco.exe");

                        return(AssemblyResolver.ResolveOrLoadAssembly("choco", string.Empty, assemblyLocation));
                    }

#if FORCE_CHOCOLATEY_OFFICIAL_KEY
                    var chocolateyGuiPublicKey = Bootstrapper.OfficialChocolateyPublicKey;
#else
                    var chocolateyGuiPublicKey = Bootstrapper.UnofficialChocolateyPublicKey;
#endif

                    if (AssemblyResolver.DoesPublicKeyTokenMatch(requestedAssembly, chocolateyGuiPublicKey) &&
                        string.Equals(requestedAssembly.Name, Bootstrapper.ChocolateyGuiCommonAssemblySimpleName, StringComparison.OrdinalIgnoreCase))
                    {
                        return(AssemblyResolver.ResolveOrLoadAssembly(
                                   Bootstrapper.ChocolateyGuiCommonAssemblySimpleName,
                                   AssemblyResolver.GetPublicKeyToken(requestedAssembly),
                                   Bootstrapper.ChocolateyGuiCommonAssemblyLocation));
                    }

                    if (AssemblyResolver.DoesPublicKeyTokenMatch(requestedAssembly, chocolateyGuiPublicKey) &&
                        string.Equals(requestedAssembly.Name, Bootstrapper.ChocolateyGuiCommonWindowsAssemblySimpleName, StringComparison.OrdinalIgnoreCase))
                    {
                        return(AssemblyResolver.ResolveOrLoadAssembly(
                                   Bootstrapper.ChocolateyGuiCommonWindowsAssemblySimpleName,
                                   AssemblyResolver.GetPublicKeyToken(requestedAssembly),
                                   Bootstrapper.ChocolateyGuiCommonWindowsAssemblyLocation));
                    }
                }
                catch (Exception ex)
                {
                    // TODO: Possibly make these values translatable, do not use Resources directly, instead Use L(nameof(Resources.KEY_NAME));
                    var errorMessage = string.Format("Unable to load Chocolatey GUI assembly. {0}", ex.Message);
                    ChocolateyMessageBox.Show(errorMessage);
                    throw new ApplicationException(errorMessage);
                }

                return(null);
            };

            InitializeComponent();
        }