summary refs log tree commit diff
path: root/BatchBeatmapDownloader
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
downloadBatchBeatmapDownloader-master.tar.xz
Initial commit HEAD master
Diffstat (limited to '')
-rw-r--r--BatchBeatmapDownloader.sln22
-rw-r--r--BatchBeatmapDownloader/App.axaml15
-rw-r--r--BatchBeatmapDownloader/App.axaml.cs23
-rw-r--r--BatchBeatmapDownloader/Assets/avalonia-logo.icobin0 -> 176111 bytes
-rw-r--r--BatchBeatmapDownloader/BatchBeatmapDownloader.csproj32
-rw-r--r--BatchBeatmapDownloader/ObjectCollectionWrapper.cs7
-rw-r--r--BatchBeatmapDownloader/Program.cs22
-rw-r--r--BatchBeatmapDownloader/ViewLocator.cs23
-rw-r--r--BatchBeatmapDownloader/ViewModels/MainWindowViewModel.cs31
-rw-r--r--BatchBeatmapDownloader/ViewModels/ViewModelBase.cs5
-rw-r--r--BatchBeatmapDownloader/Views/MainWindow.axaml93
-rw-r--r--BatchBeatmapDownloader/Views/MainWindow.axaml.cs34
-rw-r--r--BatchBeatmapDownloader/app.manifest18
13 files changed, 325 insertions, 0 deletions
diff --git a/BatchBeatmapDownloader.sln b/BatchBeatmapDownloader.sln
new file mode 100644
index 0000000..82783c5
--- /dev/null
+++ b/BatchBeatmapDownloader.sln
@@ -0,0 +1,22 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BatchBeatmapDownloader", "BatchBeatmapDownloader\BatchBeatmapDownloader.csproj", "{71940BDB-FA45-4F13-BAF0-285079C103D0}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibBeatmapDownload", "LibBeatmapDownload\LibBeatmapDownload.csproj", "{2E2E3BBD-8D47-4554-A8CD-1A51428383BD}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{71940BDB-FA45-4F13-BAF0-285079C103D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{71940BDB-FA45-4F13-BAF0-285079C103D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{71940BDB-FA45-4F13-BAF0-285079C103D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{71940BDB-FA45-4F13-BAF0-285079C103D0}.Release|Any CPU.Build.0 = Release|Any CPU
+		{2E2E3BBD-8D47-4554-A8CD-1A51428383BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{2E2E3BBD-8D47-4554-A8CD-1A51428383BD}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{2E2E3BBD-8D47-4554-A8CD-1A51428383BD}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{2E2E3BBD-8D47-4554-A8CD-1A51428383BD}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+EndGlobal
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 @@
+<Application xmlns="https://github.com/avaloniaui"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             x:Class="BatchBeatmapDownloader.App"
+             xmlns:local="using:BatchBeatmapDownloader"
+             RequestedThemeVariant="Default">
+             <!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
+
+    <Application.DataTemplates>
+        <local:ViewLocator/>
+    </Application.DataTemplates>
+  
+    <Application.Styles>
+        <FluentTheme />
+    </Application.Styles>
+</Application>
\ 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
--- /dev/null
+++ b/BatchBeatmapDownloader/Assets/avalonia-logo.ico
Binary files differdiff --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 @@
+<Project Sdk="Microsoft.NET.Sdk">
+    <PropertyGroup>
+        <OutputType>WinExe</OutputType>
+        <TargetFramework>net7.0</TargetFramework>
+        <Nullable>enable</Nullable>
+        <BuiltInComInteropSupport>true</BuiltInComInteropSupport>
+        <ApplicationManifest>app.manifest</ApplicationManifest>
+        <AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
+        <LangVersion>preview</LangVersion>
+    </PropertyGroup>
+
+    <ItemGroup>
+        <Folder Include="Models\"/>
+        <AvaloniaResource Include="Assets\**"/>
+    </ItemGroup>
+
+
+    <ItemGroup>
+        <PackageReference Include="Avalonia" Version="11.0.0"/>
+        <PackageReference Include="Avalonia.Desktop" Version="11.0.0"/>
+        <PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.0"/>
+        <PackageReference Include="Avalonia.Fonts.Inter" Version="11.0.0"/>
+        <!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
+        <PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.0"/>
+        <PackageReference Include="Avalonia.ReactiveUI" Version="11.0.0"/>
+    </ItemGroup>
+
+
+    <ItemGroup>
+      <ProjectReference Include="..\LibBeatmapDownload\LibBeatmapDownload.csproj" />
+    </ItemGroup>
+</Project>
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<T>(IEnumerable<T> items) {
+	public List<T> 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<App>()
+			.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<DownloadTask> 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<DomainStats>(x)).ToList();
+			this.RaisePropertyChanged(nameof(DomainStatsChunked));
+		}
+	}
+
+	public List<ObjectCollectionWrapper<DomainStats>> DomainStatsChunked { get; set; } = DownloadTask.MirrorStats.Select(x => x.Value).ToList().Chunk(2)
+		.Select(x => new ObjectCollectionWrapper<DomainStats>(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 @@
+<Window xmlns="https://github.com/avaloniaui"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        xmlns:vm="using:BatchBeatmapDownloader.ViewModels"
+        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+        xmlns:batchBeatmapDownloader="clr-namespace:BatchBeatmapDownloader"
+        xmlns:generic="clr-namespace:System.Collections.Generic;assembly=System.Collections"
+        xmlns:libBeatmapDownload="clr-namespace:LibBeatmapDownload;assembly=LibBeatmapDownload"
+        mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
+        x:Class="BatchBeatmapDownloader.Views.MainWindow"
+        x:DataType="vm:MainWindowViewModel"
+        Icon="/Assets/avalonia-logo.ico"
+        Title="BatchBeatmapDownloader">
+
+    <Design.DataContext>
+        <!-- This only sets the DataContext for the previewer in an IDE,
+             to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
+        <vm:MainWindowViewModel/>
+    </Design.DataContext>
+    <StackPanel Orientation="Vertical">
+        <!-- horizontal listbox with progress bars -->
+        <ListBox ItemsSource="{Binding DomainStatsChunked}">
+            <ListBox.ItemsPanel>
+                <ItemsPanelTemplate>
+                    <UniformGrid Rows="{Binding DomainStatsChunked.Count}"/>
+                </ItemsPanelTemplate>
+            </ListBox.ItemsPanel>
+            <ListBox.ItemTemplate>
+                <DataTemplate>
+                    <ListBox ItemsSource="{Binding Items}">
+                        <ListBox.ItemsPanel>
+                            <ItemsPanelTemplate>
+                                <UniformGrid Columns="{Binding Items.Count}"/>
+                            </ItemsPanelTemplate>
+                        </ListBox.ItemsPanel>
+                        <ListBox.ItemTemplate>
+                            <DataTemplate DataType="libBeatmapDownload:DomainStats">
+                                <Grid>
+                                    <Grid.RowDefinitions>
+                                        <RowDefinition Height="Auto"/>
+                                        <RowDefinition Height="Auto"/>
+                                    </Grid.RowDefinitions>
+                                    <ProgressBar Value="{Binding Progress, Mode=OneWay}" />
+                                    <TextBlock Grid.Row="1" Text="{Binding ProgressString, Mode=OneWay}" HorizontalAlignment="Center" VerticalAlignment="Center" />
+                                </Grid>
+                            </DataTemplate>
+                        </ListBox.ItemTemplate>
+                    </ListBox>
+                </DataTemplate>
+            </ListBox.ItemTemplate>
+        </ListBox>
+        <!--
+        <ListBox ItemsSource="{Binding DomainStats}">
+            <ListBox.ItemsPanel>
+                <ItemsPanelTemplate>
+                    <UniformGrid Columns="{Binding DomainStats.Count}"/>
+                </ItemsPanelTemplate>
+            </ListBox.ItemsPanel>
+            <ListBox.ItemTemplate>
+                <DataTemplate DataType="batchBeatmapDownloader:DomainStats">
+                    <Grid>
+                        <Grid.RowDefinitions>
+                            <RowDefinition Height="Auto"/>
+                            <RowDefinition Height="Auto"/>
+                        </Grid.RowDefinitions>
+                        <ProgressBar Value="{Binding Progress, Mode=OneWay}" />
+                        <TextBlock Grid.Row="1" Text="{Binding ProgressString, Mode=OneWay}" HorizontalAlignment="Center" VerticalAlignment="Center" />
+                    </Grid>
+                </DataTemplate>
+            </ListBox.ItemTemplate>
+        </ListBox>
+        -->
+
+        <ListBox ItemsSource="{Binding DownloadTasks.Tasks}">
+            <ListBox.ItemsPanel>
+                <ItemsPanelTemplate>
+                    <VirtualizingStackPanel></VirtualizingStackPanel>
+                </ItemsPanelTemplate>
+            </ListBox.ItemsPanel>
+            <ListBox.ItemTemplate>
+                <DataTemplate DataType="libBeatmapDownload:DownloadTask">
+                    <!-- Progress bar with text overlayed -->
+                    <Grid>
+                        <ProgressBar Value="{Binding Progress, Mode=OneWay}" />
+                        <TextBlock Text="{Binding ProgressString, Mode=OneWay}" HorizontalAlignment="Center" VerticalAlignment="Center" />
+                    </Grid>
+
+                </DataTemplate>
+            </ListBox.ItemTemplate>
+        </ListBox>
+    </StackPanel>
+
+</Window>
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 @@
+<?xml version="1.0" encoding="utf-8"?>
+<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
+  <!-- This manifest is used on Windows only.
+       Don't remove it as it might cause problems with window transparency and embeded controls.
+       For more details visit https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests -->
+  <assemblyIdentity version="1.0.0.0" name="BatchBeatmapDownloader.Desktop"/>
+
+  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
+    <application>
+      <!-- A list of the Windows versions that this application has been tested on
+           and is designed to work with. Uncomment the appropriate elements
+           and Windows will automatically select the most compatible environment. -->
+
+      <!-- Windows 10 -->
+      <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
+    </application>
+  </compatibility>
+</assembly>