Fix progress bars
This commit is contained in:
parent
f2a9c3468f
commit
4df91e0ff8
4 changed files with 15 additions and 27 deletions
|
@ -6,7 +6,7 @@
|
||||||
<UseWindowsForms>true</UseWindowsForms>
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
<ApplicationIcon>ini.ico</ApplicationIcon>
|
<ApplicationIcon>ini.ico</ApplicationIcon>
|
||||||
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
|
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
|
||||||
<Version>1.0.6.0</Version>
|
<Version>1.0.6.1</Version>
|
||||||
<PackageIcon>ini.ico</PackageIcon>
|
<PackageIcon>ini.ico</PackageIcon>
|
||||||
<PackageIconUrl />
|
<PackageIconUrl />
|
||||||
<Description>Automatically downloads and installs CreamAPI files for programs/games.</Description>
|
<Description>Automatically downloads and installs CreamAPI files for programs/games.</Description>
|
||||||
|
|
|
@ -23,9 +23,13 @@ namespace CreamInstaller
|
||||||
logTextBox.BackColor = LogColor.Background;
|
logTextBox.BackColor = LogColor.Background;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int OperationsCount;
|
||||||
|
private int CompleteOperationsCount;
|
||||||
public void UpdateProgress(int progress)
|
public void UpdateProgress(int progress)
|
||||||
{
|
{
|
||||||
Program.UpdateProgressInstantly(userProgressBar, progress);
|
int value = (int)((float)((float)CompleteOperationsCount / (float)OperationsCount) * 100) + (progress / OperationsCount);
|
||||||
|
if (value < userProgressBar.Value) { return; }
|
||||||
|
userProgressBar.Value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateUser(string text, Color color, bool log = true)
|
public void UpdateUser(string text, Color color, bool log = true)
|
||||||
|
@ -41,7 +45,7 @@ namespace CreamInstaller
|
||||||
logTextBox.AppendText(userInfoLabel.Text, color);
|
logTextBox.AppendText(userInfoLabel.Text, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task OperateFor(ProgramSelection selection)
|
private async Task OperateFor(ProgramSelection selection)
|
||||||
{
|
{
|
||||||
UpdateProgress(0);
|
UpdateProgress(0);
|
||||||
|
@ -70,9 +74,6 @@ namespace CreamInstaller
|
||||||
Program.OutputTask = Program.MegaApiClient.DownloadFileAsync(selection.DownloadNode, Program.OutputFile, progress, Program.CancellationTokenSource.Token);
|
Program.OutputTask = Program.MegaApiClient.DownloadFileAsync(selection.DownloadNode, Program.OutputFile, progress, Program.CancellationTokenSource.Token);
|
||||||
await Program.OutputTask;
|
await Program.OutputTask;
|
||||||
UpdateUser($"Downloaded file: {Program.OutputFile}", LogColor.Resource);
|
UpdateUser($"Downloaded file: {Program.OutputFile}", LogColor.Resource);
|
||||||
UpdateProgress(100);
|
|
||||||
|
|
||||||
UpdateProgress(0);
|
|
||||||
UpdateUser("Searching for CreamAPI files in downloaded archive . . . ", LogColor.Operation);
|
UpdateUser("Searching for CreamAPI files in downloaded archive . . . ", LogColor.Operation);
|
||||||
string resourcePath = null;
|
string resourcePath = null;
|
||||||
List<ZipArchiveEntry> resources = new List<ZipArchiveEntry>();
|
List<ZipArchiveEntry> resources = new List<ZipArchiveEntry>();
|
||||||
|
@ -102,14 +103,10 @@ namespace CreamInstaller
|
||||||
{
|
{
|
||||||
throw new Exception($"Unable to find CreamAPI files in downloaded archive: {Program.OutputFile}");
|
throw new Exception($"Unable to find CreamAPI files in downloaded archive: {Program.OutputFile}");
|
||||||
}
|
}
|
||||||
UpdateProgress(100);
|
|
||||||
|
|
||||||
if (!Program.IsProgramRunningDialog(this, selection))
|
if (!Program.IsProgramRunningDialog(this, selection))
|
||||||
{
|
{
|
||||||
throw new OperationCanceledException();
|
throw new OperationCanceledException();
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateProgress(0);
|
|
||||||
UpdateUser("Installing CreamAPI files for " + selection.ProgramName + " . . . ", LogColor.Operation);
|
UpdateUser("Installing CreamAPI files for " + selection.ProgramName + " . . . ", LogColor.Operation);
|
||||||
int currentFileCount = 0;
|
int currentFileCount = 0;
|
||||||
foreach (string directory in selection.SteamApiDllDirectories)
|
foreach (string directory in selection.SteamApiDllDirectories)
|
||||||
|
@ -174,6 +171,9 @@ namespace CreamInstaller
|
||||||
|
|
||||||
private async Task Operate()
|
private async Task Operate()
|
||||||
{
|
{
|
||||||
|
OperationsCount = Program.ProgramSelections.FindAll(selection => selection.Enabled).Count;
|
||||||
|
CompleteOperationsCount = 0;
|
||||||
|
|
||||||
foreach (ProgramSelection selection in Program.ProgramSelections.ToList())
|
foreach (ProgramSelection selection in Program.ProgramSelections.ToList())
|
||||||
{
|
{
|
||||||
if (Program.Canceled)
|
if (Program.Canceled)
|
||||||
|
@ -201,6 +201,8 @@ namespace CreamInstaller
|
||||||
{
|
{
|
||||||
UpdateUser($"Operation failed for {selection.ProgramName}: " + exception.Message, LogColor.Error);
|
UpdateUser($"Operation failed for {selection.ProgramName}: " + exception.Message, LogColor.Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
++CompleteOperationsCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
Program.Cleanup(logout: false);
|
Program.Cleanup(logout: false);
|
||||||
|
@ -228,6 +230,7 @@ namespace CreamInstaller
|
||||||
retryButton.Enabled = false;
|
retryButton.Enabled = false;
|
||||||
cancelButton.Enabled = true;
|
cancelButton.Enabled = true;
|
||||||
reselectButton.Enabled = false;
|
reselectButton.Enabled = false;
|
||||||
|
userProgressBar.Value = userProgressBar.Minimum;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await Operate();
|
await Operate();
|
||||||
|
@ -238,6 +241,7 @@ namespace CreamInstaller
|
||||||
UpdateUser("CreamAPI download and/or installation failed: " + exception.Message, LogColor.Error);
|
UpdateUser("CreamAPI download and/or installation failed: " + exception.Message, LogColor.Error);
|
||||||
retryButton.Enabled = true;
|
retryButton.Enabled = true;
|
||||||
}
|
}
|
||||||
|
userProgressBar.Value = userProgressBar.Maximum;
|
||||||
acceptButton.Enabled = true;
|
acceptButton.Enabled = true;
|
||||||
cancelButton.Enabled = false;
|
cancelButton.Enabled = false;
|
||||||
reselectButton.Enabled = true;
|
reselectButton.Enabled = true;
|
||||||
|
|
|
@ -140,7 +140,7 @@ namespace CreamInstaller
|
||||||
progress.ProgressChanged += new EventHandler<double>(delegate (object sender, double _progress)
|
progress.ProgressChanged += new EventHandler<double>(delegate (object sender, double _progress)
|
||||||
{
|
{
|
||||||
label1.Text = $"Updating . . . {(int)_progress}%";
|
label1.Text = $"Updating . . . {(int)_progress}%";
|
||||||
Program.UpdateProgressInstantly(progressBar1, (int)_progress);
|
progressBar1.Value = (int)_progress;
|
||||||
});
|
});
|
||||||
|
|
||||||
label1.Text = "Updating . . . ";
|
label1.Text = "Updating . . . ";
|
||||||
|
|
|
@ -83,32 +83,21 @@ namespace CreamInstaller
|
||||||
public static Task OutputTask;
|
public static Task OutputTask;
|
||||||
public static string OutputFile;
|
public static string OutputFile;
|
||||||
|
|
||||||
public static void UpdateProgressInstantly(ProgressBar progressBar, int progress)
|
|
||||||
{
|
|
||||||
progressBar.Maximum++;
|
|
||||||
progressBar.Value = progress + 1;
|
|
||||||
progressBar.Value = progress;
|
|
||||||
progressBar.Maximum--;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Cleanup(bool cancel = true, bool logout = true)
|
public static void Cleanup(bool cancel = true, bool logout = true)
|
||||||
{
|
{
|
||||||
Canceled = cancel;
|
Canceled = cancel;
|
||||||
if (OutputArchive != null || CancellationTokenSource != null || OutputTask != null || OutputFile != null)
|
if (OutputArchive != null || CancellationTokenSource != null || OutputTask != null || OutputFile != null)
|
||||||
{
|
{
|
||||||
InstallForm?.UpdateProgress(0);
|
|
||||||
InstallForm?.UpdateUser("Cleaning up . . . ", LogColor.Cleanup);
|
InstallForm?.UpdateUser("Cleaning up . . . ", LogColor.Cleanup);
|
||||||
}
|
}
|
||||||
if (OutputArchive != null)
|
if (OutputArchive != null)
|
||||||
{
|
{
|
||||||
OutputArchive.Dispose();
|
OutputArchive.Dispose();
|
||||||
OutputArchive = null;
|
OutputArchive = null;
|
||||||
InstallForm?.UpdateProgress(25);
|
|
||||||
}
|
}
|
||||||
if (CancellationTokenSource != null)
|
if (CancellationTokenSource != null)
|
||||||
{
|
{
|
||||||
CancellationTokenSource.Cancel();
|
CancellationTokenSource.Cancel();
|
||||||
InstallForm?.UpdateProgress(40);
|
|
||||||
}
|
}
|
||||||
if (OutputTask != null)
|
if (OutputTask != null)
|
||||||
{
|
{
|
||||||
|
@ -119,13 +108,11 @@ namespace CreamInstaller
|
||||||
catch (AggregateException) { }
|
catch (AggregateException) { }
|
||||||
OutputTask.Dispose();
|
OutputTask.Dispose();
|
||||||
OutputTask = null;
|
OutputTask = null;
|
||||||
InstallForm?.UpdateProgress(50);
|
|
||||||
}
|
}
|
||||||
if (CancellationTokenSource != null)
|
if (CancellationTokenSource != null)
|
||||||
{
|
{
|
||||||
CancellationTokenSource.Dispose();
|
CancellationTokenSource.Dispose();
|
||||||
CancellationTokenSource = null;
|
CancellationTokenSource = null;
|
||||||
InstallForm?.UpdateProgress(75);
|
|
||||||
}
|
}
|
||||||
if (OutputFile != null && File.Exists(OutputFile))
|
if (OutputFile != null && File.Exists(OutputFile))
|
||||||
{
|
{
|
||||||
|
@ -139,13 +126,10 @@ namespace CreamInstaller
|
||||||
}
|
}
|
||||||
OutputFile = null;
|
OutputFile = null;
|
||||||
}
|
}
|
||||||
InstallForm?.UpdateProgress(100);
|
|
||||||
if (logout && MegaApiClient != null && MegaApiClient.IsLoggedIn)
|
if (logout && MegaApiClient != null && MegaApiClient.IsLoggedIn)
|
||||||
{
|
{
|
||||||
InstallForm?.UpdateProgress(0);
|
|
||||||
InstallForm?.UpdateUser("Logging out of MEGA . . . ", LogColor.Cleanup);
|
InstallForm?.UpdateUser("Logging out of MEGA . . . ", LogColor.Cleanup);
|
||||||
MegaApiClient.Logout();
|
MegaApiClient.Logout();
|
||||||
InstallForm?.UpdateProgress(100);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue