From bef1d59cffaae749661d0a5d90914839a54cc8e7 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Mon, 9 Oct 2023 00:26:46 +0200 Subject: Initial commit --- BatchBeatmapDownloader/App.axaml | 15 ++++ BatchBeatmapDownloader/App.axaml.cs | 23 +++++ BatchBeatmapDownloader/Assets/avalonia-logo.ico | Bin 0 -> 176111 bytes .../BatchBeatmapDownloader.csproj | 32 +++++++ BatchBeatmapDownloader/ObjectCollectionWrapper.cs | 7 ++ BatchBeatmapDownloader/Program.cs | 22 +++++ BatchBeatmapDownloader/ViewLocator.cs | 23 +++++ .../ViewModels/MainWindowViewModel.cs | 31 +++++++ BatchBeatmapDownloader/ViewModels/ViewModelBase.cs | 5 ++ BatchBeatmapDownloader/Views/MainWindow.axaml | 93 +++++++++++++++++++++ BatchBeatmapDownloader/Views/MainWindow.axaml.cs | 34 ++++++++ BatchBeatmapDownloader/app.manifest | 18 ++++ 12 files changed, 303 insertions(+) create mode 100644 BatchBeatmapDownloader/App.axaml create mode 100644 BatchBeatmapDownloader/App.axaml.cs create mode 100644 BatchBeatmapDownloader/Assets/avalonia-logo.ico create mode 100644 BatchBeatmapDownloader/BatchBeatmapDownloader.csproj create mode 100644 BatchBeatmapDownloader/ObjectCollectionWrapper.cs create mode 100644 BatchBeatmapDownloader/Program.cs create mode 100644 BatchBeatmapDownloader/ViewLocator.cs create mode 100644 BatchBeatmapDownloader/ViewModels/MainWindowViewModel.cs create mode 100644 BatchBeatmapDownloader/ViewModels/ViewModelBase.cs create mode 100644 BatchBeatmapDownloader/Views/MainWindow.axaml create mode 100644 BatchBeatmapDownloader/Views/MainWindow.axaml.cs create mode 100644 BatchBeatmapDownloader/app.manifest (limited to 'BatchBeatmapDownloader') diff --git a/BatchBeatmapDownloader/App.axaml b/BatchBeatmapDownloader/App.axaml new file mode 100644 index 0000000..0f4f164 --- /dev/null +++ b/BatchBeatmapDownloader/App.axaml @@ -0,0 +1,15 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/BatchBeatmapDownloader/App.axaml.cs b/BatchBeatmapDownloader/App.axaml.cs new file mode 100644 index 0000000..0a1b270 --- /dev/null +++ b/BatchBeatmapDownloader/App.axaml.cs @@ -0,0 +1,23 @@ +using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Markup.Xaml; +using BatchBeatmapDownloader.ViewModels; +using BatchBeatmapDownloader.Views; + +namespace BatchBeatmapDownloader; + +public partial class App : Application { + public override void Initialize() { + AvaloniaXamlLoader.Load(this); + } + + public override void OnFrameworkInitializationCompleted() { + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { + desktop.MainWindow = new MainWindow { + DataContext = new MainWindowViewModel(), + }; + } + + base.OnFrameworkInitializationCompleted(); + } +} diff --git a/BatchBeatmapDownloader/Assets/avalonia-logo.ico b/BatchBeatmapDownloader/Assets/avalonia-logo.ico new file mode 100644 index 0000000..da8d49f Binary files /dev/null and b/BatchBeatmapDownloader/Assets/avalonia-logo.ico differ diff --git a/BatchBeatmapDownloader/BatchBeatmapDownloader.csproj b/BatchBeatmapDownloader/BatchBeatmapDownloader.csproj new file mode 100644 index 0000000..0e104cf --- /dev/null +++ b/BatchBeatmapDownloader/BatchBeatmapDownloader.csproj @@ -0,0 +1,32 @@ + + + WinExe + net7.0 + enable + true + app.manifest + true + preview + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BatchBeatmapDownloader/ObjectCollectionWrapper.cs b/BatchBeatmapDownloader/ObjectCollectionWrapper.cs new file mode 100644 index 0000000..2171969 --- /dev/null +++ b/BatchBeatmapDownloader/ObjectCollectionWrapper.cs @@ -0,0 +1,7 @@ +using System.Collections.Generic; + +namespace BatchBeatmapDownloader; + +public class ObjectCollectionWrapper(IEnumerable items) { + public List Items { get; set; } = new(items); +} diff --git a/BatchBeatmapDownloader/Program.cs b/BatchBeatmapDownloader/Program.cs new file mode 100644 index 0000000..87236fd --- /dev/null +++ b/BatchBeatmapDownloader/Program.cs @@ -0,0 +1,22 @@ +using System; +using Avalonia; +using Avalonia.ReactiveUI; + +namespace BatchBeatmapDownloader; + +internal class Program { + // Initialization code. Don't use any Avalonia, third-party APIs or any + // SynchronizationContext-reliant code before AppMain is called: things aren't initialized + // yet and stuff might break. + [STAThread] + public static void Main(string[] args) => BuildAvaloniaApp() + .StartWithClassicDesktopLifetime(args); + + // Avalonia configuration, don't remove; also used by visual designer. + public static AppBuilder BuildAvaloniaApp() + => AppBuilder.Configure() + .UsePlatformDetect() + .WithInterFont() + .LogToTrace() + .UseReactiveUI(); +} diff --git a/BatchBeatmapDownloader/ViewLocator.cs b/BatchBeatmapDownloader/ViewLocator.cs new file mode 100644 index 0000000..e22d652 --- /dev/null +++ b/BatchBeatmapDownloader/ViewLocator.cs @@ -0,0 +1,23 @@ +using System; +using Avalonia.Controls; +using Avalonia.Controls.Templates; +using BatchBeatmapDownloader.ViewModels; + +namespace BatchBeatmapDownloader; + +public class ViewLocator : IDataTemplate { + public Control Build(object data) { + var name = data.GetType().FullName!.Replace("ViewModel", "View"); + var type = Type.GetType(name); + + if (type != null) { + return (Control)Activator.CreateInstance(type)!; + } + + return new TextBlock { Text = "Not Found: " + name }; + } + + public bool Match(object data) { + return data is ViewModelBase; + } +} diff --git a/BatchBeatmapDownloader/ViewModels/MainWindowViewModel.cs b/BatchBeatmapDownloader/ViewModels/MainWindowViewModel.cs new file mode 100644 index 0000000..1e5d23a --- /dev/null +++ b/BatchBeatmapDownloader/ViewModels/MainWindowViewModel.cs @@ -0,0 +1,31 @@ +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using LibBeatmapDownload; +using ReactiveUI; + +namespace BatchBeatmapDownloader.ViewModels; + +public class MainWindowViewModel : ViewModelBase { + // public List DownloadTasks { get; set; } = new(); + public DownloadTaskList DownloadTasks { get; set; } = new(); + + private int _windowWidth = 800; + + public int WindowWidth { + set { + _windowWidth = value; + Debug.WriteLine($"Window width: {_windowWidth}"); + DomainStatsChunked = DownloadTask.MirrorStats.Select(x => x.Value).ToList().Chunk(value/300) + .Select(x => new ObjectCollectionWrapper(x)).ToList(); + this.RaisePropertyChanged(nameof(DomainStatsChunked)); + } + } + + public List> DomainStatsChunked { get; set; } = DownloadTask.MirrorStats.Select(x => x.Value).ToList().Chunk(2) + .Select(x => new ObjectCollectionWrapper(x)).ToList(); + + public void RaiseDownloadListChanged() { + this.RaisePropertyChanged(nameof(DownloadTasks)); + } +} diff --git a/BatchBeatmapDownloader/ViewModels/ViewModelBase.cs b/BatchBeatmapDownloader/ViewModels/ViewModelBase.cs new file mode 100644 index 0000000..e0f04e3 --- /dev/null +++ b/BatchBeatmapDownloader/ViewModels/ViewModelBase.cs @@ -0,0 +1,5 @@ +using ReactiveUI; + +namespace BatchBeatmapDownloader.ViewModels; + +public class ViewModelBase : ReactiveObject { } diff --git a/BatchBeatmapDownloader/Views/MainWindow.axaml b/BatchBeatmapDownloader/Views/MainWindow.axaml new file mode 100644 index 0000000..d6ed94f --- /dev/null +++ b/BatchBeatmapDownloader/Views/MainWindow.axaml @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BatchBeatmapDownloader/Views/MainWindow.axaml.cs b/BatchBeatmapDownloader/Views/MainWindow.axaml.cs new file mode 100644 index 0000000..d062f92 --- /dev/null +++ b/BatchBeatmapDownloader/Views/MainWindow.axaml.cs @@ -0,0 +1,34 @@ +using System.Diagnostics; +using System.IO; +using System.Linq; +using ArcaneLibs.Extensions; +using Avalonia.Controls; +using Avalonia.Interactivity; +using BatchBeatmapDownloader.ViewModels; +using LibBeatmapDownload; + +namespace BatchBeatmapDownloader.Views; + +public partial class MainWindow : Window { + public MainWindow() { + InitializeComponent(); + } + + protected override async void OnLoaded(RoutedEventArgs e) { + base.OnLoaded(e); + var ctx = DataContext as MainWindowViewModel; + Resized += (_, args) => ctx.WindowWidth = (int)args.ClientSize.Width; + var lines = File.ReadLinesAsync("/home/root@Rory/Downloads/maps.tsv"); + await foreach (var line in lines) { + var parts = line.Split('\t'); + var downloadTask = new DownloadTask(int.Parse(parts[0]), parts.Length > 1 ? parts[1] : null); + ctx?.DownloadTasks.Tasks.Add(downloadTask); + if (ctx!.DownloadTasks.Tasks.Count > 100) break; + } + + var tasks = ctx.DownloadTasks.Tasks.Select(x => x.Download()).ToAsyncEnumerable(); + await foreach (var result in tasks) { + Debug.WriteLine($"Downloaded {result}"); + } + } +} diff --git a/BatchBeatmapDownloader/app.manifest b/BatchBeatmapDownloader/app.manifest new file mode 100644 index 0000000..265e183 --- /dev/null +++ b/BatchBeatmapDownloader/app.manifest @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + -- cgit 1.5.1