new_version_init

This commit is contained in:
2024-02-13 02:59:40 +01:00
Unverified
parent e36c1404ee
commit 91f9b645bd
352 changed files with 6777 additions and 8326 deletions

View File

@@ -0,0 +1,44 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VDownload.GUI.Converters
{
public class BooleanToGridLengthConverter : IValueConverter
{
#region METHODS
public object Convert(object value, Type targetType, object parameter, string language)
{
GridLength notVisibleLength = new GridLength(0);
if (value is bool visible)
{
GridLength visibleLength = new GridLength(1, GridUnitType.Star);
if (parameter is string width)
{
if (width.ToLower() == "auto")
{
visibleLength = GridLength.Auto;
}
else if (int.TryParse(width, out int result))
{
visibleLength = new GridLength(result);
}
}
return visible ? visibleLength : notVisibleLength;
}
return notVisibleLength;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
#endregion
}
}

View File

@@ -0,0 +1,33 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VDownload.GUI.Converters
{
public class BooleanToGridLengthFillConverter : IValueConverter
{
#region METHODS
public object Convert(object value, Type targetType, object parameter, string language)
{
GridLength falseLength = GridLength.Auto;
if (value is bool boolean)
{
GridLength trueLength = new GridLength(1, GridUnitType.Star);
return boolean ? trueLength : falseLength;
}
return falseLength;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
#endregion
}
}

View File

@@ -0,0 +1,33 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VDownload.GUI.Converters
{
public class BooleanToGridLengthFillReversedConverter : IValueConverter
{
#region METHODS
public object Convert(object value, Type targetType, object parameter, string language)
{
GridLength falseLength = GridLength.Auto;
if (value is bool boolean)
{
GridLength trueLength = new GridLength(1, GridUnitType.Star);
return boolean ? falseLength : trueLength;
}
return falseLength;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
#endregion
}
}

View File

@@ -0,0 +1,44 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VDownload.GUI.Converters
{
public class BooleanToGridLengthReversedConverter : IValueConverter
{
#region METHODS
public object Convert(object value, Type targetType, object parameter, string language)
{
GridLength visibleLength = new GridLength(1, GridUnitType.Star);
if (value is bool visible)
{
GridLength notVisibleLength = new GridLength(0);
if (parameter is string width)
{
if (width.ToLower() == "auto")
{
visibleLength = GridLength.Auto;
}
else if (int.TryParse(width, out int result))
{
visibleLength = new GridLength(result);
}
}
return visible ? notVisibleLength : visibleLength;
}
return visibleLength;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
#endregion
}
}

View File

@@ -0,0 +1,30 @@
using Microsoft.UI.Xaml.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VDownload.GUI.Converters
{
public class BooleanToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value is bool boolean)
{
return boolean.ToString();
}
return bool.FalseString;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
if (value is string str)
{
return str == bool.TrueString;
}
return false;
}
}
}

View File

@@ -0,0 +1,35 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VDownload.GUI.Converters
{
public class BooleanToVisibilityConverter : IValueConverter
{
#region METHODS
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value is bool isVisible)
{
return isVisible ? Visibility.Visible : Visibility.Collapsed;
}
return Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
if (value is Visibility visibility)
{
return visibility == Visibility.Visible;
}
return false;
}
#endregion
}
}

View File

@@ -0,0 +1,29 @@
using Microsoft.UI.Xaml.Data;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace VDownload.GUI.Converters
{
public class EnumToDescriptionConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value is Enum enumValue)
{
return enumValue.GetType().GetMember(enumValue.ToString()).FirstOrDefault()?.GetCustomAttribute<DescriptionAttribute>()?.Description;
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,22 @@
using Microsoft.UI.Xaml.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VDownload.GUI.Converters
{
public class EnumToIntConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
return (int)value;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,26 @@
using Microsoft.UI.Xaml.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VDownload.GUI.Converters
{
public class EnumToStringConverter : IValueConverter
{
#region METHODS
public object Convert(object value, Type targetType, object parameter, string language)
{
return value.ToString();
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
#endregion
}
}

View File

@@ -0,0 +1,27 @@
using Microsoft.UI.Xaml.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VDownload.GUI.Converters
{
public class ReverseBooleanConverter : IValueConverter
{
#region METHODS
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value is bool boolean)
{
return !boolean;
}
return true;
}
public object ConvertBack(object value, Type targetType, object parameter, string language) => Convert(value, targetType, parameter, language);
#endregion
}
}

View File

@@ -0,0 +1,22 @@
using Microsoft.UI.Xaml.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VDownload.GUI.Converters
{
public class StringToLowerConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
return value.ToString().ToLower();
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,30 @@
using Microsoft.UI.Xaml.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VDownload.GUI.Converters
{
public class StringToUriConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value is string str)
{
return new Uri(str, UriKind.RelativeOrAbsolute);
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
if (value is Uri uri)
{
return uri.OriginalString;
}
return null;
}
}
}

View File

@@ -0,0 +1,30 @@
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VDownload.GUI.Converters
{
public class StringToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value is not string str || string.IsNullOrWhiteSpace(str))
{
return Visibility.Collapsed;
}
else
{
return Visibility.Visible;
}
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RootNamespace>VDownload.GUI.Converters</RootNamespace>
<RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
<UseWinUI>true</UseWinUI>
<UseRidGraph>true</UseRidGraph>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.4.231219000" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.2428" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\VDownload.Services\VDownload.Services\VDownload.Services.csproj" />
<ProjectReference Include="..\VDownload.GUI.ViewModels\VDownload.GUI.ViewModels.csproj" />
<ProjectReference Include="..\VDownload.GUI.Views\VDownload.GUI.Views.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,65 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VDownload.GUI.ViewModels;
using VDownload.GUI.Views;
using VDownload.Services;
namespace VDownload.GUI.Converters
{
public class ViewModelToViewConverter : IValueConverter
{
#region FIELDS
private readonly Dictionary<Type, Type> _viewModelViewBinding = new Dictionary<Type, Type>
{
{ typeof(HomeViewModel), typeof(HomeView) },
{ typeof(SettingsViewModel), typeof(SettingsView) },
{ typeof(AuthenticationViewModel), typeof(AuthenticationView) }
};
private readonly Dictionary<Type, Type> _viewViewModelBinding = new Dictionary<Type, Type>
{
{ typeof(HomeView), typeof(HomeViewModel) },
{ typeof(SettingsView), typeof(SettingsViewModel) },
{ typeof(AuthenticationView), typeof(AuthenticationViewModel) }
};
#endregion
#region METHODS
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value is null)
{
return null;
}
if (value is Type type && _viewModelViewBinding.ContainsKey(type))
{
return ServiceProvider.Instance.GetService(_viewModelViewBinding[type]);
}
if (_viewModelViewBinding.ContainsKey(value.GetType()))
{
return ServiceProvider.Instance.GetService(_viewModelViewBinding[value.GetType()]);
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
if (_viewViewModelBinding.ContainsKey(value.GetType()))
{
return _viewViewModelBinding[value.GetType()];
}
return null;
}
#endregion
}
}