-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from Drommedhar/dev
Dev
- Loading branch information
Showing
17 changed files
with
388 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<UserControl x:Class="DlssUpdater.Controls.LauncherPanel" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" | ||
xmlns:local="clr-namespace:DlssUpdater.Controls" | ||
mc:Ignorable="d" | ||
d:DesignHeight="450" d:DesignWidth="800" Margin="0,0,0,5" x:Name="LibPanel"> | ||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto"/> | ||
<RowDefinition Height="Auto"/> | ||
</Grid.RowDefinitions> | ||
<Grid Grid.Row="0" Background="#19000000"> | ||
<ui:ToggleSwitch Content="{Binding LibraryConfig.LibraryName, ElementName=LibPanel}" HorizontalAlignment="Left" Margin="5,5,0,5" IsChecked="{Binding LibraryConfig.IsChecked, ElementName=LibPanel}" Click="ToggleSwitch_Click"/> | ||
</Grid> | ||
<Grid x:Name="GridExpand" Grid.Row="1" Background="#0C000000"> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="*"/> | ||
<ColumnDefinition Width="Auto"/> | ||
<ColumnDefinition Width="Auto"/> | ||
</Grid.ColumnDefinitions> | ||
<ui:TextBox Grid.Column="0" IsReadOnly="True" Text="{Binding LibraryConfig.InstallPath, ElementName=LibPanel}" Margin="5,0,0,0"/> | ||
<ui:Button Grid.Column="1" Content="..." Margin="10,0,5,0" Click="Button_Click_1"/> | ||
<ui:Button Grid.Column="2" Content="Auto Scan" Margin="5,0,5,0" Click="Button_Click"/> | ||
</Grid> | ||
</Grid> | ||
</UserControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using DlssUpdater.Defines; | ||
using DlssUpdater.Singletons; | ||
using DLSSUpdater.Defines; | ||
using Microsoft.Win32; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Data; | ||
using System.Windows.Documents; | ||
using System.Windows.Input; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Imaging; | ||
using System.Windows.Navigation; | ||
using System.Windows.Shapes; | ||
|
||
namespace DlssUpdater.Controls | ||
{ | ||
/// <summary> | ||
/// Interaction logic for LauncherPanel.xaml | ||
/// </summary> | ||
public partial class LauncherPanel : UserControl | ||
{ | ||
public static readonly DependencyProperty LibraryConfigProperty = | ||
DependencyProperty.Register("LibraryConfig", typeof(LibraryConfig), typeof(LauncherPanel)); | ||
|
||
public LibraryConfig LibraryConfig | ||
{ | ||
get => (LibraryConfig)GetValue(LibraryConfigProperty); | ||
set => SetValue(LibraryConfigProperty, value); | ||
} | ||
|
||
private readonly Settings _settings; | ||
private readonly GameContainer _gameContainer; | ||
private readonly NLog.Logger _logger; | ||
|
||
public LauncherPanel() | ||
{ | ||
InitializeComponent(); | ||
|
||
_settings = App.GetService<Settings>()!; | ||
_gameContainer = App.GetService<GameContainer>()!; | ||
_logger = App.GetService<NLog.Logger>()!; | ||
|
||
GridExpand.Visibility = Visibility.Visible; | ||
} | ||
|
||
private async void ToggleSwitch_Click(object sender, RoutedEventArgs e) | ||
{ | ||
_settings.Save(); | ||
_logger.Debug($"Switched library '{LibraryConfig.LibraryName}' to {LibraryConfig.IsChecked}"); | ||
_gameContainer.UpdateLibraries(); | ||
await _gameContainer.ReloadLibraryGames(LibraryConfig.LibraryType); | ||
} | ||
|
||
private void Button_Click(object sender, RoutedEventArgs e) | ||
{ | ||
var libRef = _gameContainer.Libraries.FirstOrDefault(l => l.GetLibraryType() == LibraryConfig.LibraryType); | ||
libRef?.GetInstallationDirectory(); | ||
} | ||
|
||
private async void Button_Click_1(object sender, RoutedEventArgs e) | ||
{ | ||
OpenFolderDialog dlg = new() | ||
{ | ||
Multiselect = false | ||
}; | ||
if (dlg.ShowDialog() == true) | ||
{ | ||
LibraryConfig.InstallPath = dlg.FolderName; | ||
_settings.Save(); | ||
_gameContainer.UpdateLibraries(); | ||
await _gameContainer.LoadGamesAsync(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using DlssUpdater.Defines; | ||
using DlssUpdater.GameLibrary; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.Json.Serialization; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
using DLSSUpdater.Defines; | ||
|
||
namespace DLSSUpdater.Defines | ||
{ | ||
public partial class LibraryConfig : ObservableObject | ||
{ | ||
public LibraryType LibraryType { get; set; } | ||
|
||
[ObservableProperty] | ||
private bool _isChecked; | ||
|
||
[ObservableProperty] | ||
private string _libraryName; | ||
|
||
[ObservableProperty] | ||
private string _installPath; | ||
|
||
[ObservableProperty][JsonIgnore] public LibraryConfig _self; | ||
|
||
public LibraryConfig(LibraryType type, string name) | ||
{ | ||
LibraryType = type; | ||
_libraryName = name; | ||
_installPath = string.Empty; | ||
_isChecked = true; | ||
Self = this; | ||
} | ||
} | ||
} | ||
|
||
public class LibraryConvert : JsonConverter<LibraryConfig> | ||
{ | ||
public override LibraryConfig? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
bool isChecked = false; | ||
string libraryName = ""; | ||
string installPath = ""; | ||
LibraryType libraryType = LibraryType.Manual; | ||
while (reader.Read()) | ||
{ | ||
if (reader.TokenType == JsonTokenType.EndObject) | ||
{ | ||
var config = new LibraryConfig(libraryType, libraryName) | ||
{ | ||
IsChecked = isChecked, | ||
InstallPath = installPath | ||
}; | ||
return config; | ||
} | ||
// TODO: More | ||
var propName = reader.GetString(); | ||
reader.Read(); | ||
if (propName == "IsChecked") | ||
{ | ||
isChecked = reader.GetBoolean(); | ||
} | ||
if(propName == "LibraryName") | ||
{ | ||
libraryName = reader.GetString()!; | ||
} | ||
if(propName == "LibraryType") | ||
{ | ||
libraryType = (LibraryType)Enum.Parse(typeof(LibraryType), reader.GetString()!); | ||
} | ||
if(propName == "InstallPath") | ||
{ | ||
installPath = reader.GetString()!; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, LibraryConfig value, JsonSerializerOptions options) | ||
{ | ||
writer.WriteStartObject(); | ||
writer.WriteBoolean(nameof(LibraryConfig.IsChecked), value.IsChecked); | ||
writer.WriteString(nameof(LibraryConfig.LibraryName), value.LibraryName); | ||
writer.WriteString(nameof(LibraryConfig.LibraryType), value.LibraryType.ToString()); | ||
writer.WriteString(nameof(LibraryConfig.InstallPath), value.InstallPath); | ||
writer.WriteEndObject(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.