mirror of
https://github.com/BepInEx/BepInEx.git
synced 2026-10-19 15:51:45 +00:00
Checks if target Unity binaries archive exists before attempting download in case game's network conenction is blocked (#1024)
This commit is contained in:
1 parent
35f6b1b541
commit
28559fe708
1 file changed
+18
-13
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Reflection;
|
||||
using System.Security.Cryptography;
|
||||
@@ -282,25 +283,29 @@ internal static partial class Il2CppInteropManager
|
||||
}
|
||||
}
|
||||
|
||||
private static void DownloadUnityAssemblies()
|
||||
{
|
||||
private static void DownloadUnityAssemblies() {
|
||||
var unityVersion = UnityInfo.Version;
|
||||
var source =
|
||||
UnityBaseLibrariesSource.Value.Replace("{VERSION}",
|
||||
$"{unityVersion.Major}.{unityVersion.Minor}.{unityVersion.Build}");
|
||||
var version = $"{unityVersion.Major}.{unityVersion.Minor}.{unityVersion.Build}";
|
||||
var source = UnityBaseLibrariesSource.Value.Replace("{VERSION}", version);
|
||||
if (string.IsNullOrEmpty(source)) return;
|
||||
|
||||
if (!string.IsNullOrEmpty(source))
|
||||
{
|
||||
Logger.LogMessage("Downloading unity base libraries");
|
||||
|
||||
Directory.CreateDirectory(UnityBaseLibsDirectory);
|
||||
Directory.EnumerateFiles(UnityBaseLibsDirectory, "*.dll").Do(File.Delete);
|
||||
var uri = new Uri(source);
|
||||
string file = Path.GetFileName(uri.AbsolutePath);
|
||||
|
||||
var baseFolder = Directory.CreateDirectory(UnityBaseLibsDirectory);
|
||||
baseFolder.EnumerateFiles("*.dll").Do(a=>a.Delete());
|
||||
var target = baseFolder.GetFiles(file).FirstOrDefault();
|
||||
if (target != null) {
|
||||
Logger.LogMessage($"Reading unity base libraries from file {source}");
|
||||
using var fStream = target.OpenRead();
|
||||
using var zipArchive = new ZipArchive(fStream, ZipArchiveMode.Read);
|
||||
zipArchive.ExtractToDirectory(UnityBaseLibsDirectory);
|
||||
} else {
|
||||
Logger.LogMessage($"Downloading unity base libraries {source}");
|
||||
using var httpClient = new HttpClient();
|
||||
using var zipStream = httpClient.GetStreamAsync(source).GetAwaiter().GetResult();
|
||||
using var zipArchive = new ZipArchive(zipStream, ZipArchiveMode.Read);
|
||||
|
||||
Logger.LogMessage("Extracting downloaded unity base libraries");
|
||||
using var zipArchive = new ZipArchive(zipStream, ZipArchiveMode.Read);
|
||||
zipArchive.ExtractToDirectory(UnityBaseLibsDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user