-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeneralUpdateBootstrap.cs
More file actions
68 lines (62 loc) · 2.64 KB
/
Copy pathGeneralUpdateBootstrap.cs
File metadata and controls
68 lines (62 loc) · 2.64 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
65
66
67
68
using System.Net.Http;
using GeneralUpdate.Avalonia.Android.Abstractions;
using GeneralUpdate.Avalonia.Android.Models;
using GeneralUpdate.Avalonia.Android.Services;
namespace GeneralUpdate.Avalonia.Android;
public static class GeneralUpdateBootstrap
{
public static IAndroidBootstrap CreateDefault(
AndroidUpdateOptions options,
IAndroidContextProvider? contextProvider = null,
IAndroidActivityProvider? activityProvider = null,
HttpClient? httpClient = null,
IVersionComparer? versionComparer = null,
IUpdateEventDispatcher? eventDispatcher = null,
IUpdateLogger? logger = null,
HttpDownloadOptions? httpOptions = null)
{
var usedContextProvider = contextProvider ?? new DefaultAndroidContextProvider();
var context = usedContextProvider.GetContext();
var effectiveDownloadDirectory = options.DownloadDirectoryPath;
if (string.IsNullOrWhiteSpace(effectiveDownloadDirectory) && context?.CacheDir?.AbsolutePath is string cacheDirPath)
{
effectiveDownloadDirectory = Path.Combine(cacheDirPath, "update");
}
if (string.IsNullOrWhiteSpace(effectiveDownloadDirectory))
{
effectiveDownloadDirectory = Path.Combine(Path.GetTempPath(), "update");
}
var effectiveOptions = options with { DownloadDirectoryPath = effectiveDownloadDirectory };
var usedLogger = logger ?? new NoOpUpdateLogger();
var usedStorage = new PhysicalFileStorage();
HttpResumableApkDownloader downloader;
if (httpOptions != null)
{
// Use internal constructor that builds HttpClient from HttpDownloadOptions
// (SSL validation, proxy, auth, timeouts)
downloader = new HttpResumableApkDownloader(
usedStorage, effectiveOptions, httpOptions, usedLogger);
}
else
{
// Legacy path: use injected httpClient or a bare new one
var usedClient = httpClient ?? new HttpClient();
downloader = new HttpResumableApkDownloader(
usedClient, usedStorage, effectiveOptions, usedLogger);
}
var validator = new Sha256HashValidator();
var installer = new AndroidApkInstaller(
usedContextProvider,
activityProvider ?? new NullAndroidActivityProvider(),
effectiveOptions,
usedLogger);
return new AndroidBootstrap(
versionComparer ?? new SystemVersionComparer(),
downloader,
validator,
installer,
usedStorage,
eventDispatcher,
usedLogger);
}
}