Esempio n. 1
0
        private void UpdateRepo(object sender, DoWorkEventArgs e)
        {
            try
            {
                AddStatusMessage(Properties.Resources.MainRepoScanning);
                log.Debug("Scanning before repo update");
                bool scanChanged = CurrentInstance.Scan();

                AddStatusMessage(Properties.Resources.MainRepoUpdating);

                // Note the current mods' compatibility for the NewlyCompatible filter
                GameVersionCriteria       versionCriteria = CurrentInstance.VersionCriteria();
                IRegistryQuerier          registry        = RegistryManager.Instance(CurrentInstance).registry;
                Dictionary <string, bool> oldModules      = registry.CompatibleModules(versionCriteria)
                                                            .ToDictionary(m => m.identifier, m => false);
                registry.IncompatibleModules(versionCriteria)
                .Where(m => !oldModules.ContainsKey(m.identifier))
                .ToList()
                .ForEach(m => oldModules.Add(m.identifier, true));

                RepoUpdateResult result = Repo.UpdateAllRepositories(
                    RegistryManager.Instance(CurrentInstance),
                    CurrentInstance, Manager.Cache, currentUser);
                if (result == RepoUpdateResult.NoChanges && scanChanged)
                {
                    result = RepoUpdateResult.Updated;
                }
                e.Result = new KeyValuePair <RepoUpdateResult, Dictionary <string, bool> >(
                    result, oldModules);
            }
            catch (UriFormatException ex)
            {
                errorDialog.ShowErrorDialog(ex.Message);
            }
            catch (MissingCertificateKraken ex)
            {
                errorDialog.ShowErrorDialog(ex.ToString());
            }
            catch (ReinstallModuleKraken)
            {
                // Bypass the generic error dialog so the Post can handle this
                throw;
            }
            catch (Exception ex)
            {
                errorDialog.ShowErrorDialog(string.Format(Properties.Resources.MainRepoFailedToConnect, ex.Message));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Convert case insensitive mod names from the user to case sensitive identifiers
        /// </summary>
        /// <param name="ksp">Game instance forgetting the mods</param>
        /// <param name="modules">List of strings to convert, format 'identifier' or 'identifier=version'</param>
        public static void AdjustModulesCase(CKAN.GameInstance ksp, List <string> modules)
        {
            IRegistryQuerier registry = RegistryManager.Instance(ksp).registry;
            // Get the list of all compatible and incompatible mods
            List <CkanModule> mods = registry.CompatibleModules(ksp.VersionCriteria()).ToList();

            mods.AddRange(registry.IncompatibleModules(ksp.VersionCriteria()));
            for (int i = 0; i < modules.Count; ++i)
            {
                Match match = CkanModule.idAndVersionMatcher.Match(modules[i]);
                if (match.Success)
                {
                    // Handle name=version format
                    string ident   = match.Groups["mod"].Value;
                    string version = match.Groups["version"].Value;
                    modules[i] = $"{CaseInsensitiveExactMatch(mods, ident)}={version}";
                }
                else
                {
                    modules[i] = CaseInsensitiveExactMatch(mods, modules[i]);
                }
            }
        }