Added a minimal GUI based on Avalonia UI library for C#
This commit is contained in:
@@ -30,7 +30,7 @@ namespace PluginManager.Online
|
||||
/// <param name="location">The location where to store the downloaded data</param>
|
||||
/// <param name="progress">The <see cref="IProgress{T}"/> to track the download</param>
|
||||
/// <returns></returns>
|
||||
public static async Task DownloadFileAsync(string URL, string location, IProgress<float> progress, IProgress<long> downloadedBytes)
|
||||
public static async Task DownloadFileAsync(string URL, string location, IProgress<float> progress, IProgress<long>? downloadedBytes = null)
|
||||
{
|
||||
using (var client = new System.Net.Http.HttpClient())
|
||||
{
|
||||
@@ -54,8 +54,6 @@ namespace PluginManager.Online
|
||||
bool isDownloading = true;
|
||||
int c_progress = 0;
|
||||
|
||||
//long m_dwBytes = 0;
|
||||
|
||||
Others.Console_Utilities.ProgressBar pbar = new Others.Console_Utilities.ProgressBar(100, "");
|
||||
|
||||
IProgress<float> progress = new Progress<float>(percent =>
|
||||
@@ -63,11 +61,6 @@ namespace PluginManager.Online
|
||||
c_progress = (int)percent;
|
||||
});
|
||||
|
||||
IProgress<long> progress_downloaded = new Progress<long>(downloadedBytes =>
|
||||
{
|
||||
//m_dwBytes = downloadedBytes;
|
||||
});
|
||||
|
||||
Task updateProgressBarTask = new Task(() =>
|
||||
{
|
||||
while (isDownloading)
|
||||
@@ -80,11 +73,13 @@ namespace PluginManager.Online
|
||||
});
|
||||
|
||||
new System.Threading.Thread(updateProgressBarTask.Start).Start();
|
||||
await DownloadFileAsync(URL, location, progress, progress_downloaded);
|
||||
await DownloadFileAsync(URL, location, progress);
|
||||
|
||||
|
||||
isDownloading = false;
|
||||
c_progress = 100;
|
||||
pbar.Update(100);
|
||||
isDownloading = false;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,5 +237,42 @@ namespace PluginManager.Others
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extract zip to location
|
||||
/// </summary>
|
||||
/// <param name="zip">The zip location</param>
|
||||
/// <param name="folder">The target location</param>
|
||||
/// <returns></returns>
|
||||
public static async Task ExtractArchive(string zip, string folder, IProgress<double> progress)
|
||||
{
|
||||
if (!Directory.Exists(folder))
|
||||
Directory.CreateDirectory(folder);
|
||||
|
||||
|
||||
|
||||
|
||||
using (ZipArchive archive = ZipFile.OpenRead(zip))
|
||||
{
|
||||
int totalZIPFiles = archive.Entries.Count();
|
||||
int currentZIPFile = 0;
|
||||
foreach (ZipArchiveEntry entry in archive.Entries)
|
||||
{
|
||||
if (entry.FullName.EndsWith("/"))
|
||||
{
|
||||
currentZIPFile++;
|
||||
Directory.CreateDirectory(Path.Combine(folder, entry.FullName));
|
||||
}
|
||||
else
|
||||
{
|
||||
entry.ExtractToFile(Path.Combine(folder, entry.FullName), true);
|
||||
currentZIPFile++;
|
||||
}
|
||||
|
||||
await Task.Delay(10);
|
||||
progress.Report((double)currentZIPFile / totalZIPFiles * 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user