-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAUpdater.cs
More file actions
64 lines (57 loc) · 1.63 KB
/
AUpdater.cs
File metadata and controls
64 lines (57 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using System.Threading.Tasks;
using UnityEngine;
namespace NeoModLoader.AutoUpdate;
public abstract class AUpdater
{
/// <summary>
/// </summary>
/// <returns>Whether update to date now</returns>
public abstract bool CheckUpdate();
public abstract bool IsAvailable();
public abstract Task<UpdateResult> DownloadAndReplace();
/// <summary>
/// </summary>
/// <returns>Whether update to date now</returns>
public async Task<bool> Update()
{
if (!IsAvailable())
{
Debug.Log($"{GetType().Name} is not available");
return false;
}
try
{
if (CheckUpdate()) return true;
}
catch (Exception e)
{
Debug.Log($"{GetType().Name} failed to check update. The reason is below:");
Debug.Log($"{e.Message}");
Debug.Log(e.StackTrace);
return false;
}
try
{
UpdateResult res = await DownloadAndReplace();
switch (res)
{
case UpdateResult.IsTaken:
return true;
case UpdateResult.Success:
return true;
case UpdateResult.NoNeedUpdate:
return true;
case UpdateResult.Fail:
return false;
}
}
catch (Exception e)
{
Debug.Log($"{GetType().Name} failed to download and replace. The reason is below:");
Debug.Log($"{e.Message}");
Debug.Log(e.StackTrace);
}
return false;
}
}