diff --git a/App.xaml b/App.xaml index 09770ed..cb0a67e 100644 --- a/App.xaml +++ b/App.xaml @@ -1,8 +1,7 @@  + xmlns:local="clr-namespace:MossyUpdater"> diff --git a/App.xaml.cs b/App.xaml.cs index bdaab89..b9bd877 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -1,14 +1,52 @@ -using System.Configuration; -using System.Data; -using System.Windows; +using System.Windows; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Http; +using MossyUpdater.Services; +using MossyUpdater.ViewModels; namespace MossyUpdater { - /// - /// Interaction logic for App.xaml - /// public partial class App : Application { + private ServiceProvider? _serviceProvider; + + protected override void OnStartup(StartupEventArgs e) + { + base.OnStartup(e); + + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + + var mainWindow = new MainWindow + { + DataContext = _serviceProvider.GetRequiredService() + }; + mainWindow.Show(); + } + + protected override void OnExit(ExitEventArgs e) + { + var mainViewModel = _serviceProvider?.GetService(); + mainViewModel?.Dispose(); + _serviceProvider?.Dispose(); + base.OnExit(e); + } + + private static void ConfigureServices(IServiceCollection services) + { + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + + services.AddHttpClient(client => + { + client.Timeout = TimeSpan.FromMinutes(10); + client.DefaultRequestHeaders.Add("User-Agent", "MossyUpdater/1.0"); + }); + + services.AddSingleton(); + } } } diff --git a/Converters.cs b/Converters.cs new file mode 100644 index 0000000..73f454e --- /dev/null +++ b/Converters.cs @@ -0,0 +1,47 @@ +using System; +using System.Globalization; +using System.Windows; +using System.Windows.Data; +using System.Windows.Media; + +namespace MossyUpdater +{ + public class StringToVisibilityConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + return string.IsNullOrEmpty(value as string) ? Visibility.Collapsed : Visibility.Visible; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } + + public class BoolToFontWeightConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + return value is true ? FontWeights.Bold : FontWeights.Normal; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } + + public class BoolToUpdateColorConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + return value is true ? Brushes.Orange : Brushes.Green; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/MainWindow.xaml b/MainWindow.xaml index 3d84671..3929feb 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -1,7 +1,9 @@  + xmlns:local="clr-namespace:MossyUpdater" + Title="MossyUpdater" Height="450" Width="550" MinHeight="400" MinWidth="500" ResizeMode="CanResize" + Icon="pack://application:,,,/MossyUpdater;component/favicon.ico"> @@ -13,32 +15,38 @@ - + - + + + + + - + - + Text="{Binding Url, UpdateSourceTrigger=PropertyChanged}" + IsEnabled="{Binding CanInteract}"/> - + Margin="0,0,5,0" + Text="{Binding Folder, UpdateSourceTrigger=PropertyChanged}" + IsEnabled="{Binding CanInteract}"/>