Skip to content

Commit

Permalink
minor bug fix
Browse files Browse the repository at this point in the history
bug fix for DefaultResourceCompleter
  • Loading branch information
laolarou726 committed May 13, 2023
1 parent 4445dd5 commit 9419a59
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ProjBobcat/ProjBobcat/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static class Constants
#elif OSX
public const string WhereCommand = "whereis";
public const string JavaExecutable = "java";
public const string JavaExecutablePath = $"jre.bundle/Contents/Home/bin/{JavaExecutable}";
public const string JavaExecutablePath = $"Contents/Home/bin/{JavaExecutable}";
public const string JavaExecutableExtension = "*";
public const string OsSymbol = "osx";
#elif LINUX
Expand Down
22 changes: 17 additions & 5 deletions ProjBobcat/ProjBobcat/DefaultComponent/DefaultResourceCompleter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class DefaultResourceCompleter : IResourceCompleter
readonly ConcurrentBag<DownloadFile> _failedFiles = new();
readonly EventHandlerList _listEventDelegates = new();

bool disposedValue;
bool _disposedValue;

public int TotalDownloaded { get; private set; }
public int NeedToDownload { get; private set; }
Expand Down Expand Up @@ -68,6 +68,7 @@ public class DefaultResourceCompleter : IResourceCompleter
NeedToDownload = 0;
_failedFiles.Clear();

var processorCount = Environment.ProcessorCount;
var linkOptions = new DataflowLinkOptions { PropagateCompletion = true };
var gameResourceTransBlock =
new TransformBlock<IGameResource, DownloadFile>(f =>
Expand All @@ -85,7 +86,11 @@ public class DefaultResourceCompleter : IResourceCompleter
return dF;
},
new ExecutionDataflowBlockOptions());
new ExecutionDataflowBlockOptions
{
BoundedCapacity = processorCount,
MaxDegreeOfParallelism = processorCount
});
var downloadFileBlock = new ActionBlock<DownloadFile>(async df =>
{
await DownloadHelper.AdvancedDownloadFile(df, new DownloadSettings
Expand All @@ -99,6 +104,10 @@ public class DefaultResourceCompleter : IResourceCompleter
df.Completed -= WhenCompleted;
df.Dispose();
}, new ExecutionDataflowBlockOptions
{
BoundedCapacity = processorCount,
MaxDegreeOfParallelism = processorCount
});

gameResourceTransBlock.LinkTo(downloadFileBlock, linkOptions);
Expand Down Expand Up @@ -133,8 +142,11 @@ await foreach (var element in asyncEnumerable)
}

var asyncEnumerable = resolver.ResolveResourceAsync();
var tasks = new Task[MaxDegreeOfParallelism];
for (var i = 0; i < MaxDegreeOfParallelism; i++)
tasks[i] = ReceiveGameResourceTask(asyncEnumerable);

await Task.WhenAll(Enumerable.Repeat(ReceiveGameResourceTask(asyncEnumerable), MaxDegreeOfParallelism));
await Task.WhenAll(tasks);
}

gameResourceTransBlock.Complete();
Expand Down Expand Up @@ -203,13 +215,13 @@ void WhenCompleted(object? sender, DownloadFileCompletedEventArgs e)

protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
if (!_disposedValue)
{
if (disposing) _listEventDelegates.Dispose();

// TODO: 释放未托管的资源(未托管的对象)并重写终结器
// TODO: 将大型字段设置为 null
disposedValue = true;
_disposedValue = true;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using ProjBobcat.Interface;

namespace ProjBobcat.DefaultComponent.LogAnalysis.AnalysisReport;
Expand All @@ -7,4 +8,5 @@ public record AnalysisReport(CrashCauses Cause) : IAnalysisReport
{
public string? From { get; set; }
public IReadOnlyCollection<string>? Details { get; init; }
public bool HasDetails => Details?.Any() ?? false;
}
1 change: 1 addition & 0 deletions ProjBobcat/ProjBobcat/Interface/IAnalysisReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ public interface IAnalysisReport
CrashCauses Cause { get; }
IReadOnlyCollection<string>? Details { get; }
string? From { get; set; }
bool HasDetails { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static IEnumerable<string> FindJavaMacOS()

foreach (var dir in Directory.EnumerateDirectories(rootPath))
{
var filePath = $"{dir}/Contents/Home/bin/java";
var filePath = $"{dir}/{Constants.JavaExecutablePath}";
if (File.Exists(filePath))
{
#if NET7_0_OR_GREATER
Expand Down

0 comments on commit 9419a59

Please sign in to comment.