diff --git a/src/ModSink.CLI/Program.cs b/src/ModSink.CLI/Program.cs index 5a337f93..39563a5c 100644 --- a/src/ModSink.CLI/Program.cs +++ b/src/ModSink.CLI/Program.cs @@ -58,43 +58,6 @@ private static void AddColCheck(this CommandLineApplication app) }); } - private static void AddDownload(this CommandLineApplication app) - { - app.Command("download", command => - { - command.Description = "Downloads a missing files from a repo"; - command.HelpOption("-?|-h|--help"); - var uriArg = command.Argument("[uri]", "Uri to repo to download"); - var pathArg = command.Argument("[path]", "Path to local repo"); - - command.OnExecute(async () => - { - var uriStr = uriArg.Value; - var uri = new Uri(uriStr); - var localStr = pathArg.Value; - var localUri = new Uri(localStr); - var downloader = new HttpClientDownloader(); - var client = new ClientService(new DownloadService(downloader), new LocalStorageService(localUri), - downloader, new BinaryFormatter()); - - Console.WriteLine("Downloading repo"); - client.GroupUrls.Add(uriStr); - client.Modpacks.Connect().Subscribe(cs => - { - foreach (var modpack in client.Modpacks.Items) - { - Console.WriteLine($"Scheduling {modpack.Name} [{modpack.Mods.Count} mods]"); - client.DownloadMissingFiles(modpack).GetAwaiter().GetResult(); - } - }); - - - Console.ReadKey(); - return 0; - }); - }); - } - private static void AddDump(this CommandLineApplication app) { app.Command("dump", command => @@ -393,7 +356,6 @@ public static void Main(string[] args) app.AddColCheck(); app.AddSampleRepo(); - app.AddDownload(); app.AddImport(); app.AddDump(); app.AddCheck(); diff --git a/src/ModSink.Common/Client/ClientService.cs b/src/ModSink.Common/Client/ClientService.cs index 11e58501..2398a757 100644 --- a/src/ModSink.Common/Client/ClientService.cs +++ b/src/ModSink.Common/Client/ClientService.cs @@ -35,10 +35,6 @@ public ClientService(IDownloadService downloadService, ILocalStorageService loca .TransformMany(g => g.RepoInfos.Select(r => new Uri(g.BaseUri, r.Uri))) .TransformAsync(Load) .AsObservableList(); - Modpacks = Repos - .Connect() - .TransformMany(r => r.Modpacks) - .AsObservableList(); } public IDownloader Downloader { get; } @@ -48,7 +44,6 @@ public ClientService(IDownloadService downloadService, ILocalStorageService loca public ISourceList GroupUrls { get; } = new SourceList(); public IDownloadService DownloadService { get; } public ILocalStorageService LocalStorageService { get; } - public IObservableList Modpacks { get; } public IObservableList Repos { get; } diff --git a/src/ModSink.Core/Client/IClientService.cs b/src/ModSink.Core/Client/IClientService.cs index 308e13a6..919ac3b5 100644 --- a/src/ModSink.Core/Client/IClientService.cs +++ b/src/ModSink.Core/Client/IClientService.cs @@ -10,7 +10,6 @@ public interface IClientService : IReactiveObject { IDownloadService DownloadService { get; } ILocalStorageService LocalStorageService { get; } - IObservableList Modpacks { get; } IObservableList Repos { get; } ISourceList GroupUrls { get; } Task DownloadMissingFiles(Modpack modpack); diff --git a/src/ModSink.WPF/App.xaml.cs b/src/ModSink.WPF/App.xaml.cs index 09e8bfc6..0ac85ee4 100644 --- a/src/ModSink.WPF/App.xaml.cs +++ b/src/ModSink.WPF/App.xaml.cs @@ -3,18 +3,20 @@ using System.IO; using System.Net; using System.Reflection; -using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; -using System.Threading.Tasks; using System.Windows; -using System.Windows.Controls; -using Autofac; using CountlySDK; +using ModSink.Common; using ModSink.Common.Client; -using ModSink.Core; using ModSink.WPF.Helpers; +using ModSink.WPF.Model; +using ModSink.WPF.ViewModel; +using ReactiveUI; using Serilog; using Serilog.Debugging; +using Splat; +using Splat.Serilog; +using ILogger = Serilog.ILogger; namespace ModSink.WPF { @@ -25,33 +27,21 @@ public partial class App : Application private static string FullVersion => typeof(App).GetTypeInfo().Assembly .GetCustomAttribute()?.InformationalVersion; - private IContainer BuildContainer() + private void InitializeDependencyInjection() { //TODO: FIX: ServicePointManager.DefaultConnectionLimit = 10; - var builder = new ContainerBuilder(); - - builder.RegisterType().As().SingleInstance(); - builder.Register(_ => - new LocalStorageService(new Uri( - Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "ModSink_Data")))) - .AsImplementedInterfaces() - .SingleInstance(); - builder.RegisterAssemblyTypes(typeof(IModSink).Assembly, typeof(Common.ModSink).Assembly) - .Where(t => t.Name != "LocalStorageService").AsImplementedInterfaces().SingleInstance(); - - builder.RegisterAssemblyTypes(typeof(App).Assembly).Where(t => t.Name.EndsWith("Model")) - .AsImplementedInterfaces().AsSelf().SingleInstance(); - builder.RegisterAssemblyTypes(typeof(App).Assembly).Where(t => t.Name.EndsWith("ViewModel")) - .AsImplementedInterfaces().AsSelf().SingleInstance(); - builder.RegisterAssemblyTypes(typeof(App).Assembly).Where(t => t.IsAssignableTo()).AsSelf() - .As().SingleInstance(); - builder.RegisterType().AsSelf().SingleInstance(); + Locator.CurrentMutable.InitializeSplat(); + Registration.Register(log.ForContext()); + Locator.CurrentMutable.InitializeReactiveUI(); + Locator.CurrentMutable.RegisterViewsForViewModels(typeof(App).Assembly); + Locator.CurrentMutable.RegisterLazySingleton(() => new BinaryFormatter()); + Locator.CurrentMutable.RegisterLazySingleton(() => + new LocalStorageService(new Uri( + Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "ModSink_Data")))); //TODO: Load plugins, waiting on https://stackoverflow.com/questions/46351411 - - return builder.Build(); } private void FatalException(Exception e, Type source) @@ -82,10 +72,14 @@ protected override void OnStartup(StartupEventArgs e) base.OnStartup(e); - var container = BuildContainer(); + InitializeDependencyInjection(); log.Information("Starting UI"); - MainWindow = container.Resolve(); + var cs = new ClientService(new DownloadService(new HttpClientDownloader()), new LocalStorageService(new Uri( + Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "ModSink_Data"))), + new HttpClientDownloader(), new BinaryFormatter()); + MainWindow = new MainWindow(new MainWindowViewModel(new DownloadsViewModel(cs), new LibraryViewModel(cs), + new SettingsViewModel(new SettingsModel(cs)))); ShutdownMode = ShutdownMode.OnMainWindowClose; MainWindow.Show(); } diff --git a/src/ModSink.WPF/MainWindow.xaml b/src/ModSink.WPF/MainWindow.xaml index f6726d80..442a733f 100644 --- a/src/ModSink.WPF/MainWindow.xaml +++ b/src/ModSink.WPF/MainWindow.xaml @@ -14,7 +14,7 @@ d:DataContext="{d:DesignInstance vm:MainWindowViewModel}"> - + diff --git a/src/ModSink.WPF/MainWindow.xaml.cs b/src/ModSink.WPF/MainWindow.xaml.cs index 0ff01881..0ac4e9be 100644 --- a/src/ModSink.WPF/MainWindow.xaml.cs +++ b/src/ModSink.WPF/MainWindow.xaml.cs @@ -1,5 +1,4 @@ -using Autofac; -using ModSink.Common.Client; +using ModSink.Common.Client; using ModSink.Core; using ModSink.WPF.Helpers; using ModSink.WPF.View; diff --git a/src/ModSink.WPF/ModSink.WPF.csproj b/src/ModSink.WPF/ModSink.WPF.csproj index af310b98..c48e07a5 100644 --- a/src/ModSink.WPF/ModSink.WPF.csproj +++ b/src/ModSink.WPF/ModSink.WPF.csproj @@ -31,7 +31,6 @@ - @@ -43,7 +42,7 @@ - + All diff --git a/src/ModSink.WPF/View/LibraryView.xaml b/src/ModSink.WPF/View/LibraryView.xaml index 3b358afe..68748050 100644 --- a/src/ModSink.WPF/View/LibraryView.xaml +++ b/src/ModSink.WPF/View/LibraryView.xaml @@ -1,4 +1,4 @@ - - - + + - - + + + + + + + + + + + @@ -44,4 +54,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/ModSink.WPF/View/LibraryView.xaml.cs b/src/ModSink.WPF/View/LibraryView.xaml.cs index 158f76c4..34c8e6c9 100644 --- a/src/ModSink.WPF/View/LibraryView.xaml.cs +++ b/src/ModSink.WPF/View/LibraryView.xaml.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; +using System.Reactive.Disposables; using System.Text; using System.Threading.Tasks; using System.Windows; @@ -12,17 +14,24 @@ using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +using ModSink.Core.Models.Repo; +using ModSink.WPF.ViewModel; +using ReactiveUI; namespace ModSink.WPF.View { - /// - /// Interaction logic for LibraryView.xaml - /// - public partial class LibraryView : UserControl + public partial class LibraryView : ReactiveUserControl { public LibraryView() { InitializeComponent(); + + this.WhenActivated(d => + { + this.OneWayBind(ViewModel, vm => vm.Modpacks, v => v.lvModpacks.ItemsSource).DisposeWith(d); + Disposable.Create(Debugger.Break).DisposeWith(d); + + }); } } } diff --git a/src/ModSink.WPF/ViewModel/LibraryViewModel.cs b/src/ModSink.WPF/ViewModel/LibraryViewModel.cs index fe40c100..9c94a3b9 100644 --- a/src/ModSink.WPF/ViewModel/LibraryViewModel.cs +++ b/src/ModSink.WPF/ViewModel/LibraryViewModel.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Reactive; using System.Reactive.Linq; using DynamicData; @@ -16,9 +17,9 @@ public class LibraryViewModel : ReactiveObject public LibraryViewModel(IClientService clientService) { ClientService = clientService; - ClientService.Modpacks + ClientService.Repos .Connect() - .Transform(m => new ModpackViewModel(m)) + .TransformMany(r => r.Modpacks.Select(m=>new ModpackViewModel(m,r))) .ObserveOnDispatcher() .Bind(Modpacks) .Subscribe(); diff --git a/src/ModSink.WPF/ViewModel/ModpackViewModel.cs b/src/ModSink.WPF/ViewModel/ModpackViewModel.cs index c46c840e..ae20d96f 100644 --- a/src/ModSink.WPF/ViewModel/ModpackViewModel.cs +++ b/src/ModSink.WPF/ViewModel/ModpackViewModel.cs @@ -7,7 +7,7 @@ namespace ModSink.WPF.ViewModel { public class ModpackViewModel { - public ModpackViewModel(Modpack modpack) + public ModpackViewModel(Modpack modpack, Repo repo) { Modpack = modpack; Size = ByteSize.FromBytes( @@ -15,8 +15,9 @@ public ModpackViewModel(Modpack modpack) .SelectMany(m => m.Mod.Files) .Select(f => f.Value.Length) .Aggregate((sum, a) => sum + a)).Humanize("G03"); + Repo = repo.BaseUri.ToString(); } - + public string Repo { get; } public Modpack Modpack { get; } public string Size { get; }