/// <summary>
        /// Validates if the groups in the list are all valid.
        /// </summary>
        /// <param name="groups">The list of groups to validate.</param>
        /// <returns>
        /// True if all groups are valid.
        /// False if any one of them is invalid.
        /// </returns>
        public static bool ValidateGeositeGroupList(List <string> groups)
        {
            foreach (var geositeGroup in groups)
            {
                if (!GeositeUpdater.CheckGeositeGroup(geositeGroup)) // found invalid group
                {
#if DEBUG
                    logger.Debug($"Available groups:");
                    foreach (var group in GeositeUpdater.Geosites.Keys)
                    {
                        logger.Debug($"{group}");
                    }
#endif
                    logger.Warn($"The Geosite group {geositeGroup} doesn't exist. Resetting to default groups.");
                    return(false);
                }
            }
            return(true);
        }
 private async void UpdatePACFromGeositeItem_Click(object sender, EventArgs e)
 {
     await GeositeUpdater.UpdatePACFromGeosite();
 }
        /// <summary>
        /// Process the loaded configurations and set up things.
        /// </summary>
        /// <param name="config">A reference of Configuration object.</param>
        public static void Process(ref Configuration config)
        {
            // Verify if the configured geosite group exists.
            // Reset to default if no such group.
            if (!GeositeUpdater.CheckGeositeGroup(config.geositeGroup))
            {
#if DEBUG
                logger.Debug($"Current group: {config.geositeGroup}");
                foreach (var group in GeositeUpdater.Geosites.Keys)
                {
                    logger.Debug($"{group}");
                }
#endif
                config.geositeGroup = "geolocation-!cn";
                logger.Warn("The specified Geosite group doesn't exist. Using default group.");
            }

            // Mark the first run of a new version.
            if (UpdateChecker.Asset.CompareVersion(UpdateChecker.Version, config.version ?? "0") > 0)
            {
                config.firstRunOnNewVersion = true;
            }
            // Add an empty server configuration
            if (config.configs.Count == 0)
            {
                config.configs.Add(GetDefaultServer());
            }
            // Selected server
            if (config.index == -1 && string.IsNullOrEmpty(config.strategy))
            {
                config.index = 0;
            }
            if (config.index >= config.configs.Count)
            {
                config.index = config.configs.Count - 1;
            }
            // Check OS IPv6 support
            if (!System.Net.Sockets.Socket.OSSupportsIPv6)
            {
                config.isIPv6Enabled = false;
            }
            config.proxy.CheckConfig();
            // Replace $version with the version number.
            config.userAgentString = config.userAgent.Replace("$version", config.version);

            // NLog log level
            try
            {
                config.nLogConfig = NLogConfig.LoadXML();
                switch (config.nLogConfig.GetLogLevel())
                {
                case NLogConfig.LogLevel.Fatal:
                case NLogConfig.LogLevel.Error:
                case NLogConfig.LogLevel.Warn:
                case NLogConfig.LogLevel.Info:
                    config.isVerboseLogging = false;
                    break;

                case NLogConfig.LogLevel.Debug:
                case NLogConfig.LogLevel.Trace:
                    config.isVerboseLogging = true;
                    break;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show($"Cannot get the log level from NLog config file. Please check if the nlog config file exists with corresponding XML nodes.\n{e.Message}");
            }
        }