2
2
// See the LICENSE file in the repository root for full license text.
3
3
4
4
using System ;
5
+ using System . Linq ;
5
6
using System . Threading . Tasks ;
6
- using osu . Framework . Allocation ;
7
- using osu . Framework . Logging ;
8
- using osu . Framework . Platform ;
9
7
using Squirrel ;
10
- using VRCOSC . Game . Config ;
11
- using VRCOSC . Game . Graphics . Settings ;
12
8
using VRCOSC . Game . Graphics . Updater ;
13
9
14
10
namespace VRCOSC . Desktop . Updater ;
15
11
16
12
public partial class SquirrelUpdateManager : VRCOSCUpdateManager
17
13
{
18
- private GithubUpdateManager ? updateManager ;
14
+ private const string repo = "https://github.com/VolcanicArts/VRCOSC" ;
15
+
16
+ private readonly GithubUpdateManager updateManager ;
19
17
private UpdateInfo ? updateInfo ;
18
+ private bool useDelta ;
19
+
20
+ public SquirrelUpdateManager ( )
21
+ {
22
+ updateManager = new GithubUpdateManager ( repo ) ;
23
+ initialise ( ) ;
24
+ }
25
+
26
+ private void initialise ( )
27
+ {
28
+ updateInfo = null ;
29
+ useDelta = true ;
30
+ }
20
31
21
- [ Resolved ]
22
- private GameHost host { get ; set ; } = null ! ;
32
+ protected override Task PrepareUpdateAsync ( ) => UpdateManager . RestartAppWhenExited ( ) ;
23
33
24
- [ Resolved ]
25
- private VRCOSCConfigManager config { get ; set ; } = null ! ;
34
+ public override async Task PerformUpdateCheck ( ) => await checkForUpdateAsync ( ) . ConfigureAwait ( false ) ;
26
35
27
- public override async Task CheckForUpdate ( string repo , bool useDelta = true )
36
+ private async Task checkForUpdateAsync ( )
28
37
{
38
+ Log ( "Checking for updates" ) ;
39
+
40
+ if ( ! updateManager . IsInstalledApp )
41
+ {
42
+ Log ( "Portable app detected. Cancelled update check" ) ;
43
+ return ;
44
+ }
45
+
29
46
try
30
47
{
31
- updateManager ??= new GithubUpdateManager ( repo ) ;
32
- if ( ! updateManager . IsInstalledApp ) return ;
48
+ updateInfo = await updateManager . CheckForUpdate ( ! useDelta ) ;
33
49
34
- try
50
+ if ( ! updateInfo . ReleasesToApply . Any ( ) )
35
51
{
36
- updateInfo = await updateManager . CheckForUpdate ( ! useDelta ) . ConfigureAwait ( false ) ;
37
- if ( updateInfo . ReleasesToApply . Count == 0 ) return ;
52
+ Log ( "No updates found" ) ;
53
+ initialise ( ) ;
54
+ return ;
55
+ }
38
56
39
- var updateMode = config . Get < UpdateMode > ( VRCOSCSetting . UpdateMode ) ;
57
+ Log ( $ " { updateInfo . ReleasesToApply . Count } updates found" ) ;
40
58
41
- if ( updateMode == UpdateMode . Auto )
42
- await ApplyUpdates ( ) ;
43
- else
44
- PostCheckNotification ( ) ;
45
- }
46
- catch ( Exception )
47
- {
48
- //delta update may have failed due to the installed version being too outdated. Retry without trying for delta
49
- if ( useDelta )
50
- {
51
- await CheckForUpdate ( repo , false ) ;
52
- return ;
53
- }
54
-
55
- throw ;
56
- }
59
+ if ( ApplyUpdatesImmediately )
60
+ await ApplyUpdatesAsync ( ) ;
61
+ else
62
+ PostUpdateAvailableNotification ( ) ;
57
63
}
58
64
catch ( Exception e )
59
65
{
60
66
PostFailNotification ( ) ;
61
- Logger . Error ( e , "Updater Error" ) ;
67
+ LogError ( e ) ;
68
+ initialise ( ) ;
62
69
}
63
70
}
64
71
65
- protected override async Task ApplyUpdates ( )
72
+ protected override async Task ApplyUpdatesAsync ( )
66
73
{
67
- if ( updateManager is null || updateInfo is null )
74
+ Log ( "Attempting to apply updates" ) ;
75
+
76
+ if ( updateInfo is null )
68
77
throw new InvalidOperationException ( "Cannot apply updates without checking" ) ;
69
78
70
79
try
71
80
{
72
81
var notification = PostProgressNotification ( ) ;
73
- await updateManager . DownloadReleases ( updateInfo . ReleasesToApply , p => notification . Progress = map ( p / 100f , 0 , 1 , 0 , 0.5f ) ) . ConfigureAwait ( false ) ;
74
- await updateManager . ApplyReleases ( updateInfo , p => notification . Progress = map ( p / 100f , 0 , 1 , 0.5f , 1 ) ) . ConfigureAwait ( false ) ;
82
+ await updateManager . DownloadReleases ( updateInfo . ReleasesToApply , p => notification . Progress = map ( p / 100f , 0 , 1 , 0 , 0.5f ) ) ;
83
+ await updateManager . ApplyReleases ( updateInfo , p => notification . Progress = map ( p / 100f , 0 , 1 , 0.5f , 1 ) ) ;
75
84
PostSuccessNotification ( ) ;
85
+ Log ( "Update successfully applied" ) ;
86
+ initialise ( ) ;
76
87
}
77
- catch ( Exception )
88
+ catch ( Exception e )
78
89
{
90
+ // Update may have failed due to the installed version being too outdated
91
+ // Retry without trying for delta
92
+ if ( useDelta )
93
+ {
94
+ useDelta = false ;
95
+ await checkForUpdateAsync ( ) ;
96
+ return ;
97
+ }
98
+
79
99
PostFailNotification ( ) ;
100
+ LogError ( e ) ;
101
+ initialise ( ) ;
80
102
}
81
103
}
82
104
@@ -85,8 +107,9 @@ private static float map(float source, float sMin, float sMax, float dMin, float
85
107
return dMin + ( dMax - dMin ) * ( ( source - sMin ) / ( sMax - sMin ) ) ;
86
108
}
87
109
88
- protected override void RequestRestart ( )
110
+ protected override void Dispose ( bool isDisposing )
89
111
{
90
- UpdateManager . RestartAppWhenExited ( ) . ContinueWith ( _ => host . Exit ( ) ) . ConfigureAwait ( false ) ;
112
+ base . Dispose ( isDisposing ) ;
113
+ updateManager . Dispose ( ) ;
91
114
}
92
115
}
0 commit comments