Ejemplo n.º 1
0
        /// <summary>
        ///     Method to check if there is a new application version available.
        /// </summary>
        private async void UpdateAsync()
        {
            try
            {
                var update = await ApplicationUpdater.CheckForRemoteUpdateAsync().ConfigureAwait(true);

                if (update.CanUpdate)
                {
                    var boxType = update.Update.Type == UpdateType.Standard ? BoxType.Default : BoxType.Warning;
                    var boxText = update.Update.Type == UpdateType.Standard
                                                ? LocalizationEx.GetUiString("dialog_message_update_standard_text",
                                                                             Thread.CurrentThread.CurrentCulture)
                                                : LocalizationEx.GetUiString("dialog_message_update_critical_text",
                                                                             Thread.CurrentThread.CurrentCulture);
                    var boxTitle = update.Update.Type == UpdateType.Standard
                                                ? LocalizationEx.GetUiString("dialog_message_update_standard_title",
                                                                             Thread.CurrentThread.CurrentCulture)
                                                : LocalizationEx.GetUiString("dialog_message_update_critical_title",
                                                                             Thread.CurrentThread.CurrentCulture);
                    var userResult =
                        _windowManager.ShowMetroMessageBox(
                            string.Format(boxText, update.Update.Version), boxTitle,
                            MessageBoxButton.YesNo, boxType);

                    if (userResult != MessageBoxResult.Yes)
                    {
                        return;
                    }
                    var updateViewModel = new UpdateViewModel(update.Update)
                    {
                        DisplayName =
                            LocalizationEx.GetUiString("window_update_title", Thread.CurrentThread.CurrentCulture)
                    };
                    dynamic settings = new ExpandoObject();
                    settings.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                    settings.Owner = GetView();
                    var result = _windowManager.ShowDialog(updateViewModel, null, settings);
                    if (!result)
                    {
                        return;
                    }
                    if (!File.Exists(updateViewModel.InstallerPath))
                    {
                        return;
                    }
                    // start the installer
                    Process.Start(updateViewModel.InstallerPath);
                    // kill running application
                    Process.GetCurrentProcess().Kill();
                }
            }
            catch (Exception)
            {
            }
        }
Ejemplo n.º 2
0
        public async Task CheckForRemoteUpdateTest()
        {
            _remoteUpdate = await ApplicationUpdater.CheckForRemoteUpdateAsync().ConfigureAwait(false);

            Assert.AreNotEqual(_remoteUpdate, null);
            Assert.AreNotEqual(_remoteUpdate.Update, null);
            Assert.AreNotEqual(_remoteUpdate.Update.Installer, null);
            Assert.AreNotEqual(_remoteUpdate.Update.Signature, null);
            Assert.AreEqual(_remoteUpdate.Update.Publickey, Global.ApplicationUpdatePublicKey);
            Assert.AreEqual(_remoteUpdate.Update.Installer.Name, "SimpleDNSCrypt.msi");
        }
Ejemplo n.º 3
0
        private async void InitializeApplication()
        {
            try
            {
                if (IsAdministrator())
                {
                    ProgressText =
                        LocalizationEx.GetUiString("loader_administrative_rights_available", Thread.CurrentThread.CurrentCulture);
                }
                else
                {
                    ProgressText =
                        LocalizationEx.GetUiString("loader_administrative_rights_missing", Thread.CurrentThread.CurrentCulture);
                    await Task.Delay(3000).ConfigureAwait(false);

                    Process.GetCurrentProcess().Kill();
                }

                ProgressText = LocalizationEx.GetUiString("loader_redistributable_package_check", Thread.CurrentThread.CurrentCulture);
                if (PrerequisiteHelper.IsRedistributablePackageInstalled())
                {
                    ProgressText = LocalizationEx.GetUiString("loader_redistributable_package_already_installed", Thread.CurrentThread.CurrentCulture);
                }
                else
                {
                    ProgressText = LocalizationEx.GetUiString("loader_redistributable_package_installing", Thread.CurrentThread.CurrentCulture);
                    //minisign needs this (to verify the installer with libsodium)
                    await PrerequisiteHelper.DownloadAndInstallRedistributablePackage();

                    if (PrerequisiteHelper.IsRedistributablePackageInstalled())
                    {
                        ProgressText = LocalizationEx.GetUiString("loader_redistributable_package_ready", Thread.CurrentThread.CurrentCulture);
                        await Task.Delay(1000).ConfigureAwait(false);
                    }
                }

                if (Properties.Settings.Default.AutoUpdate)
                {
                    ProgressText = LocalizationEx.GetUiString("loader_checking_version", Thread.CurrentThread.CurrentCulture);
                    //TODO: remove in future version (for now we only have one channel)
                    Properties.Settings.Default.MinUpdateType = 2;
                    Properties.Settings.Default.Save();
                    var minUpdateType = (UpdateType)Properties.Settings.Default.MinUpdateType;
                    var update        = await ApplicationUpdater.CheckForRemoteUpdateAsync(minUpdateType).ConfigureAwait(false);

                    if (update.CanUpdate)
                    {
                        ProgressText =
                            string.Format(LocalizationEx.GetUiString("loader_new_version_found", Thread.CurrentThread.CurrentCulture),
                                          update.Update.Version);
                        await Task.Delay(200).ConfigureAwait(false);

                        var installer = await StartRemoteUpdateDownload(update).ConfigureAwait(false);

                        if (!string.IsNullOrEmpty(installer) && File.Exists(installer))
                        {
                            ProgressText = LocalizationEx.GetUiString("loader_starting_update", Thread.CurrentThread.CurrentCulture);
                            await Task.Delay(200).ConfigureAwait(false);

                            Process.Start(installer);
                            Process.GetCurrentProcess().Kill();
                        }
                        else
                        {
                            await Task.Delay(500).ConfigureAwait(false);

                            ProgressText = LocalizationEx.GetUiString("loader_update_failed", Thread.CurrentThread.CurrentCulture);
                        }
                    }
                    else
                    {
                        ProgressText = LocalizationEx.GetUiString("loader_latest_version", Thread.CurrentThread.CurrentCulture);
                    }
                }
                else
                {
                    await Task.Delay(500).ConfigureAwait(false);
                }

                ProgressText =
                    string.Format(LocalizationEx.GetUiString("loader_validate_folder", Thread.CurrentThread.CurrentCulture),
                                  Global.DnsCryptProxyFolder);
                var validatedFolder = ValidateDnsCryptProxyFolder();
                if (validatedFolder.Count == 0)
                {
                    ProgressText = LocalizationEx.GetUiString("loader_all_files_available", Thread.CurrentThread.CurrentCulture);
                }
                else
                {
                    var fileErrors = "";
                    foreach (var pair in validatedFolder)
                    {
                        fileErrors += $"{pair.Key}: {pair.Value}\n";
                    }

                    ProgressText =
                        string.Format(
                            LocalizationEx.GetUiString("loader_missing_files", Thread.CurrentThread.CurrentCulture).Replace("\\n", "\n"),
                            Global.DnsCryptProxyFolder, fileErrors, Global.ApplicationName);
                    await Task.Delay(5000).ConfigureAwait(false);

                    Process.GetCurrentProcess().Kill();
                }

                ProgressText = string.Format(LocalizationEx.GetUiString("loader_loading", Thread.CurrentThread.CurrentCulture),
                                             Global.DnsCryptConfigurationFile);
                if (DnscryptProxyConfigurationManager.LoadConfiguration())
                {
                    ProgressText =
                        string.Format(LocalizationEx.GetUiString("loader_successfully_loaded", Thread.CurrentThread.CurrentCulture),
                                      Global.DnsCryptConfigurationFile);
                    _mainViewModel.DnscryptProxyConfiguration = DnscryptProxyConfigurationManager.DnscryptProxyConfiguration;
                }
                else
                {
                    ProgressText =
                        string.Format(LocalizationEx.GetUiString("loader_failed_loading", Thread.CurrentThread.CurrentCulture),
                                      Global.DnsCryptConfigurationFile);
                    await Task.Delay(5000).ConfigureAwait(false);

                    Process.GetCurrentProcess().Kill();
                }

                ProgressText = LocalizationEx.GetUiString("loader_loading_network_cards", Thread.CurrentThread.CurrentCulture);

                List <LocalNetworkInterface> localNetworkInterfaces;
                if (DnscryptProxyConfigurationManager.DnscryptProxyConfiguration.listen_addresses.Contains(Global.GlobalResolver))
                {
                    var dnsServer = new List <string>
                    {
                        Global.DefaultResolverIpv4,
                        Global.DefaultResolverIpv6
                    };
                    localNetworkInterfaces = LocalNetworkInterfaceManager.GetLocalNetworkInterfaces(dnsServer);
                }
                else
                {
                    localNetworkInterfaces = LocalNetworkInterfaceManager.GetLocalNetworkInterfaces(
                        DnscryptProxyConfigurationManager.DnscryptProxyConfiguration.listen_addresses.ToList());
                }
                _mainViewModel.LocalNetworkInterfaces = new BindableCollection <LocalNetworkInterface>();
                _mainViewModel.LocalNetworkInterfaces.AddRange(localNetworkInterfaces);
                _mainViewModel.Initialize();
                ProgressText = LocalizationEx.GetUiString("loader_starting", Thread.CurrentThread.CurrentCulture);

                if (Properties.Settings.Default.TrayMode)
                {
                    Execute.OnUIThread(() => _windowManager.ShowWindow(_systemTrayViewModel));
                    Execute.OnUIThread(() => _systemTrayViewModel.ShowWindow());
                }
                else
                {
                    Execute.OnUIThread(() => _windowManager.ShowWindow(_mainViewModel));
                }

                TryClose(true);
            }
            catch (Exception exception)
            {
                Log.Error(exception);
            }
        }
Ejemplo n.º 4
0
        private async void InitializeApplication()
        {
            try
            {
                if (IsAdministrator())
                {
                    ProgressText =
                        LocalizationEx.GetUiString("loader_administrative_rights_available", Thread.CurrentThread.CurrentCulture);
                }
                else
                {
                    ProgressText =
                        LocalizationEx.GetUiString("loader_administrative_rights_missing", Thread.CurrentThread.CurrentCulture);
                    await Task.Delay(3000).ConfigureAwait(false);

                    Process.GetCurrentProcess().Kill();
                }

                ProgressText = LocalizationEx.GetUiString("loader_checking_version", Thread.CurrentThread.CurrentCulture);
                var update = await ApplicationUpdater.CheckForRemoteUpdateAsync().ConfigureAwait(false);

                if (update.CanUpdate)
                {
                    ProgressText =
                        string.Format(LocalizationEx.GetUiString("loader_new_version_found", Thread.CurrentThread.CurrentCulture),
                                      update.Update.Version);
                    await Task.Delay(200).ConfigureAwait(false);

                    var installer = await StartRemoteUpdateDownload(update).ConfigureAwait(false);

                    if (!string.IsNullOrEmpty(installer) && File.Exists(installer))
                    {
                        ProgressText = LocalizationEx.GetUiString("loader_starting_update", Thread.CurrentThread.CurrentCulture);
                        await Task.Delay(200).ConfigureAwait(false);

                        Process.Start(installer);
                        Process.GetCurrentProcess().Kill();
                    }
                    else
                    {
                        await Task.Delay(500).ConfigureAwait(false);

                        ProgressText = LocalizationEx.GetUiString("loader_update_failed", Thread.CurrentThread.CurrentCulture);
                    }
                }
                else
                {
                    ProgressText = LocalizationEx.GetUiString("loader_latest_version", Thread.CurrentThread.CurrentCulture);
                }

                ProgressText =
                    string.Format(LocalizationEx.GetUiString("loader_validate_folder", Thread.CurrentThread.CurrentCulture),
                                  Global.DnsCryptProxyFolder);
                var validatedFolder = ValidateDnsCryptProxyFolder();
                if (validatedFolder.Count == 0)
                {
                    ProgressText = LocalizationEx.GetUiString("loader_all_files_available", Thread.CurrentThread.CurrentCulture);
                }
                else
                {
                    var fileErrors = "";
                    foreach (var pair in validatedFolder)
                    {
                        fileErrors += $"{pair.Key}: {pair.Value}\n";
                    }

                    ProgressText =
                        string.Format(
                            LocalizationEx.GetUiString("loader_missing_files", Thread.CurrentThread.CurrentCulture).Replace("\\n", "\n"),
                            Global.DnsCryptProxyFolder, fileErrors, Global.ApplicationName);
                    await Task.Delay(5000).ConfigureAwait(false);

                    Process.GetCurrentProcess().Kill();
                }

                ProgressText = string.Format(LocalizationEx.GetUiString("loader_loading", Thread.CurrentThread.CurrentCulture),
                                             Global.DnsCryptConfigurationFile);
                if (DnscryptProxyConfigurationManager.LoadConfiguration())
                {
                    ProgressText =
                        string.Format(LocalizationEx.GetUiString("loader_successfully_loaded", Thread.CurrentThread.CurrentCulture),
                                      Global.DnsCryptConfigurationFile);
                    _mainViewModel.DnscryptProxyConfiguration = DnscryptProxyConfigurationManager.DnscryptProxyConfiguration;
                }
                else
                {
                    ProgressText =
                        string.Format(LocalizationEx.GetUiString("loader_failed_loading", Thread.CurrentThread.CurrentCulture),
                                      Global.DnsCryptConfigurationFile);
                    await Task.Delay(5000).ConfigureAwait(false);

                    Process.GetCurrentProcess().Kill();
                }

                ProgressText = LocalizationEx.GetUiString("loader_loading_network_cards", Thread.CurrentThread.CurrentCulture);
                var localNetworkInterfaces = LocalNetworkInterfaceManager.GetLocalNetworkInterfaces(
                    DnscryptProxyConfigurationManager.DnscryptProxyConfiguration.listen_addresses.ToList());
                _mainViewModel.LocalNetworkInterfaces = new BindableCollection <LocalNetworkInterface>();
                _mainViewModel.LocalNetworkInterfaces.AddRange(localNetworkInterfaces);
                _mainViewModel.Initialize();
                ProgressText = LocalizationEx.GetUiString("loader_starting", Thread.CurrentThread.CurrentCulture);
                Execute.OnUIThread(() => _windowManager.ShowWindow(_mainViewModel));
                TryClose(true);
            }
            catch (Exception exception)
            {
                Log.Error(exception);
            }
        }