Skip to content
This repository was archived by the owner on Sep 14, 2022. It is now read-only.

Commit dc875fa

Browse files
committed
Added Updater for testing
1 parent 472aa94 commit dc875fa

File tree

4 files changed

+100
-0
lines changed

4 files changed

+100
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace YouTubeTool.Services
8+
{
9+
public interface IUpdateService
10+
{
11+
Task<Version> CheckForUpdatesAsync();
12+
13+
Task ApplyUpdate();
14+
15+
Task PrepareUpdateAsync();
16+
17+
void ApplyUpdateAsync(bool restart = true);
18+
}
19+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using Onova;
2+
using Onova.Services;
3+
using System;
4+
using System.Threading.Tasks;
5+
6+
namespace YouTubeTool.Services
7+
{
8+
public class UpdateService : IUpdateService
9+
{
10+
private readonly UpdateManager _updateManager;
11+
12+
private Version _lastVersion;
13+
private bool _applied;
14+
15+
public UpdateService()
16+
{
17+
_updateManager = new UpdateManager(new GithubPackageResolver("remiX-", "YouTube-tool", "youtube.tool.zip"), new ZipPackageExtractor());
18+
}
19+
20+
public async Task<Version> CheckForUpdatesAsync()
21+
{
22+
#if DEBUG
23+
// Never update in DEBUG mode
24+
return null;
25+
#endif
26+
27+
// Remove some junk left over from last update
28+
_updateManager.Cleanup();
29+
30+
// Check for updates
31+
var check = await _updateManager.CheckForUpdatesAsync();
32+
33+
// Return latest version or null if running latest version already
34+
return check.CanUpdate ? _lastVersion = check.LastVersion : null;
35+
}
36+
37+
public async Task ApplyUpdate()
38+
{
39+
// Prepare an update so it can be applied later
40+
// (supports optional progress reporting and cancellation)
41+
await _updateManager.PrepareUpdateAsync(_lastVersion);
42+
43+
// Launch an executable that will apply the update
44+
// (can optionally restart application on completion)
45+
_updateManager.LaunchUpdater(_lastVersion);
46+
47+
// External updater will wait until the application exits
48+
Environment.Exit(0);
49+
}
50+
51+
public async Task PrepareUpdateAsync()
52+
{
53+
if (_lastVersion == null)
54+
return;
55+
56+
// Download and prepare update
57+
await _updateManager.PrepareUpdateAsync(_lastVersion);
58+
}
59+
60+
public void ApplyUpdateAsync(bool restart = true)
61+
{
62+
if (_lastVersion == null)
63+
return;
64+
if (_applied)
65+
return;
66+
67+
// Enqueue an update
68+
_updateManager.LaunchUpdater(_lastVersion, restart);
69+
70+
_applied = true;
71+
}
72+
}
73+
}

YouTubeTool/YouTubeTool.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
5656
<HintPath>packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
5757
</Reference>
58+
<Reference Include="Onova, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL">
59+
<HintPath>packages\Onova.2.1.0\lib\net46\Onova.dll</HintPath>
60+
</Reference>
5861
<Reference Include="policy.2.0.taglib-sharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=db62eba44689b5b0, processorArchitecture=MSIL">
5962
<HintPath>packages\taglib.2.1.0.0\lib\policy.2.0.taglib-sharp.dll</HintPath>
6063
</Reference>
@@ -66,6 +69,7 @@
6669
</Reference>
6770
<Reference Include="System" />
6871
<Reference Include="System.Data" />
72+
<Reference Include="System.IO.Compression" />
6973
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
7074
<HintPath>packages\Prism.Wpf.6.3.0\lib\net45\System.Windows.Interactivity.dll</HintPath>
7175
</Reference>
@@ -111,8 +115,11 @@
111115
<Compile Include="Core\AppGlobal.cs" />
112116
<Compile Include="Core\AppPaths.cs" />
113117
<Compile Include="Core\AppSettings.cs" />
118+
<Compile Include="Services\IUpdateService.cs" />
119+
<Compile Include="Services\UpdateService.cs" />
114120
<Compile Include="Utils\Converters\BoolToVisibilityConverter.cs" />
115121
<Compile Include="ViewModels\HamburgerMenuItem.cs" />
122+
<Compile Include="ViewModels\IMainViewModel.cs" />
116123
<Compile Include="ViewModels\MainViewModel.cs" />
117124
<Compile Include="Windows\WindowTest.xaml.cs">
118125
<DependentUpon>WindowTest.xaml</DependentUpon>

YouTubeTool/packages.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<package id="MaterialDesignColors" version="1.1.3" targetFramework="net471" />
77
<package id="MaterialDesignThemes" version="2.4.0.1044" targetFramework="net471" />
88
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net471" />
9+
<package id="Onova" version="2.1.0" targetFramework="net471" />
910
<package id="Prism.Core" version="7.0.0.396" targetFramework="net471" />
1011
<package id="Prism.Wpf" version="6.3.0" targetFramework="net471" />
1112
<package id="taglib" version="2.1.0.0" targetFramework="net471" />

0 commit comments

Comments
 (0)