mirror of
https://github.com/4sval/FModel.git
synced 2026-09-26 11:07:39 -05:00
endpoint configuration template
This commit is contained in:
@@ -22,7 +22,8 @@ public class ApiEndpointViewModel
|
||||
public ValorantApiEndpoint ValorantApi { get; }
|
||||
public FortniteCentralApiEndpoint CentralApi { get; }
|
||||
public EpicApiEndpoint EpicApi { get; }
|
||||
public FModelApi FModelApi { get; }
|
||||
public FModelApiEndpoint FModelApi { get; }
|
||||
public DynamicApiEndpoint DynamicApi { get; }
|
||||
|
||||
public ApiEndpointViewModel()
|
||||
{
|
||||
@@ -30,7 +31,8 @@ public class ApiEndpointViewModel
|
||||
ValorantApi = new ValorantApiEndpoint(_client);
|
||||
CentralApi = new FortniteCentralApiEndpoint(_client);
|
||||
EpicApi = new EpicApiEndpoint(_client);
|
||||
FModelApi = new FModelApi(_client);
|
||||
FModelApi = new FModelApiEndpoint(_client);
|
||||
DynamicApi = new DynamicApiEndpoint(_client);
|
||||
}
|
||||
|
||||
public async Task DownloadFileAsync(string fileLink, string installationPath)
|
||||
|
||||
47
FModel/ViewModels/ApiEndpoints/DynamicApiEndpoint.cs
Normal file
47
FModel/ViewModels/ApiEndpoints/DynamicApiEndpoint.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using FModel.Framework;
|
||||
using FModel.ViewModels.ApiEndpoints.Models;
|
||||
using RestSharp;
|
||||
using Serilog;
|
||||
|
||||
namespace FModel.ViewModels.ApiEndpoints;
|
||||
|
||||
public class DynamicApiEndpoint : AbstractApiProvider
|
||||
{
|
||||
public DynamicApiEndpoint(RestClient client) : base(client)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<AesResponse> GetAesKeysAsync(CancellationToken token, string url)
|
||||
{
|
||||
var request = new FRestRequest(url)
|
||||
{
|
||||
OnBeforeDeserialization = resp => { resp.ContentType = "application/json; charset=utf-8"; }
|
||||
};
|
||||
var response = await _client.ExecuteAsync<AesResponse>(request, token).ConfigureAwait(false);
|
||||
Log.Information("[{Method}] [{Status}({StatusCode})] '{Resource}'", request.Method, response.StatusDescription, (int) response.StatusCode, response.ResponseUri?.OriginalString);
|
||||
return response.Data;
|
||||
}
|
||||
|
||||
public AesResponse GetAesKeys(CancellationToken token, string url)
|
||||
{
|
||||
return GetAesKeysAsync(token, url).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
public async Task<MappingsResponse[]> GetMappingsAsync(CancellationToken token, string url)
|
||||
{
|
||||
var request = new FRestRequest(url)
|
||||
{
|
||||
OnBeforeDeserialization = resp => { resp.ContentType = "application/json; charset=utf-8"; }
|
||||
};
|
||||
var response = await _client.ExecuteAsync<MappingsResponse[]>(request, token).ConfigureAwait(false);
|
||||
Log.Information("[{Method}] [{Status}({StatusCode})] '{Resource}'", request.Method, response.StatusDescription, (int) response.StatusCode, response.ResponseUri?.OriginalString);
|
||||
return response.Data;
|
||||
}
|
||||
|
||||
public MappingsResponse[] GetMappings(CancellationToken token, string url)
|
||||
{
|
||||
return GetMappingsAsync(token, url).GetAwaiter().GetResult();
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ using MessageBoxResult = AdonisUI.Controls.MessageBoxResult;
|
||||
|
||||
namespace FModel.ViewModels.ApiEndpoints;
|
||||
|
||||
public class FModelApi : AbstractApiProvider
|
||||
public class FModelApiEndpoint : AbstractApiProvider
|
||||
{
|
||||
private News _news;
|
||||
private Info _infos;
|
||||
@@ -29,7 +29,7 @@ public class FModelApi : AbstractApiProvider
|
||||
private readonly IDictionary<string, CommunityDesign> _communityDesigns = new Dictionary<string, CommunityDesign>();
|
||||
private ApplicationViewModel _applicationView => ApplicationService.ApplicationView;
|
||||
|
||||
public FModelApi(RestClient client) : base(client)
|
||||
public FModelApiEndpoint(RestClient client) : base(client)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using FModel.Framework;
|
||||
using FModel.ViewModels.ApiEndpoints.Models;
|
||||
using RestSharp;
|
||||
using Serilog;
|
||||
|
||||
@@ -14,38 +13,6 @@ public class FortniteCentralApiEndpoint : AbstractApiProvider
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<AesResponse> GetAesKeysAsync(CancellationToken token)
|
||||
{
|
||||
var request = new FRestRequest("https://fortnitecentral.gmatrixgames.ga/api/v1/aes")
|
||||
{
|
||||
OnBeforeDeserialization = resp => { resp.ContentType = "application/json; charset=utf-8"; }
|
||||
};
|
||||
var response = await _client.ExecuteAsync<AesResponse>(request, token).ConfigureAwait(false);
|
||||
Log.Information("[{Method}] [{Status}({StatusCode})] '{Resource}'", request.Method, response.StatusDescription, (int) response.StatusCode, response.ResponseUri?.OriginalString);
|
||||
return response.Data;
|
||||
}
|
||||
|
||||
public AesResponse GetAesKeys(CancellationToken token)
|
||||
{
|
||||
return GetAesKeysAsync(token).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
public async Task<MappingsResponse[]> GetMappingsAsync(CancellationToken token)
|
||||
{
|
||||
var request = new FRestRequest("https://fortnitecentral.gmatrixgames.ga/api/v1/mappings")
|
||||
{
|
||||
OnBeforeDeserialization = resp => { resp.ContentType = "application/json; charset=utf-8"; }
|
||||
};
|
||||
var response = await _client.ExecuteAsync<MappingsResponse[]>(request, token).ConfigureAwait(false);
|
||||
Log.Information("[{Method}] [{Status}({StatusCode})] '{Resource}'", request.Method, response.StatusDescription, (int) response.StatusCode, response.ResponseUri?.OriginalString);
|
||||
return response.Data;
|
||||
}
|
||||
|
||||
public MappingsResponse[] GetMappings(CancellationToken token)
|
||||
{
|
||||
return GetMappingsAsync(token).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
public async Task<Dictionary<string, Dictionary<string, string>>> GetHotfixesAsync(CancellationToken token, string language = "en")
|
||||
{
|
||||
var request = new FRestRequest("https://fortnitecentral.gmatrixgames.ga/api/v1/hotfixes")
|
||||
|
||||
@@ -293,16 +293,18 @@ public class CUE4ParseViewModel : ViewModel
|
||||
|
||||
public async Task RefreshAes()
|
||||
{
|
||||
if (Game == FGame.FortniteGame) // game directory dependent, we don't have the provider game name yet since we don't have aes keys
|
||||
{
|
||||
await _threadWorkerView.Begin(cancellationToken =>
|
||||
{
|
||||
var aes = _apiEndpointView.CentralApi.GetAesKeys(cancellationToken);
|
||||
if (aes?.MainKey == null && aes?.DynamicKeys == null && aes?.Version == null) return;
|
||||
// game directory dependent, we don't have the provider game name yet since we don't have aes keys
|
||||
// except when this comes from the AES Manager
|
||||
if (!UserSettings.TryGetGameCustomEndpoint(Game, EEndpointType.Aes, out var endpoint))
|
||||
return;
|
||||
|
||||
UserSettings.Default.AesKeys[Game] = aes;
|
||||
});
|
||||
}
|
||||
await _threadWorkerView.Begin(cancellationToken =>
|
||||
{
|
||||
var aes = _apiEndpointView.DynamicApi.GetAesKeys(cancellationToken, endpoint.Url);
|
||||
if (aes?.MainKey == null && aes?.DynamicKeys == null) return;
|
||||
|
||||
UserSettings.Default.AesKeys[Game] = aes;
|
||||
});
|
||||
}
|
||||
|
||||
public async Task InitInformation()
|
||||
@@ -321,20 +323,21 @@ public class CUE4ParseViewModel : ViewModel
|
||||
|
||||
public async Task InitBenMappings()
|
||||
{
|
||||
if (Game != FGame.FortniteGame) return;
|
||||
if (!UserSettings.TryGetGameCustomEndpoint(Game, EEndpointType.Mapping, out var endpoint))
|
||||
return;
|
||||
|
||||
await _threadWorkerView.Begin(cancellationToken =>
|
||||
{
|
||||
if (UserSettings.Default.OverwriteMapping && File.Exists(UserSettings.Default.MappingFilePath))
|
||||
if (endpoint.Overwrite && File.Exists(endpoint.Path))
|
||||
{
|
||||
Provider.MappingsContainer = new FileUsmapTypeMappingsProvider(UserSettings.Default.MappingFilePath);
|
||||
Provider.MappingsContainer = new FileUsmapTypeMappingsProvider(endpoint.Path);
|
||||
FLogger.AppendInformation();
|
||||
FLogger.AppendText($"Mappings pulled from '{UserSettings.Default.MappingFilePath.SubstringAfterLast("\\")}'", Constants.WHITE, true);
|
||||
FLogger.AppendText($"Mappings pulled from '{endpoint.Path.SubstringAfterLast("\\")}'", Constants.WHITE, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
var mappingsFolder = Path.Combine(UserSettings.Default.OutputDirectory, ".data");
|
||||
var mappings = _apiEndpointView.CentralApi.GetMappings(cancellationToken);
|
||||
var mappings = _apiEndpointView.DynamicApi.GetMappings(cancellationToken, endpoint.Url);
|
||||
if (mappings is { Length: > 0 })
|
||||
{
|
||||
foreach (var mapping in mappings)
|
||||
|
||||
@@ -96,6 +96,13 @@ public class SettingsViewModel : ViewModel
|
||||
set => SetProperty(ref _selectedCompressedAudio, value);
|
||||
}
|
||||
|
||||
private string _currentMappingFile;
|
||||
public string CurrentMappingFile // only used so that it updates the UI
|
||||
{
|
||||
get => _currentMappingFile;
|
||||
set => SetProperty(ref _currentMappingFile, value);
|
||||
}
|
||||
|
||||
private EIconStyle _selectedCosmeticStyle;
|
||||
public EIconStyle SelectedCosmeticStyle
|
||||
{
|
||||
@@ -191,6 +198,9 @@ public class SettingsViewModel : ViewModel
|
||||
_optionsSnapshot = UserSettings.Default.OverridedOptions[_game];
|
||||
}
|
||||
|
||||
if (UserSettings.TryGetGameCustomEndpoint(_game, EEndpointType.Mapping, out var endpoint))
|
||||
CurrentMappingFile = endpoint.Path;
|
||||
|
||||
_assetLanguageSnapshot = UserSettings.Default.AssetLanguage;
|
||||
_compressedAudioSnapshot = UserSettings.Default.CompressedAudioMode;
|
||||
_cosmeticStyleSnapshot = UserSettings.Default.CosmeticStyle;
|
||||
|
||||
Reference in New Issue
Block a user