mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 03:59:50 +02:00
Merge branch 'ue' of https://github.com/tresabhi/blitzkit into ue
This commit is contained in:
commit
4b24cf313b
1 file changed
+40
-22
@@ -10,6 +10,11 @@ using CUE4Parse.UE4.Pak.Objects;
|
|||||||
using CUE4Parse.UE4.Readers;
|
using CUE4Parse.UE4.Readers;
|
||||||
using CUE4Parse.UE4.Versions;
|
using CUE4Parse.UE4.Versions;
|
||||||
using DotNet.Globbing;
|
using DotNet.Globbing;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Threading;
|
||||||
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace BlitzKit.CLI.Functions
|
namespace BlitzKit.CLI.Functions
|
||||||
{
|
{
|
||||||
@@ -17,12 +22,10 @@ namespace BlitzKit.CLI.Functions
|
|||||||
{
|
{
|
||||||
public const string CONTENT_GROUP = "p14y73c7_p5e_b10gg3RS_big_play";
|
public const string CONTENT_GROUP = "p14y73c7_p5e_b10gg3RS_big_play";
|
||||||
private const string CONTAINERS_PATH = "../../temp/containers/";
|
private const string CONTAINERS_PATH = "../../temp/containers/";
|
||||||
|
|
||||||
// this may be different from the one provided in args so check this and not args[1]
|
|
||||||
// we don't wanna delete my local installation of the game when debugging haha!
|
|
||||||
private const string TEMP_DEPOT_DIR = "../../temp/depot/";
|
private const string TEMP_DEPOT_DIR = "../../temp/depot/";
|
||||||
public const string WG_DLC_DOMAIN = "http://dl-wotblitz-gc.wargaming.net";
|
public const string WG_DLC_DOMAIN = "http://dl-wotblitz-gc.wargaming.net";
|
||||||
private const string BUILD_MANIFEST_OS = "Windows";
|
private const string BUILD_MANIFEST_OS = "Windows";
|
||||||
|
private static readonly SemaphoreSlim semaphore = new(4); // Limit to 4 concurrent downloads
|
||||||
|
|
||||||
public static async Task Unpack(string[] args)
|
public static async Task Unpack(string[] args)
|
||||||
{
|
{
|
||||||
@@ -58,25 +61,20 @@ namespace BlitzKit.CLI.Functions
|
|||||||
|
|
||||||
PrettyLog.Log($"Downloading {manifest.PakFiles.Count} containers...");
|
PrettyLog.Log($"Downloading {manifest.PakFiles.Count} containers...");
|
||||||
|
|
||||||
int done = 0;
|
Directory.CreateDirectory(CONTAINERS_PATH);
|
||||||
|
List<Task> downloadTasks = new();
|
||||||
|
|
||||||
foreach (var pakFile in manifest.PakFiles)
|
foreach (var pakFile in manifest.PakFiles)
|
||||||
{
|
{
|
||||||
var localContainerPath = Path.Combine(CONTAINERS_PATH, pakFile.FileName);
|
var localContainerPath = Path.Combine(CONTAINERS_PATH, pakFile.FileName);
|
||||||
var fullContainerURL = $"{WG_DLC_DOMAIN}/dlc/{CONTENT_GROUP}/dlc/{pakFile.RelativeUrl}";
|
var fullContainerURL = $"{WG_DLC_DOMAIN}/dlc/{CONTENT_GROUP}/dlc/{pakFile.RelativeUrl}";
|
||||||
var response = await client.GetAsync(fullContainerURL);
|
downloadTasks.Add(DownloadFileAsync(client, fullContainerURL, localContainerPath, manifest.PakFiles.Count));
|
||||||
var bytes = await response.Content.ReadAsByteArrayAsync();
|
|
||||||
|
|
||||||
Directory.CreateDirectory(CONTAINERS_PATH);
|
|
||||||
File.WriteAllBytes(localContainerPath, bytes);
|
|
||||||
done++;
|
|
||||||
|
|
||||||
PrettyLog.Log($"Downloaded {done}/{manifest.PakFiles.Count} containers...");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await Task.WhenAll(downloadTasks);
|
||||||
|
|
||||||
PrettyLog.Log("Moving pre-bundled containers...");
|
PrettyLog.Log("Moving pre-bundled containers...");
|
||||||
foreach (
|
foreach (var file in Directory.GetFiles(Path.Combine(TEMP_DEPOT_DIR, "Blitz/Content/Paks"), "*.pak"))
|
||||||
var file in Directory.GetFiles(Path.Combine(TEMP_DEPOT_DIR, "Blitz/Content/Paks"), "*.pak")
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
File.Move(file, Path.Combine(CONTAINERS_PATH, Path.GetFileName(file)));
|
File.Move(file, Path.Combine(CONTAINERS_PATH, Path.GetFileName(file)));
|
||||||
}
|
}
|
||||||
@@ -85,19 +83,39 @@ namespace BlitzKit.CLI.Functions
|
|||||||
Directory.Delete(TEMP_DEPOT_DIR, true);
|
Directory.Delete(TEMP_DEPOT_DIR, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static async Task DownloadFileAsync(HttpClient client, string url, string localPath, int totalFiles)
|
||||||
|
{
|
||||||
|
await semaphore.WaitAsync();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using HttpResponseMessage response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead);
|
||||||
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
|
using Stream contentStream = await response.Content.ReadAsStreamAsync(),
|
||||||
|
fileStream = new FileStream(localPath, FileMode.Create, FileAccess.Write, FileShare.None, 8192, true);
|
||||||
|
|
||||||
|
await contentStream.CopyToAsync(fileStream);
|
||||||
|
PrettyLog.Log($"Downloaded {Path.GetFileName(localPath)} ({totalFiles} total)");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
PrettyLog.Log($"Failed to download {url}: {ex.Message}");
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
semaphore.Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static async Task<DlcManifest> FetchManifest(string group, string build)
|
public static async Task<DlcManifest> FetchManifest(string group, string build)
|
||||||
{
|
{
|
||||||
PrettyLog.Log($"Fetching manifest for group {group} and build {build}");
|
PrettyLog.Log($"Fetching manifest for group {group} and build {build}");
|
||||||
|
|
||||||
string url =
|
string url = $"{WG_DLC_DOMAIN}/dlc/{group}/dlc/BuildManifest-{BUILD_MANIFEST_OS}-{build}.json";
|
||||||
$"{WG_DLC_DOMAIN}/dlc/{group}/dlc/BuildManifest-{BUILD_MANIFEST_OS}-{build}.json";
|
|
||||||
using HttpClient client = new();
|
using HttpClient client = new();
|
||||||
string jsonString = await client.GetStringAsync(url);
|
string jsonString = await client.GetStringAsync(url);
|
||||||
DlcManifest manifest =
|
return JsonSerializer.Deserialize<DlcManifest>(jsonString)
|
||||||
JsonSerializer.Deserialize<DlcManifest>(jsonString)
|
?? throw new Exception("Failed to deserialize manifest");
|
||||||
?? throw new Exception("Failed to deserialize manifest");
|
|
||||||
|
|
||||||
return manifest;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user