summary refs log tree commit diff
path: root/BatchBeatmapDownloader/Views/MainWindow.axaml.cs
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2023-10-09 00:26:46 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2023-10-09 00:26:46 +0200
commitbef1d59cffaae749661d0a5d90914839a54cc8e7 (patch)
treea05a726d27567bed093e77c194b1e0f9d2ac700f /BatchBeatmapDownloader/Views/MainWindow.axaml.cs
downloadBatchBeatmapDownloader-master.tar.xz
Initial commit HEAD master
Diffstat (limited to 'BatchBeatmapDownloader/Views/MainWindow.axaml.cs')
-rw-r--r--BatchBeatmapDownloader/Views/MainWindow.axaml.cs34
1 files changed, 34 insertions, 0 deletions
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}");
+		}
+	}
+}