Skip to content

Commit

Permalink
Fixed potential bug sources and missing handler
Browse files Browse the repository at this point in the history
- Fixed a potential bug that could have caused problems when actions
were cancelled
- Fixed a bug that made it possible to start the update process multiple
times using the integrated UpdaterUI
- Added forgotten event handler that should have reported failed
downloads, but consecutively did not
- Fixed a bug that fired the Finished-event, even if the download of the
packages failed
- Improved code and made it fully working now
  • Loading branch information
ProgTrade committed Apr 18, 2015
1 parent 3cb7e50 commit ae4758c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
12 changes: 10 additions & 2 deletions nUpdate/UI/Dialogs/UpdateDownloadDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ private void UpdateDownloadDialog_Load(object sender, EventArgs e)
Icon = _appIcon;
}

#region TAP

public void ShowModalDialog(object dialogResultReference)
{
((DialogResultReference)dialogResultReference).DialogResult = ShowDialog();
Expand All @@ -119,6 +117,8 @@ public void CloseDialog(object state)
Close();
}

#region TAP

public void Fail(Exception ex)
{
Invoke(new Action(() => Popup.ShowPopup(this, SystemIcons.Error,
Expand Down Expand Up @@ -155,6 +155,14 @@ public void ProgressChanged(object sender, UpdateDownloadProgressChangedEventArg
}
}

public void Failed(object sender, FailedEventArgs e)
{
Invoke(new Action(() => Popup.ShowPopup(this, SystemIcons.Error,
"Error while downloading the update package.",
e.Exception.InnerException ?? e.Exception, PopupButtons.Ok)));
DialogResult = DialogResult.Cancel;
}

public void Finished(object sender, EventArgs e)
{
DialogResult = DialogResult.OK;
Expand Down
4 changes: 2 additions & 2 deletions nUpdate/UI/Dialogs/UpdateSearchDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ public void Fail(Exception ex)
PopupButtons.Ok)));
}

public void ShowModalDialog(object state)
public void ShowModalDialog(object dialogResultReference)
{
ShowDialog();
((DialogResultReference)dialogResultReference).DialogResult = ShowDialog();
}

public void CloseDialog(object state)
Expand Down
5 changes: 3 additions & 2 deletions nUpdate/Updating/UpdateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ public void DownloadPackages()
}
}
}
catch (Exception)
finally
{
if (webResponse != null)
webResponse.Close();
Expand Down Expand Up @@ -442,7 +442,8 @@ private void DownloadTaskCompleted(Task task)
var exception = task.Exception;
if (exception != null)
OnUpdateDownloadFailed(exception.InnerException ?? exception);
OnUpdateDownloadFinished(this, EventArgs.Empty);
else
OnUpdateDownloadFinished(this, EventArgs.Empty);
}

#if PROVIDE_TAP
Expand Down
11 changes: 8 additions & 3 deletions nUpdate/Updating/UpdaterUi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public void ShowUserInterface()
if (_isTaskRunning)
return;

_isTaskRunning = true;
var searchDialog = new UpdateSearchDialog {LanguageName = _updateManager.LanguageCulture.Name};
searchDialog.CancelButtonClicked += UpdateSearchDialogCancelButtonClick;

Expand All @@ -140,10 +141,10 @@ public void ShowUserInterface()

#if PROVIDE_TAP


// TAP
TaskEx.Run(async delegate
{
_isTaskRunning = true;
if (!UseHiddenSearch)
_context.Post(searchDialog.ShowModalDialog, null);

Expand Down Expand Up @@ -248,13 +249,15 @@ public void ShowUserInterface()
_isTaskRunning = false;
});


#else
//EAP
_updateManager.UpdateSearchFinished += SearchFinished;
_updateManager.UpdateSearchFinished += searchDialog.Finished;
_updateManager.UpdateSearchFailed += searchDialog.Failed;
_updateManager.PackagesDownloadProgressChanged += downloadDialog.ProgressChanged;
_updateManager.PackagesDownloadFinished += downloadDialog.Finished;
_updateManager.PackagesDownloadFailed += downloadDialog.Failed;

Task.Factory.StartNew(() =>
{
Expand All @@ -263,8 +266,9 @@ public void ShowUserInterface()
{
var searchDialogResultReference = new DialogResultReference();
_context.Send(searchDialog.ShowModalDialog, searchDialogResultReference);
if (searchDialogResultReference.DialogResult == DialogResult.OK)
_context.Send(searchDialog.CloseDialog, null);
_context.Send(searchDialog.CloseDialog, null);
if (searchDialogResultReference.DialogResult == DialogResult.Cancel)
return;
}
else
{
Expand Down Expand Up @@ -326,6 +330,7 @@ public void ShowUserInterface()
PopupButtons.Ok), null);
else
_updateManager.InstallPackage();
_isTaskRunning = false;
});
#endif
}
Expand Down

0 comments on commit ae4758c

Please sign in to comment.