Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat reinstalling a changed module as an update #3828

Merged
merged 1 commit into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cmdline/Action/List.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)
{
log.DebugFormat(" {0} installed version not found in registry", mod.Key);
}

// Check if mod is replaceable
if (current.replaced_by != null)
{
Expand All @@ -99,7 +99,7 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)
}
}
}
else if (latest.version.IsEqualTo(current_version))
else if (latest.version.IsEqualTo(current_version) && !registry.HasUpdate(mod.Key, instance.VersionCriteria()))
{
// Up to date
log.InfoFormat("Latest {0} is {1}", mod.Key, latest.version);
Expand All @@ -116,7 +116,7 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)
}
}
}
else if (latest.version.IsGreaterThan(mod.Value))
else if (latest.version.IsGreaterThan(mod.Value) || registry.HasUpdate(mod.Key, instance.VersionCriteria()))
{
// Upgradable
bullet = "^";
Expand Down
4 changes: 0 additions & 4 deletions Cmdline/Action/Update.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)
{
UpdateRepository(instance);
}
catch (ReinstallModuleKraken rmk)
{
Upgrade.UpgradeModules(manager, user, instance, false, rmk.Modules);
}
catch (MissingCertificateKraken kraken)
{
// Handling the kraken means we have prettier output.
Expand Down
2 changes: 1 addition & 1 deletion Cmdline/Action/Upgrade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)
continue;
}

if (latest.version.IsGreaterThan(mod.Value))
if (latest.version.IsGreaterThan(mod.Value) || registry.HasUpdate(mod.Key, instance.VersionCriteria()))
{
// Upgradable
log.InfoFormat("New version {0} found for {1}",
Expand Down
6 changes: 0 additions & 6 deletions ConsoleUI/ModListScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -446,12 +446,6 @@ private bool UpdateRegistry(ConsoleTheme theme, bool showNewModsPrompt = true)
manager.Cache,
ps
);
} catch (ReinstallModuleKraken rmk) {
ChangePlan reinstPlan = new ChangePlan();
foreach (CkanModule m in rmk.Modules) {
reinstPlan.ToggleUpgrade(m);
}
LaunchSubScreen(theme, new InstallScreen(manager, reinstPlan, debug));
} catch (Exception ex) {
// There can be errors while you re-install mods with changed metadata
ps.RaiseError(ex.Message + ex.StackTrace);
Expand Down
141 changes: 0 additions & 141 deletions Core/Net/Repo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,7 @@ public static RepoUpdateResult UpdateAllRepositories(RegistryManager registry_ma
registry_manager.registry.SetAllAvailable(modules);
registry_manager.registry.SetDownloadCounts(dlCounts);
registry_manager.Save(enforce_consistency: false);

ShowUserInconsistencies(registry_manager.registry, user);
List<CkanModule> metadataChanges = GetChangedInstalledModules(registry_manager.registry);
if (metadataChanges.Count > 0 && cache != null)
{
HandleModuleChanges(metadataChanges, user, ksp, cache, registry_manager);
}
}

// Report success
Expand Down Expand Up @@ -263,141 +257,6 @@ private static List<CkanModule> ModulesFromZip(Repository repo, string path, IUs
return modules;
}

/// <summary>
/// Find installed modules that have different metadata in their equivalent available module
/// </summary>
/// <param name="registry">Registry to scan</param>
/// <returns>
/// List of CkanModules that are available and have changed metadata
/// </returns>
private static List<CkanModule> GetChangedInstalledModules(Registry registry)
{
List<CkanModule> metadataChanges = new List<CkanModule>();
foreach (InstalledModule installedModule in registry.InstalledModules)
{
string identifier = installedModule.identifier;

ModuleVersion installedVersion = registry.InstalledVersion(identifier);
if (!(registry.available_modules.ContainsKey(identifier)))
{
log.InfoFormat("UpdateRegistry, module {0}, version {1} not in registry", identifier, installedVersion);
continue;
}

if (!registry.available_modules[identifier].module_version.ContainsKey(installedVersion))
{
continue;
}

// if the mod is installed and the metadata is different we have to reinstall it
CkanModule metadata = registry.available_modules[identifier].module_version[installedVersion];

CkanModule oldMetadata = registry.InstalledModule(identifier).Module;

if (!MetadataEquals(metadata, oldMetadata))
{
metadataChanges.Add(registry.available_modules[identifier].module_version[installedVersion]);
}
}
return metadataChanges;
}

/// <summary>
/// Resolve differences between installed and available metadata for given ModuleInstaller
/// </summary>
/// <param name="metadataChanges">List of modules that changed</param>
/// <param name="user">Object for user interaction callbacks</param>
/// <param name="ksp">Game instance</param>
/// <param name="cache">Cacne object for mod downloads</param>
/// <param name="registry_manager">Manager that holds our game instances</param>
private static void HandleModuleChanges(List<CkanModule> metadataChanges, IUser user, GameInstance ksp, NetModuleCache cache, RegistryManager registry_manager)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < metadataChanges.Count; i++)
{
CkanModule module = metadataChanges[i];
sb.AppendLine(string.Format("- {0} {1}", module.identifier, module.version));
}

if (user.RaiseYesNoDialog(string.Format(Properties.Resources.NetRepoChangedModulesReinstallPrompt, sb)))
{
throw new ReinstallModuleKraken(metadataChanges);
}
}

private static bool MetadataEquals(CkanModule metadata, CkanModule oldMetadata)
{
if ((metadata.install == null) != (oldMetadata.install == null)
|| (metadata.install != null
&& metadata.install.Length != oldMetadata.install.Length))
{
return false;
}
else if (metadata.install != null)
{
for (int i = 0; i < metadata.install.Length; i++)
{
if (!metadata.install[i].Equals(oldMetadata.install[i]))
return false;
}
}
if (metadata.install_size != oldMetadata.install_size)
{
return false;
}

if (!RelationshipsAreEquivalent(metadata.conflicts, oldMetadata.conflicts))
return false;

if (!RelationshipsAreEquivalent(metadata.depends, oldMetadata.depends))
return false;

if (!RelationshipsAreEquivalent(metadata.recommends, oldMetadata.recommends))
return false;

if (metadata.provides != oldMetadata.provides)
{
if (metadata.provides == null || oldMetadata.provides == null)
return false;
else if (!metadata.provides.OrderBy(i => i).SequenceEqual(oldMetadata.provides.OrderBy(i => i)))
return false;
}
return true;
}

private static bool RelationshipsAreEquivalent(List<RelationshipDescriptor> a, List<RelationshipDescriptor> b)
{
if (a == b)
// If they're the same exact object they must be equivalent
return true;

if (a == null || b == null)
// If they're not the same exact object and either is null then must not be equivalent
return false;

if (a.Count != b.Count)
// If their counts different they must not be equivalent
return false;

// Sort the lists so we can compare each relationship
var aSorted = a.OrderBy(i => i.ToString()).ToList();
var bSorted = b.OrderBy(i => i.ToString()).ToList();

for (var i = 0; i < a.Count; i++)
{
var aRel = aSorted[i];
var bRel = bSorted[i];

if (!aRel.Equals(bRel))
{
return false;
}
}

// If we couldn't find any differences they must be equivalent
return true;
}

private static CkanModule ProcessRegistryMetadataFromJSON(string metadata, string filename)
{
try
Expand Down
6 changes: 0 additions & 6 deletions Core/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions Core/Properties/Resources.fr-FR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,6 @@ Installez le paquet `mono-complete` ou un équivalent pour votre système d'expl
<data name="NetRepoFailedDownload" xml:space="preserve">
<value>Échec du téléchargement de {0} : {1}</value>
</data>
<data name="NetRepoChangedModulesReinstallPrompt" xml:space="preserve">
<value>Les mods suivants ont eu leurs métadonnées changées depuis la dernière mise à jour :

{0}
Vous devriez les réinstaller pour préserver la cohérence avec le répertoire.

Souhaitez-vous réinstaller maintenant ?</value>
</data>
<data name="NetRepoInconsistenciesHeader" xml:space="preserve">
<value>Les incohérences suivantes ont été trouvées :</value>
</data>
Expand Down Expand Up @@ -565,9 +557,6 @@ Pensez à ajouter un jeton d'authentification pour augmenter la limite avant bri
Si vous êtes certain que ce n'est pas le cas, alors supprimez :
"{0}"</value>
</data>
<data name="KrakenReinstallModule" xml:space="preserve">
<value>Changement de métadonnées, réinstallation recommandée : {0}</value>
</data>
<data name="NotEnoughSpaceToDownload" xml:space="preserve">
<value>Pas assez d'espace dans le dossier temporaire pour télécharger les modules !</value>
</data>
Expand Down
11 changes: 0 additions & 11 deletions Core/Properties/Resources.it-IT.resx
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,6 @@ Installa il pacchetto `mono-complete` o un pacchetto equivalente per il tuo sist
<data name="NetRepoFailedDownload" xml:space="preserve">
<value>Impossibile scaricare {0}: {1}</value>
</data>
<data name="NetRepoChangedModulesReinstallPrompt" xml:space="preserve">
<value>Le seguenti mod hanno cambiato i loro metadati dall'ultimo aggiornamento:

{0}
Dovresti reinstallarle per mantenere la coerenza con il repository.

Vuoi reinstallare ora?</value>
</data>
<data name="NetRepoInconsistenciesHeader" xml:space="preserve">
<value>Sono state rilevate le seguenti incoerenze:</value>
</data>
Expand Down Expand Up @@ -565,9 +557,6 @@ Prendi in considerazione l'aggiunta di un token di autenticazione per aumentare
Se sei sicuro che non sia questo il caso, elimina:
"{0}"</value>
</data>
<data name="KrakenReinstallModule" xml:space="preserve">
<value>Metadati cambiati, reinstallazione raccomandata: {0}</value>
</data>
<data name="NotEnoughSpaceToDownload" xml:space="preserve">
<value>Spazio insufficiente nella cartella temporanea per scaricare i moduli!</value>
</data>
Expand Down
11 changes: 0 additions & 11 deletions Core/Properties/Resources.pl-PL.resx
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,6 @@ Zainstaluj pakiet `mono-complete` lub pasujący do twojego systemu operacyjnego.
<data name="NetRepoFailedDownload" xml:space="preserve">
<value>Nie udało się pobrać {0}: {1}</value>
</data>
<data name="NetRepoChangedModulesReinstallPrompt" xml:space="preserve">
<value>Następujące modyfikacje zmieniły swoje metadane od ostatniej aktualizacji:

{0}
Powinieneś je ponownie zainstalować, aby zachować spójność z repozytorium.

Czy chcesz je zainstalować ponownie teraz?</value>
</data>
<data name="NetRepoInconsistenciesHeader" xml:space="preserve">
<value>Znaleziono następujące niespójności:</value>
</data>
Expand Down Expand Up @@ -565,9 +557,6 @@ Rozważ dodanie tokenu uwierzytelniającego, aby zwiększyć limit ograniczania.
Jeśli jesteś pewien, że tak nie jest, to usuń:
"{0}"</value>
</data>
<data name="KrakenReinstallModule" xml:space="preserve">
<value>Metadane zmienione, zalecana ponowna instalacja: {0}</value>
</data>
<data name="NotEnoughSpaceToDownload" xml:space="preserve">
<value>Za mało miejsca w folderze tymczasowym do pobrania modułów!</value>
</data>
Expand Down
7 changes: 0 additions & 7 deletions Core/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,6 @@ Install the `mono-complete` package or equivalent for your operating system.</va
<data name="NetRepoUpdatedAll" xml:space="preserve"><value>Repositories updated</value></data>
<data name="NetRepoNoModules" xml:space="preserve"><value>No modules found!</value></data>
<data name="NetRepoFailedDownload" xml:space="preserve"><value>Failed to download {0}: {1}</value></data>
<data name="NetRepoChangedModulesReinstallPrompt" xml:space="preserve"><value>The following mods have had their metadata changed since last update:

{0}
You should reinstall them in order to preserve consistency with the repository.

Do you wish to reinstall now?</value></data>
<data name="NetRepoInconsistenciesHeader" xml:space="preserve"><value>The following inconsistencies were found:</value></data>
<data name="NetRepoLoadingModulesFromRepo" xml:space="preserve"><value>Loading modules from {0} repository...</value></data>
<data name="NetRepoLoadedDownloadCounts" xml:space="preserve"><value>Loaded download counts from {0} repository</value></data>
Expand Down Expand Up @@ -281,7 +275,6 @@ Consider adding an authentication token to increase the throttling limit.</value

If you're certain this is not the case, then delete:
"{0}"</value></data>
<data name="KrakenReinstallModule" xml:space="preserve"><value>Metadata changed, reinstallation recommended: {0}</value></data>
<data name="NotEnoughSpaceToDownload" xml:space="preserve"><value>Not enough space in temp folder to download modules!</value></data>
<data name="NotEnoughSpaceToCache" xml:space="preserve"><value>Not enough space in cache folder to store modules!</value></data>
<data name="NotEnoughSpaceToInstall" xml:space="preserve"><value>Not enough space in game folder to install modules!</value></data>
Expand Down
7 changes: 0 additions & 7 deletions Core/Properties/Resources.ru-RU.resx
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,6 @@
<data name="NetRepoUpdatedAll" xml:space="preserve"><value>Репозитории обновлены</value></data>
<data name="NetRepoNoModules" xml:space="preserve"><value>Не найдено ни одного модуля!</value></data>
<data name="NetRepoFailedDownload" xml:space="preserve"><value>Не удалось загрузить «{0}»: {1}</value></data>
<data name="NetRepoChangedModulesReinstallPrompt" xml:space="preserve"><value>С последнего обновления были изменены метаданные следующих модификаций:

{0}
Ради сохранения согласованности с репозиторием рекомендуется их переустановка.

Хотите ли вы переустановить их сейчас?</value></data>
<data name="NetRepoInconsistenciesHeader" xml:space="preserve"><value>Найдены следующие несоответствия:</value></data>
<data name="JsonRelationshipConverterAnyOfCombined" xml:space="preserve"><value>`any_of` не должно сочетаться с `{0}`</value></data>
<data name="RegistryFileConflict" xml:space="preserve"><value>{0} желает установить {1}, который принадлежит {2}</value></data>
Expand Down Expand Up @@ -277,7 +271,6 @@ https://github.com/KSP-CKAN/CKAN/wiki/SSL-certificate-errors</value></data>

Если вы уверены, что это не так, удалите:
"{0}"</value></data>
<data name="KrakenReinstallModule" xml:space="preserve"><value>Метаданные изменены, рекомендуется переустановка: {0}</value></data>
<data name="RelationshipResolverConflictsWith" xml:space="preserve"><value>{0} конфликтует с {1}</value></data>
<data name="RelationshipResolverRequiredButResolver" xml:space="preserve"><value>Необходима {0}, но в ресольвере несовместимая версия</value></data>
<data name="RelationshipResolverRequiredButInstalled" xml:space="preserve"><value>Необходима {0}, но установлена несовместимая версия</value></data>
Expand Down
Loading