Repository navigation
Expand file tree
/
Copy pathMapDownloaderPlugin.cs
More file actions
62 lines (52 loc) · 2.27 KB
/
Copy pathMapDownloaderPlugin.cs
File metadata and controls
62 lines (52 loc) · 2.27 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
using System;
using System.IO;
using System.Net;
using BepInEx;
using UnityEngine;
namespace MapDownloader
{
[BepInPlugin("com.onwardmodcommunity.mapdownloader", "Map Downloader", "1.0.0")]
public class MapDownloaderPlugin : BaseUnityPlugin
{
public static BepInEx.Logging.ManualLogSource Log { get; private set; }
private const string RemoteManifestUrl =
"https://pub-6f026005d71a45f583e1bbe8f75cc62f.r2.dev/map_list.json";
private static readonly string MapsDestinationPath = Path.GetFullPath(Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
@"..\LocalLow\Downpour Interactive\Onward\CustomContent"));
private MapDownloader downloader;
private void Awake()
{
Log = Logger;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
Logger.LogInfo("MapDownloader plugin loaded.");
DontDestroyOnLoad(gameObject);
downloader = new MapDownloader(
remoteManifestUrl: RemoteManifestUrl,
mapsDestinationPath: MapsDestinationPath,
onComplete: OnDownloadComplete,
logger: Logger
);
downloader.StartDownload();
}
private void OnDownloadComplete(MapDownloadResult result)
{
switch (result.Status)
{
case MapDownloadStatus.AllCurrent:
Logger.LogInfo($"All maps are up to date. ({result.SkippedCount} checked)");
break;
case MapDownloadStatus.DownloadedSuccessfully:
Logger.LogInfo($"Maps downloaded successfully! ({result.DownloadedCount} downloaded, {result.SkippedCount} already current)");
break;
case MapDownloadStatus.CompletedWithErrors:
Logger.LogWarning(
$"Map download finished with {result.FailedMaps.Count} error(s). " +
$"{result.DownloadedCount} downloaded, {result.SkippedCount} already current. " +
$"Failed: {string.Join(", ", result.FailedMaps)}"
);
break;
}
}
}
}