Skip to content

Commit

Permalink
Revert "Merge #1929 Allow uninstall of incompatible mods in GUI"
Browse files Browse the repository at this point in the history
This reverts commit 85d72b6, reversing
changes made to bcf87c2.
  • Loading branch information
politas committed Oct 17, 2017
1 parent 464c693 commit bc9848c
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 84 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

All notable changes to this project will be documented in this file.

## v1.24.0-PRE
## v1.22.6-PRE

### Bugfixes

- [GUI] REVERT: Allow uninstall of incompatible mods in GUI (#1929 by: ayan4m1; reviewed: politas)
- [GUI] Fix search box tab order (#2141 by: HebaruSan; reviewed: politas)
- [Core] Check for stale lock files (#2139 by: HebaruSan; reviewed: politas)
- [NetKAN] Improve error output (#2144 by: HebaruSan; reviewed: Olympic1)
Expand Down
94 changes: 47 additions & 47 deletions GUI/GUIMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,67 +42,70 @@ public string Name
public bool IsCKAN { get; private set; }
public string Abbrevation { get; private set; }

public string Version => IsInstalled ? InstalledVersion : LatestVersion;
public string Version
{
get { return IsInstalled ? InstalledVersion : LatestVersion; }
}

public GUIMod(CkanModule mod, IRegistryQuerier registry, KspVersionCriteria currentKspVersion)
public GUIMod(CkanModule mod, IRegistryQuerier registry, KspVersionCriteria current_ksp_version)
{
IsCKAN = mod is CkanModule;
//Currently anything which could alter these causes a full reload of the modlist
// If this is ever changed these could be moved into the properties
Mod = mod;
IsInstalled = registry.IsInstalled(mod.identifier, false);
IsInstallChecked = IsInstalled;
HasUpdate = registry.HasUpdate(mod.identifier, currentKspVersion);
IsIncompatible = !mod.IsCompatibleKSP(currentKspVersion);
HasUpdate = registry.HasUpdate(mod.identifier, current_ksp_version);
IsIncompatible = !mod.IsCompatibleKSP(current_ksp_version);
IsAutodetected = registry.IsAutodetected(mod.identifier);
Authors = mod.author == null ? "N/A" : String.Join(",", mod.author);

var installedVersion = registry.InstalledVersion(mod.identifier);
Version latestVersion = null;
var kspVersion = mod.ksp_version;
var installed_version = registry.InstalledVersion(mod.identifier);
Version latest_version = null;
var ksp_version = mod.ksp_version;

try
{
var latestAvailable = registry.LatestAvailable(mod.identifier, currentKspVersion);
if (latestAvailable != null)
latestVersion = latestAvailable.version;
var latest_available = registry.LatestAvailable(mod.identifier, current_ksp_version);
if (latest_available != null)
latest_version = latest_available.version;
}
catch (ModuleNotFoundKraken)
{
latestVersion = installedVersion;
latest_version = installed_version;
}

InstalledVersion = installedVersion != null ? installedVersion.ToString() : "-";
InstalledVersion = installed_version != null ? installed_version.ToString() : "-";

// Let's try to find the compatibility for this mod. If it's not in the registry at
// all (because it's a DarkKAN mod) then this might fail.

CkanModule latestAvailableForAnyVersion = null;
CkanModule latest_available_for_any_ksp = null;

try
{
latestAvailableForAnyVersion = registry.LatestAvailable(mod.identifier, null);
latest_available_for_any_ksp = registry.LatestAvailable(mod.identifier, null);
}
catch
{
// If we can't find the mod in the CKAN, but we've a CkanModule installed, then
// use that.
if (IsCKAN)
latestAvailableForAnyVersion = (CkanModule) mod;
latest_available_for_any_ksp = (CkanModule) mod;
}

// If there's known information for this mod in any form, calculate the highest compatible
// KSP.
if (latestAvailableForAnyVersion != null)
if (latest_available_for_any_ksp != null)
{
KSPCompatibility = KSPCompatibilityLong = registry.LatestCompatibleKSP(mod.identifier)?.ToString() ?? mod.LatestCompatibleKSP().ToString();
KSPCompatibility = KSPCompatibilityLong = latest_available_for_any_ksp.HighestCompatibleKSP();

// If the mod we have installed is *not* the mod we have installed, or we don't know
// what we have installed, indicate that an upgrade would be needed.
if (installedVersion == null || !latestAvailableForAnyVersion.version.IsEqualTo(installedVersion))
if (installed_version == null || !latest_available_for_any_ksp.version.IsEqualTo(installed_version))
{
KSPCompatibilityLong = string.Format("{0} (using mod version {1})",
KSPCompatibility, latestAvailableForAnyVersion.version);
KSPCompatibility, latest_available_for_any_ksp.version);
}
}
else
Expand All @@ -111,20 +114,20 @@ public GUIMod(CkanModule mod, IRegistryQuerier registry, KspVersionCriteria curr
KSPCompatibility = KSPCompatibilityLong = "unknown";
}

if (latestVersion != null)
if (latest_version != null)
{
LatestVersion = latestVersion.ToString();
LatestVersion = latest_version.ToString();
}
else if (latestAvailableForAnyVersion != null)
else if (latest_available_for_any_ksp != null)
{
LatestVersion = latestAvailableForAnyVersion.version.ToString();
LatestVersion = latest_available_for_any_ksp.version.ToString();
}
else
{
LatestVersion = "-";
}

KSPversion = kspVersion != null ? kspVersion.ToString() : "-";
KSPversion = ksp_version != null ? ksp_version.ToString() : "-";

Abstract = mod.@abstract;

Expand Down Expand Up @@ -192,8 +195,8 @@ public CkanModule ToModule()
{
if (IsInstalled ^ IsInstallChecked)
{
var changeType = IsInstalled ? GUIModChangeType.Remove : GUIModChangeType.Install;
return new KeyValuePair<GUIMod, GUIModChangeType>(this, changeType);
var change_type = IsInstalled ? GUIModChangeType.Remove : GUIModChangeType.Install;
return new KeyValuePair<GUIMod, GUIModChangeType>(this, change_type);
}
if (IsInstalled && (IsInstallChecked && HasUpdate && IsUpgradeChecked))
{
Expand All @@ -207,37 +210,33 @@ public static implicit operator CkanModule(GUIMod mod)
return mod.ToModule();
}

public void SetUpgradeChecked(DataGridViewRow row, bool? newValue = null)
public void SetUpgradeChecked(DataGridViewRow row, bool? set_value_to = null)
{
var updateCell = row.Cells[1] as DataGridViewCheckBoxCell;
if (updateCell == null)
{
throw new Kraken("Expected second column to contain a checkbox.");
}
var oldValue = (bool) updateCell.Value;
//Contract.Requires<ArgumentException>(row.Cells[1] is DataGridViewCheckBoxCell);
var update_cell = row.Cells[1] as DataGridViewCheckBoxCell;
var old_value = (bool) update_cell.Value;

var value = newValue ?? oldValue;
bool value = set_value_to ?? old_value;
IsUpgradeChecked = value;
if (oldValue != value) updateCell.Value = value;
if (old_value != value) update_cell.Value = value;
}

public void SetInstallChecked(DataGridViewRow row, bool? newValue = null)
public void SetInstallChecked(DataGridViewRow row, bool? set_value_to = null)
{
var installCell = row.Cells[0] as DataGridViewCheckBoxCell;
if (installCell == null)
{
throw new Kraken("Expected first column to contain a checkbox.");
}

var changeTo = newValue ?? (bool)installCell.Value;
//Contract.Requires<ArgumentException>(row.Cells[0] is DataGridViewCheckBoxCell);
var install_cell = row.Cells[0] as DataGridViewCheckBoxCell;
bool changeTo = set_value_to != null ? (bool)set_value_to : (bool)install_cell.Value;
//Need to do this check here to prevent an infinite loop
//which is at least happening on Linux
//TODO: Elimate the cause
if (changeTo == IsInstallChecked) return;
IsInstallChecked = changeTo;
installCell.Value = IsInstallChecked;
if (changeTo != IsInstallChecked)
{
IsInstallChecked = changeTo;
install_cell.Value = IsInstallChecked;
}
}


private bool Equals(GUIMod other)
{
return Equals(Name, other.Name);
Expand All @@ -247,7 +246,8 @@ public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
return obj.GetType() == GetType() && Equals((GUIMod) obj);
if (obj.GetType() != GetType()) return false;
return Equals((GUIMod) obj);
}

public override int GetHashCode()
Expand Down
50 changes: 24 additions & 26 deletions GUI/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,8 @@ public void CurrentInstanceUpdated()
}

UpdateModsList();
ChangeSet = new List<ModChange>();
Conflicts = new Dictionary<GUIMod, string>();
ChangeSet = null;
Conflicts = null;

Filter((GUIModFilter)configuration.ActiveFilter);
}
Expand Down Expand Up @@ -643,7 +643,7 @@ private void ModList_KeyPress(object sender, KeyPressEventArgs e)
var gui_mod = ((GUIMod)current_row.Tag);
if (gui_mod.IsInstallable())
{
MarkModForInstall(gui_mod.Identifier, gui_mod.IsInstallChecked);
MarkModForInstall(gui_mod.Identifier,uncheck:gui_mod.IsInstallChecked);
}
}
e.Handled = true;
Expand Down Expand Up @@ -703,47 +703,45 @@ private void ModList_CellMouseDoubleClick(object sender, DataGridViewCellMouseEv

private async void ModList_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
var rowIndex = e.RowIndex;
var columnIndex = e.ColumnIndex;
if (rowIndex < 0 || columnIndex < 0)
if (mainModList.ModFilter == GUIModFilter.Incompatible)
{
return;
}
var row_index = e.RowIndex;
var column_index = e.ColumnIndex;

var registryManager = RegistryManager.Instance(CurrentInstance);
var grid = sender as DataGridView;
if (sender == null)
if (row_index < 0 || column_index < 0)
{
throw new Kraken("Could not find DataGridView!");
return;
}
var registry_manager = RegistryManager.Instance(CurrentInstance);

var grid = sender as DataGridView;

var row = grid.Rows[rowIndex];
var gridCell = row.Cells[columnIndex];
var row = grid.Rows[row_index];
var grid_view_cell = row.Cells[column_index];

if (gridCell is DataGridViewLinkCell)
if (grid_view_cell is DataGridViewLinkCell)
{
var cell = gridCell as DataGridViewLinkCell;
var cell = grid_view_cell as DataGridViewLinkCell;
Process.Start(cell.Value.ToString());
}
else if (columnIndex < 2)
else if (column_index < 2)
{
var guiMod = ((GUIMod)row.Tag);
switch (columnIndex)
var gui_mod = ((GUIMod)row.Tag);
switch (column_index)
{
case 0:
guiMod.SetInstallChecked(row);

if (guiMod.IsInstallChecked)
{
lastModToggled.Push(guiMod);
}
gui_mod.SetInstallChecked(row);
if(gui_mod.IsInstallChecked)
last_mod_to_have_install_toggled.Push(gui_mod);
break;
case 1:
guiMod.SetUpgradeChecked(row);
gui_mod.SetUpgradeChecked(row);
break;
}

var registry = registryManager.registry;
var registry = registry_manager.registry;
await UpdateChangeSetAndConflicts(registry);
}
}
Expand Down Expand Up @@ -781,7 +779,7 @@ await mainModList.ComputeChangeSetFromModList(registry, user_change_set, module_
new_conflicts = Conflicts;
full_change_set = ChangeSet;
}
lastModToggled.Clear();
last_mod_to_have_install_toggled.Clear();
Conflicts = new_conflicts;
ChangeSet = full_change_set;
}
Expand Down
10 changes: 5 additions & 5 deletions GUI/MainDialogs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public bool YesNoDialog(string text)

//Ugly Hack. Possible fix is to alter the relationship provider so we can use a loop
//over reason for to find a user requested mod. Or, you know, pass in a handler to it.
private readonly ConcurrentStack<GUIMod> lastModToggled = new ConcurrentStack<GUIMod>();
private readonly ConcurrentStack<GUIMod> last_mod_to_have_install_toggled = new ConcurrentStack<GUIMod>();
public async Task<CkanModule> TooManyModsProvide(TooManyModsProvideKraken kraken)
{
//We want LMtHIT to be the last user selection. If we alter this handling a too many provides
Expand All @@ -57,8 +57,8 @@ public async Task<CkanModule> TooManyModsProvide(TooManyModsProvideKraken kraken

if (module == null)
{
lastModToggled.TryPeek(out mod);
MarkModForInstall(mod.Identifier, true);
last_mod_to_have_install_toggled.TryPeek(out mod);
MarkModForInstall(mod.Identifier,uncheck:true);
}
Util.Invoke(this, () =>
{
Expand All @@ -72,8 +72,8 @@ public async Task<CkanModule> TooManyModsProvide(TooManyModsProvideKraken kraken
if(module!=null)
MarkModForInstall(module.identifier);

lastModToggled.TryPop(out mod);
last_mod_to_have_install_toggled.TryPop(out mod);
return module;
}
}
}
}
8 changes: 4 additions & 4 deletions GUI/MainModList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,12 @@ private void _UpdateModsList(bool repo_updated)
UpdateFilters(this);
}

public void MarkModForInstall(string identifier, bool installed = false)
public void MarkModForInstall(string identifier, bool uncheck = false)
{
Util.Invoke(this, () => _MarkModForInstall(identifier, installed));
Util.Invoke(this, () => _MarkModForInstall(identifier, uncheck));
}

private void _MarkModForInstall(string identifier, bool install)
private void _MarkModForInstall(string identifier, bool uninstall)
{
if (!mainModList.full_list_of_mod_rows.ContainsKey(identifier))
{
Expand All @@ -225,7 +225,7 @@ private void _MarkModForInstall(string identifier, bool install)
var mod = (GUIMod)row.Tag;
if (mod.Identifier == identifier)
{
mod.SetInstallChecked(row, install);
mod.SetInstallChecked(row, !uninstall);
}
}

Expand Down

0 comments on commit bc9848c

Please sign in to comment.