Skip to content

Commit

Permalink
Queue module version changes in change set
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Jul 6, 2019
1 parent 2ee75c1 commit f1fb60e
Show file tree
Hide file tree
Showing 14 changed files with 245 additions and 115 deletions.
17 changes: 15 additions & 2 deletions Core/ModuleInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ public void InstallList(ICollection<CkanModule> modules, RelationshipResolverOpt
{
for (int i = 0; i < modsToInstall.Count; i++)
{
int percent_complete = (i * 100) / modsToInstall.Count;
// The post-install steps start at 70%, so count up to 60% for installation
int percent_complete = (i * 60) / modsToInstall.Count;

User.RaiseProgress(String.Format("Installing mod \"{0}\"", modsToInstall[i]),
percent_complete);
Expand Down Expand Up @@ -984,20 +985,29 @@ public void AddRemove(IEnumerable<CkanModule> add = null, IEnumerable<InstalledM

using (var tx = CkanTransaction.CreateTransactionScope())
{

int totSteps = (remove?.Count() ?? 0)
+ (add?.Count() ?? 0);
int step = 0;
foreach (InstalledModule instMod in remove)
{
// The post-install steps start at 80%, so count up to 70% for installation
int percent_complete = (step++ * 70) / totSteps;
User.RaiseProgress($"Removing \"{instMod}\"", percent_complete);
Uninstall(instMod.Module.identifier);
}

foreach (CkanModule module in add)
{
var previous = remove?.FirstOrDefault(im => im.Module.identifier == module.identifier);
int percent_complete = (step++ * 70) / totSteps;
User.RaiseProgress($"Installing \"{module}\"", percent_complete);
Install(module, previous?.AutoInstalled ?? false);
}

User.RaiseProgress("Updating registry", 80);
registry_manager.Save(enforceConsistency);

User.RaiseProgress("Committing filesystem changes", 90);
tx.Complete();

EnforceCacheSizeLimit();
Expand All @@ -1022,6 +1032,8 @@ public void Upgrade(IEnumerable<string> identifiers, IDownloader netAsyncDownloa
/// </summary>
public void Upgrade(IEnumerable<CkanModule> modules, IDownloader netAsyncDownloader, bool enforceConsistency = true)
{
User.RaiseMessage("About to upgrade...\r\n");

// Start by making sure we've downloaded everything.
DownloadModules(modules, netAsyncDownloader);

Expand Down Expand Up @@ -1073,6 +1085,7 @@ public void Upgrade(IEnumerable<CkanModule> modules, IDownloader netAsyncDownloa
to_remove,
enforceConsistency
);
User.RaiseProgress("Done!", 100);
}

/// <summary>
Expand Down
107 changes: 87 additions & 20 deletions GUI/GUIMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,64 @@
using System.Collections.Generic;
using System.Windows.Forms;
using System.Linq;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using CKAN.Versioning;

namespace CKAN
{
public sealed class GUIMod
public sealed class GUIMod : INotifyPropertyChanged
{
private CkanModule Mod { get; set; }
private InstalledModule InstalledMod { get; set; }
private CkanModule Mod { get; set; }
private CkanModule LatestCompatibleMod { get; set; }
private InstalledModule InstalledMod { get; set; }

/// <summary>
/// The module of the checkbox that is checked in the MainAllModVersions list if any,
/// null otherwise.
/// Used for generating this mod's part of the change set.
/// </summary>
public CkanModule SelectedMod
{
get { return selectedMod; }
set
{
if (!(selectedMod?.Equals(value) ?? value?.Equals(selectedMod) ?? true))
{
selectedMod = value;
var row = Main.Instance?.mainModList?.full_list_of_mod_rows?[Identifier];

if (IsInstalled && HasUpdate)
{
var isLatest = (LatestCompatibleMod?.Equals(selectedMod) ?? false);
if (IsUpgradeChecked ^ isLatest)
{
// Try upgrading if they pick the latest
Main.Instance.MarkModForUpdate(Identifier, isLatest);
}

}
Main.Instance.MarkModForInstall(Identifier, selectedMod == null);

Main.Instance.UpdateChangeSetAndConflicts(
RegistryManager.Instance(Main.Instance.Manager.CurrentInstance).registry
);

OnPropertyChanged();
}
}
}
private CkanModule selectedMod = null;

/// <summary>
/// Notify listeners when certain properties change.
/// Currently used to tell MainAllModVersions to update its checkboxes.
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string name = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}

public string Name { get; private set; }
public bool IsInstalled { get; private set; }
Expand Down Expand Up @@ -85,6 +135,7 @@ public GUIMod(InstalledModule instMod, IRegistryQuerier registry, KspVersionCrit
IsInstalled = true;
IsInstallChecked = true;
InstalledMod = instMod;
SelectedMod = instMod.Module;
IsAutoInstalled = instMod.AutoInstalled;
InstallDate = instMod.InstallTime;
InstalledVersion = instMod.Module.version.ToString();
Expand Down Expand Up @@ -157,7 +208,8 @@ public GUIMod(string identifier, IRegistryQuerier registry, KspVersionCriteria c
ModuleVersion latest_version = null;
try
{
latest_version = registry.LatestAvailable(identifier, current_ksp_version)?.version;
LatestCompatibleMod = registry.LatestAvailable(identifier, current_ksp_version);
latest_version = LatestCompatibleMod?.version;
}
catch (ModuleNotFoundKraken)
{
Expand Down Expand Up @@ -234,22 +286,32 @@ public CkanModule ToModule()
return Mod;
}

public KeyValuePair<GUIMod, GUIModChangeType>? GetRequestedChange()
public IEnumerable<KeyValuePair<CkanModule, GUIModChangeType>> GetRequestedChanges()
{
if (IsInstalled ^ IsInstallChecked)
if (IsInstalled && !IsInstallChecked)
{
// Uninstall the version we have installed
yield return new KeyValuePair<CkanModule, GUIModChangeType>(InstalledMod.Module, GUIModChangeType.Remove);
}
else if (!IsInstalled && IsInstallChecked)
{
yield return new KeyValuePair<CkanModule, GUIModChangeType>(SelectedMod ?? Mod, GUIModChangeType.Install);
}
else if (IsInstalled && (IsInstallChecked && HasUpdate && IsUpgradeChecked))
{
var change_type = IsInstalled ? GUIModChangeType.Remove : GUIModChangeType.Install;
return new KeyValuePair<GUIMod, GUIModChangeType>(this, change_type);
yield return new KeyValuePair<CkanModule, GUIModChangeType>(Mod, GUIModChangeType.Update);
}
if (IsInstalled && (IsInstallChecked && HasUpdate && IsUpgradeChecked))
else if (IsReplaceChecked)
{
return new KeyValuePair<GUIMod, GUIModChangeType>(this, GUIModChangeType.Update);
yield return new KeyValuePair<CkanModule, GUIModChangeType>(Mod, GUIModChangeType.Replace);
}
if (IsReplaceChecked)
else if (IsInstalled
&& SelectedMod != null
&& !InstalledMod.Module.Equals(SelectedMod))
{
return new KeyValuePair<GUIMod, GUIModChangeType>(this, GUIModChangeType.Replace);
yield return new KeyValuePair<CkanModule, GUIModChangeType>(InstalledMod.Module, GUIModChangeType.Remove);
yield return new KeyValuePair<CkanModule, GUIModChangeType>(SelectedMod, GUIModChangeType.Install);
}
return null;
}

/// <summary>
Expand Down Expand Up @@ -282,35 +344,40 @@ public void SetRequestedChange(GUIModChangeType change)
}
}

public static implicit operator CkanModule(GUIMod mod)
{
return mod.ToModule();
}

public void SetUpgradeChecked(DataGridViewRow row, DataGridViewColumn col, bool? set_value_to = null)
{
var update_cell = row.Cells[col.Index] as DataGridViewCheckBoxCell;
var update_cell = row?.Cells[col.Index] as DataGridViewCheckBoxCell;
if (update_cell != null)
{
var old_value = (bool) update_cell.Value;

bool value = set_value_to ?? old_value;
IsUpgradeChecked = value;
if (old_value != value)
{
update_cell.Value = value;
SelectedMod = value ? LatestCompatibleMod : (SelectedMod ?? InstalledMod?.Module);
}
else if (!set_value_to.HasValue)
{
var isLatest = (LatestCompatibleMod?.Equals(selectedMod) ?? false);
SelectedMod = value ? LatestCompatibleMod
: isLatest ? InstalledMod?.Module : SelectedMod;
}
}
}

public void SetInstallChecked(DataGridViewRow row, DataGridViewColumn col, bool? set_value_to = null)
{
var install_cell = row.Cells[col.Index] as DataGridViewCheckBoxCell;
var install_cell = row?.Cells[col.Index] as DataGridViewCheckBoxCell;
if (install_cell != null)
{
bool changeTo = set_value_to ?? (bool)install_cell.Value;
if (IsInstallChecked != changeTo)
{
IsInstallChecked = changeTo;
}
SelectedMod = changeTo ? (SelectedMod ?? Mod) : null;
// Setting this property causes ModList_CellValueChanged to be called,
// which calls SetInstallChecked again. Treat it conservatively.
if ((bool)install_cell.Value != IsInstallChecked)
Expand Down
11 changes: 6 additions & 5 deletions GUI/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ private void ChangeSetUpdated()
tabController.HideTab("ChangesetTabPage");
ApplyToolButton.Enabled = false;
auditRecommendationsMenuItem.Enabled = true;
InstallAllCheckbox.Checked = true;
}
}

Expand Down Expand Up @@ -483,7 +484,7 @@ protected override void OnFormClosing(FormClosingEventArgs e)
{
// Ask if they want to discard the change set
string changeDescrip = ChangeSet
.GroupBy(ch => ch.ChangeType, ch => ch.Mod.Name)
.GroupBy(ch => ch.ChangeType, ch => ch.Mod.name)
.Select(grp => $"{grp.Key}: "
+ grp.Aggregate((a, b) => $"{a}, {b}"))
.Aggregate((a, b) => $"{a}\r\n{b}");
Expand Down Expand Up @@ -595,7 +596,7 @@ private void MarkAllUpdatesToolButton_Click(object sender, EventArgs e)
var mod = (GUIMod)row.Tag;
if (mod.HasUpdate)
{
MarkModForUpdate(mod.Identifier);
MarkModForUpdate(mod.Identifier, true);
}
}

Expand Down Expand Up @@ -713,7 +714,7 @@ private void OnFilterUpdateTimer(object source, EventArgs e)
filterTimer.Stop();
}

private async Task UpdateChangeSetAndConflicts(IRegistryQuerier registry)
public async Task UpdateChangeSetAndConflicts(IRegistryQuerier registry)
{
IEnumerable<ModChange> full_change_set = null;
Dictionary<GUIMod, string> new_conflicts = null;
Expand Down Expand Up @@ -1230,7 +1231,7 @@ private void reinstallToolStripMenuItem_Click(object sender, EventArgs e)
// Build the list of changes, first the mod to remove:
List<ModChange> toReinstall = new List<ModChange>()
{
new ModChange(module, GUIModChangeType.Remove, null)
new ModChange(module.ToModule(), GUIModChangeType.Remove, null)
};
// Then everything we need to re-install:
var revdep = registry.FindReverseDependencies(new List<string>() { module.Identifier });
Expand All @@ -1242,7 +1243,7 @@ private void reinstallToolStripMenuItem_Click(object sender, EventArgs e)
foreach (string id in goners)
{
toReinstall.Add(new ModChange(
mainModList.full_list_of_mod_rows[id]?.Tag as GUIMod,
(mainModList.full_list_of_mod_rows[id]?.Tag as GUIMod).ToModule(),
GUIModChangeType.Install,
null
));
Expand Down
5 changes: 3 additions & 2 deletions GUI/MainAllModVersions.Designer.cs

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

Loading

0 comments on commit f1fb60e

Please sign in to comment.