- tweak: speedup unpack
This commit is contained in:
74
Nebula.Shared/FileApis/FtpFileApi.cs
Normal file
74
Nebula.Shared/FileApis/FtpFileApi.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using System.Net;
|
||||
using FluentFTP;
|
||||
using Nebula.Shared.FileApis.Interfaces;
|
||||
|
||||
namespace Nebula.Shared.FileApis;
|
||||
|
||||
public class FtpFileApi : IWriteFileApi, IDisposable
|
||||
{
|
||||
private readonly string _ftpHost;
|
||||
private readonly string _username;
|
||||
private readonly string _password;
|
||||
|
||||
private readonly FtpClient Client;
|
||||
|
||||
public FtpFileApi(string ftpHost, string username, string password)
|
||||
{
|
||||
_ftpHost = ftpHost;
|
||||
_username = username;
|
||||
_password = password;
|
||||
Client = CreateClient();
|
||||
Client.AutoConnect();
|
||||
}
|
||||
|
||||
public bool Save(string path, Stream input)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = Client.UploadStream(input, path, FtpRemoteExists.Overwrite, true);
|
||||
return result == FtpStatus.Success;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Remove(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
Client.DeleteFile(path);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Has(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Client.FileExists(path);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private FtpClient CreateClient()
|
||||
{
|
||||
var client = new FtpClient(_ftpHost, _username, _password);
|
||||
client.Config.EncryptionMode = FtpEncryptionMode.None;
|
||||
client.Config.ValidateAnyCertificate = true;
|
||||
return client;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Client.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -11,14 +11,15 @@
|
||||
<EmbeddedResource Include="Utils\runtime.json">
|
||||
<LogicalName>Utility.runtime.json</LogicalName>
|
||||
</EmbeddedResource>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0"/>
|
||||
<PackageReference Include="Robust.Natives" Version="0.1.1"/>
|
||||
<PackageReference Include="SharpZstd.Interop" Version="1.5.6"/>
|
||||
<PackageReference Include="FluentFTP" Version="52.1.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
|
||||
<PackageReference Include="Robust.Natives" Version="0.1.1" />
|
||||
<PackageReference Include="SharpZstd.Interop" Version="1.5.6" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Nebula.SourceGenerators\Nebula.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>
|
||||
<ProjectReference Include="..\Robust.LoaderApi\Robust.LoaderApi\Robust.LoaderApi.csproj"/>
|
||||
<ProjectReference Include="..\Nebula.SourceGenerators\Nebula.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
|
||||
<ProjectReference Include="..\Robust.LoaderApi\Robust.LoaderApi\Robust.LoaderApi.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -69,12 +69,18 @@ public partial class ContentService
|
||||
debugService.Log("Unpack manifest files");
|
||||
var items = hashApi.Manifest.Values.ToList();
|
||||
loadingHandler.AppendJob(items.Count);
|
||||
foreach (var item in items)
|
||||
|
||||
var options = new ParallelOptions
|
||||
{
|
||||
MaxDegreeOfParallelism = 10
|
||||
};
|
||||
|
||||
Parallel.ForEach(items, options, item =>
|
||||
{
|
||||
if (hashApi.TryOpen(item, out var stream))
|
||||
{
|
||||
debugService.Log($"Unpack {item.Hash} to: {item.Path}");
|
||||
otherApi.Save(item.Path, stream);
|
||||
otherApi.Save(item.Hash, stream);
|
||||
stream.Close();
|
||||
}
|
||||
else
|
||||
@@ -83,7 +89,9 @@ public partial class ContentService
|
||||
}
|
||||
|
||||
loadingHandler.AppendResolvedJob();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
if (loadingHandler is IDisposable disposable)
|
||||
{
|
||||
|
||||
2
Nebula.sln.DotSettings.user
Normal file
2
Nebula.sln.DotSettings.user
Normal file
@@ -0,0 +1,2 @@
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AFrozenDictionary_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FUsers_003FCinka_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F89dff9063ddb01ff8125b579122b88bf4de94526490d77bcbbef7d0ee662a_003FFrozenDictionary_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>
|
||||
Reference in New Issue
Block a user