Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract Mono runtime builds from each Unity version #2

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ config.toml
data/
.idea
*.user
.vs/
launchSettings.json
64 changes: 64 additions & 0 deletions UnityDataMiner/DownloadableAssetCollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using AssetRipper.Primitives;
using Serilog;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;

namespace UnityDataMiner
{
internal class DownloadableAssetCollection
{
// url -> path
private readonly Dictionary<string, string> assets = new();

// returns actual asset path
public string AddAsset(string url, string destPath)
{
if (!assets.TryGetValue(url, out var realPath))
{
assets.Add(url, realPath = destPath);
}

return realPath;
}

public async Task DownloadAssetsAsync(Func<string, string, CancellationToken, Task> downloadFunc, UnityVersion version,
SemaphoreSlim? downloadLock = null, CancellationToken cancellationToken = default)
{
while (true)
{
try
{
if (downloadLock is not null)
{
await downloadLock.WaitAsync(cancellationToken);
}
try
{
foreach (var (url, dest) in assets)
{
await downloadFunc(url, dest, cancellationToken);
}
}
finally
{
if (!cancellationToken.IsCancellationRequested && downloadLock is not null)
{
downloadLock.Release();
}
}

break;
}
catch (IOException e) when (e.InnerException is SocketException { SocketErrorCode: SocketError.ConnectionReset })
{
Log.Warning("Failed to download {Version}, waiting 5 seconds before retrying...", version);
await Task.Delay(5000, cancellationToken);
}
}
}
}
}
File renamed without changes.
Loading