Skip to content

Commit

Permalink
Fix for test and build.
Browse files Browse the repository at this point in the history
Seems await in catch is breaking things.
  • Loading branch information
RichardLake committed Jun 1, 2015
1 parent 814da57 commit 90c751a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 33 deletions.
36 changes: 20 additions & 16 deletions GUI/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public Main(string[] cmdlineArgs, GUIUser User, bool showConsole)
ModInfoTabControl.Enabled = false;

// WinForms on Mac OS X has a nasty bug where the UI thread hogs the CPU,
// making our download speeds really slow unless you move the mouse while
// making our download speeds really slow unless you move the mouse while
// downloading. Yielding periodically addresses that.
// https://bugzilla.novell.com/show_bug.cgi?id=663433
if (Platform.IsMac)
Expand Down Expand Up @@ -416,7 +416,7 @@ private void MarkAllUpdatesToolButton_Click(object sender, EventArgs e)
private void ModList_SelectedIndexChanged(object sender, EventArgs e)
{
var module = GetSelectedModule();

ModInfoTabControl.Enabled = module!=null;
if (module == null) return;

Expand Down Expand Up @@ -464,8 +464,8 @@ private void FilterByAuthorTextBox_TextChanged(object sender, EventArgs e)
}

/// <summary>
/// Start or restart a timer to update the filter after an interval
/// since the last keypress. On Mac OS X, this prevents the search
/// Start or restart a timer to update the filter after an interval
/// since the last keypress. On Mac OS X, this prevents the search
/// field from locking up due to DataGridViews being slow and
/// key strokes being interpreted incorrectly when slowed down:
/// http://mono.1490590.n4.nabble.com/Incorrect-missing-and-duplicate-keypress-events-td4658863.html
Expand All @@ -486,7 +486,7 @@ private void RunFilterUpdateTimer() {
}

/// <summary>
/// Updates the filter after an interval of time has passed since the
/// Updates the filter after an interval of time has passed since the
/// last keypress.
/// </summary>
/// <param name="source">Source</param>
Expand All @@ -499,10 +499,10 @@ private void OnFilterUpdateTimer(Object source, EventArgs e)
}

/// <summary>
/// Called on key press when the mod is focused. Scrolls to the first mod
/// Called on key press when the mod is focused. Scrolls to the first mod
/// with name begining with the key pressed. If space is pressed, the checkbox
/// at the current row is toggled.
/// </summary>
/// </summary>
private void ModList_KeyPress(object sender, KeyPressEventArgs e)
{
// Check the key. If it is space, mark the current mod as selected.
Expand All @@ -514,9 +514,9 @@ private void ModList_KeyPress(object sender, KeyPressEventArgs e)
{
var gui_mod = ((GUIMod)selected_row.Tag);
if (gui_mod.IsInstallable())
{
MarkModForInstall(gui_mod.Identifier,uninstall:gui_mod.IsInstallChecked);
}
{
MarkModForInstall(gui_mod.Identifier,uninstall:gui_mod.IsInstallChecked);
}
}
e.Handled = true;
return;
Expand Down Expand Up @@ -594,17 +594,17 @@ private async void ModList_CellValueChanged(object sender, DataGridViewCellEvent

private async Task UpdateChangeSetAndConflicts(Registry registry)
{
IEnumerable<KeyValuePair<CkanModule, GUIModChangeType>> full_change_set;
Dictionary<Module, string> conflicts;
IEnumerable<KeyValuePair<CkanModule, GUIModChangeType>> full_change_set = null;
Dictionary<Module, string> conflicts = null;

bool too_many_provides_thrown = false;
var user_change_set = mainModList.ComputeUserChangeSet();
try
{
var module_installer = ModuleInstaller.GetInstance(CurrentInstance, GUI.user);
full_change_set =
await mainModList.ComputeChangeSetFromModList(registry, user_change_set, module_installer,
CurrentInstance.Version());
conflicts = null;
}
catch (InconsistentKraken)
{
Expand All @@ -617,6 +617,10 @@ await mainModList.ComputeChangeSetFromModList(registry, user_change_set, module_
{
//Can be thrown by ComputeChangeSetFromModList if the user cancels out of it.
//We can just rerun it as the ModInfoTabControl has been removed.
too_many_provides_thrown = true;
}
if (too_many_provides_thrown)
{
await UpdateChangeSetAndConflicts(registry);
conflicts = Conflicts;
full_change_set = ChangeSet;
Expand Down Expand Up @@ -706,7 +710,7 @@ private CkanModule GetSelectedModule()
return null;
}

var module = ((GUIMod) selected_item.Tag).ToCkanModule();
var module = ((GUIMod) selected_item.Tag).ToCkanModule();
return module;
}

Expand All @@ -721,7 +725,7 @@ private void launchKSPToolStripMenuItem_Click(object sender, EventArgs e)

var binary = split[0];
var args = string.Join(" ",split.Skip(1));

try
{
Directory.SetCurrentDirectory(CurrentInstance.GameDir());
Expand Down Expand Up @@ -764,7 +768,7 @@ private void pluginsToolStripMenuItem_Click(object sender, EventArgs e)
Enabled = true;
}



private void installFromckanToolStripMenuItem_Click(object sender, EventArgs e)
{
Expand Down
44 changes: 27 additions & 17 deletions GUI/MainModList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private void _UpdateModsList(bool repo_updated)

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

private void _MarkModForInstall(string identifier, bool uninstall)
Expand Down Expand Up @@ -139,7 +139,8 @@ public class MainModList
{
internal List<DataGridViewRow> full_list_of_mod_rows;

public MainModList(ModFiltersUpdatedEvent onModFiltersUpdated, HandleTooManyProvides too_many_provides, IUser user = null)
public MainModList(ModFiltersUpdatedEvent onModFiltersUpdated, HandleTooManyProvides too_many_provides,
IUser user = null)
{
this.too_many_provides = too_many_provides;
this.user = user ?? new NullUser();
Expand All @@ -149,6 +150,7 @@ public MainModList(ModFiltersUpdatedEvent onModFiltersUpdated, HandleTooManyProv
}

public delegate void ModFiltersUpdatedEvent(MainModList source);

//TODO Move to relationship resolver and have it use this.
public delegate Task<CkanModule> HandleTooManyProvides(TooManyModsProvideKraken kraken);

Expand Down Expand Up @@ -192,7 +194,7 @@ public string ModAuthorFilter
private GUIModFilter _modFilter = GUIModFilter.Compatible;
private string _modNameFilter = String.Empty;
private string _modAuthorFilter = String.Empty;
private IUser user;
private IUser user;

/// <summary>
/// This function returns a changeset based on the selections of the user.
Expand Down Expand Up @@ -231,31 +233,39 @@ public async Task<IEnumerable<KeyValuePair<CkanModule, GUIModChangeType>>> Compu
}
}

//May throw InconsistentKraken
while (true)
bool handled_all_to_many_provides = false;
while (!handled_all_to_many_provides)
{
//Can't await in catch clause - doesn't seem to work in mono. Hence this flag
TooManyModsProvideKraken kraken = null;
try
{
new RelationshipResolver(modules_to_install.ToList(), options, registry, version);
handled_all_to_many_provides = true;
continue;
}
catch (TooManyModsProvideKraken kraken)
catch (TooManyModsProvideKraken k)
{
var mod = await too_many_provides(kraken);
if (mod != null)
{
modules_to_install.Add(mod.identifier);
continue;
}
throw;
kraken = k;
}
catch (ModuleNotFoundKraken kraken)
catch (ModuleNotFoundKraken k)
{
//We shouldn't need this. However the relationship provider will throw TMPs with incompatible mods.
user.RaiseError("Module {0} has not been found. This may be because it is not compatible " +
"with the currently installed version of KSP", kraken.module);
"with the currently installed version of KSP", k.module);
return null;
}
break;
//Shouldn't get here unless there is a kraken.
var mod = await too_many_provides(kraken);
if (mod != null)
{
modules_to_install.Add(mod.identifier);
}
else
{
//TODO Is could be a new type of Kraken.
throw kraken;
}
}

var resolver = new RelationshipResolver(modules_to_install.ToList(), options, registry, version);
Expand Down Expand Up @@ -319,7 +329,7 @@ public IEnumerable<DataGridViewRow> ConstructModList(IEnumerable<GUIMod> modules
: new DataGridViewTextBoxCell();

installed_cell.Value = mod.IsInstallable()
? (object)mod.IsInstalled
? (object) mod.IsInstalled
: (mod.IsAutodetected ? "AD" : "-");

var update_cell = mod.HasUpdate && !mod.IsAutodetected
Expand Down

0 comments on commit 90c751a

Please sign in to comment.