Skip to content

Commit

Permalink
FluentCore Updata 1.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
natsurainko committed Feb 11, 2022
1 parent 809c440 commit 9f65be4
Show file tree
Hide file tree
Showing 26 changed files with 427 additions and 52 deletions.
Binary file added .vs/FluentCore/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
16 changes: 16 additions & 0 deletions .vs/FluentCore/project-colors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"Version": 1,
"ProjectMap": {
"83cc849a-a467-4414-8b99-84ba2c094640": {
"ProjectGuid": "83cc849a-a467-4414-8b99-84ba2c094640",
"DisplayName": "FluentCore",
"ColorIndex": 0
},
"2981059d-ccf8-4f2c-b21e-661f8a98f06b": {
"ProjectGuid": "2981059d-ccf8-4f2c-b21e-661f8a98f06b",
"DisplayName": "FluentCore.Extend",
"ColorIndex": 1
}
},
"NextColorIndex": 2
}
Binary file added .vs/FluentCore/v16/.suo
Binary file not shown.
Binary file added .vs/FluentCore/v17/.futdcache.v1
Binary file not shown.
Binary file added .vs/FluentCore/v17/.suo
Binary file not shown.
2 changes: 1 addition & 1 deletion FluentCore.Extend/FluentCore.Extend.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>FluentCore.Extend</RootNamespace>
<Version>1.1.2</Version>
<Version>1.1.3</Version>
<PackageId>FluentLauncher.Core.Extend</PackageId>
<Authors>xuan2006 - Xcube Studio</Authors>
<Company>Xcube Studio</Company>
Expand Down
2 changes: 1 addition & 1 deletion FluentCore/FluentCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ A Core Work for Minecraft Launcher</Description>
<PackageReleaseNotes></PackageReleaseNotes>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
<Version>1.1.2</Version>
<Version>1.1.3</Version>
<PackageId>FluentLauncher.Core</PackageId>
</PropertyGroup>

Expand Down
7 changes: 6 additions & 1 deletion FluentCore/Model/Game/Asset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ public HttpDownloadRequest GetDownloadRequest(string root)
Sha1 = this.Hash,
Size = this.Size,
Url = $"{SystemConfiguration.Api.Assets}/{this.Hash.Substring(0, 2)}/{this.Hash}",
Directory = new FileInfo($"{PathHelper.GetAssetsFolder(root)}{PathHelper.X}{this.GetRelativePath()}").Directory
Directory = new FileInfo($"{PathHelper.GetAssetsFolder(root)}{PathHelper.X}{this.GetRelativePath()}").Directory,
FileName = this.Hash
};
}

/// <summary>
/// 获取游戏依赖相对于.minecraft/assets的路径
/// </summary>
/// <returns></returns>
public virtual string GetRelativePath() => $"objects{PathHelper.X}{this.Hash.Substring(0, 2)}{PathHelper.X}{this.Hash}";
}
}
4 changes: 2 additions & 2 deletions FluentCore/Model/Game/CoreModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class CoreModel
public string Assets { get; set; }

[JsonProperty("javaVersion")]
public JavaVersion JavaVersion { get; set; }
public JavaVersion JavaVersion { get; set; } = new JavaVersion() { MajorVersion = 8 };

[JsonProperty("downloads")]
public Dictionary<string, FileModel> Downloads { get; set; }
Expand All @@ -27,7 +27,7 @@ public class CoreModel
public string Id { get; set; }

[JsonProperty("libraries")]
public IEnumerable<Library> Libraries { get; set; }
public List<Library> Libraries { get; set; }

[JsonProperty("logging")]
public Logging Logging { get; set; }
Expand Down
39 changes: 38 additions & 1 deletion FluentCore/Model/Game/Library.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,50 @@ public class Library : IDependence
[JsonProperty("clientreq")]
public bool? ClientReq { get; set; }

public virtual HttpDownloadRequest GetDownloadRequest(string root, bool useOriginalUrl)
{
string url;

if (useOriginalUrl && !string.IsNullOrEmpty(this.Downloads?.Artifact.Url))
url = this.Downloads?.Artifact.Url;
else url = SystemConfiguration.Api != new Mojang() ? $"{SystemConfiguration.Api.Libraries}/{this.GetRelativePath().Replace("\\", "/")}" : this.Url;

if (useOriginalUrl)
return new HttpDownloadRequest
{
Sha1 = this.Downloads?.Artifact.Sha1,
Size = this.Downloads?.Artifact.Size,
Url = url,
Directory = new FileInfo($"{PathHelper.GetLibrariesFolder(root)}{PathHelper.X}{this.GetRelativePath()}").Directory,
FileName = Path.GetFileName(this.GetRelativePath())
};

return new HttpDownloadRequest
{
Sha1 = this.Downloads?.Artifact.Sha1,
Size = this.Downloads?.Artifact.Size,
Url = SystemConfiguration.Api != new Mojang() ? $"{SystemConfiguration.Api.Libraries}/{this.GetRelativePath().Replace("\\", "/")}" : this.Url,
Directory = new FileInfo($"{PathHelper.GetLibrariesFolder(root)}{PathHelper.X}{this.GetRelativePath()}").Directory,
FileName = Path.GetFileName(this.GetRelativePath())
};
}

public virtual HttpDownloadRequest GetDownloadRequest(string root)
{
return new HttpDownloadRequest
{
Sha1 = this.Downloads?.Artifact.Sha1,
Size = this.Downloads?.Artifact.Size,
Url = SystemConfiguration.Api != new Mojang() ? $"{SystemConfiguration.Api.Libraries}/{this.GetRelativePath().Replace("\\", "/")}" : this.Url,
Directory = new FileInfo($"{PathHelper.GetLibrariesFolder(root)}{PathHelper.X}{this.GetRelativePath()}").Directory
Directory = new FileInfo($"{PathHelper.GetLibrariesFolder(root)}{PathHelper.X}{this.GetRelativePath()}").Directory,
FileName = Path.GetFileName(this.GetRelativePath())
};
}

/// <summary>
/// 获取游戏依赖相对于.minecraft/libraries的路径
/// </summary>
/// <returns></returns>
public virtual string GetRelativePath()
{
if (this.Name.Contains("@"))
Expand All @@ -62,6 +95,10 @@ public virtual string GetRelativePath()
}

string[] temp = Name.Split(':');

if (temp.Length == 4)
return $"{temp[0].Replace(".", PathHelper.X)}{PathHelper.X}{temp[1]}{PathHelper.X}{temp[2]}{PathHelper.X}{temp[1]}-{temp[2]}-{temp[3]}.jar";

return $"{temp[0].Replace(".", PathHelper.X)}{PathHelper.X}{temp[1]}{PathHelper.X}{temp[2]}{PathHelper.X}{temp[1]}-{temp[2]}.jar";
}
}
Expand Down
3 changes: 2 additions & 1 deletion FluentCore/Model/Game/Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public override HttpDownloadRequest GetDownloadRequest(string root)
Sha1 = file.Sha1,
Size = file.Size,
Url = $"{SystemConfiguration.Api.Libraries}/{this.GetRelativePath().Replace("\\", "/")}",
Directory = new FileInfo($"{PathHelper.GetLibrariesFolder(root)}{PathHelper.X}{this.GetRelativePath()}").Directory
Directory = new FileInfo($"{PathHelper.GetLibrariesFolder(root)}{PathHelper.X}{this.GetRelativePath()}").Directory,
FileName = Path.GetFileName(GetRelativePath())
};
}

Expand Down
5 changes: 5 additions & 0 deletions FluentCore/Model/HttpModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public class HttpDownloadRequest
/// 目标文件Sha1(仅供验证文件)
/// </summary>
public string Sha1 { get; set; }

/// <summary>
/// 目标文件名(可不指定)
/// </summary>
public string FileName { get; set; }
}

/// <summary>
Expand Down
3 changes: 0 additions & 3 deletions FluentCore/Model/Install/Forge/ForgeInstallerResultModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ namespace FluentCore.Model.Install.Forge
{
/// <summary>
/// Forge安装器结果模型
/// <para>
/// 1.13+
/// </para>
/// </summary>
public class ForgeInstallerResultModel
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class LegacyForgeInstallProfileModel
public JObject VersionInfo { get; set; }

[JsonProperty("optionals")]
public IEnumerable<string> Optionals { get; set; }
public IEnumerable<object> Optionals { get; set; }
}

public class LegacyForgeInstallModel
Expand Down
34 changes: 34 additions & 0 deletions FluentCore/Model/Install/OptiFine/OptiFineInstallerResultModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FluentCore.Model.Install.OptiFine
{
/// <summary>
/// OptiFine安装器结果模型
/// </summary>
public class OptiFineInstallerResultModel
{
/// <summary>
/// 是否成功
/// </summary>
public bool IsSuccessful { get; set; }

/// <summary>
/// 安装过程中进程输出
/// </summary>
public IEnumerable<string> ProcessOutput { get; set; }

/// <summary>
/// 安装过程中进程错误输出
/// </summary>
public IEnumerable<string> ProcessErrorOutput { get; set; }

/// <summary>
/// 安装结果
/// </summary>
public string Message { get; set; }
}
}
3 changes: 3 additions & 0 deletions FluentCore/Model/Launch/GameCore.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FluentCore.Model.Game;
using Newtonsoft.Json;
using System.Collections.Generic;

namespace FluentCore.Model.Launch
Expand Down Expand Up @@ -31,5 +32,7 @@ public class GameCore
public string Id { get; set; }

public string Type { get; set; }

public JavaVersion JavaVersion { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public async Task CompleteAsync()
var mainJarRequest = GetMainJarDownloadRequest();
if (mainJarRequest != null)
{
var res = await HttpHelper.HttpDownloadAsync(mainJarRequest);
var res = await HttpHelper.HttpDownloadAsync(mainJarRequest, "client.jar");
File.Move(res.FileInfo.FullName, this.GameCore.MainJar);
}

Expand All @@ -68,15 +68,15 @@ public async Task CompleteAsync()
if (!x.Directory.Exists)
x.Directory.Create();

var res = await HttpHelper.HttpDownloadAsync(x);
var res = await HttpHelper.HttpDownloadAsync(x, x.FileName);
if (res.HttpStatusCode != HttpStatusCode.OK)
this.ErrorDownloadResponses.Add(res);

SingleDownloadedEvent?.Invoke(this, res);
}, blockOptions);

var linkOptions = new DataflowLinkOptions { PropagateCompletion = true };
_ = manyBlock.LinkTo(actionBlock, linkOptions);
var dis = manyBlock.LinkTo(actionBlock, linkOptions);

var req = await GetRequestsAsync();
this.NeedDownloadDependencesCount = req.Count();
Expand All @@ -85,6 +85,8 @@ public async Task CompleteAsync()
manyBlock.Complete();

await actionBlock.Completion;
dis.Dispose();

GC.Collect();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public async Task<ForgeInstallerResultModel> InstallAsync()
if (!x.Directory.Exists)
x.Directory.Create();

var res = await HttpHelper.HttpDownloadAsync(x);
var res = await HttpHelper.HttpDownloadAsync(x, x.FileName);
}, blockOptions);

var linkOptions = new DataflowLinkOptions { PropagateCompletion = true };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
using FluentCore.Service.Component.Launch;
using FluentCore.Service.Local;
using FluentCore.Service.Network;
using FluentCore.Service.Network.Api;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using System.Threading.Tasks.Dataflow;

Expand Down Expand Up @@ -45,6 +47,8 @@ public class ModernForgeInstaller : InstallerBase
/// </summary>
public string ForgeInstallerPackagePath { get; set; }

public List<HttpDownloadRequest> ErrorDownload = new List<HttpDownloadRequest>();

public ModernForgeInstaller(CoreLocator locator, string mcVersion, string mcVersionId, string javaPath, string forgeInstallerPackagePath)
: base(locator)
{
Expand Down Expand Up @@ -192,34 +196,69 @@ public async Task<ForgeInstallerResultModel> InstallAsync()

#region Download Libraries

var downloadList = versionModel.Libraries.Union(forgeInstallProfile.Libraries).Select(x => x.GetDownloadRequest(this.CoreLocator.Root));
var manyBlock = new TransformManyBlock<IEnumerable<HttpDownloadRequest>, HttpDownloadRequest>(x => x);
var blockOptions = new ExecutionDataflowBlockOptions
{
BoundedCapacity = DependencesCompleter.MaxThread,
MaxDegreeOfParallelism = DependencesCompleter.MaxThread
};
for(int i = 0;i < versionModel.Libraries.Count;i++)
if (versionModel.Libraries[i].Name == forgeInstallProfile.Path)
versionModel.Libraries.Remove(versionModel.Libraries[i]);

for (int i = 0; i < forgeInstallProfile.Libraries.Count; i++)
if (forgeInstallProfile.Libraries[i].Name == $"{forgeInstallProfile.Path}:universal")
forgeInstallProfile.Libraries.Remove(forgeInstallProfile.Libraries[i]);

var actionBlock = new ActionBlock<HttpDownloadRequest>(async x =>
async Task Download(IEnumerable<HttpDownloadRequest> requests)
{
if (!x.Directory.Exists)
x.Directory.Create();
var manyBlock = new TransformManyBlock<IEnumerable<HttpDownloadRequest>, HttpDownloadRequest>(x => x);
var blockOptions = new ExecutionDataflowBlockOptions
{
BoundedCapacity = DependencesCompleter.MaxThread,
MaxDegreeOfParallelism = DependencesCompleter.MaxThread
};

var res = await HttpHelper.HttpDownloadAsync(x);
//if (res.HttpStatusCode != HttpStatusCode.OK)
// this.ErrorDownloadResponses.Add(res);
var actionBlock = new ActionBlock<HttpDownloadRequest>(async x =>
{
try
{
if (!x.Directory.Exists)
x.Directory.Create();

var res = await HttpHelper.HttpDownloadAsync(x, x.FileName);
if (res.HttpStatusCode != HttpStatusCode.OK)
this.ErrorDownload.Add(x);
}
catch
{
throw;
}
}, blockOptions);

var linkOptions = new DataflowLinkOptions { PropagateCompletion = true };
_ = manyBlock.LinkTo(actionBlock, linkOptions);

_ = manyBlock.Post(requests);
manyBlock.Complete();

await actionBlock.Completion;
GC.Collect();
}

var downloadList = versionModel.Libraries.Union(forgeInstallProfile.Libraries).Select(x =>
{
var result = x.GetDownloadRequest(this.CoreLocator.Root, true);

//SingleDownloadedEvent?.Invoke(this, res);
}, blockOptions);
if (SystemConfiguration.Api.Url != new Mojang().Url)
result.Url = result.Url.Replace("https://maven.minecraftforge.net", $"{SystemConfiguration.Api.Url}/maven");

var linkOptions = new DataflowLinkOptions { PropagateCompletion = true };
_ = manyBlock.LinkTo(actionBlock, linkOptions);
return result;
});

_ = manyBlock.Post(downloadList);
manyBlock.Complete();
await Download(downloadList);

await actionBlock.Completion;
GC.Collect();
//Try Again
if (ErrorDownload.Count > 0)
await Download(ErrorDownload.Select(x =>
{
x.Url = x.Url.Replace($"{SystemConfiguration.Api.Url}/maven", "https://maven.minecraftforge.net");
return x;
}));

#endregion

Expand Down
Loading

0 comments on commit 9f65be4

Please sign in to comment.