mirror of
https://github.com/4sval/FModel.git
synced 2026-09-13 12:06:39 -05:00
xml 1 - json 0
This commit is contained in:
@@ -6,7 +6,11 @@ public class FEndpoint : ViewModel
|
||||
public string Url
|
||||
{
|
||||
get => _url;
|
||||
set => SetProperty(ref _url, value);
|
||||
set
|
||||
{
|
||||
SetProperty(ref _url, value);
|
||||
RaisePropertyChanged(nameof(IsEnabled));
|
||||
}
|
||||
}
|
||||
|
||||
private bool _overwrite;
|
||||
|
||||
@@ -1,17 +1,25 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using J = Newtonsoft.Json.JsonPropertyAttribute;
|
||||
using I = Newtonsoft.Json.JsonIgnoreAttribute;
|
||||
|
||||
namespace FModel.ViewModels.ApiEndpoints.Models;
|
||||
|
||||
[DebuggerDisplay("{" + nameof(Version) + "}")]
|
||||
public class AesResponse
|
||||
{
|
||||
[J("version")] public string Version { get; private set; }
|
||||
[I][J("version")] public string Version { get; private set; }
|
||||
[J("mainKey")] public string MainKey { get; set; }
|
||||
[J("dynamicKeys")] public List<DynamicKey> DynamicKeys { get; set; }
|
||||
|
||||
public bool HasDynamicKeys => DynamicKeys is { Count: > 0 };
|
||||
public AesResponse()
|
||||
{
|
||||
MainKey = string.Empty;
|
||||
DynamicKeys = new List<DynamicKey>();
|
||||
}
|
||||
|
||||
[I] public bool HasDynamicKeys => DynamicKeys is { Count: > 0 };
|
||||
[I] public bool IsValid => !string.IsNullOrEmpty(MainKey);
|
||||
}
|
||||
|
||||
[DebuggerDisplay("{" + nameof(Key) + "}")]
|
||||
@@ -20,4 +28,7 @@ public class DynamicKey
|
||||
[J("name")] public string Name { get; set; }
|
||||
[J("guid")] public string Guid { get; set; }
|
||||
[J("key")] public string Key { get; set; }
|
||||
|
||||
[I] public bool IsValid => !string.IsNullOrEmpty(Guid) &&
|
||||
!string.IsNullOrEmpty(Key);
|
||||
}
|
||||
|
||||
@@ -1,22 +1,41 @@
|
||||
using System.Diagnostics;
|
||||
using J = Newtonsoft.Json.JsonPropertyAttribute;
|
||||
using I = Newtonsoft.Json.JsonIgnoreAttribute;
|
||||
|
||||
namespace FModel.ViewModels.ApiEndpoints.Models;
|
||||
|
||||
[DebuggerDisplay("{" + nameof(FileName) + "}")]
|
||||
public class MappingsResponse
|
||||
{
|
||||
[J] public string Url { get; private set; }
|
||||
[J] public string FileName { get; private set; }
|
||||
[J] public string Hash { get; private set; }
|
||||
[J] public long Length { get; private set; }
|
||||
[J] public string Uploaded { get; private set; }
|
||||
[J] public Meta Meta { get; private set; }
|
||||
[J] public string Url { get; set; }
|
||||
[J] public string FileName { get; set; }
|
||||
[I][J] public string Hash { get; private set; }
|
||||
[I][J] public long Length { get; private set; }
|
||||
[I][J] public string Uploaded { get; private set; }
|
||||
[J] public Meta Meta { get; set; }
|
||||
|
||||
public MappingsResponse()
|
||||
{
|
||||
Url = string.Empty;
|
||||
FileName = string.Empty;
|
||||
Meta = new Meta();
|
||||
}
|
||||
|
||||
[I] public bool IsValid => !string.IsNullOrEmpty(Url) &&
|
||||
!string.IsNullOrEmpty(FileName) &&
|
||||
Meta != null;
|
||||
}
|
||||
|
||||
[DebuggerDisplay("{" + nameof(CompressionMethod) + "}")]
|
||||
public class Meta
|
||||
{
|
||||
[J] public string Version { get; private set; }
|
||||
[J] public string CompressionMethod { get; private set; }
|
||||
}
|
||||
[I][J] public string Version { get; private set; }
|
||||
[J] public string CompressionMethod { get; set; }
|
||||
|
||||
public Meta()
|
||||
{
|
||||
CompressionMethod = "Oodle";
|
||||
}
|
||||
|
||||
[I] public bool IsValid => CompressionMethod == "Oodle";
|
||||
}
|
||||
|
||||
@@ -12,10 +12,9 @@ public class PlaylistResponse
|
||||
[J] public Playlist Data { get; private set; }
|
||||
[J] public string Error { get; private set; }
|
||||
|
||||
public bool IsSuccess => Status == 200;
|
||||
public bool HasError => Error != null;
|
||||
|
||||
private object DebuggerDisplay => IsSuccess ? Data : $"Error: {Status} | {Error}";
|
||||
[I] public bool IsSuccess => Status == 200;
|
||||
[I] public bool HasError => Error != null;
|
||||
[I] private object DebuggerDisplay => IsSuccess ? Data : $"Error: {Status} | {Error}";
|
||||
}
|
||||
|
||||
[DebuggerDisplay("{" + nameof(Id) + "}")]
|
||||
@@ -32,4 +31,4 @@ public class PlaylistImages
|
||||
|
||||
[I] public bool HasShowcase => Showcase != null;
|
||||
[I] public bool HasMissionIcon => MissionIcon != null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -301,7 +301,7 @@ public class CUE4ParseViewModel : ViewModel
|
||||
await _threadWorkerView.Begin(cancellationToken =>
|
||||
{
|
||||
var aes = _apiEndpointView.DynamicApi.GetAesKeys(cancellationToken, endpoint.Url);
|
||||
if (aes?.MainKey == null && aes?.DynamicKeys == null) return;
|
||||
if (aes is not { IsValid: true }) return;
|
||||
|
||||
UserSettings.Default.AesKeys[Game] = aes;
|
||||
});
|
||||
@@ -342,7 +342,7 @@ public class CUE4ParseViewModel : ViewModel
|
||||
{
|
||||
foreach (var mapping in mappings)
|
||||
{
|
||||
if (mapping.Meta.CompressionMethod != "Oodle") continue;
|
||||
if (!mapping.IsValid || !mapping.Meta.IsValid) continue;
|
||||
|
||||
var mappingPath = Path.Combine(mappingsFolder, mapping.FileName);
|
||||
if (!File.Exists(mappingPath))
|
||||
|
||||
@@ -324,6 +324,12 @@ public class SettingsViewModel : ViewModel
|
||||
UserSettings.Default.OverridedOptions[_game] = SelectedOptions;
|
||||
}
|
||||
|
||||
if (UserSettings.Default.CustomEndpoints.TryGetValue(_game, out var endpoints))
|
||||
{
|
||||
endpoints[0] = AesEndpoint;
|
||||
endpoints[1] = MappingEndpoint;
|
||||
}
|
||||
|
||||
UserSettings.Default.AssetLanguage = SelectedAssetLanguage;
|
||||
UserSettings.Default.CompressedAudioMode = SelectedCompressedAudio;
|
||||
UserSettings.Default.CosmeticStyle = SelectedCosmeticStyle;
|
||||
|
||||
78
FModel/Views/Resources/Controls/EndpointEditor.xaml
Normal file
78
FModel/Views/Resources/Controls/EndpointEditor.xaml
Normal file
@@ -0,0 +1,78 @@
|
||||
<adonisControls:AdonisWindow x:Class="FModel.Views.Resources.Controls.EndpointEditor"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:converters="clr-namespace:FModel.Views.Resources.Converters"
|
||||
xmlns:avalonEdit="http://icsharpcode.net/sharpdevelop/avalonedit"
|
||||
xmlns:adonisUi="clr-namespace:AdonisUI;assembly=AdonisUI"
|
||||
xmlns:adonisControls="clr-namespace:AdonisUI.Controls;assembly=AdonisUI"
|
||||
xmlns:adonisExtensions="clr-namespace:AdonisUI.Extensions;assembly=AdonisUI"
|
||||
WindowStartupLocation="CenterScreen" IconVisibility="Collapsed" ResizeMode="NoResize"
|
||||
Width="{Binding Source={x:Static SystemParameters.MaximizedPrimaryScreenWidth}, Converter={converters:RatioConverter}, ConverterParameter='0.50'}"
|
||||
Height="{Binding Source={x:Static SystemParameters.MaximizedPrimaryScreenWidth}, Converter={converters:RatioConverter}, ConverterParameter='0.30'}">
|
||||
<adonisControls:AdonisWindow.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="../Resources.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</adonisControls:AdonisWindow.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="5"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Grid Grid.Row="0" Margin="{adonisUi:Space 1, 0.5}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="10" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="5" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<TextBlock Grid.Column="0" Text="Endpoint" VerticalAlignment="Center" Margin="0 0 0 5" />
|
||||
<TextBox x:Name="EndpointUrl" Grid.Column="2" Margin="0 0 0 5" />
|
||||
<Button Grid.Column="4" Content="Send" HorizontalAlignment="Right" Margin="0 0 0 5"
|
||||
Style="{DynamicResource {x:Static adonisUi:Styles.AccentButton}}" Click="OnSend"/>
|
||||
</Grid>
|
||||
|
||||
<Grid Grid.Row="2">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="5" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<avalonEdit:TextEditor x:Name="EndpointResponse" Grid.Column="0" Background="{DynamicResource {x:Static adonisUi:Brushes.Layer3BackgroundBrush}}"
|
||||
FontFamily="Consolas" FontSize="8pt" IsReadOnly="True" ShowLineNumbers="True" Foreground="#DAE5F2" />
|
||||
<avalonEdit:TextEditor x:Name="TargetResponse" Grid.Column="2" Background="{DynamicResource {x:Static adonisUi:Brushes.Layer3BackgroundBrush}}"
|
||||
FontFamily="Consolas" FontSize="8pt" IsReadOnly="False" ShowLineNumbers="True" Foreground="#DAE5F2" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
<Border Grid.Row="1"
|
||||
Background="{DynamicResource {x:Static adonisUi:Brushes.Layer1BackgroundBrush}}"
|
||||
adonisExtensions:LayerExtension.IncreaseLayer="True">
|
||||
<Grid Margin="30, 12, 6, 12">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Button Grid.Column="0" MinWidth="78" Margin="0 0 12 0" IsDefault="True" IsCancel="False"
|
||||
HorizontalAlignment="Right" VerticalAlignment="Bottom" Content="OK" Click="OnClick" />
|
||||
<Button Grid.Column="1" MinWidth="78" Margin="0 0 12 0" IsDefault="False" IsCancel="True"
|
||||
HorizontalAlignment="Right" VerticalAlignment="Bottom" Content="Cancel" />
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
</adonisControls:AdonisWindow>
|
||||
|
||||
72
FModel/Views/Resources/Controls/EndpointEditor.xaml.cs
Normal file
72
FModel/Views/Resources/Controls/EndpointEditor.xaml.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using FModel.Extensions;
|
||||
using FModel.Framework;
|
||||
using FModel.ViewModels.ApiEndpoints.Models;
|
||||
using ICSharpCode.AvalonEdit.Document;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using RestSharp;
|
||||
|
||||
namespace FModel.Views.Resources.Controls;
|
||||
|
||||
public partial class EndpointEditor
|
||||
{
|
||||
private readonly AesResponse _defaultAesResponse = new ();
|
||||
private readonly MappingsResponse[] _defaultMappingResponse = {new ()};
|
||||
private JObject _body;
|
||||
|
||||
public FEndpoint Endpoint { get; private set; }
|
||||
|
||||
public EndpointEditor(FEndpoint endpoint, string title, EEndpointType type)
|
||||
{
|
||||
DataContext = endpoint;
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
Title = title;
|
||||
EndpointUrl.Text = endpoint.Url;
|
||||
TargetResponse.SyntaxHighlighting = EndpointResponse.SyntaxHighlighting = AvalonExtensions.HighlighterSelector("json");
|
||||
TargetResponse.Document = new TextDocument
|
||||
{
|
||||
Text = JsonConvert.SerializeObject(type switch
|
||||
{
|
||||
EEndpointType.Aes => _defaultAesResponse,
|
||||
EEndpointType.Mapping => _defaultMappingResponse,
|
||||
_ => throw new NotImplementedException()
|
||||
}, Formatting.Indented)
|
||||
};
|
||||
}
|
||||
|
||||
private void OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Endpoint = new FEndpoint(EndpointUrl.Text);
|
||||
DialogResult = true;
|
||||
Close();
|
||||
}
|
||||
|
||||
private async void OnSend(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await new RestClient().ExecuteAsync(new FRestRequest(EndpointUrl.Text)
|
||||
{
|
||||
OnBeforeDeserialization = resp => { resp.ContentType = "application/json; charset=utf-8"; }
|
||||
}).ConfigureAwait(false);
|
||||
_body = JObject.Parse(response.Content!);
|
||||
|
||||
Application.Current.Dispatcher.Invoke(delegate
|
||||
{
|
||||
EndpointResponse.Document = new TextDocument
|
||||
{
|
||||
Text = _body.ToString(Formatting.Indented)
|
||||
};
|
||||
});
|
||||
}
|
||||
catch
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,8 +184,8 @@
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Button Grid.Column="0" Content="AES" />
|
||||
<Button Grid.Column="2" Content="Mapping">
|
||||
<Button Grid.Column="0" Content="AES" Click="OpenAesEndpoint" />
|
||||
<Button Grid.Column="2" Content="Mapping" Click="OpenMappingEndpoint">
|
||||
<Button.Style>
|
||||
<Style TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
|
||||
<Setter Property="IsEnabled" Value="False"/>
|
||||
|
||||
@@ -146,27 +146,53 @@ public partial class SettingsView
|
||||
|
||||
private void OpenCustomVersions(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var dictionary = new DictionaryEditor(
|
||||
var editor = new DictionaryEditor(
|
||||
_applicationView.SettingsView.SelectedCustomVersions,
|
||||
"Versioning Configuration (Custom Versions)",
|
||||
_applicationView.SettingsView.EnableElements);
|
||||
var result = dictionary.ShowDialog();
|
||||
var result = editor.ShowDialog();
|
||||
if (!result.HasValue || !result.Value)
|
||||
return;
|
||||
|
||||
_applicationView.SettingsView.SelectedCustomVersions = dictionary.CustomVersions;
|
||||
_applicationView.SettingsView.SelectedCustomVersions = editor.CustomVersions;
|
||||
}
|
||||
|
||||
private void OpenOptions(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var dictionary = new DictionaryEditor(
|
||||
var editor = new DictionaryEditor(
|
||||
_applicationView.SettingsView.SelectedOptions,
|
||||
"Versioning Configuration (Options)",
|
||||
_applicationView.SettingsView.EnableElements);
|
||||
var result = dictionary.ShowDialog();
|
||||
var result = editor.ShowDialog();
|
||||
if (!result.HasValue || !result.Value)
|
||||
return;
|
||||
|
||||
_applicationView.SettingsView.SelectedOptions = dictionary.Options;
|
||||
_applicationView.SettingsView.SelectedOptions = editor.Options;
|
||||
}
|
||||
|
||||
private void OpenAesEndpoint(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var editor = new EndpointEditor(
|
||||
_applicationView.SettingsView.AesEndpoint,
|
||||
"Endpoint Configuration (AES)",
|
||||
EEndpointType.Aes);
|
||||
var result = editor.ShowDialog();
|
||||
if (!result.HasValue || !result.Value)
|
||||
return;
|
||||
|
||||
_applicationView.SettingsView.AesEndpoint = editor.Endpoint;
|
||||
}
|
||||
|
||||
private void OpenMappingEndpoint(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var editor = new EndpointEditor(
|
||||
_applicationView.SettingsView.MappingEndpoint,
|
||||
"Endpoint Configuration (Mapping)",
|
||||
EEndpointType.Mapping);
|
||||
var result = editor.ShowDialog();
|
||||
if (!result.HasValue || !result.Value)
|
||||
return;
|
||||
|
||||
_applicationView.SettingsView.MappingEndpoint = editor.Endpoint;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user