Skip to content

Commit

Permalink
xml 1 - json 0
Browse files Browse the repository at this point in the history
  • Loading branch information
4sval committed Aug 6, 2022
1 parent e2a5a6a commit a8c60ac
Show file tree
Hide file tree
Showing 10 changed files with 242 additions and 27 deletions.
6 changes: 5 additions & 1 deletion FModel/Framework/FEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 13 additions & 2 deletions FModel/ViewModels/ApiEndpoints/Models/AesResponse.cs
Original file line number Diff line number Diff line change
@@ -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) + "}")]
Expand All @@ -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);
}
37 changes: 28 additions & 9 deletions FModel/ViewModels/ApiEndpoints/Models/MappingsResponse.cs
Original file line number Diff line number Diff line change
@@ -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";
}
9 changes: 4 additions & 5 deletions FModel/ViewModels/ApiEndpoints/Models/PlaylistResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) + "}")]
Expand All @@ -32,4 +31,4 @@ public class PlaylistImages

[I] public bool HasShowcase => Showcase != null;
[I] public bool HasMissionIcon => MissionIcon != null;
}
}
4 changes: 2 additions & 2 deletions FModel/ViewModels/CUE4ParseViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public async Task RefreshAes()
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;
});
Expand Down Expand Up @@ -342,7 +342,7 @@ await _threadWorkerView.Begin(cancellationToken =>
{
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))
Expand Down
6 changes: 6 additions & 0 deletions FModel/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,12 @@ public SettingsOut Save()
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;
Expand Down
78 changes: 78 additions & 0 deletions FModel/Views/Resources/Controls/EndpointEditor.xaml
Original file line number Diff line number Diff line change
@@ -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 changes: 72 additions & 0 deletions FModel/Views/Resources/Controls/EndpointEditor.xaml.cs
Original file line number Diff line number Diff line change
@@ -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
{
//
}
}
}

4 changes: 2 additions & 2 deletions FModel/Views/SettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand Down
38 changes: 32 additions & 6 deletions FModel/Views/SettingsView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,27 +146,53 @@ private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)

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;
}
}

0 comments on commit a8c60ac

Please sign in to comment.