mirror of
https://github.com/WowUp/WowUp.git
synced 2026-05-19 03:54:44 -04:00
12
WowUp.WPF/Models/Events/AddonStateEventArgs.cs
Normal file
12
WowUp.WPF/Models/Events/AddonStateEventArgs.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using WowUp.Common.Enums;
|
||||
using WowUp.WPF.Entities;
|
||||
|
||||
namespace WowUp.WPF.Models.Events
|
||||
{
|
||||
public class AddonStateEventArgs
|
||||
{
|
||||
public Addon Addon { get; set; }
|
||||
public AddonInstallState AddonInstallState { get; set; }
|
||||
public decimal Progress { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -45,6 +45,7 @@ namespace WowUp.WPF.Services
|
||||
public event AddonEventHandler AddonUninstalled;
|
||||
public event AddonEventHandler AddonInstalled;
|
||||
public event AddonEventHandler AddonUpdated;
|
||||
public event AddonStateEventHandler AddonStateChanged;
|
||||
|
||||
public string BackupPath => Path.Combine(FileUtilities.AppDataPath, BackupFolder);
|
||||
|
||||
@@ -383,6 +384,19 @@ namespace WowUp.WPF.Services
|
||||
await InstallAddon(addon.Id, onUpdate);
|
||||
}
|
||||
|
||||
private void SendAddonStateChange(
|
||||
Addon addon,
|
||||
AddonInstallState addonInstallState,
|
||||
decimal progress)
|
||||
{
|
||||
AddonStateChanged?.Invoke(this, new AddonStateEventArgs
|
||||
{
|
||||
Addon = addon,
|
||||
AddonInstallState = addonInstallState,
|
||||
Progress = progress
|
||||
});
|
||||
}
|
||||
|
||||
public async Task InstallAddon(int addonId, Action<AddonInstallState, decimal> updateAction = null)
|
||||
{
|
||||
var addon = GetAddon(addonId);
|
||||
@@ -392,6 +406,7 @@ namespace WowUp.WPF.Services
|
||||
}
|
||||
|
||||
updateAction?.Invoke(AddonInstallState.Downloading, 25m);
|
||||
SendAddonStateChange(addon, AddonInstallState.Downloading, 25m);
|
||||
|
||||
string downloadedFilePath = string.Empty;
|
||||
string unzippedDirectory = string.Empty;
|
||||
@@ -405,11 +420,13 @@ namespace WowUp.WPF.Services
|
||||
if (!string.IsNullOrEmpty(addon.InstalledVersion))
|
||||
{
|
||||
updateAction?.Invoke(AddonInstallState.BackingUp, 0.50m);
|
||||
SendAddonStateChange(addon, AddonInstallState.BackingUp, 75m);
|
||||
var backupZipFilePath = Path.Combine(BackupPath, $"{addon.Name}-{addon.InstalledVersion}.zip");
|
||||
//await _downloadService.ZipFile(downloadedFilePath, backupZipFilePath);
|
||||
}
|
||||
|
||||
updateAction?.Invoke(AddonInstallState.Installing, 75m);
|
||||
SendAddonStateChange(addon, AddonInstallState.Installing, 75m);
|
||||
|
||||
unzippedDirectory = await _downloadService.UnzipFile(downloadedFilePath);
|
||||
|
||||
@@ -449,6 +466,7 @@ namespace WowUp.WPF.Services
|
||||
}
|
||||
|
||||
updateAction?.Invoke(AddonInstallState.Complete, 100m);
|
||||
SendAddonStateChange(addon, AddonInstallState.Complete, 100m);
|
||||
}
|
||||
|
||||
private async Task CacheThumbnail(Addon addon)
|
||||
|
||||
@@ -9,12 +9,14 @@ using WowUp.WPF.Models.Events;
|
||||
namespace WowUp.WPF.Services.Contracts
|
||||
{
|
||||
public delegate void AddonEventHandler(object sender, AddonEventArgs e);
|
||||
public delegate void AddonStateEventHandler(object sender, AddonStateEventArgs e);
|
||||
|
||||
public interface IAddonService
|
||||
{
|
||||
event AddonEventHandler AddonUninstalled;
|
||||
event AddonEventHandler AddonInstalled;
|
||||
event AddonEventHandler AddonUpdated;
|
||||
event AddonStateEventHandler AddonStateChanged;
|
||||
|
||||
string BackupPath { get; }
|
||||
|
||||
|
||||
@@ -327,12 +327,9 @@ namespace WowUp.WPF.ViewModels
|
||||
|
||||
public async Task UpdateAddon()
|
||||
{
|
||||
ShowStatusText = false;
|
||||
ShowUpdateButton = false;
|
||||
|
||||
try
|
||||
{
|
||||
await _addonService.InstallAddon(_addon.Id, OnInstallUpdate);
|
||||
await _addonService.InstallAddon(_addon.Id);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -423,8 +420,11 @@ namespace WowUp.WPF.ViewModels
|
||||
_analyticsService.TrackUserAction("Addons", "Channel", channelType.ToString());
|
||||
}
|
||||
|
||||
private void OnInstallUpdate(AddonInstallState installState, decimal percent)
|
||||
public void OnInstallUpdate(AddonInstallState installState, decimal percent)
|
||||
{
|
||||
ShowStatusText = false;
|
||||
ShowUpdateButton = false;
|
||||
|
||||
try
|
||||
{
|
||||
ProgressText = GetInstallStateText(installState);
|
||||
|
||||
@@ -212,6 +212,15 @@ namespace WowUp.WPF.ViewModels
|
||||
AddonUpdated(args.Addon);
|
||||
};
|
||||
|
||||
_addonService.AddonStateChanged += (sender, args) =>
|
||||
{
|
||||
var addon = DisplayAddons.FirstOrDefault(listItem => listItem.Addon.Id == args.Addon.Id);
|
||||
if(addon != null)
|
||||
{
|
||||
addon.OnInstallUpdate(args.AddonInstallState, args.Progress);
|
||||
}
|
||||
};
|
||||
|
||||
_warcraftService.ProductChanged += (sender, args) =>
|
||||
{
|
||||
SetClientNames();
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<PackageId>WowUp</PackageId>
|
||||
<Authors>Jliddev</Authors>
|
||||
<Product>WowUp</Product>
|
||||
<Version>1.17.0</Version>
|
||||
<Version>1.17.1</Version>
|
||||
<ApplicationIcon>wowup_logo_512np_RRT_icon.ico</ApplicationIcon>
|
||||
<Copyright>jliddev</Copyright>
|
||||
<PackageProjectUrl>https://wowup.io</PackageProjectUrl>
|
||||
|
||||
Reference in New Issue
Block a user