private void CopyFile(string source, string destination)
{
CreatePath(destination);
UpdateUI(" " + destination, true);
// loop until the file is successfully copied, or user is tired of retrying
while (true)
{
try
{
File.Copy(source, destination, true);
}
catch (UnauthorizedAccessException) //The exception that is thrown when the operating system denies access because of an I/O error or a specific type of security error.
{
MessageBox.Show(this,
"Access denied for copying files. Program Files and such are not the best place to run AWB from.\r\n" +
"Please run the updater with Administrator rights.");
Fail();
}
catch (Exception ex)
{
if (MessageBox.Show(
this,
"Problem replacing file:\r\n " + ex.Message + "\r\n\r\n" +
"Please close all applications that may use it and press 'Retry' to try again " +
"or 'Cancel' to cancel the upgrade.",
"Error",
MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry)
{
continue;
}
Fail();
}
break;
}
}