mirror of
				https://github.com/chylex/Discord-History-Tracker.git
				synced 2025-11-04 03:40:12 +01:00 
			
		
		
		
	Compare commits
	
		
			1 Commits
		
	
	
		
			8aeb590bb3
			...
			app-json-2
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						
						
							
						
						9448cd05b6
	
				 | 
					
					
						
							
								
								
									
										16
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								README.md
									
									
									
									
									
								
							@@ -16,6 +16,7 @@ Fork the repository and clone it to your computer (if you've never used git, you
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
Folder organization:
 | 
					Folder organization:
 | 
				
			||||||
* `app/` contains a Visual Studio solution for the desktop app
 | 
					* `app/` contains a Visual Studio solution for the desktop app
 | 
				
			||||||
 | 
					* `lib/` contains utilities required to build the project
 | 
				
			||||||
* `web/` contains source code of the [official website](https://dht.chylex.com), which can be used as a template when making your own website
 | 
					* `web/` contains source code of the [official website](https://dht.chylex.com), which can be used as a template when making your own website
 | 
				
			||||||
 | 
					
 | 
				
			||||||
To start editing source code for the desktop app, install the [.NET 8 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/8.0), and then open `app/DiscordHistoryTracker.sln` in [Visual Studio](https://visualstudio.microsoft.com/downloads/) or [Rider](https://www.jetbrains.com/rider/).
 | 
					To start editing source code for the desktop app, install the [.NET 8 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/8.0), and then open `app/DiscordHistoryTracker.sln` in [Visual Studio](https://visualstudio.microsoft.com/downloads/) or [Rider](https://www.jetbrains.com/rider/).
 | 
				
			||||||
@@ -28,13 +29,22 @@ To build a `Release` version of the desktop app, follow the instructions for you
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#### Release – Windows (64-bit)
 | 
					#### Release – Windows (64-bit)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
1. Install [Powershell 5](https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows) or newer (on Windows 10, the included version of Powershell should be enough)
 | 
					1. Install [Python 3](https://www.python.org/downloads), and ensure the `python` executable is in your `PATH`
 | 
				
			||||||
 | 
					2. Install [Powershell 5](https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows) or newer (on Windows 10, the included version of Powershell should be enough)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					The `lib/` folder contains an installation of [Node](https://nodejs.org/en) and [uglify-js](https://www.npmjs.com/package/uglify-js), which are used to minify the tracking script. This installation will only work on 64-bit Windows; building on 32-bit Windows is not supported, but you can try.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Run the `app/build.bat` script, and read the [Distribution](#distribution) section below.
 | 
					Run the `app/build.bat` script, and read the [Distribution](#distribution) section below.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#### Release – Other Operating Systems
 | 
					#### Release – Other Operating Systems
 | 
				
			||||||
 | 
					
 | 
				
			||||||
1. Install the `zip` package from your repository
 | 
					1. Install [Python 3](https://www.python.org/downloads), and ensure the `python` executable exists and launches Python 3
 | 
				
			||||||
 | 
					   - On Debian and derivatives, you can install `python-is-python3`
 | 
				
			||||||
 | 
					   - On other distributions, you can create a link manually, for ex. `ln -s /usr/bin/python3 /usr/bin/python`
 | 
				
			||||||
 | 
					   - If you don't want `python` to mean Python 3, then edit `Desktop.csproj` and change `python` to `python3`
 | 
				
			||||||
 | 
					2. Install [Node + npm](https://nodejs.org/en)
 | 
				
			||||||
 | 
					3. Install [uglify-js](https://www.npmjs.com/package/uglify-js) globally (`npm install -g uglify-js`)
 | 
				
			||||||
 | 
					4. Install the `zip` package from your repository
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Run the `app/build.sh` script, and read the [Distribution](#distribution) section below.
 | 
					Run the `app/build.sh` script, and read the [Distribution](#distribution) section below.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -42,4 +52,4 @@ Run the `app/build.sh` script, and read the [Distribution](#distribution) sectio
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
The mentioned build scripts will prepare `Release` builds ready for distribution. Once the script finishes, the `app/bin` folder will contain self-contained executables for each major operating system, and a portable version that works on all other systems but requires .NET 8 to be installed.
 | 
					The mentioned build scripts will prepare `Release` builds ready for distribution. Once the script finishes, the `app/bin` folder will contain self-contained executables for each major operating system, and a portable version that works on all other systems but requires .NET 8 to be installed.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Note that when building on Windows, the generated `.zip` files for Linux and Mac will not have correct file permissions, so it will not be possible to run them by double-clicking the executable. Since .NET 8 fixed several issues with publishing Windows executables on Linux, I recommend using Linux to build the app for all operating systems.
 | 
					Note that when building on Windows, the generated `.zip` files for Linux and Mac will not have correct file permissions, so it will not be possible to run them by double-clicking `DiscordHistoryTracker`. I tried using Python to re-create the archives with correct file permissions, but found that Linux `zip` tools could not see them. The only working solution is building the Windows + portable version on Windows, and Linux + Mac version on Linux.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,28 +0,0 @@
 | 
				
			|||||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
					 | 
				
			||||||
<project version="4">
 | 
					 | 
				
			||||||
  <component name="AvaloniaProject">
 | 
					 | 
				
			||||||
    <option name="projectPerEditor">
 | 
					 | 
				
			||||||
      <map>
 | 
					 | 
				
			||||||
        <entry key="Desktop/App.axaml" value="Desktop/Desktop.csproj" />
 | 
					 | 
				
			||||||
        <entry key="Desktop/Dialogs/CheckBox/CheckBoxDialog.axaml" value="Desktop/Desktop.csproj" />
 | 
					 | 
				
			||||||
        <entry key="Desktop/Dialogs/Message/MessageDialog.axaml" value="Desktop/Desktop.csproj" />
 | 
					 | 
				
			||||||
        <entry key="Desktop/Dialogs/Progress/ProgressDialog.axaml" value="Desktop/Desktop.csproj" />
 | 
					 | 
				
			||||||
        <entry key="Desktop/Dialogs/TextBox/TextBoxDialog.axaml" value="Desktop/Desktop.csproj" />
 | 
					 | 
				
			||||||
        <entry key="Desktop/Main/AboutWindow.axaml" value="Desktop/Desktop.csproj" />
 | 
					 | 
				
			||||||
        <entry key="Desktop/Main/Controls/AttachmentFilterPanel.axaml" value="Desktop/Desktop.csproj" />
 | 
					 | 
				
			||||||
        <entry key="Desktop/Main/Controls/MessageFilterPanel.axaml" value="Desktop/Desktop.csproj" />
 | 
					 | 
				
			||||||
        <entry key="Desktop/Main/Controls/ServerConfigurationPanel.axaml" value="Desktop/Desktop.csproj" />
 | 
					 | 
				
			||||||
        <entry key="Desktop/Main/Controls/StatusBar.axaml" value="Desktop/Desktop.csproj" />
 | 
					 | 
				
			||||||
        <entry key="Desktop/Main/MainWindow.axaml" value="Desktop/Desktop.csproj" />
 | 
					 | 
				
			||||||
        <entry key="Desktop/Main/Pages/AdvancedPage.axaml" value="Desktop/Desktop.csproj" />
 | 
					 | 
				
			||||||
        <entry key="Desktop/Main/Pages/AttachmentsPage.axaml" value="Desktop/Desktop.csproj" />
 | 
					 | 
				
			||||||
        <entry key="Desktop/Main/Pages/DatabasePage.axaml" value="Desktop/Desktop.csproj" />
 | 
					 | 
				
			||||||
        <entry key="Desktop/Main/Pages/DebugPage.axaml" value="Desktop/Desktop.csproj" />
 | 
					 | 
				
			||||||
        <entry key="Desktop/Main/Pages/TrackingPage.axaml" value="Desktop/Desktop.csproj" />
 | 
					 | 
				
			||||||
        <entry key="Desktop/Main/Pages/ViewerPage.axaml" value="Desktop/Desktop.csproj" />
 | 
					 | 
				
			||||||
        <entry key="Desktop/Main/Screens/MainContentScreen.axaml" value="Desktop/Desktop.csproj" />
 | 
					 | 
				
			||||||
        <entry key="Desktop/Main/Screens/WelcomeScreen.axaml" value="Desktop/Desktop.csproj" />
 | 
					 | 
				
			||||||
      </map>
 | 
					 | 
				
			||||||
    </option>
 | 
					 | 
				
			||||||
  </component>
 | 
					 | 
				
			||||||
</project>
 | 
					 | 
				
			||||||
@@ -29,6 +29,9 @@
 | 
				
			|||||||
    <H2CodeStyleSettings version="6">
 | 
					    <H2CodeStyleSettings version="6">
 | 
				
			||||||
      <option name="USE_GENERIC_STYLE" value="true" />
 | 
					      <option name="USE_GENERIC_STYLE" value="true" />
 | 
				
			||||||
    </H2CodeStyleSettings>
 | 
					    </H2CodeStyleSettings>
 | 
				
			||||||
 | 
					    <H2CodeStyleSettings version="6">
 | 
				
			||||||
 | 
					      <option name="USE_GENERIC_STYLE" value="true" />
 | 
				
			||||||
 | 
					    </H2CodeStyleSettings>
 | 
				
			||||||
    <HSQLCodeStyleSettings version="6">
 | 
					    <HSQLCodeStyleSettings version="6">
 | 
				
			||||||
      <option name="USE_GENERIC_STYLE" value="true" />
 | 
					      <option name="USE_GENERIC_STYLE" value="true" />
 | 
				
			||||||
    </HSQLCodeStyleSettings>
 | 
					    </HSQLCodeStyleSettings>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,8 +1,8 @@
 | 
				
			|||||||
<component name="ProjectRunConfigurationManager">
 | 
					<component name="ProjectRunConfigurationManager">
 | 
				
			||||||
  <configuration default="false" name="Desktop" type="DotNetProject" factoryName=".NET Project">
 | 
					  <configuration default="false" name="Desktop" type="DotNetProject" factoryName=".NET Project">
 | 
				
			||||||
    <option name="EXE_PATH" value="$PROJECT_DIR$/.artifacts/bin/Desktop/debug/DiscordHistoryTracker.exe" />
 | 
					    <option name="EXE_PATH" value="$PROJECT_DIR$/Desktop/bin/Debug/net5.0/DiscordHistoryTracker.exe" />
 | 
				
			||||||
    <option name="PROGRAM_PARAMETERS" value="" />
 | 
					    <option name="PROGRAM_PARAMETERS" value="" />
 | 
				
			||||||
    <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/.artifacts/bin/Desktop/debug" />
 | 
					    <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/Desktop/bin/Debug/net5.0" />
 | 
				
			||||||
    <option name="PASS_PARENT_ENVS" value="1" />
 | 
					    <option name="PASS_PARENT_ENVS" value="1" />
 | 
				
			||||||
    <option name="USE_EXTERNAL_CONSOLE" value="0" />
 | 
					    <option name="USE_EXTERNAL_CONSOLE" value="0" />
 | 
				
			||||||
    <option name="USE_MONO" value="0" />
 | 
					    <option name="USE_MONO" value="0" />
 | 
				
			||||||
@@ -12,7 +12,7 @@
 | 
				
			|||||||
    <option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
 | 
					    <option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
 | 
				
			||||||
    <option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="1" />
 | 
					    <option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="1" />
 | 
				
			||||||
    <option name="PROJECT_KIND" value="DotNetCore" />
 | 
					    <option name="PROJECT_KIND" value="DotNetCore" />
 | 
				
			||||||
    <option name="PROJECT_TFM" value="net8.0" />
 | 
					    <option name="PROJECT_TFM" value="net5.0" />
 | 
				
			||||||
    <method v="2">
 | 
					    <method v="2">
 | 
				
			||||||
      <option name="Build" />
 | 
					      <option name="Build" />
 | 
				
			||||||
    </method>
 | 
					    </method>
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										23
									
								
								app/.idea/.idea.DiscordHistoryTracker/.idea/runConfigurations/Minify.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								app/.idea/.idea.DiscordHistoryTracker/.idea/runConfigurations/Minify.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							@@ -0,0 +1,23 @@
 | 
				
			|||||||
 | 
					<component name="ProjectRunConfigurationManager">
 | 
				
			||||||
 | 
					  <configuration default="false" name="Minify" type="PythonConfigurationType" factoryName="Python">
 | 
				
			||||||
 | 
					    <module name="rider.module" />
 | 
				
			||||||
 | 
					    <option name="INTERPRETER_OPTIONS" value="" />
 | 
				
			||||||
 | 
					    <option name="PARENT_ENVS" value="true" />
 | 
				
			||||||
 | 
					    <envs>
 | 
				
			||||||
 | 
					      <env name="PYTHONUNBUFFERED" value="1" />
 | 
				
			||||||
 | 
					    </envs>
 | 
				
			||||||
 | 
					    <option name="SDK_HOME" value="" />
 | 
				
			||||||
 | 
					    <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
 | 
				
			||||||
 | 
					    <option name="IS_MODULE_SDK" value="false" />
 | 
				
			||||||
 | 
					    <option name="ADD_CONTENT_ROOTS" value="false" />
 | 
				
			||||||
 | 
					    <option name="ADD_SOURCE_ROOTS" value="false" />
 | 
				
			||||||
 | 
					    <option name="SCRIPT_NAME" value="$PROJECT_DIR$/minify.py" />
 | 
				
			||||||
 | 
					    <option name="PARAMETERS" value="" />
 | 
				
			||||||
 | 
					    <option name="SHOW_COMMAND_LINE" value="false" />
 | 
				
			||||||
 | 
					    <option name="EMULATE_TERMINAL" value="false" />
 | 
				
			||||||
 | 
					    <option name="MODULE_MODE" value="false" />
 | 
				
			||||||
 | 
					    <option name="REDIRECT_INPUT" value="false" />
 | 
				
			||||||
 | 
					    <option name="INPUT_FILE" value="" />
 | 
				
			||||||
 | 
					    <method v="2" />
 | 
				
			||||||
 | 
					  </configuration>
 | 
				
			||||||
 | 
					</component>
 | 
				
			||||||
@@ -1,9 +1,8 @@
 | 
				
			|||||||
<Application xmlns="https://github.com/avaloniaui"
 | 
					<Application xmlns="https://github.com/avaloniaui"
 | 
				
			||||||
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
					             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
				
			||||||
             xmlns:common="clr-namespace:DHT.Desktop.Common"
 | 
					 | 
				
			||||||
             xmlns:system="clr-namespace:System;assembly=System.Runtime"
 | 
					             xmlns:system="clr-namespace:System;assembly=System.Runtime"
 | 
				
			||||||
             x:Class="DHT.Desktop.App"
 | 
					             xmlns:common="clr-namespace:DHT.Desktop.App.Common"
 | 
				
			||||||
             RequestedThemeVariant="Light">
 | 
					             x:Class="DHT.Desktop.App.App">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <Application.Styles>
 | 
					    <Application.Styles>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -2,9 +2,9 @@ using System;
 | 
				
			|||||||
using Avalonia;
 | 
					using Avalonia;
 | 
				
			||||||
using Avalonia.Controls.ApplicationLifetimes;
 | 
					using Avalonia.Controls.ApplicationLifetimes;
 | 
				
			||||||
using Avalonia.Markup.Xaml;
 | 
					using Avalonia.Markup.Xaml;
 | 
				
			||||||
using DHT.Desktop.Main;
 | 
					using DHT.Desktop.App.Windows;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Desktop;
 | 
					namespace DHT.Desktop.App;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
sealed class App : Application {
 | 
					sealed class App : Application {
 | 
				
			||||||
	public override void Initialize() {
 | 
						public override void Initialize() {
 | 
				
			||||||
@@ -2,7 +2,7 @@ using System;
 | 
				
			|||||||
using System.Globalization;
 | 
					using System.Globalization;
 | 
				
			||||||
using Avalonia.Data.Converters;
 | 
					using Avalonia.Data.Converters;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Desktop.Common;
 | 
					namespace DHT.Desktop.App.Common;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
sealed class BytesValueConverter : IValueConverter {
 | 
					sealed class BytesValueConverter : IValueConverter {
 | 
				
			||||||
	private sealed class Unit {
 | 
						private sealed class Unit {
 | 
				
			||||||
@@ -4,14 +4,14 @@ using System.IO;
 | 
				
			|||||||
using System.Threading.Tasks;
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
using Avalonia.Controls;
 | 
					using Avalonia.Controls;
 | 
				
			||||||
using Avalonia.Platform.Storage;
 | 
					using Avalonia.Platform.Storage;
 | 
				
			||||||
using DHT.Desktop.Dialogs.File;
 | 
					using DHT.Desktop.App.Dialogs.File;
 | 
				
			||||||
using DHT.Desktop.Dialogs.Message;
 | 
					using DHT.Desktop.App.Dialogs.Message;
 | 
				
			||||||
using DHT.Server.Database;
 | 
					using DHT.Server.Database;
 | 
				
			||||||
using DHT.Server.Database.Exceptions;
 | 
					using DHT.Server.Database.Exceptions;
 | 
				
			||||||
using DHT.Server.Database.Sqlite;
 | 
					using DHT.Server.Database.Sqlite;
 | 
				
			||||||
using DHT.Utils.Logging;
 | 
					using DHT.Utils.Logging;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Desktop.Common;
 | 
					namespace DHT.Desktop.App.Common;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static class DatabaseGui {
 | 
					static class DatabaseGui {
 | 
				
			||||||
	private static readonly Log Log = Log.ForType(typeof(DatabaseGui));
 | 
						private static readonly Log Log = Log.ForType(typeof(DatabaseGui));
 | 
				
			||||||
@@ -2,7 +2,7 @@ using System;
 | 
				
			|||||||
using System.Globalization;
 | 
					using System.Globalization;
 | 
				
			||||||
using Avalonia.Data.Converters;
 | 
					using Avalonia.Data.Converters;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Desktop.Common;
 | 
					namespace DHT.Desktop.App.Common;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
sealed class NumberValueConverter : IValueConverter {
 | 
					sealed class NumberValueConverter : IValueConverter {
 | 
				
			||||||
	public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) {
 | 
						public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) {
 | 
				
			||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
namespace DHT.Desktop.Common;
 | 
					namespace DHT.Desktop.App.Common;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static class TextFormat {
 | 
					static class TextFormat {
 | 
				
			||||||
	public static string Format(this int number) {
 | 
						public static string Format(this int number) {
 | 
				
			||||||
@@ -2,9 +2,9 @@
 | 
				
			|||||||
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
					             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
				
			||||||
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
					             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
				
			||||||
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
					             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
				
			||||||
             xmlns:controls="clr-namespace:DHT.Desktop.Main.Controls"
 | 
					             xmlns:controls="clr-namespace:DHT.Desktop.App.Controls"
 | 
				
			||||||
             mc:Ignorable="d"
 | 
					             mc:Ignorable="d"
 | 
				
			||||||
             x:Class="DHT.Desktop.Main.Controls.ServerConfigurationPanel">
 | 
					             x:Class="DHT.Desktop.App.Controls.ServerConfigurationPanel">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <Design.DataContext>
 | 
					    <Design.DataContext>
 | 
				
			||||||
        <controls:ServerConfigurationPanelModel />
 | 
					        <controls:ServerConfigurationPanelModel />
 | 
				
			||||||
@@ -1,7 +1,7 @@
 | 
				
			|||||||
using System.Diagnostics.CodeAnalysis;
 | 
					using System.Diagnostics.CodeAnalysis;
 | 
				
			||||||
using Avalonia.Controls;
 | 
					using Avalonia.Controls;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Desktop.Main.Controls;
 | 
					namespace DHT.Desktop.App.Controls;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
					[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
				
			||||||
public sealed partial class ServerConfigurationPanel : UserControl {
 | 
					public sealed partial class ServerConfigurationPanel : UserControl {
 | 
				
			||||||
@@ -1,12 +1,12 @@
 | 
				
			|||||||
using System;
 | 
					using System;
 | 
				
			||||||
using Avalonia.Controls;
 | 
					using Avalonia.Controls;
 | 
				
			||||||
using DHT.Desktop.Dialogs.Message;
 | 
					using DHT.Desktop.App.Dialogs.Message;
 | 
				
			||||||
using DHT.Desktop.Server;
 | 
					using DHT.Desktop.Server;
 | 
				
			||||||
using DHT.Server.Database;
 | 
					using DHT.Server.Database;
 | 
				
			||||||
using DHT.Server.Service;
 | 
					using DHT.Server.Service;
 | 
				
			||||||
using DHT.Utils.Models;
 | 
					using DHT.Utils.Models;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Desktop.Main.Controls;
 | 
					namespace DHT.Desktop.App.Controls;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
sealed class ServerConfigurationPanelModel : BaseModel, IDisposable {
 | 
					sealed class ServerConfigurationPanelModel : BaseModel, IDisposable {
 | 
				
			||||||
	private string inputPort;
 | 
						private string inputPort;
 | 
				
			||||||
@@ -2,9 +2,9 @@
 | 
				
			|||||||
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
					             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
				
			||||||
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
					             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
				
			||||||
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
					             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
				
			||||||
             xmlns:controls="clr-namespace:DHT.Desktop.Main.Controls"
 | 
					             xmlns:controls="clr-namespace:DHT.Desktop.App.Controls"
 | 
				
			||||||
             mc:Ignorable="d"
 | 
					             mc:Ignorable="d"
 | 
				
			||||||
             x:Class="DHT.Desktop.Main.Controls.StatusBar">
 | 
					             x:Class="DHT.Desktop.App.Controls.StatusBar">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <Design.DataContext>
 | 
					    <Design.DataContext>
 | 
				
			||||||
        <controls:StatusBarModel />
 | 
					        <controls:StatusBarModel />
 | 
				
			||||||
@@ -1,7 +1,7 @@
 | 
				
			|||||||
using System.Diagnostics.CodeAnalysis;
 | 
					using System.Diagnostics.CodeAnalysis;
 | 
				
			||||||
using Avalonia.Controls;
 | 
					using Avalonia.Controls;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Desktop.Main.Controls;
 | 
					namespace DHT.Desktop.App.Controls;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
					[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
				
			||||||
public sealed partial class StatusBar : UserControl {
 | 
					public sealed partial class StatusBar : UserControl {
 | 
				
			||||||
@@ -1,12 +1,8 @@
 | 
				
			|||||||
using System;
 | 
					 | 
				
			||||||
using DHT.Server.Database;
 | 
					 | 
				
			||||||
using DHT.Utils.Models;
 | 
					using DHT.Utils.Models;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Desktop.Main.Controls;
 | 
					namespace DHT.Desktop.App.Controls;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
sealed class StatusBarModel : BaseModel {
 | 
					sealed class StatusBarModel : BaseModel {
 | 
				
			||||||
	public DatabaseStatistics DatabaseStatistics { get; }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private Status status = Status.Stopped;
 | 
						private Status status = Status.Stopped;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public Status CurrentStatus {
 | 
						public Status CurrentStatus {
 | 
				
			||||||
@@ -29,13 +25,6 @@ sealed class StatusBarModel : BaseModel {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	[Obsolete("Designer")]
 | 
					 | 
				
			||||||
	public StatusBarModel() : this(new DatabaseStatistics()) {}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public StatusBarModel(DatabaseStatistics databaseStatistics) {
 | 
					 | 
				
			||||||
		this.DatabaseStatistics = databaseStatistics;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public enum Status {
 | 
						public enum Status {
 | 
				
			||||||
		Starting,
 | 
							Starting,
 | 
				
			||||||
		Ready,
 | 
							Ready,
 | 
				
			||||||
@@ -2,16 +2,16 @@
 | 
				
			|||||||
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
					        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
				
			||||||
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
					        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
				
			||||||
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
					        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
				
			||||||
        xmlns:namespace="clr-namespace:DHT.Desktop.Dialogs.CheckBox"
 | 
					        xmlns:checkBox="clr-namespace:DHT.Desktop.App.Dialogs.CheckBox"
 | 
				
			||||||
        mc:Ignorable="d" d:DesignWidth="500"
 | 
					        mc:Ignorable="d" d:DesignWidth="500"
 | 
				
			||||||
        x:Class="DHT.Desktop.Dialogs.CheckBox.CheckBoxDialog"
 | 
					        x:Class="DHT.Desktop.App.Dialogs.CheckBox.CheckBoxDialog"
 | 
				
			||||||
        Title="{Binding Title}"
 | 
					        Title="{Binding Title}"
 | 
				
			||||||
        Icon="avares://DiscordHistoryTracker/Resources/icon.ico"
 | 
					        Icon="avares://DiscordHistoryTracker/Resources/icon.ico"
 | 
				
			||||||
        Width="500" SizeToContent="Height" CanResize="False"
 | 
					        Width="500" SizeToContent="Height" CanResize="False"
 | 
				
			||||||
        WindowStartupLocation="CenterOwner">
 | 
					        WindowStartupLocation="CenterOwner">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <Window.DataContext>
 | 
					    <Window.DataContext>
 | 
				
			||||||
        <namespace:CheckBoxDialogModel />
 | 
					        <checkBox:CheckBoxDialogModel />
 | 
				
			||||||
    </Window.DataContext>
 | 
					    </Window.DataContext>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <Window.Styles>
 | 
					    <Window.Styles>
 | 
				
			||||||
@@ -1,9 +1,9 @@
 | 
				
			|||||||
using System.Diagnostics.CodeAnalysis;
 | 
					using System.Diagnostics.CodeAnalysis;
 | 
				
			||||||
using Avalonia.Controls;
 | 
					using Avalonia.Controls;
 | 
				
			||||||
using Avalonia.Interactivity;
 | 
					using Avalonia.Interactivity;
 | 
				
			||||||
using DHT.Desktop.Dialogs.Message;
 | 
					using DHT.Desktop.App.Dialogs.Message;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Desktop.Dialogs.CheckBox;
 | 
					namespace DHT.Desktop.App.Dialogs.CheckBox;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
					[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
				
			||||||
public sealed partial class CheckBoxDialog : Window {
 | 
					public sealed partial class CheckBoxDialog : Window {
 | 
				
			||||||
@@ -4,7 +4,7 @@ using System.ComponentModel;
 | 
				
			|||||||
using System.Linq;
 | 
					using System.Linq;
 | 
				
			||||||
using DHT.Utils.Models;
 | 
					using DHT.Utils.Models;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Desktop.Dialogs.CheckBox;
 | 
					namespace DHT.Desktop.App.Dialogs.CheckBox;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class CheckBoxDialogModel : BaseModel {
 | 
					class CheckBoxDialogModel : BaseModel {
 | 
				
			||||||
	public string Title { get; init; } = "";
 | 
						public string Title { get; init; } = "";
 | 
				
			||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
using DHT.Utils.Models;
 | 
					using DHT.Utils.Models;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Desktop.Dialogs.CheckBox;
 | 
					namespace DHT.Desktop.App.Dialogs.CheckBox;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class CheckBoxItem : BaseModel {
 | 
					class CheckBoxItem : BaseModel {
 | 
				
			||||||
	public string Title { get; init; } = "";
 | 
						public string Title { get; init; } = "";
 | 
				
			||||||
@@ -5,7 +5,7 @@ using System.Threading.Tasks;
 | 
				
			|||||||
using Avalonia.Controls;
 | 
					using Avalonia.Controls;
 | 
				
			||||||
using Avalonia.Platform.Storage;
 | 
					using Avalonia.Platform.Storage;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Desktop.Dialogs.File;
 | 
					namespace DHT.Desktop.App.Dialogs.File;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static class FileDialogs {
 | 
					static class FileDialogs {
 | 
				
			||||||
	public static async Task<string[]> OpenFiles(this IStorageProvider storageProvider, FilePickerOpenOptions options) {
 | 
						public static async Task<string[]> OpenFiles(this IStorageProvider storageProvider, FilePickerOpenOptions options) {
 | 
				
			||||||
@@ -2,7 +2,7 @@ using System.Threading.Tasks;
 | 
				
			|||||||
using Avalonia.Controls;
 | 
					using Avalonia.Controls;
 | 
				
			||||||
using Avalonia.Threading;
 | 
					using Avalonia.Threading;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Desktop.Dialogs.Message;
 | 
					namespace DHT.Desktop.App.Dialogs.Message;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static class Dialog {
 | 
					static class Dialog {
 | 
				
			||||||
	public static async Task ShowOk(Window owner, string title, string message) {
 | 
						public static async Task ShowOk(Window owner, string title, string message) {
 | 
				
			||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
using System;
 | 
					using System;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Desktop.Dialogs.Message;
 | 
					namespace DHT.Desktop.App.Dialogs.Message;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static class DialogResult {
 | 
					static class DialogResult {
 | 
				
			||||||
	public enum All {
 | 
						public enum All {
 | 
				
			||||||
@@ -2,16 +2,16 @@
 | 
				
			|||||||
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
					        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
				
			||||||
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
					        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
				
			||||||
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
					        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
				
			||||||
        xmlns:namespace="clr-namespace:DHT.Desktop.Dialogs.Message"
 | 
					        xmlns:message="clr-namespace:DHT.Desktop.App.Dialogs.Message"
 | 
				
			||||||
        mc:Ignorable="d" d:DesignWidth="500"
 | 
					        mc:Ignorable="d" d:DesignWidth="500"
 | 
				
			||||||
        x:Class="DHT.Desktop.Dialogs.Message.MessageDialog"
 | 
					        x:Class="DHT.Desktop.App.Dialogs.Message.MessageDialog"
 | 
				
			||||||
        Title="{Binding Title}"
 | 
					        Title="{Binding Title}"
 | 
				
			||||||
        Icon="avares://DiscordHistoryTracker/Resources/icon.ico"
 | 
					        Icon="avares://DiscordHistoryTracker/Resources/icon.ico"
 | 
				
			||||||
        Width="500" SizeToContent="Height" CanResize="False"
 | 
					        Width="500" SizeToContent="Height" CanResize="False"
 | 
				
			||||||
        WindowStartupLocation="CenterOwner">
 | 
					        WindowStartupLocation="CenterOwner">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <Window.DataContext>
 | 
					    <Window.DataContext>
 | 
				
			||||||
        <namespace:MessageDialogModel />
 | 
					        <message:MessageDialogModel />
 | 
				
			||||||
    </Window.DataContext>
 | 
					    </Window.DataContext>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <Window.Styles>
 | 
					    <Window.Styles>
 | 
				
			||||||
@@ -2,7 +2,7 @@ using System.Diagnostics.CodeAnalysis;
 | 
				
			|||||||
using Avalonia.Controls;
 | 
					using Avalonia.Controls;
 | 
				
			||||||
using Avalonia.Interactivity;
 | 
					using Avalonia.Interactivity;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Desktop.Dialogs.Message;
 | 
					namespace DHT.Desktop.App.Dialogs.Message;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
					[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
				
			||||||
public sealed partial class MessageDialog : Window {
 | 
					public sealed partial class MessageDialog : Window {
 | 
				
			||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
namespace DHT.Desktop.Dialogs.Message;
 | 
					namespace DHT.Desktop.App.Dialogs.Message;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
sealed class MessageDialogModel {
 | 
					sealed class MessageDialogModel {
 | 
				
			||||||
	public string Title { get; init; } = "";
 | 
						public string Title { get; init; } = "";
 | 
				
			||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
using System.Threading.Tasks;
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Desktop.Dialogs.Progress;
 | 
					namespace DHT.Desktop.App.Dialogs.Progress;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
interface IProgressCallback {
 | 
					interface IProgressCallback {
 | 
				
			||||||
	Task Update(string message, int finishedItems, int totalItems);
 | 
						Task Update(string message, int finishedItems, int totalItems);
 | 
				
			||||||
@@ -2,9 +2,9 @@
 | 
				
			|||||||
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
					        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
				
			||||||
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
					        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
				
			||||||
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
					        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
				
			||||||
        xmlns:namespace="clr-namespace:DHT.Desktop.Dialogs.Progress"
 | 
					        xmlns:progress="clr-namespace:DHT.Desktop.App.Dialogs.Progress"
 | 
				
			||||||
        mc:Ignorable="d" d:DesignWidth="500"
 | 
					        mc:Ignorable="d" d:DesignWidth="500"
 | 
				
			||||||
        x:Class="DHT.Desktop.Dialogs.Progress.ProgressDialog"
 | 
					        x:Class="DHT.Desktop.App.Dialogs.Progress.ProgressDialog"
 | 
				
			||||||
        Title="{Binding Title}"
 | 
					        Title="{Binding Title}"
 | 
				
			||||||
        Icon="avares://DiscordHistoryTracker/Resources/icon.ico"
 | 
					        Icon="avares://DiscordHistoryTracker/Resources/icon.ico"
 | 
				
			||||||
        Opened="OnOpened"
 | 
					        Opened="OnOpened"
 | 
				
			||||||
@@ -13,7 +13,7 @@
 | 
				
			|||||||
        WindowStartupLocation="CenterOwner">
 | 
					        WindowStartupLocation="CenterOwner">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <Window.DataContext>
 | 
					    <Window.DataContext>
 | 
				
			||||||
        <namespace:ProgressDialogModel />
 | 
					        <progress:ProgressDialogModel />
 | 
				
			||||||
    </Window.DataContext>
 | 
					    </Window.DataContext>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <Window.Styles>
 | 
					    <Window.Styles>
 | 
				
			||||||
@@ -3,7 +3,7 @@ using System.Diagnostics.CodeAnalysis;
 | 
				
			|||||||
using System.Threading.Tasks;
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
using Avalonia.Controls;
 | 
					using Avalonia.Controls;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Desktop.Dialogs.Progress;
 | 
					namespace DHT.Desktop.App.Dialogs.Progress;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
					[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
				
			||||||
public sealed partial class ProgressDialog : Window {
 | 
					public sealed partial class ProgressDialog : Window {
 | 
				
			||||||
@@ -1,10 +1,10 @@
 | 
				
			|||||||
using System;
 | 
					using System;
 | 
				
			||||||
using System.Threading.Tasks;
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
using Avalonia.Threading;
 | 
					using Avalonia.Threading;
 | 
				
			||||||
using DHT.Desktop.Common;
 | 
					using DHT.Desktop.App.Common;
 | 
				
			||||||
using DHT.Utils.Models;
 | 
					using DHT.Utils.Models;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Desktop.Dialogs.Progress;
 | 
					namespace DHT.Desktop.App.Dialogs.Progress;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
sealed class ProgressDialogModel : BaseModel {
 | 
					sealed class ProgressDialogModel : BaseModel {
 | 
				
			||||||
	public string Title { get; init; } = "";
 | 
						public string Title { get; init; } = "";
 | 
				
			||||||
@@ -2,16 +2,16 @@
 | 
				
			|||||||
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
					        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
				
			||||||
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
					        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
				
			||||||
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
					        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
				
			||||||
        xmlns:namespace="clr-namespace:DHT.Desktop.Dialogs.TextBox"
 | 
					        xmlns:textBox="clr-namespace:DHT.Desktop.App.Dialogs.TextBox"
 | 
				
			||||||
        mc:Ignorable="d" d:DesignWidth="500"
 | 
					        mc:Ignorable="d" d:DesignWidth="500"
 | 
				
			||||||
        x:Class="DHT.Desktop.Dialogs.TextBox.TextBoxDialog"
 | 
					        x:Class="DHT.Desktop.App.Dialogs.TextBox.TextBoxDialog"
 | 
				
			||||||
        Title="{Binding Title}"
 | 
					        Title="{Binding Title}"
 | 
				
			||||||
        Icon="avares://DiscordHistoryTracker/Resources/icon.ico"
 | 
					        Icon="avares://DiscordHistoryTracker/Resources/icon.ico"
 | 
				
			||||||
        Width="500" SizeToContent="Height" CanResize="False"
 | 
					        Width="500" SizeToContent="Height" CanResize="False"
 | 
				
			||||||
        WindowStartupLocation="CenterOwner">
 | 
					        WindowStartupLocation="CenterOwner">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <Window.DataContext>
 | 
					    <Window.DataContext>
 | 
				
			||||||
        <namespace:TextBoxDialogModel />
 | 
					        <textBox:TextBoxDialogModel />
 | 
				
			||||||
    </Window.DataContext>
 | 
					    </Window.DataContext>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <Window.Styles>
 | 
					    <Window.Styles>
 | 
				
			||||||
@@ -1,9 +1,9 @@
 | 
				
			|||||||
using System.Diagnostics.CodeAnalysis;
 | 
					using System.Diagnostics.CodeAnalysis;
 | 
				
			||||||
using Avalonia.Controls;
 | 
					using Avalonia.Controls;
 | 
				
			||||||
using Avalonia.Interactivity;
 | 
					using Avalonia.Interactivity;
 | 
				
			||||||
using DHT.Desktop.Dialogs.Message;
 | 
					using DHT.Desktop.App.Dialogs.Message;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Desktop.Dialogs.TextBox; 
 | 
					namespace DHT.Desktop.App.Dialogs.TextBox; 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
					[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
				
			||||||
public sealed partial class TextBoxDialog : Window {
 | 
					public sealed partial class TextBoxDialog : Window {
 | 
				
			||||||
@@ -4,7 +4,7 @@ using System.ComponentModel;
 | 
				
			|||||||
using System.Linq;
 | 
					using System.Linq;
 | 
				
			||||||
using DHT.Utils.Models;
 | 
					using DHT.Utils.Models;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Desktop.Dialogs.TextBox; 
 | 
					namespace DHT.Desktop.App.Dialogs.TextBox; 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TextBoxDialogModel : BaseModel {
 | 
					class TextBoxDialogModel : BaseModel {
 | 
				
			||||||
	public string Title { get; init; } = "";
 | 
						public string Title { get; init; } = "";
 | 
				
			||||||
@@ -3,7 +3,7 @@ using System.Collections;
 | 
				
			|||||||
using System.ComponentModel;
 | 
					using System.ComponentModel;
 | 
				
			||||||
using DHT.Utils.Models;
 | 
					using DHT.Utils.Models;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Desktop.Dialogs.TextBox; 
 | 
					namespace DHT.Desktop.App.Dialogs.TextBox; 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TextBoxItem : BaseModel, INotifyDataErrorInfo {
 | 
					class TextBoxItem : BaseModel, INotifyDataErrorInfo {
 | 
				
			||||||
	public string Title { get; init; } = "";
 | 
						public string Title { get; init; } = "";
 | 
				
			||||||
@@ -2,10 +2,10 @@
 | 
				
			|||||||
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
					             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
				
			||||||
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
					             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
				
			||||||
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
					             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
				
			||||||
             xmlns:pages="clr-namespace:DHT.Desktop.Main.Pages"
 | 
					             xmlns:pages="clr-namespace:DHT.Desktop.App.Pages"
 | 
				
			||||||
             xmlns:controls="clr-namespace:DHT.Desktop.Main.Controls"
 | 
					             xmlns:controls="clr-namespace:DHT.Desktop.App.Controls"
 | 
				
			||||||
             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
 | 
					             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
 | 
				
			||||||
             x:Class="DHT.Desktop.Main.Pages.AdvancedPage">
 | 
					             x:Class="DHT.Desktop.App.Pages.AdvancedPage">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <Design.DataContext>
 | 
					    <Design.DataContext>
 | 
				
			||||||
        <pages:AdvancedPageModel />
 | 
					        <pages:AdvancedPageModel />
 | 
				
			||||||
@@ -1,7 +1,7 @@
 | 
				
			|||||||
using System.Diagnostics.CodeAnalysis;
 | 
					using System.Diagnostics.CodeAnalysis;
 | 
				
			||||||
using Avalonia.Controls;
 | 
					using Avalonia.Controls;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Desktop.Main.Pages;
 | 
					namespace DHT.Desktop.App.Pages;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
					[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
				
			||||||
public sealed partial class AdvancedPage : UserControl {
 | 
					public sealed partial class AdvancedPage : UserControl {
 | 
				
			||||||
@@ -1,12 +1,12 @@
 | 
				
			|||||||
using System;
 | 
					using System;
 | 
				
			||||||
using Avalonia.Controls;
 | 
					using Avalonia.Controls;
 | 
				
			||||||
using DHT.Desktop.Dialogs.Message;
 | 
					using DHT.Desktop.App.Controls;
 | 
				
			||||||
using DHT.Desktop.Main.Controls;
 | 
					using DHT.Desktop.App.Dialogs.Message;
 | 
				
			||||||
using DHT.Desktop.Server;
 | 
					using DHT.Desktop.Server;
 | 
				
			||||||
using DHT.Server.Database;
 | 
					using DHT.Server.Database;
 | 
				
			||||||
using DHT.Utils.Models;
 | 
					using DHT.Utils.Models;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Desktop.Main.Pages;
 | 
					namespace DHT.Desktop.App.Pages;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
sealed class AdvancedPageModel : BaseModel, IDisposable {
 | 
					sealed class AdvancedPageModel : BaseModel, IDisposable {
 | 
				
			||||||
	public ServerConfigurationPanelModel ServerConfigurationModel { get; }
 | 
						public ServerConfigurationPanelModel ServerConfigurationModel { get; }
 | 
				
			||||||
@@ -2,9 +2,9 @@
 | 
				
			|||||||
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
					             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
				
			||||||
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
					             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
				
			||||||
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
					             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
				
			||||||
             xmlns:pages="clr-namespace:DHT.Desktop.Main.Pages"
 | 
					             xmlns:pages="clr-namespace:DHT.Desktop.App.Pages"
 | 
				
			||||||
             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
 | 
					             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
 | 
				
			||||||
             x:Class="DHT.Desktop.Main.Pages.DatabasePage">
 | 
					             x:Class="DHT.Desktop.App.Pages.DatabasePage">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <Design.DataContext>
 | 
					    <Design.DataContext>
 | 
				
			||||||
        <pages:DatabasePageModel />
 | 
					        <pages:DatabasePageModel />
 | 
				
			||||||
@@ -23,8 +23,6 @@
 | 
				
			|||||||
        </DockPanel>
 | 
					        </DockPanel>
 | 
				
			||||||
        <WrapPanel>
 | 
					        <WrapPanel>
 | 
				
			||||||
            <Button Command="{Binding OpenDatabaseFolder}">Open Database Folder</Button>
 | 
					            <Button Command="{Binding OpenDatabaseFolder}">Open Database Folder</Button>
 | 
				
			||||||
            <Button Command="{Binding MergeWithDatabase}">Merge with Database(s)...</Button>
 | 
					 | 
				
			||||||
            <Button Command="{Binding ImportLegacyArchive}">Import Legacy Archive(s)...</Button>
 | 
					 | 
				
			||||||
        </WrapPanel>
 | 
					        </WrapPanel>
 | 
				
			||||||
    </StackPanel>
 | 
					    </StackPanel>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1,7 +1,7 @@
 | 
				
			|||||||
using System.Diagnostics.CodeAnalysis;
 | 
					using System.Diagnostics.CodeAnalysis;
 | 
				
			||||||
using Avalonia.Controls;
 | 
					using Avalonia.Controls;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Desktop.Main.Pages;
 | 
					namespace DHT.Desktop.App.Pages;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
					[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
				
			||||||
public sealed partial class DatabasePage : UserControl {
 | 
					public sealed partial class DatabasePage : UserControl {
 | 
				
			||||||
							
								
								
									
										59
									
								
								app/Desktop/App/Pages/DatabasePageModel.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								app/Desktop/App/Pages/DatabasePageModel.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,59 @@
 | 
				
			|||||||
 | 
					using System;
 | 
				
			||||||
 | 
					using System.Diagnostics;
 | 
				
			||||||
 | 
					using System.IO;
 | 
				
			||||||
 | 
					using Avalonia.Controls;
 | 
				
			||||||
 | 
					using DHT.Desktop.App.Dialogs.Message;
 | 
				
			||||||
 | 
					using DHT.Server.Database;
 | 
				
			||||||
 | 
					using DHT.Utils.Logging;
 | 
				
			||||||
 | 
					using DHT.Utils.Models;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace DHT.Desktop.App.Pages; 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					sealed class DatabasePageModel : BaseModel {
 | 
				
			||||||
 | 
						private static readonly Log Log = Log.ForType<DatabasePageModel>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public IDatabaseFile Db { get; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public event EventHandler? DatabaseClosed;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private readonly Window window;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						[Obsolete("Designer")]
 | 
				
			||||||
 | 
						public DatabasePageModel() : this(null!, DummyDatabaseFile.Instance) {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public DatabasePageModel(Window window, IDatabaseFile db) {
 | 
				
			||||||
 | 
							this.window = window;
 | 
				
			||||||
 | 
							this.Db = db;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public async void OpenDatabaseFolder() {
 | 
				
			||||||
 | 
							string file = Db.Path;
 | 
				
			||||||
 | 
							string? folder = Path.GetDirectoryName(file);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (folder == null) {
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							switch (Environment.OSVersion.Platform) {
 | 
				
			||||||
 | 
								case PlatformID.Win32NT:
 | 
				
			||||||
 | 
									Process.Start("explorer.exe", "/select,\"" + file + "\"");
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								case PlatformID.Unix:
 | 
				
			||||||
 | 
									Process.Start("xdg-open", new string[] { folder });
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								case PlatformID.MacOSX:
 | 
				
			||||||
 | 
									Process.Start("open", new string[] { folder });
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								default:
 | 
				
			||||||
 | 
									await Dialog.ShowOk(window, "Feature Not Supported", "This feature is not supported for your operating system.");
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public void CloseDatabase() {
 | 
				
			||||||
 | 
							DatabaseClosed?.Invoke(this, EventArgs.Empty);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -2,9 +2,9 @@
 | 
				
			|||||||
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
					             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
				
			||||||
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
					             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
				
			||||||
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
					             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
				
			||||||
             xmlns:pages="clr-namespace:DHT.Desktop.Main.Pages"
 | 
					             xmlns:pages="clr-namespace:DHT.Desktop.App.Pages"
 | 
				
			||||||
             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
 | 
					             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
 | 
				
			||||||
             x:Class="DHT.Desktop.Main.Pages.TrackingPage">
 | 
					             x:Class="DHT.Desktop.App.Pages.TrackingPage">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <Design.DataContext>
 | 
					    <Design.DataContext>
 | 
				
			||||||
        <pages:TrackingPageModel />
 | 
					        <pages:TrackingPageModel />
 | 
				
			||||||
@@ -4,7 +4,7 @@ using System.Threading.Tasks;
 | 
				
			|||||||
using Avalonia.Controls;
 | 
					using Avalonia.Controls;
 | 
				
			||||||
using Avalonia.Interactivity;
 | 
					using Avalonia.Interactivity;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Desktop.Main.Pages;
 | 
					namespace DHT.Desktop.App.Pages;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
					[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
				
			||||||
public sealed partial class TrackingPage : UserControl {
 | 
					public sealed partial class TrackingPage : UserControl {
 | 
				
			||||||
@@ -2,13 +2,12 @@ using System;
 | 
				
			|||||||
using System.Threading.Tasks;
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
using System.Web;
 | 
					using System.Web;
 | 
				
			||||||
using Avalonia.Controls;
 | 
					using Avalonia.Controls;
 | 
				
			||||||
using DHT.Desktop.Dialogs.Message;
 | 
					using DHT.Desktop.App.Dialogs.Message;
 | 
				
			||||||
using DHT.Desktop.Discord;
 | 
					using DHT.Desktop.Discord;
 | 
				
			||||||
using DHT.Desktop.Server;
 | 
					using DHT.Desktop.Server;
 | 
				
			||||||
using DHT.Utils.Models;
 | 
					using DHT.Utils.Models;
 | 
				
			||||||
using static DHT.Desktop.Program;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Desktop.Main.Pages;
 | 
					namespace DHT.Desktop.App.Pages;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
sealed class TrackingPageModel : BaseModel {
 | 
					sealed class TrackingPageModel : BaseModel {
 | 
				
			||||||
	private bool areDevToolsEnabled;
 | 
						private bool areDevToolsEnabled;
 | 
				
			||||||
@@ -52,10 +51,14 @@ sealed class TrackingPageModel : BaseModel {
 | 
				
			|||||||
			OnPropertyChanged(nameof(IsToggleAppDevToolsButtonEnabled));
 | 
								OnPropertyChanged(nameof(IsToggleAppDevToolsButtonEnabled));
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
					
 | 
				
			||||||
	public async Task<bool> OnClickCopyTrackingScript() {
 | 
						public async Task<bool> OnClickCopyTrackingScript() {
 | 
				
			||||||
		string url = $"http://127.0.0.1:{ServerManager.Port}/get-tracking-script?token={HttpUtility.UrlEncode(ServerManager.Token)}";
 | 
							string bootstrap = await Resources.ReadTextAsync("Tracker/bootstrap.js");
 | 
				
			||||||
		string script = (await Resources.ReadTextAsync("tracker-loader.js")).Trim().Replace("{url}", url);
 | 
							string script = bootstrap.Replace("= 0; /*[PORT]*/", "= " + ServerManager.Port + ";")
 | 
				
			||||||
 | 
							                         .Replace("/*[TOKEN]*/", HttpUtility.JavaScriptStringEncode(ServerManager.Token))
 | 
				
			||||||
 | 
							                         .Replace("/*[IMPORTS]*/", await Resources.ReadJoinedAsync("Tracker/scripts/", '\n'))
 | 
				
			||||||
 | 
							                         .Replace("/*[CSS-CONTROLLER]*/", await Resources.ReadTextAsync("Tracker/styles/controller.css"))
 | 
				
			||||||
 | 
							                         .Replace("/*[CSS-SETTINGS]*/", await Resources.ReadTextAsync("Tracker/styles/settings.css"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		var clipboard = window.Clipboard;
 | 
							var clipboard = window.Clipboard;
 | 
				
			||||||
		if (clipboard == null) {
 | 
							if (clipboard == null) {
 | 
				
			||||||
@@ -2,10 +2,10 @@
 | 
				
			|||||||
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
					             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
				
			||||||
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
					             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
				
			||||||
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
					             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
				
			||||||
             xmlns:controls="clr-namespace:DHT.Desktop.Main.Controls"
 | 
					             xmlns:screens="clr-namespace:DHT.Desktop.App.Screens"
 | 
				
			||||||
             xmlns:screens="clr-namespace:DHT.Desktop.Main.Screens"
 | 
					             xmlns:controls="clr-namespace:DHT.Desktop.App.Controls"
 | 
				
			||||||
             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
 | 
					             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
 | 
				
			||||||
             x:Class="DHT.Desktop.Main.Screens.MainContentScreen">
 | 
					             x:Class="DHT.Desktop.App.Screens.MainContentScreen">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <Design.DataContext>
 | 
					    <Design.DataContext>
 | 
				
			||||||
        <screens:MainContentScreenModel />
 | 
					        <screens:MainContentScreenModel />
 | 
				
			||||||
@@ -80,7 +80,7 @@
 | 
				
			|||||||
        <TabControl x:Name="TabControl" TabStripPlacement="Left" DockPanel.Dock="Top">
 | 
					        <TabControl x:Name="TabControl" TabStripPlacement="Left" DockPanel.Dock="Top">
 | 
				
			||||||
            <TabControl.ItemsPanel>
 | 
					            <TabControl.ItemsPanel>
 | 
				
			||||||
                <ItemsPanelTemplate>
 | 
					                <ItemsPanelTemplate>
 | 
				
			||||||
                    <Grid ColumnDefinitions="Auto" RowDefinitions="Auto,Auto,Auto,Auto,*,Auto,Auto" />
 | 
					                    <Grid ColumnDefinitions="Auto" RowDefinitions="Auto,Auto,*,Auto" />
 | 
				
			||||||
                </ItemsPanelTemplate>
 | 
					                </ItemsPanelTemplate>
 | 
				
			||||||
            </TabControl.ItemsPanel>
 | 
					            </TabControl.ItemsPanel>
 | 
				
			||||||
            <TabItem x:Name="TabDatabase" Header="Database" Classes="first" Grid.Row="0">
 | 
					            <TabItem x:Name="TabDatabase" Header="Database" Classes="first" Grid.Row="0">
 | 
				
			||||||
@@ -93,26 +93,11 @@
 | 
				
			|||||||
                    <ContentPresenter Content="{Binding TrackingPage}" Classes="page" />
 | 
					                    <ContentPresenter Content="{Binding TrackingPage}" Classes="page" />
 | 
				
			||||||
                </ScrollViewer>
 | 
					                </ScrollViewer>
 | 
				
			||||||
            </TabItem>
 | 
					            </TabItem>
 | 
				
			||||||
            <TabItem x:Name="TabAttachments" Header="Attachments" Grid.Row="2">
 | 
					            <TabItem x:Name="TabAdvanced" Header="Advanced" Grid.Row="3">
 | 
				
			||||||
                <ScrollViewer>
 | 
					 | 
				
			||||||
                    <ContentPresenter Content="{Binding AttachmentsPage}" Classes="page" />
 | 
					 | 
				
			||||||
                </ScrollViewer>
 | 
					 | 
				
			||||||
            </TabItem>
 | 
					 | 
				
			||||||
            <TabItem x:Name="TabViewer" Header="Viewer" Grid.Row="3">
 | 
					 | 
				
			||||||
                <ScrollViewer>
 | 
					 | 
				
			||||||
                    <ContentPresenter Content="{Binding ViewerPage}" Classes="page" />
 | 
					 | 
				
			||||||
                </ScrollViewer>
 | 
					 | 
				
			||||||
            </TabItem>
 | 
					 | 
				
			||||||
            <TabItem x:Name="TabAdvanced" Header="Advanced" Grid.Row="5">
 | 
					 | 
				
			||||||
                <ScrollViewer>
 | 
					                <ScrollViewer>
 | 
				
			||||||
                    <ContentPresenter Content="{Binding AdvancedPage}" Classes="page" />
 | 
					                    <ContentPresenter Content="{Binding AdvancedPage}" Classes="page" />
 | 
				
			||||||
                </ScrollViewer>
 | 
					                </ScrollViewer>
 | 
				
			||||||
            </TabItem>
 | 
					            </TabItem>
 | 
				
			||||||
            <TabItem x:Name="TabDebug" Header="Debug" Grid.Row="6" IsVisible="{Binding HasDebugPage}">
 | 
					 | 
				
			||||||
                <ScrollViewer>
 | 
					 | 
				
			||||||
                    <ContentPresenter Content="{Binding DebugPage}" Classes="page" />
 | 
					 | 
				
			||||||
                </ScrollViewer>
 | 
					 | 
				
			||||||
            </TabItem>
 | 
					 | 
				
			||||||
        </TabControl>
 | 
					        </TabControl>
 | 
				
			||||||
    </DockPanel>
 | 
					    </DockPanel>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1,7 +1,7 @@
 | 
				
			|||||||
using System.Diagnostics.CodeAnalysis;
 | 
					using System.Diagnostics.CodeAnalysis;
 | 
				
			||||||
using Avalonia.Controls;
 | 
					using Avalonia.Controls;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Desktop.Main.Screens;
 | 
					namespace DHT.Desktop.App.Screens;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
					[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
				
			||||||
public sealed partial class MainContentScreen : UserControl {
 | 
					public sealed partial class MainContentScreen : UserControl {
 | 
				
			||||||
@@ -1,15 +1,14 @@
 | 
				
			|||||||
using System;
 | 
					using System;
 | 
				
			||||||
using System.Threading.Tasks;
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
using Avalonia.Controls;
 | 
					using Avalonia.Controls;
 | 
				
			||||||
using DHT.Desktop.Dialogs.Message;
 | 
					using DHT.Desktop.App.Controls;
 | 
				
			||||||
using DHT.Desktop.Main.Controls;
 | 
					using DHT.Desktop.App.Dialogs.Message;
 | 
				
			||||||
using DHT.Desktop.Main.Pages;
 | 
					using DHT.Desktop.App.Pages;
 | 
				
			||||||
using DHT.Desktop.Server;
 | 
					using DHT.Desktop.Server;
 | 
				
			||||||
using DHT.Server.Database;
 | 
					using DHT.Server.Database;
 | 
				
			||||||
using DHT.Server.Service;
 | 
					 | 
				
			||||||
using DHT.Utils.Logging;
 | 
					using DHT.Utils.Logging;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Desktop.Main.Screens;
 | 
					namespace DHT.Desktop.App.Screens;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
sealed class MainContentScreenModel : IDisposable {
 | 
					sealed class MainContentScreenModel : IDisposable {
 | 
				
			||||||
	private static readonly Log Log = Log.ForType<MainContentScreenModel>();
 | 
						private static readonly Log Log = Log.ForType<MainContentScreenModel>();
 | 
				
			||||||
@@ -20,24 +19,9 @@ sealed class MainContentScreenModel : IDisposable {
 | 
				
			|||||||
	public TrackingPage TrackingPage { get; }
 | 
						public TrackingPage TrackingPage { get; }
 | 
				
			||||||
	private TrackingPageModel TrackingPageModel { get; }
 | 
						private TrackingPageModel TrackingPageModel { get; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public AttachmentsPage AttachmentsPage { get; }
 | 
					 | 
				
			||||||
	private AttachmentsPageModel AttachmentsPageModel { get; }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public ViewerPage ViewerPage { get; }
 | 
					 | 
				
			||||||
	private ViewerPageModel ViewerPageModel { get; }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public AdvancedPage AdvancedPage { get; }
 | 
						public AdvancedPage AdvancedPage { get; }
 | 
				
			||||||
	private AdvancedPageModel AdvancedPageModel { get; }
 | 
						private AdvancedPageModel AdvancedPageModel { get; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public DebugPage? DebugPage { get; }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	#if DEBUG
 | 
					 | 
				
			||||||
	public bool HasDebugPage => true;
 | 
					 | 
				
			||||||
	private DebugPageModel DebugPageModel { get; }
 | 
					 | 
				
			||||||
	#else
 | 
					 | 
				
			||||||
		public bool HasDebugPage => false;
 | 
					 | 
				
			||||||
	#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public StatusBarModel StatusBarModel { get; }
 | 
						public StatusBarModel StatusBarModel { get; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public event EventHandler? DatabaseClosed {
 | 
						public event EventHandler? DatabaseClosed {
 | 
				
			||||||
@@ -67,23 +51,10 @@ sealed class MainContentScreenModel : IDisposable {
 | 
				
			|||||||
		TrackingPageModel = new TrackingPageModel(window);
 | 
							TrackingPageModel = new TrackingPageModel(window);
 | 
				
			||||||
		TrackingPage = new TrackingPage { DataContext = TrackingPageModel };
 | 
							TrackingPage = new TrackingPage { DataContext = TrackingPageModel };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		AttachmentsPageModel = new AttachmentsPageModel(db);
 | 
					 | 
				
			||||||
		AttachmentsPage = new AttachmentsPage { DataContext = AttachmentsPageModel };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		ViewerPageModel = new ViewerPageModel(window, db);
 | 
					 | 
				
			||||||
		ViewerPage = new ViewerPage { DataContext = ViewerPageModel };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		AdvancedPageModel = new AdvancedPageModel(window, db, serverManager);
 | 
							AdvancedPageModel = new AdvancedPageModel(window, db, serverManager);
 | 
				
			||||||
		AdvancedPage = new AdvancedPage { DataContext = AdvancedPageModel };
 | 
							AdvancedPage = new AdvancedPage { DataContext = AdvancedPageModel };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		#if DEBUG
 | 
							StatusBarModel = new StatusBarModel();
 | 
				
			||||||
		DebugPageModel = new DebugPageModel(window, db);
 | 
					 | 
				
			||||||
		DebugPage = new DebugPage { DataContext = DebugPageModel };
 | 
					 | 
				
			||||||
		#else
 | 
					 | 
				
			||||||
			DebugPage = null;
 | 
					 | 
				
			||||||
		#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		StatusBarModel = new StatusBarModel(db.Statistics);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		AdvancedPageModel.ServerConfigurationModel.ServerStatusChanged += OnServerStatusChanged;
 | 
							AdvancedPageModel.ServerConfigurationModel.ServerStatusChanged += OnServerStatusChanged;
 | 
				
			||||||
		DatabaseClosed += OnDatabaseClosed;
 | 
							DatabaseClosed += OnDatabaseClosed;
 | 
				
			||||||
@@ -99,8 +70,6 @@ sealed class MainContentScreenModel : IDisposable {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	public void Dispose() {
 | 
						public void Dispose() {
 | 
				
			||||||
		ServerLauncher.ServerManagementExceptionCaught -= ServerLauncherOnServerManagementExceptionCaught;
 | 
							ServerLauncher.ServerManagementExceptionCaught -= ServerLauncherOnServerManagementExceptionCaught;
 | 
				
			||||||
		AttachmentsPageModel.Dispose();
 | 
					 | 
				
			||||||
		ViewerPageModel.Dispose();
 | 
					 | 
				
			||||||
		serverManager.Dispose();
 | 
							serverManager.Dispose();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -2,9 +2,9 @@
 | 
				
			|||||||
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
					             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
				
			||||||
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
					             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
				
			||||||
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
					             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
				
			||||||
             xmlns:screens="clr-namespace:DHT.Desktop.Main.Screens"
 | 
					             xmlns:screens="clr-namespace:DHT.Desktop.App.Screens"
 | 
				
			||||||
             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
 | 
					             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
 | 
				
			||||||
             x:Class="DHT.Desktop.Main.Screens.WelcomeScreen">
 | 
					             x:Class="DHT.Desktop.App.Screens.WelcomeScreen">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <Design.DataContext>
 | 
					    <Design.DataContext>
 | 
				
			||||||
        <screens:WelcomeScreenModel />
 | 
					        <screens:WelcomeScreenModel />
 | 
				
			||||||
@@ -1,7 +1,7 @@
 | 
				
			|||||||
using System.Diagnostics.CodeAnalysis;
 | 
					using System.Diagnostics.CodeAnalysis;
 | 
				
			||||||
using Avalonia.Controls;
 | 
					using Avalonia.Controls;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Desktop.Main.Screens;
 | 
					namespace DHT.Desktop.App.Screens;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
					[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
				
			||||||
public sealed partial class WelcomeScreen : UserControl {
 | 
					public sealed partial class WelcomeScreen : UserControl {
 | 
				
			||||||
@@ -2,12 +2,13 @@ using System;
 | 
				
			|||||||
using System.IO;
 | 
					using System.IO;
 | 
				
			||||||
using System.Threading.Tasks;
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
using Avalonia.Controls;
 | 
					using Avalonia.Controls;
 | 
				
			||||||
using DHT.Desktop.Common;
 | 
					using DHT.Desktop.App.Common;
 | 
				
			||||||
using DHT.Desktop.Dialogs.Message;
 | 
					using DHT.Desktop.App.Dialogs.Message;
 | 
				
			||||||
 | 
					using DHT.Desktop.App.Windows;
 | 
				
			||||||
using DHT.Server.Database;
 | 
					using DHT.Server.Database;
 | 
				
			||||||
using DHT.Utils.Models;
 | 
					using DHT.Utils.Models;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Desktop.Main.Screens;
 | 
					namespace DHT.Desktop.App.Screens;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
sealed class WelcomeScreenModel : BaseModel, IDisposable {
 | 
					sealed class WelcomeScreenModel : BaseModel, IDisposable {
 | 
				
			||||||
	public string Version => Program.Version;
 | 
						public string Version => Program.Version;
 | 
				
			||||||
@@ -2,16 +2,16 @@
 | 
				
			|||||||
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
					        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
				
			||||||
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
					        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
				
			||||||
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
					        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
				
			||||||
        xmlns:main="clr-namespace:DHT.Desktop.Main"
 | 
					        xmlns:windows="clr-namespace:DHT.Desktop.App.Windows"
 | 
				
			||||||
        mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="295"
 | 
					        mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="295"
 | 
				
			||||||
        x:Class="DHT.Desktop.Main.AboutWindow"
 | 
					        x:Class="DHT.Desktop.App.Windows.AboutWindow"
 | 
				
			||||||
        Title="About Discord History Tracker"
 | 
					        Title="About Discord History Tracker"
 | 
				
			||||||
        Icon="avares://DiscordHistoryTracker/Resources/icon.ico"
 | 
					        Icon="avares://DiscordHistoryTracker/Resources/icon.ico"
 | 
				
			||||||
        Width="480" Height="295" CanResize="False"
 | 
					        Width="480" Height="295" CanResize="False"
 | 
				
			||||||
        WindowStartupLocation="CenterOwner">
 | 
					        WindowStartupLocation="CenterOwner">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <Design.DataContext>
 | 
					    <Design.DataContext>
 | 
				
			||||||
        <main:AboutWindowModel />
 | 
					        <windows:AboutWindowModel />
 | 
				
			||||||
    </Design.DataContext>
 | 
					    </Design.DataContext>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <Window.Styles>
 | 
					    <Window.Styles>
 | 
				
			||||||
@@ -1,7 +1,7 @@
 | 
				
			|||||||
using System.Diagnostics.CodeAnalysis;
 | 
					using System.Diagnostics.CodeAnalysis;
 | 
				
			||||||
using Avalonia.Controls;
 | 
					using Avalonia.Controls;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Desktop.Main;
 | 
					namespace DHT.Desktop.App.Windows;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
					[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
				
			||||||
public sealed partial class AboutWindow : Window {
 | 
					public sealed partial class AboutWindow : Window {
 | 
				
			||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
using System.Diagnostics;
 | 
					using System.Diagnostics;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Desktop.Main;
 | 
					namespace DHT.Desktop.App.Windows;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
sealed class AboutWindowModel {
 | 
					sealed class AboutWindowModel {
 | 
				
			||||||
	public void ShowOfficialWebsite() {
 | 
						public void ShowOfficialWebsite() {
 | 
				
			||||||
@@ -2,9 +2,9 @@
 | 
				
			|||||||
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
					        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
				
			||||||
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
					        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
				
			||||||
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
					        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
				
			||||||
        xmlns:main="clr-namespace:DHT.Desktop.Main"
 | 
					        xmlns:windows="clr-namespace:DHT.Desktop.App.Windows"
 | 
				
			||||||
        mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
 | 
					        mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
 | 
				
			||||||
        x:Class="DHT.Desktop.Main.MainWindow"
 | 
					        x:Class="DHT.Desktop.App.Windows.MainWindow"
 | 
				
			||||||
        Title="{Binding Title}"
 | 
					        Title="{Binding Title}"
 | 
				
			||||||
        Icon="avares://DiscordHistoryTracker/Resources/icon.ico"
 | 
					        Icon="avares://DiscordHistoryTracker/Resources/icon.ico"
 | 
				
			||||||
        Width="800" Height="500"
 | 
					        Width="800" Height="500"
 | 
				
			||||||
@@ -13,7 +13,7 @@
 | 
				
			|||||||
        Closed="OnClosed">
 | 
					        Closed="OnClosed">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <Design.DataContext>
 | 
					    <Design.DataContext>
 | 
				
			||||||
        <main:MainWindowModel />
 | 
					        <windows:MainWindowModel />
 | 
				
			||||||
    </Design.DataContext>
 | 
					    </Design.DataContext>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <Panel>
 | 
					    <Panel>
 | 
				
			||||||
@@ -1,11 +1,9 @@
 | 
				
			|||||||
using System;
 | 
					using System;
 | 
				
			||||||
using System.Diagnostics.CodeAnalysis;
 | 
					using System.Diagnostics.CodeAnalysis;
 | 
				
			||||||
using System.IO;
 | 
					 | 
				
			||||||
using Avalonia.Controls;
 | 
					using Avalonia.Controls;
 | 
				
			||||||
using DHT.Desktop.Main.Pages;
 | 
					 | 
				
			||||||
using JetBrains.Annotations;
 | 
					using JetBrains.Annotations;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Desktop.Main;
 | 
					namespace DHT.Desktop.App.Windows;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
					[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
				
			||||||
public sealed partial class MainWindow : Window {
 | 
					public sealed partial class MainWindow : Window {
 | 
				
			||||||
@@ -24,13 +22,5 @@ public sealed partial class MainWindow : Window {
 | 
				
			|||||||
		if (DataContext is IDisposable disposable) {
 | 
							if (DataContext is IDisposable disposable) {
 | 
				
			||||||
			disposable.Dispose();
 | 
								disposable.Dispose();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					 | 
				
			||||||
		foreach (var temporaryFile in ViewerPageModel.TemporaryFiles) {
 | 
					 | 
				
			||||||
			try {
 | 
					 | 
				
			||||||
				File.Delete(temporaryFile);
 | 
					 | 
				
			||||||
			} catch (Exception) {
 | 
					 | 
				
			||||||
				// ignored
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -4,13 +4,13 @@ using System.IO;
 | 
				
			|||||||
using System.Runtime.InteropServices;
 | 
					using System.Runtime.InteropServices;
 | 
				
			||||||
using System.Threading.Tasks;
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
using Avalonia.Controls;
 | 
					using Avalonia.Controls;
 | 
				
			||||||
using DHT.Desktop.Dialogs.Message;
 | 
					using DHT.Desktop.App.Dialogs.Message;
 | 
				
			||||||
using DHT.Desktop.Main.Screens;
 | 
					using DHT.Desktop.App.Screens;
 | 
				
			||||||
using DHT.Desktop.Server;
 | 
					using DHT.Desktop.Server;
 | 
				
			||||||
using DHT.Server.Database;
 | 
					using DHT.Server.Database;
 | 
				
			||||||
using DHT.Utils.Models;
 | 
					using DHT.Utils.Models;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Desktop.Main;
 | 
					namespace DHT.Desktop.App.Windows;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
sealed class MainWindowModel : BaseModel, IDisposable {
 | 
					sealed class MainWindowModel : BaseModel, IDisposable {
 | 
				
			||||||
	private const string DefaultTitle = "Discord History Tracker";
 | 
						private const string DefaultTitle = "Discord History Tracker";
 | 
				
			||||||
@@ -1,44 +1,67 @@
 | 
				
			|||||||
<Project Sdk="Microsoft.NET.Sdk">
 | 
					<Project Sdk="Microsoft.NET.Sdk">
 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  <PropertyGroup>
 | 
					 | 
				
			||||||
    <RootNamespace>DHT.Desktop</RootNamespace>
 | 
					 | 
				
			||||||
    <AssemblyName>DiscordHistoryTracker</AssemblyName>
 | 
					 | 
				
			||||||
    <PackageId>DiscordHistoryTracker</PackageId>
 | 
					 | 
				
			||||||
  </PropertyGroup>
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  <PropertyGroup>
 | 
					  <PropertyGroup>
 | 
				
			||||||
    <OutputType>WinExe</OutputType>
 | 
					    <OutputType>WinExe</OutputType>
 | 
				
			||||||
 | 
					    <Nullable>enable</Nullable>
 | 
				
			||||||
 | 
					    <AssemblyName>DiscordHistoryTracker</AssemblyName>
 | 
				
			||||||
 | 
					    <RootNamespace>DHT.Desktop</RootNamespace>
 | 
				
			||||||
 | 
					    <PackageId>DiscordHistoryTracker</PackageId>
 | 
				
			||||||
 | 
					    <Authors>chylex</Authors>
 | 
				
			||||||
 | 
					    <Company>DiscordHistoryTracker</Company>
 | 
				
			||||||
 | 
					    <Product>DiscordHistoryTracker</Product>
 | 
				
			||||||
    <ApplicationIcon>./Resources/icon.ico</ApplicationIcon>
 | 
					    <ApplicationIcon>./Resources/icon.ico</ApplicationIcon>
 | 
				
			||||||
    <CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
 | 
					    <CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
 | 
				
			||||||
    <SatelliteResourceLanguages>en</SatelliteResourceLanguages>
 | 
					    <SatelliteResourceLanguages>en</SatelliteResourceLanguages>
 | 
				
			||||||
 | 
					    <GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
 | 
				
			||||||
 | 
					    <GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
 | 
				
			||||||
 | 
					    <GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
 | 
				
			||||||
 | 
					  </PropertyGroup>
 | 
				
			||||||
 | 
					  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
 | 
				
			||||||
 | 
					    <DebugSymbols>true</DebugSymbols>
 | 
				
			||||||
 | 
					    <DebugType>none</DebugType>
 | 
				
			||||||
  </PropertyGroup>
 | 
					  </PropertyGroup>
 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  <ItemGroup>
 | 
					  <ItemGroup>
 | 
				
			||||||
    <PackageReference Include="Avalonia" Version="11.0.6" />
 | 
					    <PackageReference Include="Avalonia" Version="11.0.0" />
 | 
				
			||||||
    <PackageReference Include="Avalonia.Controls.DataGrid" Version="11.0.6" />
 | 
					    <PackageReference Include="Avalonia.Controls.DataGrid" Version="11.0.0" />
 | 
				
			||||||
    <PackageReference Include="Avalonia.Controls.ItemsRepeater" Version="11.0.6" />
 | 
					    <PackageReference Include="Avalonia.Controls.ItemsRepeater" Version="11.0.0" />
 | 
				
			||||||
    <PackageReference Include="Avalonia.Desktop" Version="11.0.6" />
 | 
					    <PackageReference Include="Avalonia.Desktop" Version="11.0.0" />
 | 
				
			||||||
    <PackageReference Include="Avalonia.Diagnostics" Version="11.0.6" Condition=" '$(Configuration)' == 'Debug' " />
 | 
					    <PackageReference Include="Avalonia.Diagnostics" Version="11.0.0" Condition=" '$(Configuration)' == 'Debug' " />
 | 
				
			||||||
    <PackageReference Include="Avalonia.Fonts.Inter" Version="11.0.6" />
 | 
					    <PackageReference Include="Avalonia.Fonts.Inter" Version="11.0.0" />
 | 
				
			||||||
    <PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.6" />
 | 
					    <PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.0" />
 | 
				
			||||||
  </ItemGroup>
 | 
					  </ItemGroup>
 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  <ItemGroup>
 | 
					  <ItemGroup>
 | 
				
			||||||
    <ProjectReference Include="..\Server\Server.csproj" />
 | 
					    <ProjectReference Include="..\Server\Server.csproj" />
 | 
				
			||||||
  </ItemGroup>
 | 
					  </ItemGroup>
 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  <ItemGroup>
 | 
					  <ItemGroup>
 | 
				
			||||||
    <Compile Include="..\Version.cs" Link="Version.cs" />
 | 
					    <Compile Include="..\Version.cs" Link="Version.cs" />
 | 
				
			||||||
    <Compile Update="Dialogs\TextBox\TextBoxDialog.axaml.cs">
 | 
					    <Compile Update="App\App.axaml.cs">
 | 
				
			||||||
      <DependentUpon>CheckBoxDialog.axaml</DependentUpon>
 | 
					      <DependentUpon>App.axaml</DependentUpon>
 | 
				
			||||||
 | 
					      <SubType>Code</SubType>
 | 
				
			||||||
 | 
					    </Compile>
 | 
				
			||||||
 | 
					    <Compile Update="App\Windows\AboutWindow.axaml.cs">
 | 
				
			||||||
 | 
					      <DependentUpon>AboutWindow.axaml</DependentUpon>
 | 
				
			||||||
 | 
					      <SubType>Code</SubType>
 | 
				
			||||||
 | 
					    </Compile>
 | 
				
			||||||
 | 
					    <Compile Update="App\Windows\MainWindow.axaml.cs">
 | 
				
			||||||
 | 
					      <DependentUpon>MainWindow.axaml</DependentUpon>
 | 
				
			||||||
      <SubType>Code</SubType>
 | 
					      <SubType>Code</SubType>
 | 
				
			||||||
    </Compile>
 | 
					    </Compile>
 | 
				
			||||||
  </ItemGroup>
 | 
					  </ItemGroup>
 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  <ItemGroup>
 | 
					  <ItemGroup>
 | 
				
			||||||
    <AvaloniaResource Include="Resources/icon.ico" />
 | 
					    <AvaloniaResource Include="Resources/icon.ico" />
 | 
				
			||||||
    <EmbeddedResource Include="Resources/tracker-loader.js">
 | 
					    <EmbeddedResource Include="../Resources/Tracker/bootstrap.js">
 | 
				
			||||||
      <LogicalName>tracker-loader.js</LogicalName>
 | 
					      <LogicalName>Tracker\%(RecursiveDir)%(Filename)%(Extension)</LogicalName>
 | 
				
			||||||
 | 
					      <Link>Resources/Tracker/%(RecursiveDir)%(Filename)%(Extension)</Link>
 | 
				
			||||||
 | 
					      <Visible>false</Visible>
 | 
				
			||||||
 | 
					    </EmbeddedResource>
 | 
				
			||||||
 | 
					    <EmbeddedResource Include="../Resources/Tracker/scripts/**" Condition=" '$(Configuration)' == 'Debug' ">
 | 
				
			||||||
 | 
					      <LogicalName>Tracker\scripts\%(RecursiveDir)%(Filename)%(Extension)</LogicalName>
 | 
				
			||||||
 | 
					      <Link>Resources/Tracker/scripts/%(RecursiveDir)%(Filename)%(Extension)</Link>
 | 
				
			||||||
 | 
					      <Visible>false</Visible>
 | 
				
			||||||
 | 
					    </EmbeddedResource>
 | 
				
			||||||
 | 
					    <EmbeddedResource Include="../Resources/Tracker/styles/**">
 | 
				
			||||||
 | 
					      <LogicalName>Tracker\styles\%(RecursiveDir)%(Filename)%(Extension)</LogicalName>
 | 
				
			||||||
 | 
					      <Link>Resources/Tracker/styles/%(RecursiveDir)%(Filename)%(Extension)</Link>
 | 
				
			||||||
 | 
					      <Visible>false</Visible>
 | 
				
			||||||
    </EmbeddedResource>
 | 
					    </EmbeddedResource>
 | 
				
			||||||
    <EmbeddedResource Include="../Resources/Viewer/**">
 | 
					    <EmbeddedResource Include="../Resources/Viewer/**">
 | 
				
			||||||
      <LogicalName>Viewer\%(RecursiveDir)%(Filename)%(Extension)</LogicalName>
 | 
					      <LogicalName>Viewer\%(RecursiveDir)%(Filename)%(Extension)</LogicalName>
 | 
				
			||||||
@@ -46,5 +69,39 @@
 | 
				
			|||||||
      <Visible>false</Visible>
 | 
					      <Visible>false</Visible>
 | 
				
			||||||
    </EmbeddedResource>
 | 
					    </EmbeddedResource>
 | 
				
			||||||
  </ItemGroup>
 | 
					  </ItemGroup>
 | 
				
			||||||
  
 | 
					  <ItemGroup>
 | 
				
			||||||
 | 
					    <AdditionalFiles Include="App\Controls\ServerConfigurationPanel.axaml" />
 | 
				
			||||||
 | 
					    <AdditionalFiles Include="App\Controls\StatusBar.axaml" />
 | 
				
			||||||
 | 
					    <AdditionalFiles Include="App\Dialogs\CheckBox\CheckBoxDialog.axaml" />
 | 
				
			||||||
 | 
					    <AdditionalFiles Include="App\Dialogs\Message\MessageDialog.axaml" />
 | 
				
			||||||
 | 
					    <AdditionalFiles Include="App\Dialogs\Progress\ProgressDialog.axaml" />
 | 
				
			||||||
 | 
					    <AdditionalFiles Include="App\Dialogs\TextBox\TextBoxDialog.axaml" />
 | 
				
			||||||
 | 
					    <AdditionalFiles Include="App\Pages\AdvancedPage.axaml" />
 | 
				
			||||||
 | 
					    <AdditionalFiles Include="App\Pages\DatabasePage.axaml" />
 | 
				
			||||||
 | 
					    <AdditionalFiles Include="App\Pages\TrackingPage.axaml" />
 | 
				
			||||||
 | 
					    <AdditionalFiles Include="App\Screens\MainContentScreen.axaml" />
 | 
				
			||||||
 | 
					    <AdditionalFiles Include="App\Screens\WelcomeScreen.axaml" />
 | 
				
			||||||
 | 
					  </ItemGroup>
 | 
				
			||||||
 | 
					  <ItemGroup>
 | 
				
			||||||
 | 
					    <UpToDateCheckInput Remove="Main\Pages\AdvancedPage.axaml" />
 | 
				
			||||||
 | 
					    <UpToDateCheckInput Remove="Main\Pages\DatabasePage.axaml" />
 | 
				
			||||||
 | 
					    <UpToDateCheckInput Remove="Main\Pages\TrackingPage.axaml" />
 | 
				
			||||||
 | 
					    <UpToDateCheckInput Remove="Main\Screens\MainContentScreen.axaml" />
 | 
				
			||||||
 | 
					    <UpToDateCheckInput Remove="Main\Screens\WelcomeScreen.axaml" />
 | 
				
			||||||
 | 
					  </ItemGroup>
 | 
				
			||||||
 | 
					  <Target Name="MinifyResources" BeforeTargets="PrepareForBuild" Condition=" '$(Configuration)' == 'Release' ">
 | 
				
			||||||
 | 
					    <PropertyGroup>
 | 
				
			||||||
 | 
					      <MinifiedResourceDir>$(ProjectDir)bin/.res/scripts</MinifiedResourceDir>
 | 
				
			||||||
 | 
					    </PropertyGroup>
 | 
				
			||||||
 | 
					    <ItemGroup>
 | 
				
			||||||
 | 
					      <UpToDateCheckInput Include="$(ProjectDir)../Resources/Tracker/scripts/**" Visible="false" />
 | 
				
			||||||
 | 
					      <EmbeddedResource Include="$(MinifiedResourceDir)/discord.js" LogicalName="Tracker\scripts\discord.js" Visible="false" />
 | 
				
			||||||
 | 
					      <EmbeddedResource Include="$(MinifiedResourceDir)/dom.js" LogicalName="Tracker\scripts\dom.js" Visible="false" />
 | 
				
			||||||
 | 
					      <EmbeddedResource Include="$(MinifiedResourceDir)/gui.js" LogicalName="Tracker\scripts\gui.js" Visible="false" />
 | 
				
			||||||
 | 
					      <EmbeddedResource Include="$(MinifiedResourceDir)/settings.js" LogicalName="Tracker\scripts\settings.js" Visible="false" />
 | 
				
			||||||
 | 
					      <EmbeddedResource Include="$(MinifiedResourceDir)/state.js" LogicalName="Tracker\scripts\state.js" Visible="false" />
 | 
				
			||||||
 | 
					    </ItemGroup>
 | 
				
			||||||
 | 
					    <RemoveDir Directories="$(ProjectDir)bin/.res/scripts" />
 | 
				
			||||||
 | 
					    <Exec Command="python $(ProjectDir)../Resources/minify.py" WorkingDirectory="$(ProjectDir)../Resources" IgnoreExitCode="false" />
 | 
				
			||||||
 | 
					  </Target>
 | 
				
			||||||
</Project>
 | 
					</Project>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -40,9 +40,7 @@ static class DiscordAppSettings {
 | 
				
			|||||||
	public static async Task<bool?> AreDevToolsEnabled() {
 | 
						public static async Task<bool?> AreDevToolsEnabled() {
 | 
				
			||||||
		try {
 | 
							try {
 | 
				
			||||||
			return AreDevToolsEnabled(await ReadSettingsJson());
 | 
								return AreDevToolsEnabled(await ReadSettingsJson());
 | 
				
			||||||
		} catch (Exception e) {
 | 
							} catch (Exception) {
 | 
				
			||||||
			Log.Error("Cannot read settings file.");
 | 
					 | 
				
			||||||
			Log.Error(e);
 | 
					 | 
				
			||||||
			return null;
 | 
								return null;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,51 +0,0 @@
 | 
				
			|||||||
<UserControl xmlns="https://github.com/avaloniaui"
 | 
					 | 
				
			||||||
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
					 | 
				
			||||||
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
					 | 
				
			||||||
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
					 | 
				
			||||||
             xmlns:controls="clr-namespace:DHT.Desktop.Main.Controls"
 | 
					 | 
				
			||||||
             mc:Ignorable="d"
 | 
					 | 
				
			||||||
             x:Class="DHT.Desktop.Main.Controls.AttachmentFilterPanel">
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    <Design.DataContext>
 | 
					 | 
				
			||||||
        <controls:AttachmentFilterPanelModel />
 | 
					 | 
				
			||||||
    </Design.DataContext>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    <UserControl.Styles>
 | 
					 | 
				
			||||||
        <Style Selector="WrapPanel > StackPanel">
 | 
					 | 
				
			||||||
            <Setter Property="Margin" Value="0 20 40 0" />
 | 
					 | 
				
			||||||
            <Setter Property="Spacing" Value="4" />
 | 
					 | 
				
			||||||
        </Style>
 | 
					 | 
				
			||||||
        <Style Selector="WrapPanel > StackPanel:nth-last-child(1)">
 | 
					 | 
				
			||||||
            <Setter Property="Margin" Value="0 20 0 0" />
 | 
					 | 
				
			||||||
        </Style>
 | 
					 | 
				
			||||||
        <Style Selector="Grid > Label">
 | 
					 | 
				
			||||||
            <Setter Property="VerticalAlignment" Value="Center" />
 | 
					 | 
				
			||||||
        </Style>
 | 
					 | 
				
			||||||
        <Style Selector="ComboBox">
 | 
					 | 
				
			||||||
            <Setter Property="Margin" Value="8 0 0 0" />
 | 
					 | 
				
			||||||
        </Style>
 | 
					 | 
				
			||||||
        <Style Selector="Button">
 | 
					 | 
				
			||||||
            <Setter Property="Margin" Value="0 0 0 8" />
 | 
					 | 
				
			||||||
        </Style>
 | 
					 | 
				
			||||||
    </UserControl.Styles>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    <StackPanel>
 | 
					 | 
				
			||||||
        <TextBlock Text="{Binding FilterStatisticsText}" />
 | 
					 | 
				
			||||||
        <WrapPanel>
 | 
					 | 
				
			||||||
            <StackPanel>
 | 
					 | 
				
			||||||
                <CheckBox IsChecked="{Binding LimitSize}">Limit Size</CheckBox>
 | 
					 | 
				
			||||||
                <StackPanel Orientation="Horizontal">
 | 
					 | 
				
			||||||
                    <TextBox Text="{Binding MaximumSize}" IsEnabled="{Binding LimitSize}" HorizontalContentAlignment="Right" />
 | 
					 | 
				
			||||||
                    <ComboBox IsEnabled="{Binding LimitSize}" ItemsSource="{Binding Units}" SelectedItem="{Binding MaximumSizeUnit}">
 | 
					 | 
				
			||||||
                        <ComboBox.ItemTemplate>
 | 
					 | 
				
			||||||
                            <DataTemplate>
 | 
					 | 
				
			||||||
                                <TextBlock Text="{Binding Name}" />
 | 
					 | 
				
			||||||
                            </DataTemplate>
 | 
					 | 
				
			||||||
                        </ComboBox.ItemTemplate>
 | 
					 | 
				
			||||||
                    </ComboBox>
 | 
					 | 
				
			||||||
                </StackPanel>
 | 
					 | 
				
			||||||
            </StackPanel>
 | 
					 | 
				
			||||||
        </WrapPanel>
 | 
					 | 
				
			||||||
    </StackPanel>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
</UserControl>
 | 
					 | 
				
			||||||
@@ -1,11 +0,0 @@
 | 
				
			|||||||
using System.Diagnostics.CodeAnalysis;
 | 
					 | 
				
			||||||
using Avalonia.Controls;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace DHT.Desktop.Main.Controls;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
					 | 
				
			||||||
public sealed partial class AttachmentFilterPanel : UserControl {
 | 
					 | 
				
			||||||
	public AttachmentFilterPanel() {
 | 
					 | 
				
			||||||
		InitializeComponent();
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,129 +0,0 @@
 | 
				
			|||||||
using System;
 | 
					 | 
				
			||||||
using System.Collections.Generic;
 | 
					 | 
				
			||||||
using System.ComponentModel;
 | 
					 | 
				
			||||||
using DHT.Desktop.Common;
 | 
					 | 
				
			||||||
using DHT.Server.Data.Filters;
 | 
					 | 
				
			||||||
using DHT.Server.Database;
 | 
					 | 
				
			||||||
using DHT.Utils.Models;
 | 
					 | 
				
			||||||
using DHT.Utils.Tasks;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace DHT.Desktop.Main.Controls;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
sealed class AttachmentFilterPanelModel : BaseModel, IDisposable {
 | 
					 | 
				
			||||||
	public sealed record Unit(string Name, uint Scale);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private static readonly Unit[] AllUnits = {
 | 
					 | 
				
			||||||
		new ("B", 1),
 | 
					 | 
				
			||||||
		new ("kB", 1024),
 | 
					 | 
				
			||||||
		new ("MB", 1024 * 1024)
 | 
					 | 
				
			||||||
	};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private static readonly HashSet<string> FilterProperties = new () {
 | 
					 | 
				
			||||||
		nameof(LimitSize),
 | 
					 | 
				
			||||||
		nameof(MaximumSize),
 | 
					 | 
				
			||||||
		nameof(MaximumSizeUnit)
 | 
					 | 
				
			||||||
	};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public string FilterStatisticsText { get; private set; } = "";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private bool limitSize = false;
 | 
					 | 
				
			||||||
	private ulong maximumSize = 0L;
 | 
					 | 
				
			||||||
	private Unit maximumSizeUnit = AllUnits[0];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public bool LimitSize {
 | 
					 | 
				
			||||||
		get => limitSize;
 | 
					 | 
				
			||||||
		set => Change(ref limitSize, value);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public ulong MaximumSize {
 | 
					 | 
				
			||||||
		get => maximumSize;
 | 
					 | 
				
			||||||
		set => Change(ref maximumSize, value);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public Unit MaximumSizeUnit {
 | 
					 | 
				
			||||||
		get => maximumSizeUnit;
 | 
					 | 
				
			||||||
		set => Change(ref maximumSizeUnit, value);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public IEnumerable<Unit> Units => AllUnits;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private readonly IDatabaseFile db;
 | 
					 | 
				
			||||||
	private readonly string verb;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private readonly AsyncValueComputer<long> matchingAttachmentCountComputer;
 | 
					 | 
				
			||||||
	private long? matchingAttachmentCount;
 | 
					 | 
				
			||||||
	private long? totalAttachmentCount;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	[Obsolete("Designer")]
 | 
					 | 
				
			||||||
	public AttachmentFilterPanelModel() : this(DummyDatabaseFile.Instance) {}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public AttachmentFilterPanelModel(IDatabaseFile db, string verb = "Matches") {
 | 
					 | 
				
			||||||
		this.db = db;
 | 
					 | 
				
			||||||
		this.verb = verb;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		this.matchingAttachmentCountComputer = AsyncValueComputer<long>.WithResultProcessor(SetAttachmentCounts).Build();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		UpdateFilterStatistics();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		PropertyChanged += OnPropertyChanged;
 | 
					 | 
				
			||||||
		db.Statistics.PropertyChanged += OnDbStatisticsChanged;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public void Dispose() {
 | 
					 | 
				
			||||||
		db.Statistics.PropertyChanged -= OnDbStatisticsChanged;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private void OnPropertyChanged(object? sender, PropertyChangedEventArgs e) {
 | 
					 | 
				
			||||||
		if (e.PropertyName != null && FilterProperties.Contains(e.PropertyName)) {
 | 
					 | 
				
			||||||
			UpdateFilterStatistics();
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private void OnDbStatisticsChanged(object? sender, PropertyChangedEventArgs e) {
 | 
					 | 
				
			||||||
		if (e.PropertyName == nameof(DatabaseStatistics.TotalAttachments)) {
 | 
					 | 
				
			||||||
			totalAttachmentCount = db.Statistics.TotalAttachments;
 | 
					 | 
				
			||||||
			UpdateFilterStatistics();
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private void UpdateFilterStatistics() {
 | 
					 | 
				
			||||||
		var filter = CreateFilter();
 | 
					 | 
				
			||||||
		if (filter.IsEmpty) {
 | 
					 | 
				
			||||||
			matchingAttachmentCountComputer.Cancel();
 | 
					 | 
				
			||||||
			matchingAttachmentCount = totalAttachmentCount;
 | 
					 | 
				
			||||||
			UpdateFilterStatisticsText();
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		else {
 | 
					 | 
				
			||||||
			matchingAttachmentCount = null;
 | 
					 | 
				
			||||||
			UpdateFilterStatisticsText();
 | 
					 | 
				
			||||||
			matchingAttachmentCountComputer.Compute(() => db.CountAttachments(filter));
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private void SetAttachmentCounts(long matchingAttachmentCount) {
 | 
					 | 
				
			||||||
		this.matchingAttachmentCount = matchingAttachmentCount;
 | 
					 | 
				
			||||||
		UpdateFilterStatisticsText();
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private void UpdateFilterStatisticsText() {
 | 
					 | 
				
			||||||
		var matchingAttachmentCountStr = matchingAttachmentCount?.Format() ?? "(...)";
 | 
					 | 
				
			||||||
		var totalAttachmentCountStr = totalAttachmentCount?.Format() ?? "(...)";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		FilterStatisticsText = verb + " " + matchingAttachmentCountStr + " out of " + totalAttachmentCountStr + " attachment" + (totalAttachmentCount is null or 1 ? "." : "s.");
 | 
					 | 
				
			||||||
		OnPropertyChanged(nameof(FilterStatisticsText));
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public AttachmentFilter CreateFilter() {
 | 
					 | 
				
			||||||
		AttachmentFilter filter = new();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if (LimitSize) {
 | 
					 | 
				
			||||||
			try {
 | 
					 | 
				
			||||||
				filter.MaxBytes = maximumSize * maximumSizeUnit.Scale;
 | 
					 | 
				
			||||||
			} catch (ArithmeticException) {
 | 
					 | 
				
			||||||
				// set no size limit, because the overflown size is larger than any file could possibly be
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		return filter;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,63 +0,0 @@
 | 
				
			|||||||
<UserControl xmlns="https://github.com/avaloniaui"
 | 
					 | 
				
			||||||
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
					 | 
				
			||||||
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
					 | 
				
			||||||
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
					 | 
				
			||||||
             xmlns:controls="clr-namespace:DHT.Desktop.Main.Controls"
 | 
					 | 
				
			||||||
             mc:Ignorable="d"
 | 
					 | 
				
			||||||
             x:Class="DHT.Desktop.Main.Controls.MessageFilterPanel">
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    <Design.DataContext>
 | 
					 | 
				
			||||||
        <controls:MessageFilterPanelModel />
 | 
					 | 
				
			||||||
    </Design.DataContext>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    <UserControl.Styles>
 | 
					 | 
				
			||||||
        <Style Selector="WrapPanel > StackPanel">
 | 
					 | 
				
			||||||
            <Setter Property="Margin" Value="0 20 40 0" />
 | 
					 | 
				
			||||||
            <Setter Property="Spacing" Value="4" />
 | 
					 | 
				
			||||||
        </Style>
 | 
					 | 
				
			||||||
        <Style Selector="WrapPanel > StackPanel:nth-last-child(1)">
 | 
					 | 
				
			||||||
            <Setter Property="Margin" Value="0 20 0 0" />
 | 
					 | 
				
			||||||
        </Style>
 | 
					 | 
				
			||||||
        <Style Selector="Grid > Label">
 | 
					 | 
				
			||||||
            <Setter Property="VerticalAlignment" Value="Center" />
 | 
					 | 
				
			||||||
        </Style>
 | 
					 | 
				
			||||||
        <Style Selector="Grid > CalendarDatePicker">
 | 
					 | 
				
			||||||
            <Setter Property="CornerRadius" Value="0" />
 | 
					 | 
				
			||||||
            <Setter Property="HorizontalAlignment" Value="Stretch" />
 | 
					 | 
				
			||||||
            <Setter Property="HorizontalContentAlignment" Value="Center" />
 | 
					 | 
				
			||||||
            <Setter Property="VerticalAlignment" Value="Center" />
 | 
					 | 
				
			||||||
            <Setter Property="VerticalContentAlignment" Value="Center" />
 | 
					 | 
				
			||||||
            <Setter Property="IsTodayHighlighted" Value="True" />
 | 
					 | 
				
			||||||
            <Setter Property="SelectedDateFormat" Value="Short" />
 | 
					 | 
				
			||||||
        </Style>
 | 
					 | 
				
			||||||
        <Style Selector="Button">
 | 
					 | 
				
			||||||
            <Setter Property="Margin" Value="0 0 0 8" />
 | 
					 | 
				
			||||||
        </Style>
 | 
					 | 
				
			||||||
    </UserControl.Styles>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    <StackPanel>
 | 
					 | 
				
			||||||
        <TextBlock Text="{Binding FilterStatisticsText}" />
 | 
					 | 
				
			||||||
        <WrapPanel>
 | 
					 | 
				
			||||||
            <StackPanel>
 | 
					 | 
				
			||||||
                <CheckBox IsChecked="{Binding FilterByDate}">Filter by Date</CheckBox>
 | 
					 | 
				
			||||||
                <Grid ColumnDefinitions="Auto, 4, 125" RowDefinitions="Auto, 4, Auto" Margin="4 0">
 | 
					 | 
				
			||||||
                    <Label Grid.Row="0" Grid.Column="0">From:</Label>
 | 
					 | 
				
			||||||
                    <CalendarDatePicker Grid.Row="0" Grid.Column="2" x:Name="StartDatePicker" IsEnabled="{Binding FilterByDate}" SelectedDateChanged="CalendarDatePicker_OnSelectedDateChanged" />
 | 
					 | 
				
			||||||
                    <Label Grid.Row="2" Grid.Column="0">To:</Label>
 | 
					 | 
				
			||||||
                    <CalendarDatePicker Grid.Row="2" Grid.Column="2" x:Name="EndDatePicker" IsEnabled="{Binding FilterByDate}" SelectedDateChanged="CalendarDatePicker_OnSelectedDateChanged" />
 | 
					 | 
				
			||||||
                </Grid>
 | 
					 | 
				
			||||||
            </StackPanel>
 | 
					 | 
				
			||||||
            <StackPanel>
 | 
					 | 
				
			||||||
                <CheckBox IsChecked="{Binding FilterByChannel}">Filter by Channel</CheckBox>
 | 
					 | 
				
			||||||
                <Button Command="{Binding OpenChannelFilterDialog}" IsEnabled="{Binding FilterByChannel}">Select Channels...</Button>
 | 
					 | 
				
			||||||
                <TextBlock Text="{Binding ChannelFilterLabel}" />
 | 
					 | 
				
			||||||
            </StackPanel>
 | 
					 | 
				
			||||||
            <StackPanel>
 | 
					 | 
				
			||||||
                <CheckBox IsChecked="{Binding FilterByUser}">Filter by User</CheckBox>
 | 
					 | 
				
			||||||
                <Button Command="{Binding OpenUserFilterDialog}" IsEnabled="{Binding FilterByUser}">Select Users...</Button>
 | 
					 | 
				
			||||||
                <TextBlock Text="{Binding UserFilterLabel}" />
 | 
					 | 
				
			||||||
            </StackPanel>
 | 
					 | 
				
			||||||
        </WrapPanel>
 | 
					 | 
				
			||||||
    </StackPanel>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
</UserControl>
 | 
					 | 
				
			||||||
@@ -1,26 +0,0 @@
 | 
				
			|||||||
using System.Diagnostics.CodeAnalysis;
 | 
					 | 
				
			||||||
using Avalonia.Controls;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace DHT.Desktop.Main.Controls;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
					 | 
				
			||||||
public sealed partial class MessageFilterPanel : UserControl {
 | 
					 | 
				
			||||||
	public MessageFilterPanel() {
 | 
					 | 
				
			||||||
		InitializeComponent();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		var culture = Program.Culture;
 | 
					 | 
				
			||||||
		foreach (var picker in new CalendarDatePicker[] { StartDatePicker, EndDatePicker }) {
 | 
					 | 
				
			||||||
			picker.FirstDayOfWeek = culture.DateTimeFormat.FirstDayOfWeek;
 | 
					 | 
				
			||||||
			picker.SelectedDateFormat = CalendarDatePickerFormat.Custom;
 | 
					 | 
				
			||||||
			picker.CustomDateFormatString = culture.DateTimeFormat.ShortDatePattern;
 | 
					 | 
				
			||||||
			picker.Watermark = culture.DateTimeFormat.ShortDatePattern;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public void CalendarDatePicker_OnSelectedDateChanged(object? sender, SelectionChangedEventArgs e) {
 | 
					 | 
				
			||||||
		if (DataContext is MessageFilterPanelModel model) {
 | 
					 | 
				
			||||||
			model.StartDate = StartDatePicker.SelectedDate;
 | 
					 | 
				
			||||||
			model.EndDate = EndDatePicker.SelectedDate;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,285 +0,0 @@
 | 
				
			|||||||
using System;
 | 
					 | 
				
			||||||
using System.Collections.Generic;
 | 
					 | 
				
			||||||
using System.ComponentModel;
 | 
					 | 
				
			||||||
using System.Linq;
 | 
					 | 
				
			||||||
using System.Text;
 | 
					 | 
				
			||||||
using System.Threading.Tasks;
 | 
					 | 
				
			||||||
using Avalonia.Controls;
 | 
					 | 
				
			||||||
using DHT.Desktop.Common;
 | 
					 | 
				
			||||||
using DHT.Desktop.Dialogs.CheckBox;
 | 
					 | 
				
			||||||
using DHT.Desktop.Dialogs.Message;
 | 
					 | 
				
			||||||
using DHT.Server.Data;
 | 
					 | 
				
			||||||
using DHT.Server.Data.Filters;
 | 
					 | 
				
			||||||
using DHT.Server.Database;
 | 
					 | 
				
			||||||
using DHT.Utils.Models;
 | 
					 | 
				
			||||||
using DHT.Utils.Tasks;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace DHT.Desktop.Main.Controls;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
sealed class MessageFilterPanelModel : BaseModel, IDisposable {
 | 
					 | 
				
			||||||
	private static readonly HashSet<string> FilterProperties = new () {
 | 
					 | 
				
			||||||
		nameof(FilterByDate),
 | 
					 | 
				
			||||||
		nameof(StartDate),
 | 
					 | 
				
			||||||
		nameof(EndDate),
 | 
					 | 
				
			||||||
		nameof(FilterByChannel),
 | 
					 | 
				
			||||||
		nameof(IncludedChannels),
 | 
					 | 
				
			||||||
		nameof(FilterByUser),
 | 
					 | 
				
			||||||
		nameof(IncludedUsers)
 | 
					 | 
				
			||||||
	};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public string FilterStatisticsText { get; private set; } = "";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public event PropertyChangedEventHandler? FilterPropertyChanged;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public bool HasAnyFilters => FilterByDate || FilterByChannel || FilterByUser;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private bool filterByDate = false;
 | 
					 | 
				
			||||||
	private DateTime? startDate = null;
 | 
					 | 
				
			||||||
	private DateTime? endDate = null;
 | 
					 | 
				
			||||||
	private bool filterByChannel = false;
 | 
					 | 
				
			||||||
	private HashSet<ulong>? includedChannels = null;
 | 
					 | 
				
			||||||
	private bool filterByUser = false;
 | 
					 | 
				
			||||||
	private HashSet<ulong>? includedUsers = null;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public bool FilterByDate {
 | 
					 | 
				
			||||||
		get => filterByDate;
 | 
					 | 
				
			||||||
		set => Change(ref filterByDate, value);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public DateTime? StartDate {
 | 
					 | 
				
			||||||
		get => startDate;
 | 
					 | 
				
			||||||
		set => Change(ref startDate, value);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public DateTime? EndDate {
 | 
					 | 
				
			||||||
		get => endDate;
 | 
					 | 
				
			||||||
		set => Change(ref endDate, value);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public bool FilterByChannel {
 | 
					 | 
				
			||||||
		get => filterByChannel;
 | 
					 | 
				
			||||||
		set => Change(ref filterByChannel, value);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public HashSet<ulong> IncludedChannels {
 | 
					 | 
				
			||||||
		get => includedChannels ?? db.GetAllChannels().Select(static channel => channel.Id).ToHashSet();
 | 
					 | 
				
			||||||
		set => Change(ref includedChannels, value);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public bool FilterByUser {
 | 
					 | 
				
			||||||
		get => filterByUser;
 | 
					 | 
				
			||||||
		set => Change(ref filterByUser, value);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public HashSet<ulong> IncludedUsers {
 | 
					 | 
				
			||||||
		get => includedUsers ?? db.GetAllUsers().Select(static user => user.Id).ToHashSet();
 | 
					 | 
				
			||||||
		set => Change(ref includedUsers, value);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private string channelFilterLabel = "";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public string ChannelFilterLabel {
 | 
					 | 
				
			||||||
		get => channelFilterLabel;
 | 
					 | 
				
			||||||
		set => Change(ref channelFilterLabel, value);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private string userFilterLabel = "";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public string UserFilterLabel {
 | 
					 | 
				
			||||||
		get => userFilterLabel;
 | 
					 | 
				
			||||||
		set => Change(ref userFilterLabel, value);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private readonly Window window;
 | 
					 | 
				
			||||||
	private readonly IDatabaseFile db;
 | 
					 | 
				
			||||||
	private readonly string verb;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private readonly AsyncValueComputer<long> exportedMessageCountComputer;
 | 
					 | 
				
			||||||
	private long? exportedMessageCount;
 | 
					 | 
				
			||||||
	private long? totalMessageCount;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	[Obsolete("Designer")]
 | 
					 | 
				
			||||||
	public MessageFilterPanelModel() : this(null!, DummyDatabaseFile.Instance) {}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public MessageFilterPanelModel(Window window, IDatabaseFile db, string verb = "Matches") {
 | 
					 | 
				
			||||||
		this.window = window;
 | 
					 | 
				
			||||||
		this.db = db;
 | 
					 | 
				
			||||||
		this.verb = verb;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		this.exportedMessageCountComputer = AsyncValueComputer<long>.WithResultProcessor(SetExportedMessageCount).Build();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		UpdateFilterStatistics();
 | 
					 | 
				
			||||||
		UpdateChannelFilterLabel();
 | 
					 | 
				
			||||||
		UpdateUserFilterLabel();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		PropertyChanged += OnPropertyChanged;
 | 
					 | 
				
			||||||
		db.Statistics.PropertyChanged += OnDbStatisticsChanged;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public void Dispose() {
 | 
					 | 
				
			||||||
		db.Statistics.PropertyChanged -= OnDbStatisticsChanged;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private void OnPropertyChanged(object? sender, PropertyChangedEventArgs e) {
 | 
					 | 
				
			||||||
		if (e.PropertyName != null && FilterProperties.Contains(e.PropertyName)) {
 | 
					 | 
				
			||||||
			UpdateFilterStatistics();
 | 
					 | 
				
			||||||
			FilterPropertyChanged?.Invoke(sender, e);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if (e.PropertyName is nameof(FilterByChannel) or nameof(IncludedChannels)) {
 | 
					 | 
				
			||||||
			UpdateChannelFilterLabel();
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		else if (e.PropertyName is nameof(FilterByUser) or nameof(IncludedUsers)) {
 | 
					 | 
				
			||||||
			UpdateUserFilterLabel();
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private void OnDbStatisticsChanged(object? sender, PropertyChangedEventArgs e) {
 | 
					 | 
				
			||||||
		if (e.PropertyName == nameof(DatabaseStatistics.TotalMessages)) {
 | 
					 | 
				
			||||||
			totalMessageCount = db.Statistics.TotalMessages;
 | 
					 | 
				
			||||||
			UpdateFilterStatistics();
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		else if (e.PropertyName == nameof(DatabaseStatistics.TotalChannels)) {
 | 
					 | 
				
			||||||
			UpdateChannelFilterLabel();
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		else if (e.PropertyName == nameof(DatabaseStatistics.TotalUsers)) {
 | 
					 | 
				
			||||||
			UpdateUserFilterLabel();
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private void UpdateFilterStatistics() {
 | 
					 | 
				
			||||||
		var filter = CreateFilter();
 | 
					 | 
				
			||||||
		if (filter.IsEmpty) {
 | 
					 | 
				
			||||||
			exportedMessageCountComputer.Cancel();
 | 
					 | 
				
			||||||
			exportedMessageCount = totalMessageCount;
 | 
					 | 
				
			||||||
			UpdateFilterStatisticsText();
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		else {
 | 
					 | 
				
			||||||
			exportedMessageCount = null;
 | 
					 | 
				
			||||||
			UpdateFilterStatisticsText();
 | 
					 | 
				
			||||||
			exportedMessageCountComputer.Compute(() => db.CountMessages(filter));
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private void SetExportedMessageCount(long exportedMessageCount) {
 | 
					 | 
				
			||||||
		this.exportedMessageCount = exportedMessageCount;
 | 
					 | 
				
			||||||
		UpdateFilterStatisticsText();
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private void UpdateFilterStatisticsText() {
 | 
					 | 
				
			||||||
		var exportedMessageCountStr = exportedMessageCount?.Format() ?? "(...)";
 | 
					 | 
				
			||||||
		var totalMessageCountStr = totalMessageCount?.Format() ?? "(...)";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		FilterStatisticsText = verb + " " + exportedMessageCountStr + " out of " + totalMessageCountStr + " message" + (totalMessageCount is null or 1 ? "." : "s.");
 | 
					 | 
				
			||||||
		OnPropertyChanged(nameof(FilterStatisticsText));
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public async void OpenChannelFilterDialog() {
 | 
					 | 
				
			||||||
		var servers = db.GetAllServers().ToDictionary(static server => server.Id);
 | 
					 | 
				
			||||||
		var items = new List<CheckBoxItem<ulong>>();
 | 
					 | 
				
			||||||
		var included = IncludedChannels;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		foreach (var channel in db.GetAllChannels()) {
 | 
					 | 
				
			||||||
			var channelId = channel.Id;
 | 
					 | 
				
			||||||
			var channelName = channel.Name;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			string title;
 | 
					 | 
				
			||||||
			if (servers.TryGetValue(channel.Server, out var server)) {
 | 
					 | 
				
			||||||
				var titleBuilder = new StringBuilder();
 | 
					 | 
				
			||||||
				var serverType = server.Type;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				titleBuilder.Append('[')
 | 
					 | 
				
			||||||
				            .Append(ServerTypes.ToString(serverType))
 | 
					 | 
				
			||||||
				            .Append("] ");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				if (serverType == ServerType.DirectMessage) {
 | 
					 | 
				
			||||||
					titleBuilder.Append(channelName);
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
				else {
 | 
					 | 
				
			||||||
					titleBuilder.Append(server.Name)
 | 
					 | 
				
			||||||
					            .Append(" - ")
 | 
					 | 
				
			||||||
					            .Append(channelName);
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				title = titleBuilder.ToString();
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			else {
 | 
					 | 
				
			||||||
				title = channelName;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			items.Add(new CheckBoxItem<ulong>(channelId) {
 | 
					 | 
				
			||||||
				Title = title,
 | 
					 | 
				
			||||||
				Checked = included.Contains(channelId)
 | 
					 | 
				
			||||||
			});
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		var result = await OpenIdFilterDialog(window, "Included Channels", items);
 | 
					 | 
				
			||||||
		if (result != null) {
 | 
					 | 
				
			||||||
			IncludedChannels = result;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public async void OpenUserFilterDialog() {
 | 
					 | 
				
			||||||
		var items = new List<CheckBoxItem<ulong>>();
 | 
					 | 
				
			||||||
		var included = IncludedUsers;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		foreach (var user in db.GetAllUsers()) {
 | 
					 | 
				
			||||||
			var name = user.Name;
 | 
					 | 
				
			||||||
			var discriminator = user.Discriminator;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			items.Add(new CheckBoxItem<ulong>(user.Id) {
 | 
					 | 
				
			||||||
				Title = discriminator == null ? name : name + " #" + discriminator,
 | 
					 | 
				
			||||||
				Checked = included.Contains(user.Id)
 | 
					 | 
				
			||||||
			});
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		var result = await OpenIdFilterDialog(window, "Included Users", items);
 | 
					 | 
				
			||||||
		if (result != null) {
 | 
					 | 
				
			||||||
			IncludedUsers = result;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private void UpdateChannelFilterLabel() {
 | 
					 | 
				
			||||||
		long total = db.Statistics.TotalChannels;
 | 
					 | 
				
			||||||
		long included = FilterByChannel ? IncludedChannels.Count : total;
 | 
					 | 
				
			||||||
		ChannelFilterLabel = "Selected " + included.Format() + " / " + total.Pluralize("channel") + ".";
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private void UpdateUserFilterLabel() {
 | 
					 | 
				
			||||||
		long total = db.Statistics.TotalUsers;
 | 
					 | 
				
			||||||
		long included = FilterByUser ? IncludedUsers.Count : total;
 | 
					 | 
				
			||||||
		UserFilterLabel = "Selected " + included.Format() + " / " + total.Pluralize("user") + ".";
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public MessageFilter CreateFilter() {
 | 
					 | 
				
			||||||
		MessageFilter filter = new();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if (FilterByDate) {
 | 
					 | 
				
			||||||
			filter.StartDate = StartDate;
 | 
					 | 
				
			||||||
			filter.EndDate = EndDate?.AddDays(1).AddMilliseconds(-1);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if (FilterByChannel) {
 | 
					 | 
				
			||||||
			filter.ChannelIds = new HashSet<ulong>(IncludedChannels);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if (FilterByUser) {
 | 
					 | 
				
			||||||
			filter.UserIds = new HashSet<ulong>(IncludedUsers);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		return filter;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private static async Task<HashSet<ulong>?> OpenIdFilterDialog(Window window, string title, List<CheckBoxItem<ulong>> items) {
 | 
					 | 
				
			||||||
		items.Sort(static (item1, item2) => item1.Title.CompareTo(item2.Title));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		var model = new CheckBoxDialogModel<ulong>(items) {
 | 
					 | 
				
			||||||
			Title = title
 | 
					 | 
				
			||||||
		};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		var dialog = new CheckBoxDialog { DataContext = model };
 | 
					 | 
				
			||||||
		var result = await dialog.ShowDialog<DialogResult.OkCancel>(window);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		return result == DialogResult.OkCancel.Ok ? model.SelectedItems.Select(static item => item.Item).ToHashSet() : null;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,54 +0,0 @@
 | 
				
			|||||||
<UserControl xmlns="https://github.com/avaloniaui"
 | 
					 | 
				
			||||||
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
					 | 
				
			||||||
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
					 | 
				
			||||||
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
					 | 
				
			||||||
             xmlns:pages="clr-namespace:DHT.Desktop.Main.Pages"
 | 
					 | 
				
			||||||
             xmlns:controls="clr-namespace:DHT.Desktop.Main.Controls"
 | 
					 | 
				
			||||||
             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
 | 
					 | 
				
			||||||
             x:Class="DHT.Desktop.Main.Pages.AttachmentsPage">
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    <Design.DataContext>
 | 
					 | 
				
			||||||
        <pages:AttachmentsPageModel />
 | 
					 | 
				
			||||||
    </Design.DataContext>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    <UserControl.Styles>
 | 
					 | 
				
			||||||
        <Style Selector="Expander">
 | 
					 | 
				
			||||||
            <Setter Property="Margin" Value="0 5 0 0" />
 | 
					 | 
				
			||||||
        </Style>
 | 
					 | 
				
			||||||
        <Style Selector="DataGridColumnHeader">
 | 
					 | 
				
			||||||
            <Setter Property="FontWeight" Value="Medium" />
 | 
					 | 
				
			||||||
        </Style>
 | 
					 | 
				
			||||||
        <Style Selector="DataGridColumnHeader:nth-child(2)">
 | 
					 | 
				
			||||||
            <Setter Property="HorizontalContentAlignment" Value="Right" />
 | 
					 | 
				
			||||||
        </Style>
 | 
					 | 
				
			||||||
        <Style Selector="DataGridColumnHeader:nth-child(3)">
 | 
					 | 
				
			||||||
            <Setter Property="HorizontalContentAlignment" Value="Right" />
 | 
					 | 
				
			||||||
        </Style>
 | 
					 | 
				
			||||||
        <Style Selector="DataGridCell.right">
 | 
					 | 
				
			||||||
            <Setter Property="HorizontalContentAlignment" Value="Right" />
 | 
					 | 
				
			||||||
        </Style>
 | 
					 | 
				
			||||||
    </UserControl.Styles>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    <StackPanel Orientation="Vertical" Spacing="20">
 | 
					 | 
				
			||||||
        <DockPanel>
 | 
					 | 
				
			||||||
            <Button Command="{Binding OnClickToggleDownload}" Content="{Binding ToggleDownloadButtonText}" IsEnabled="{Binding IsToggleDownloadButtonEnabled}" DockPanel.Dock="Left" />
 | 
					 | 
				
			||||||
            <TextBlock Text="{Binding DownloadMessage}" Margin="10 0 0 0" VerticalAlignment="Center" DockPanel.Dock="Left" />
 | 
					 | 
				
			||||||
            <ProgressBar Value="{Binding DownloadProgress}" IsVisible="{Binding IsDownloading}" Margin="15 0" VerticalAlignment="Center" DockPanel.Dock="Right" />
 | 
					 | 
				
			||||||
        </DockPanel>
 | 
					 | 
				
			||||||
        <controls:AttachmentFilterPanel DataContext="{Binding FilterModel}" IsEnabled="{Binding !DataContext.IsDownloading, RelativeSource={RelativeSource AncestorType=UserControl}}" />
 | 
					 | 
				
			||||||
        <StackPanel Orientation="Vertical" Spacing="12">
 | 
					 | 
				
			||||||
            <Expander Header="Download Status" IsExpanded="True">
 | 
					 | 
				
			||||||
                <DataGrid ItemsSource="{Binding StatisticsRows}" AutoGenerateColumns="False" CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserSortColumns="False" IsReadOnly="True">
 | 
					 | 
				
			||||||
                    <DataGrid.Columns>
 | 
					 | 
				
			||||||
                        <DataGridTextColumn Header="State" Binding="{Binding State}" Width="*" />
 | 
					 | 
				
			||||||
                        <DataGridTextColumn Header="Attachments" Binding="{Binding Items, Converter={StaticResource NumberValueConverter}}" Width="*" CellStyleClasses="right" />
 | 
					 | 
				
			||||||
                        <DataGridTextColumn Header="Size" Binding="{Binding Size, Converter={StaticResource BytesValueConverter}}" Width="*" CellStyleClasses="right" />
 | 
					 | 
				
			||||||
                    </DataGrid.Columns>
 | 
					 | 
				
			||||||
                </DataGrid>
 | 
					 | 
				
			||||||
            </Expander>
 | 
					 | 
				
			||||||
            <StackPanel Orientation="Horizontal" Spacing="10">
 | 
					 | 
				
			||||||
                <Button Command="{Binding OnClickRetryFailedDownloads}" IsEnabled="{Binding HasFailedDownloads}">Retry Failed Downloads</Button>
 | 
					 | 
				
			||||||
            </StackPanel>
 | 
					 | 
				
			||||||
        </StackPanel>
 | 
					 | 
				
			||||||
    </StackPanel>
 | 
					 | 
				
			||||||
</UserControl>
 | 
					 | 
				
			||||||
@@ -1,11 +0,0 @@
 | 
				
			|||||||
using System.Diagnostics.CodeAnalysis;
 | 
					 | 
				
			||||||
using Avalonia.Controls;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace DHT.Desktop.Main.Pages;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
					 | 
				
			||||||
public sealed partial class AttachmentsPage : UserControl {
 | 
					 | 
				
			||||||
	public AttachmentsPage() {
 | 
					 | 
				
			||||||
		InitializeComponent();
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,205 +0,0 @@
 | 
				
			|||||||
using System;
 | 
					 | 
				
			||||||
using System.Collections.Generic;
 | 
					 | 
				
			||||||
using System.ComponentModel;
 | 
					 | 
				
			||||||
using System.Threading;
 | 
					 | 
				
			||||||
using Avalonia.Threading;
 | 
					 | 
				
			||||||
using DHT.Desktop.Common;
 | 
					 | 
				
			||||||
using DHT.Desktop.Main.Controls;
 | 
					 | 
				
			||||||
using DHT.Server.Data;
 | 
					 | 
				
			||||||
using DHT.Server.Data.Aggregations;
 | 
					 | 
				
			||||||
using DHT.Server.Data.Filters;
 | 
					 | 
				
			||||||
using DHT.Server.Database;
 | 
					 | 
				
			||||||
using DHT.Server.Download;
 | 
					 | 
				
			||||||
using DHT.Utils.Models;
 | 
					 | 
				
			||||||
using DHT.Utils.Tasks;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace DHT.Desktop.Main.Pages;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
sealed class AttachmentsPageModel : BaseModel, IDisposable {
 | 
					 | 
				
			||||||
	private static readonly DownloadItemFilter EnqueuedItemFilter = new() {
 | 
					 | 
				
			||||||
		IncludeStatuses = new HashSet<DownloadStatus> {
 | 
					 | 
				
			||||||
			DownloadStatus.Enqueued
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private bool isThreadDownloadButtonEnabled = true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public string ToggleDownloadButtonText => downloadThread == null ? "Start Downloading" : "Stop Downloading";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public bool IsToggleDownloadButtonEnabled {
 | 
					 | 
				
			||||||
		get => isThreadDownloadButtonEnabled;
 | 
					 | 
				
			||||||
		set => Change(ref isThreadDownloadButtonEnabled, value);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public string DownloadMessage { get; set; } = "";
 | 
					 | 
				
			||||||
	public double DownloadProgress => allItemsCount is null or 0 ? 0.0 : 100.0 * doneItemsCount / allItemsCount.Value;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public AttachmentFilterPanelModel FilterModel { get; }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private readonly StatisticsRow statisticsEnqueued = new ("Enqueued");
 | 
					 | 
				
			||||||
	private readonly StatisticsRow statisticsDownloaded = new ("Downloaded");
 | 
					 | 
				
			||||||
	private readonly StatisticsRow statisticsFailed = new ("Failed");
 | 
					 | 
				
			||||||
	private readonly StatisticsRow statisticsSkipped = new ("Skipped");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public List<StatisticsRow> StatisticsRows {
 | 
					 | 
				
			||||||
		get {
 | 
					 | 
				
			||||||
			return new List<StatisticsRow> {
 | 
					 | 
				
			||||||
				statisticsEnqueued,
 | 
					 | 
				
			||||||
				statisticsDownloaded,
 | 
					 | 
				
			||||||
				statisticsFailed,
 | 
					 | 
				
			||||||
				statisticsSkipped
 | 
					 | 
				
			||||||
			};
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public bool IsDownloading => downloadThread != null;
 | 
					 | 
				
			||||||
	public bool HasFailedDownloads => statisticsFailed.Items > 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private readonly IDatabaseFile db;
 | 
					 | 
				
			||||||
	private readonly AsyncValueComputer<DownloadStatusStatistics>.Single downloadStatisticsComputer;
 | 
					 | 
				
			||||||
	private BackgroundDownloadThread? downloadThread;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private int doneItemsCount;
 | 
					 | 
				
			||||||
	private int? allItemsCount;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public AttachmentsPageModel() : this(DummyDatabaseFile.Instance) {}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public AttachmentsPageModel(IDatabaseFile db) {
 | 
					 | 
				
			||||||
		this.db = db;
 | 
					 | 
				
			||||||
		this.FilterModel = new AttachmentFilterPanelModel(db);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		this.downloadStatisticsComputer = AsyncValueComputer<DownloadStatusStatistics>.WithResultProcessor(UpdateStatistics).WithOutdatedResults().BuildWithComputer(db.GetDownloadStatusStatistics);
 | 
					 | 
				
			||||||
		this.downloadStatisticsComputer.Recompute();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		db.Statistics.PropertyChanged += OnDbStatisticsChanged;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public void Dispose() {
 | 
					 | 
				
			||||||
		db.Statistics.PropertyChanged -= OnDbStatisticsChanged;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		FilterModel.Dispose();
 | 
					 | 
				
			||||||
		DisposeDownloadThread();
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private void OnDbStatisticsChanged(object? sender, PropertyChangedEventArgs e) {
 | 
					 | 
				
			||||||
		if (e.PropertyName == nameof(DatabaseStatistics.TotalAttachments)) {
 | 
					 | 
				
			||||||
			if (IsDownloading) {
 | 
					 | 
				
			||||||
				EnqueueDownloadItems();
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			else {
 | 
					 | 
				
			||||||
				downloadStatisticsComputer.Recompute();
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		else if (e.PropertyName == nameof(DatabaseStatistics.TotalDownloads)) {
 | 
					 | 
				
			||||||
			downloadStatisticsComputer.Recompute();
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private void EnqueueDownloadItems() {
 | 
					 | 
				
			||||||
		var filter = FilterModel.CreateFilter();
 | 
					 | 
				
			||||||
		filter.DownloadItemRule = AttachmentFilter.DownloadItemRules.OnlyNotPresent;
 | 
					 | 
				
			||||||
		db.EnqueueDownloadItems(filter);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		downloadStatisticsComputer.Recompute();
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private void UpdateStatistics(DownloadStatusStatistics statusStatistics) {
 | 
					 | 
				
			||||||
		var hadFailedDownloads = HasFailedDownloads;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		statisticsEnqueued.Items = statusStatistics.EnqueuedCount;
 | 
					 | 
				
			||||||
		statisticsEnqueued.Size = statusStatistics.EnqueuedSize;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		statisticsDownloaded.Items = statusStatistics.SuccessfulCount;
 | 
					 | 
				
			||||||
		statisticsDownloaded.Size = statusStatistics.SuccessfulSize;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		statisticsFailed.Items = statusStatistics.FailedCount;
 | 
					 | 
				
			||||||
		statisticsFailed.Size = statusStatistics.FailedSize;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		statisticsSkipped.Items = statusStatistics.SkippedCount;
 | 
					 | 
				
			||||||
		statisticsSkipped.Size = statusStatistics.SkippedSize;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		OnPropertyChanged(nameof(StatisticsRows));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if (hadFailedDownloads != HasFailedDownloads) {
 | 
					 | 
				
			||||||
			OnPropertyChanged(nameof(HasFailedDownloads));
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		allItemsCount = doneItemsCount + statisticsEnqueued.Items;
 | 
					 | 
				
			||||||
		UpdateDownloadMessage();
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private void UpdateDownloadMessage() {
 | 
					 | 
				
			||||||
		DownloadMessage = IsDownloading ? doneItemsCount.Format() + " / " + (allItemsCount?.Format() ?? "?") : "";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		OnPropertyChanged(nameof(DownloadMessage));
 | 
					 | 
				
			||||||
		OnPropertyChanged(nameof(DownloadProgress));
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private void DownloadThreadOnOnItemFinished(object? sender, DownloadItem e) {
 | 
					 | 
				
			||||||
		Interlocked.Increment(ref doneItemsCount);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		Dispatcher.UIThread.Invoke(UpdateDownloadMessage);
 | 
					 | 
				
			||||||
		downloadStatisticsComputer.Recompute();
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private void DownloadThreadOnOnServerStopped(object? sender, EventArgs e) {
 | 
					 | 
				
			||||||
		downloadStatisticsComputer.Recompute();
 | 
					 | 
				
			||||||
		IsToggleDownloadButtonEnabled = true;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public void OnClickToggleDownload() {
 | 
					 | 
				
			||||||
		if (downloadThread == null) {
 | 
					 | 
				
			||||||
			EnqueueDownloadItems();
 | 
					 | 
				
			||||||
			downloadThread = new BackgroundDownloadThread(db);
 | 
					 | 
				
			||||||
			downloadThread.OnItemFinished += DownloadThreadOnOnItemFinished;
 | 
					 | 
				
			||||||
			downloadThread.OnServerStopped += DownloadThreadOnOnServerStopped;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		else {
 | 
					 | 
				
			||||||
			IsToggleDownloadButtonEnabled = false;
 | 
					 | 
				
			||||||
			DisposeDownloadThread();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			db.RemoveDownloadItems(EnqueuedItemFilter, FilterRemovalMode.RemoveMatching);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			doneItemsCount = 0;
 | 
					 | 
				
			||||||
			allItemsCount = null;
 | 
					 | 
				
			||||||
			UpdateDownloadMessage();
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		OnPropertyChanged(nameof(ToggleDownloadButtonText));
 | 
					 | 
				
			||||||
		OnPropertyChanged(nameof(IsDownloading));
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public void OnClickRetryFailedDownloads() {
 | 
					 | 
				
			||||||
		var allExceptFailedFilter = new DownloadItemFilter {
 | 
					 | 
				
			||||||
			IncludeStatuses = new HashSet<DownloadStatus> {
 | 
					 | 
				
			||||||
				DownloadStatus.Enqueued,
 | 
					 | 
				
			||||||
				DownloadStatus.Success
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		db.RemoveDownloadItems(allExceptFailedFilter, FilterRemovalMode.KeepMatching);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if (IsDownloading) {
 | 
					 | 
				
			||||||
			EnqueueDownloadItems();
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private void DisposeDownloadThread() {
 | 
					 | 
				
			||||||
		if (downloadThread != null) {
 | 
					 | 
				
			||||||
			downloadThread.OnItemFinished -= DownloadThreadOnOnItemFinished;
 | 
					 | 
				
			||||||
			downloadThread.StopThread();
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		downloadThread = null;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public sealed class StatisticsRow {
 | 
					 | 
				
			||||||
		public string State { get; }
 | 
					 | 
				
			||||||
		public int Items { get; set; }
 | 
					 | 
				
			||||||
		public ulong? Size { get; set; }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public StatisticsRow(string state) {
 | 
					 | 
				
			||||||
			State = state;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,245 +0,0 @@
 | 
				
			|||||||
using System;
 | 
					 | 
				
			||||||
using System.Collections.Generic;
 | 
					 | 
				
			||||||
using System.Diagnostics;
 | 
					 | 
				
			||||||
using System.IO;
 | 
					 | 
				
			||||||
using System.Linq;
 | 
					 | 
				
			||||||
using System.Text;
 | 
					 | 
				
			||||||
using System.Threading;
 | 
					 | 
				
			||||||
using System.Threading.Tasks;
 | 
					 | 
				
			||||||
using Avalonia.Controls;
 | 
					 | 
				
			||||||
using Avalonia.Platform.Storage;
 | 
					 | 
				
			||||||
using Avalonia.Threading;
 | 
					 | 
				
			||||||
using DHT.Desktop.Common;
 | 
					 | 
				
			||||||
using DHT.Desktop.Dialogs.File;
 | 
					 | 
				
			||||||
using DHT.Desktop.Dialogs.Message;
 | 
					 | 
				
			||||||
using DHT.Desktop.Dialogs.Progress;
 | 
					 | 
				
			||||||
using DHT.Desktop.Dialogs.TextBox;
 | 
					 | 
				
			||||||
using DHT.Server.Data;
 | 
					 | 
				
			||||||
using DHT.Server.Database;
 | 
					 | 
				
			||||||
using DHT.Server.Database.Import;
 | 
					 | 
				
			||||||
using DHT.Utils.Logging;
 | 
					 | 
				
			||||||
using DHT.Utils.Models;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace DHT.Desktop.Main.Pages; 
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
sealed class DatabasePageModel : BaseModel {
 | 
					 | 
				
			||||||
	private static readonly Log Log = Log.ForType<DatabasePageModel>();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public IDatabaseFile Db { get; }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public event EventHandler? DatabaseClosed;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private readonly Window window;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	[Obsolete("Designer")]
 | 
					 | 
				
			||||||
	public DatabasePageModel() : this(null!, DummyDatabaseFile.Instance) {}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public DatabasePageModel(Window window, IDatabaseFile db) {
 | 
					 | 
				
			||||||
		this.window = window;
 | 
					 | 
				
			||||||
		this.Db = db;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public async void OpenDatabaseFolder() {
 | 
					 | 
				
			||||||
		string file = Db.Path;
 | 
					 | 
				
			||||||
		string? folder = Path.GetDirectoryName(file);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if (folder == null) {
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		switch (Environment.OSVersion.Platform) {
 | 
					 | 
				
			||||||
			case PlatformID.Win32NT:
 | 
					 | 
				
			||||||
				Process.Start("explorer.exe", "/select,\"" + file + "\"");
 | 
					 | 
				
			||||||
				break;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			case PlatformID.Unix:
 | 
					 | 
				
			||||||
				Process.Start("xdg-open", new string[] { folder });
 | 
					 | 
				
			||||||
				break;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			case PlatformID.MacOSX:
 | 
					 | 
				
			||||||
				Process.Start("open", new string[] { folder });
 | 
					 | 
				
			||||||
				break;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			default:
 | 
					 | 
				
			||||||
				await Dialog.ShowOk(window, "Feature Not Supported", "This feature is not supported for your operating system.");
 | 
					 | 
				
			||||||
				break;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public void CloseDatabase() {
 | 
					 | 
				
			||||||
		DatabaseClosed?.Invoke(this, EventArgs.Empty);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public async void MergeWithDatabase() {
 | 
					 | 
				
			||||||
		var paths = await DatabaseGui.NewOpenDatabaseFilesDialog(window, Path.GetDirectoryName(Db.Path));
 | 
					 | 
				
			||||||
		if (paths.Length == 0) {
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		ProgressDialog progressDialog = new ProgressDialog();
 | 
					 | 
				
			||||||
		progressDialog.DataContext = new ProgressDialogModel(async callback => await MergeWithDatabaseFromPaths(Db, paths, progressDialog, callback)) {
 | 
					 | 
				
			||||||
			Title = "Database Merge"
 | 
					 | 
				
			||||||
		};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		await progressDialog.ShowDialog(window);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private static async Task MergeWithDatabaseFromPaths(IDatabaseFile target, string[] paths, ProgressDialog dialog, IProgressCallback callback) {
 | 
					 | 
				
			||||||
		int total = paths.Length;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		DialogResult.YesNo? upgradeResult = null;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		async Task<bool> CheckCanUpgradeDatabase() {
 | 
					 | 
				
			||||||
			upgradeResult ??= total > 1
 | 
					 | 
				
			||||||
				                  ? await DatabaseGui.ShowCanUpgradeMultipleDatabaseDialog(dialog)
 | 
					 | 
				
			||||||
				                  : await DatabaseGui.ShowCanUpgradeDatabaseDialog(dialog);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			return DialogResult.YesNo.Yes == upgradeResult;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		await PerformImport(target, paths, dialog, callback, "Database Merge", "Database Error", "database file", async path => {
 | 
					 | 
				
			||||||
			SynchronizationContext? prevSyncContext = SynchronizationContext.Current;
 | 
					 | 
				
			||||||
			SynchronizationContext.SetSynchronizationContext(new AvaloniaSynchronizationContext());
 | 
					 | 
				
			||||||
			IDatabaseFile? db = await DatabaseGui.TryOpenOrCreateDatabaseFromPath(path, dialog, CheckCanUpgradeDatabase);
 | 
					 | 
				
			||||||
			SynchronizationContext.SetSynchronizationContext(prevSyncContext);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			if (db == null) {
 | 
					 | 
				
			||||||
				return false;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			try {
 | 
					 | 
				
			||||||
				target.AddFrom(db);
 | 
					 | 
				
			||||||
				return true;
 | 
					 | 
				
			||||||
			} finally {
 | 
					 | 
				
			||||||
				db.Dispose();
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		});
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public async void ImportLegacyArchive() {
 | 
					 | 
				
			||||||
		var paths = await window.StorageProvider.OpenFiles(new FilePickerOpenOptions {
 | 
					 | 
				
			||||||
			Title = "Open Legacy DHT Archive",
 | 
					 | 
				
			||||||
			SuggestedStartLocation = await FileDialogs.GetSuggestedStartLocation(window, Path.GetDirectoryName(Db.Path)),
 | 
					 | 
				
			||||||
			AllowMultiple = true
 | 
					 | 
				
			||||||
		});
 | 
					 | 
				
			||||||
			
 | 
					 | 
				
			||||||
		if (paths.Length == 0) {
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		ProgressDialog progressDialog = new ProgressDialog();
 | 
					 | 
				
			||||||
		progressDialog.DataContext = new ProgressDialogModel(async callback => await ImportLegacyArchiveFromPaths(Db, paths, progressDialog, callback)) {
 | 
					 | 
				
			||||||
			Title = "Legacy Archive Import"
 | 
					 | 
				
			||||||
		};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		await progressDialog.ShowDialog(window);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private static async Task ImportLegacyArchiveFromPaths(IDatabaseFile target, string[] paths, ProgressDialog dialog, IProgressCallback callback) {
 | 
					 | 
				
			||||||
		var fakeSnowflake = new FakeSnowflake();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		await PerformImport(target, paths, dialog, callback, "Legacy Archive Import", "Legacy Archive Error", "archive file", async path => {
 | 
					 | 
				
			||||||
			await using var jsonStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
 | 
					 | 
				
			||||||
				
 | 
					 | 
				
			||||||
			return await LegacyArchiveImport.Read(jsonStream, target, fakeSnowflake, async servers => {
 | 
					 | 
				
			||||||
				SynchronizationContext? prevSyncContext = SynchronizationContext.Current;
 | 
					 | 
				
			||||||
				SynchronizationContext.SetSynchronizationContext(new AvaloniaSynchronizationContext());
 | 
					 | 
				
			||||||
				Dictionary<DHT.Server.Data.Server, ulong>? result = await Dispatcher.UIThread.InvokeAsync(() => AskForServerIds(dialog, servers));
 | 
					 | 
				
			||||||
				SynchronizationContext.SetSynchronizationContext(prevSyncContext);
 | 
					 | 
				
			||||||
				return result;
 | 
					 | 
				
			||||||
			});
 | 
					 | 
				
			||||||
		});
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private static async Task<Dictionary<DHT.Server.Data.Server, ulong>?> AskForServerIds(Window window, DHT.Server.Data.Server[] servers) {
 | 
					 | 
				
			||||||
		static bool IsValidSnowflake(string value) {
 | 
					 | 
				
			||||||
			return string.IsNullOrEmpty(value) || ulong.TryParse(value, out _);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
			
 | 
					 | 
				
			||||||
		var items = new List<TextBoxItem<DHT.Server.Data.Server>>();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		foreach (var server in servers.OrderBy(static server => server.Type).ThenBy(static server => server.Name)) {
 | 
					 | 
				
			||||||
			items.Add(new TextBoxItem<DHT.Server.Data.Server>(server) {
 | 
					 | 
				
			||||||
				Title = server.Name + " (" + ServerTypes.ToNiceString(server.Type) + ")",
 | 
					 | 
				
			||||||
				ValidityCheck = IsValidSnowflake
 | 
					 | 
				
			||||||
			});
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		var model = new TextBoxDialogModel<DHT.Server.Data.Server>(items) {
 | 
					 | 
				
			||||||
			Title = "Imported Server IDs",
 | 
					 | 
				
			||||||
			Description = "Please fill in the IDs of servers and direct messages. First enable Developer Mode in Discord, then right-click each server or direct message, click 'Copy ID', and paste it into the input field. If a server no longer exists, leave its input field empty to use a random ID."
 | 
					 | 
				
			||||||
		};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		var dialog = new TextBoxDialog { DataContext = model };
 | 
					 | 
				
			||||||
		var result = await dialog.ShowDialog<DialogResult.OkCancel>(window);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if (result != DialogResult.OkCancel.Ok) {
 | 
					 | 
				
			||||||
			return null;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		return model.ValidItems
 | 
					 | 
				
			||||||
		            .Where(static item => !string.IsNullOrEmpty(item.Value))
 | 
					 | 
				
			||||||
		            .ToDictionary(static item => item.Item, static item => ulong.Parse(item.Value));
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private static async Task PerformImport(IDatabaseFile target, string[] paths, ProgressDialog dialog, IProgressCallback callback, string neutralDialogTitle, string errorDialogTitle, string itemName, Func<string, Task<bool>> performImport) {
 | 
					 | 
				
			||||||
		int total = paths.Length;
 | 
					 | 
				
			||||||
		var oldStatistics = target.SnapshotStatistics();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		int successful = 0;
 | 
					 | 
				
			||||||
		int finished = 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		foreach (string path in paths) {
 | 
					 | 
				
			||||||
			await callback.Update(Path.GetFileName(path), finished, total);
 | 
					 | 
				
			||||||
			++finished;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			if (!File.Exists(path)) {
 | 
					 | 
				
			||||||
				await Dialog.ShowOk(dialog, errorDialogTitle, "File '" + Path.GetFileName(path) + "' no longer exists.");
 | 
					 | 
				
			||||||
				continue;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			try {
 | 
					 | 
				
			||||||
				if (await performImport(path)) {
 | 
					 | 
				
			||||||
					++successful;
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			} catch (Exception ex) {
 | 
					 | 
				
			||||||
				Log.Error(ex);
 | 
					 | 
				
			||||||
				await Dialog.ShowOk(dialog, errorDialogTitle, "File '" + Path.GetFileName(path) + "' could not be imported: " + ex.Message);
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		await callback.Update("Done", finished, total);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if (successful == 0) {
 | 
					 | 
				
			||||||
			await Dialog.ShowOk(dialog, neutralDialogTitle, "Nothing was imported.");
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		await Dialog.ShowOk(dialog, neutralDialogTitle, GetImportDialogMessage(oldStatistics, target.SnapshotStatistics(), successful, total, itemName));
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private static string GetImportDialogMessage(DatabaseStatisticsSnapshot oldStatistics, DatabaseStatisticsSnapshot newStatistics, int successfulItems, int totalItems, string itemName) {
 | 
					 | 
				
			||||||
		long newServers = newStatistics.TotalServers - oldStatistics.TotalServers;
 | 
					 | 
				
			||||||
		long newChannels = newStatistics.TotalChannels - oldStatistics.TotalChannels;
 | 
					 | 
				
			||||||
		long newUsers = newStatistics.TotalUsers - oldStatistics.TotalUsers;
 | 
					 | 
				
			||||||
		long newMessages = newStatistics.TotalMessages - oldStatistics.TotalMessages;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		StringBuilder message = new StringBuilder();
 | 
					 | 
				
			||||||
		message.Append("Processed ");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if (successfulItems == totalItems) {
 | 
					 | 
				
			||||||
			message.Append(successfulItems.Pluralize(itemName));
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		else {
 | 
					 | 
				
			||||||
			message.Append(successfulItems.Format()).Append(" out of ").Append(totalItems.Pluralize(itemName));
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		message.Append(" and added:\n\n  \u2022 ");
 | 
					 | 
				
			||||||
		message.Append(newServers.Pluralize("server")).Append("\n  \u2022 ");
 | 
					 | 
				
			||||||
		message.Append(newChannels.Pluralize("channel")).Append("\n  \u2022 ");
 | 
					 | 
				
			||||||
		message.Append(newUsers.Pluralize("user")).Append("\n  \u2022 ");
 | 
					 | 
				
			||||||
		message.Append(newMessages.Pluralize("message"));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		return message.ToString();
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,45 +0,0 @@
 | 
				
			|||||||
<UserControl xmlns="https://github.com/avaloniaui"
 | 
					 | 
				
			||||||
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
					 | 
				
			||||||
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
					 | 
				
			||||||
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
					 | 
				
			||||||
             xmlns:pages="clr-namespace:DHT.Desktop.Main.Pages"
 | 
					 | 
				
			||||||
             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
 | 
					 | 
				
			||||||
             x:Class="DHT.Desktop.Main.Pages.DebugPage">
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    <Design.DataContext>
 | 
					 | 
				
			||||||
        <pages:DebugPageModel />
 | 
					 | 
				
			||||||
    </Design.DataContext>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    <UserControl.Styles>
 | 
					 | 
				
			||||||
        <Style Selector="TextBox">
 | 
					 | 
				
			||||||
            <Setter Property="FontFamily" Value="Consolas,Courier" />
 | 
					 | 
				
			||||||
            <Setter Property="FontSize" Value="15" />
 | 
					 | 
				
			||||||
        </Style>
 | 
					 | 
				
			||||||
        <Style Selector="WrapPanel > StackPanel">
 | 
					 | 
				
			||||||
            <Setter Property="Orientation" Value="Vertical" />
 | 
					 | 
				
			||||||
            <Setter Property="Margin" Value="0 0 10 10" />
 | 
					 | 
				
			||||||
        </Style>
 | 
					 | 
				
			||||||
    </UserControl.Styles>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    <StackPanel Orientation="Vertical" Spacing="10">
 | 
					 | 
				
			||||||
        <Expander Header="Generate Random Data" IsExpanded="True">
 | 
					 | 
				
			||||||
            <WrapPanel>
 | 
					 | 
				
			||||||
                <StackPanel>
 | 
					 | 
				
			||||||
                    <Label Target="Channels">Channels</Label>
 | 
					 | 
				
			||||||
                    <TextBox x:Name="Channels" Width="100" Text="{Binding GenerateChannels}" />
 | 
					 | 
				
			||||||
                </StackPanel>
 | 
					 | 
				
			||||||
                <StackPanel>
 | 
					 | 
				
			||||||
                    <Label Target="Users">Users</Label>
 | 
					 | 
				
			||||||
                    <TextBox x:Name="Users" Width="100" Text="{Binding GenerateUsers}" />
 | 
					 | 
				
			||||||
                </StackPanel>
 | 
					 | 
				
			||||||
                <StackPanel>
 | 
					 | 
				
			||||||
                    <Label Target="Messages">Messages</Label>
 | 
					 | 
				
			||||||
                    <TextBox x:Name="Messages" Width="100" Text="{Binding GenerateMessages}" />
 | 
					 | 
				
			||||||
                </StackPanel>
 | 
					 | 
				
			||||||
                <StackPanel VerticalAlignment="Bottom">
 | 
					 | 
				
			||||||
                    <Button Command="{Binding OnClickAddRandomDataToDatabase}">Add to Database</Button>
 | 
					 | 
				
			||||||
                </StackPanel>
 | 
					 | 
				
			||||||
            </WrapPanel>
 | 
					 | 
				
			||||||
        </Expander>
 | 
					 | 
				
			||||||
    </StackPanel>
 | 
					 | 
				
			||||||
</UserControl>
 | 
					 | 
				
			||||||
@@ -1,11 +0,0 @@
 | 
				
			|||||||
using System.Diagnostics.CodeAnalysis;
 | 
					 | 
				
			||||||
using Avalonia.Controls;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace DHT.Desktop.Main.Pages;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
					 | 
				
			||||||
public sealed partial class DebugPage : UserControl {
 | 
					 | 
				
			||||||
	public DebugPage() {
 | 
					 | 
				
			||||||
		InitializeComponent();
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,185 +0,0 @@
 | 
				
			|||||||
#if DEBUG
 | 
					 | 
				
			||||||
using System;
 | 
					 | 
				
			||||||
using System.Collections.Immutable;
 | 
					 | 
				
			||||||
using System.Linq;
 | 
					 | 
				
			||||||
using System.Threading.Tasks;
 | 
					 | 
				
			||||||
using Avalonia.Controls;
 | 
					 | 
				
			||||||
using DHT.Desktop.Dialogs.Message;
 | 
					 | 
				
			||||||
using DHT.Desktop.Dialogs.Progress;
 | 
					 | 
				
			||||||
using DHT.Server.Data;
 | 
					 | 
				
			||||||
using DHT.Server.Database;
 | 
					 | 
				
			||||||
using DHT.Server.Service;
 | 
					 | 
				
			||||||
using DHT.Utils.Models;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace DHT.Desktop.Main.Pages {
 | 
					 | 
				
			||||||
	sealed class DebugPageModel : BaseModel {
 | 
					 | 
				
			||||||
		public string GenerateChannels { get; set; } = "0";
 | 
					 | 
				
			||||||
		public string GenerateUsers { get; set; } = "0";
 | 
					 | 
				
			||||||
		public string GenerateMessages { get; set; } = "0";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		private readonly Window window;
 | 
					 | 
				
			||||||
		private readonly IDatabaseFile db;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		[Obsolete("Designer")]
 | 
					 | 
				
			||||||
		public DebugPageModel() : this(null!, DummyDatabaseFile.Instance) {}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public DebugPageModel(Window window, IDatabaseFile db) {
 | 
					 | 
				
			||||||
			this.window = window;
 | 
					 | 
				
			||||||
			this.db = db;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public async void OnClickAddRandomDataToDatabase() {
 | 
					 | 
				
			||||||
			if (!int.TryParse(GenerateChannels, out int channels) || channels < 1) {
 | 
					 | 
				
			||||||
				await Dialog.ShowOk(window, "Generate Random Data", "Amount of channels must be at least 1!");
 | 
					 | 
				
			||||||
				return;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			if (!int.TryParse(GenerateUsers, out int users) || users < 1) {
 | 
					 | 
				
			||||||
				await Dialog.ShowOk(window, "Generate Random Data", "Amount of users must be at least 1!");
 | 
					 | 
				
			||||||
				return;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			if (!int.TryParse(GenerateMessages, out int messages) || messages < 1) {
 | 
					 | 
				
			||||||
				await Dialog.ShowOk(window, "Generate Random Data", "Amount of messages must be at least 1!");
 | 
					 | 
				
			||||||
				return;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			ProgressDialog progressDialog = new ProgressDialog {
 | 
					 | 
				
			||||||
				DataContext = new ProgressDialogModel(async callback => await GenerateRandomData(channels, users, messages, callback)) {
 | 
					 | 
				
			||||||
					Title = "Generating Random Data"
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			await progressDialog.ShowDialog(window);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		private const int BatchSize = 500;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		private async Task GenerateRandomData(int channelCount, int userCount, int messageCount, IProgressCallback callback) {
 | 
					 | 
				
			||||||
			int batchCount = (messageCount + BatchSize - 1) / BatchSize;
 | 
					 | 
				
			||||||
			await callback.Update("Adding messages in batches of " + BatchSize, 0, batchCount);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			var rand = new Random();
 | 
					 | 
				
			||||||
			var server = new DHT.Server.Data.Server {
 | 
					 | 
				
			||||||
				Id = RandomId(rand),
 | 
					 | 
				
			||||||
				Name = RandomName("s"),
 | 
					 | 
				
			||||||
				Type = ServerType.Server,
 | 
					 | 
				
			||||||
			};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			var channels = Enumerable.Range(0, channelCount).Select(i => new Channel {
 | 
					 | 
				
			||||||
				Id = RandomId(rand),
 | 
					 | 
				
			||||||
				Server = server.Id,
 | 
					 | 
				
			||||||
				Name = RandomName("c"),
 | 
					 | 
				
			||||||
				ParentId = null,
 | 
					 | 
				
			||||||
				Position = i,
 | 
					 | 
				
			||||||
				Topic = RandomText(rand, 10),
 | 
					 | 
				
			||||||
				Nsfw = rand.Next(4) == 0,
 | 
					 | 
				
			||||||
			}).ToArray();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			var users = Enumerable.Range(0, userCount).Select(_ => new User {
 | 
					 | 
				
			||||||
				Id = RandomId(rand),
 | 
					 | 
				
			||||||
				Name = RandomName("u"),
 | 
					 | 
				
			||||||
				AvatarUrl = null,
 | 
					 | 
				
			||||||
				Discriminator = rand.Next(0, 9999).ToString(),
 | 
					 | 
				
			||||||
			}).ToArray();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			db.AddServer(server);
 | 
					 | 
				
			||||||
			db.AddUsers(users);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			foreach (var channel in channels) {
 | 
					 | 
				
			||||||
				db.AddChannel(channel);
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			var now = DateTimeOffset.Now;
 | 
					 | 
				
			||||||
			int batchIndex = 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			while (messageCount > 0) {
 | 
					 | 
				
			||||||
				int hourOffset = batchIndex;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				var messages = Enumerable.Range(0, Math.Min(messageCount, BatchSize)).Select(i => {
 | 
					 | 
				
			||||||
					DateTimeOffset time = now.AddHours(hourOffset).AddMinutes(i * 60.0 / BatchSize);
 | 
					 | 
				
			||||||
					DateTimeOffset? edit = rand.Next(100) == 0 ? time.AddSeconds(rand.Next(1, 60)) : null;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
					var timeMillis = time.ToUnixTimeMilliseconds();
 | 
					 | 
				
			||||||
					var editMillis = edit?.ToUnixTimeMilliseconds();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
					return new Message {
 | 
					 | 
				
			||||||
						Id = (ulong) timeMillis,
 | 
					 | 
				
			||||||
						Sender = RandomBiasedIndex(rand, users).Id,
 | 
					 | 
				
			||||||
						Channel = RandomBiasedIndex(rand, channels).Id,
 | 
					 | 
				
			||||||
						Text = RandomText(rand, 100),
 | 
					 | 
				
			||||||
						Timestamp = timeMillis,
 | 
					 | 
				
			||||||
						EditTimestamp = editMillis,
 | 
					 | 
				
			||||||
						RepliedToId = null,
 | 
					 | 
				
			||||||
						Attachments = ImmutableArray<Attachment>.Empty,
 | 
					 | 
				
			||||||
						Embeds = ImmutableArray<Embed>.Empty,
 | 
					 | 
				
			||||||
						Reactions = ImmutableArray<Reaction>.Empty,
 | 
					 | 
				
			||||||
					};
 | 
					 | 
				
			||||||
				}).ToArray();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				db.AddMessages(messages);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				messageCount -= BatchSize;
 | 
					 | 
				
			||||||
				await callback.Update("Adding messages in batches of " + BatchSize, ++batchIndex, batchCount);
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		private static ulong RandomId(Random rand) {
 | 
					 | 
				
			||||||
			ulong h = unchecked((ulong) rand.Next());
 | 
					 | 
				
			||||||
			ulong l = unchecked((ulong) rand.Next());
 | 
					 | 
				
			||||||
			return (h << 32) | l;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		private static string RandomName(string prefix) {
 | 
					 | 
				
			||||||
			return prefix + "-" + ServerUtils.GenerateRandomToken(5);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		private static T RandomBiasedIndex<T>(Random rand, T[] options) {
 | 
					 | 
				
			||||||
			return options[(int) Math.Floor(options.Length * rand.NextDouble() * rand.NextDouble())];
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		private static readonly string[] RandomWords = {
 | 
					 | 
				
			||||||
			"apple", "apricot", "artichoke", "arugula", "asparagus", "avocado",
 | 
					 | 
				
			||||||
			"banana", "bean", "beechnut", "beet", "blackberry", "blackcurrant", "blueberry", "boysenberry", "bramble", "broccoli",
 | 
					 | 
				
			||||||
			"cabbage", "cacao", "cantaloupe", "caper", "carambola", "carrot", "cauliflower", "celery", "chard", "cherry", "chokeberry", "citron", "clementine", "coconut", "corn", "crabapple", "cranberry", "cucumber", "currant",
 | 
					 | 
				
			||||||
			"daikon", "date", "dewberry", "durian",
 | 
					 | 
				
			||||||
			"edamame", "eggplant", "elderberry", "endive",
 | 
					 | 
				
			||||||
			"fig",
 | 
					 | 
				
			||||||
			"garlic", "ginger", "gooseberry", "grape", "grapefruit", "guava",
 | 
					 | 
				
			||||||
			"honeysuckle", "horseradish", "huckleberry",
 | 
					 | 
				
			||||||
			"jackfruit", "jicama",
 | 
					 | 
				
			||||||
			"kale", "kiwi", "kohlrabi", "kumquat",
 | 
					 | 
				
			||||||
			"leek", "lemon", "lentil", "lettuce", "lime",
 | 
					 | 
				
			||||||
			"mandarin", "mango", "mushroom", "myrtle",
 | 
					 | 
				
			||||||
			"nectarine", "nut",
 | 
					 | 
				
			||||||
			"olive", "okra", "onion", "orange",
 | 
					 | 
				
			||||||
			"papaya", "parsnip", "pawpaw", "peach", "pear", "pea", "pepper", "persimmon", "pineapple", "plum", "plantain", "pomegranate", "pomelo", "potato", "prune", "pumpkin",
 | 
					 | 
				
			||||||
			"quandong", "quinoa",
 | 
					 | 
				
			||||||
			"radicchio", "radish", "raisin", "raspberry", "redcurrant", "rhubarb", "rutabaga",
 | 
					 | 
				
			||||||
			"spinach", "strawberry", "squash",
 | 
					 | 
				
			||||||
			"tamarind", "tangerine", "tomatillo", "tomato", "turnip",
 | 
					 | 
				
			||||||
			"vanilla",
 | 
					 | 
				
			||||||
			"watercress", "watermelon",
 | 
					 | 
				
			||||||
			"yam",
 | 
					 | 
				
			||||||
			"zucchini",
 | 
					 | 
				
			||||||
		};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		private static string RandomText(Random rand, int maxWords) {
 | 
					 | 
				
			||||||
			int wordCount = 1 + (int) Math.Floor(maxWords * Math.Pow(rand.NextDouble(), 3));
 | 
					 | 
				
			||||||
			return string.Join(' ', Enumerable.Range(0, wordCount).Select(_ => RandomWords[rand.Next(RandomWords.Length)]));
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
using DHT.Utils.Models;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace DHT.Desktop.Main.Pages {
 | 
					 | 
				
			||||||
	sealed class DebugPageModel : BaseModel {
 | 
					 | 
				
			||||||
		public string GenerateChannels { get; set; } = "0";
 | 
					 | 
				
			||||||
		public string GenerateUsers { get; set; } = "0";
 | 
					 | 
				
			||||||
		public string GenerateMessages { get; set; } = "0";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public void OnClickAddRandomDataToDatabase() {}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
@@ -1,37 +0,0 @@
 | 
				
			|||||||
<UserControl xmlns="https://github.com/avaloniaui"
 | 
					 | 
				
			||||||
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
					 | 
				
			||||||
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
					 | 
				
			||||||
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
					 | 
				
			||||||
             xmlns:pages="clr-namespace:DHT.Desktop.Main.Pages"
 | 
					 | 
				
			||||||
             xmlns:controls="clr-namespace:DHT.Desktop.Main.Controls"
 | 
					 | 
				
			||||||
             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
 | 
					 | 
				
			||||||
             x:Class="DHT.Desktop.Main.Pages.ViewerPage">
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    <Design.DataContext>
 | 
					 | 
				
			||||||
        <pages:ViewerPageModel />
 | 
					 | 
				
			||||||
    </Design.DataContext>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    <UserControl.Styles>
 | 
					 | 
				
			||||||
        <Style Selector="Expander">
 | 
					 | 
				
			||||||
            <Setter Property="Margin" Value="0 5 0 0" />
 | 
					 | 
				
			||||||
        </Style>
 | 
					 | 
				
			||||||
    </UserControl.Styles>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    <StackPanel Orientation="Vertical" Spacing="20">
 | 
					 | 
				
			||||||
        <StackPanel Orientation="Horizontal" VerticalAlignment="Top">
 | 
					 | 
				
			||||||
            <Button Command="{Binding OnClickOpenViewer}" Margin="0 0 5 0">Open Viewer</Button>
 | 
					 | 
				
			||||||
            <Button Command="{Binding OnClickSaveViewer}" Margin="5 0 0 0">Save Viewer</Button>
 | 
					 | 
				
			||||||
        </StackPanel>
 | 
					 | 
				
			||||||
        <controls:MessageFilterPanel DataContext="{Binding FilterModel}" />
 | 
					 | 
				
			||||||
        <Expander Header="Database Tools">
 | 
					 | 
				
			||||||
            <StackPanel Orientation="Vertical" Spacing="10">
 | 
					 | 
				
			||||||
                <StackPanel Orientation="Vertical" Spacing="4">
 | 
					 | 
				
			||||||
                    <RadioButton GroupName="DatabaseToolFilterMode" IsEnabled="{Binding HasFilters}" IsChecked="{Binding DatabaseToolFilterModeKeep}">Keep Only Messages Matching Filters</RadioButton>
 | 
					 | 
				
			||||||
                    <RadioButton GroupName="DatabaseToolFilterMode" IsEnabled="{Binding HasFilters}" IsChecked="{Binding DatabaseToolFilterModeRemove}">Remove Messages Matching Filters</RadioButton>
 | 
					 | 
				
			||||||
                </StackPanel>
 | 
					 | 
				
			||||||
                <Button IsEnabled="{Binding HasFilters}" Command="{Binding OnClickApplyFiltersToDatabase}">Apply Filters to Database</Button>
 | 
					 | 
				
			||||||
            </StackPanel>
 | 
					 | 
				
			||||||
        </Expander>
 | 
					 | 
				
			||||||
    </StackPanel>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
</UserControl>
 | 
					 | 
				
			||||||
@@ -1,11 +0,0 @@
 | 
				
			|||||||
using System.Diagnostics.CodeAnalysis;
 | 
					 | 
				
			||||||
using Avalonia.Controls;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace DHT.Desktop.Main.Pages;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
					 | 
				
			||||||
public sealed partial class ViewerPage : UserControl {
 | 
					 | 
				
			||||||
	public ViewerPage() {
 | 
					 | 
				
			||||||
		InitializeComponent();
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,149 +0,0 @@
 | 
				
			|||||||
using System;
 | 
					 | 
				
			||||||
using System.Collections.Concurrent;
 | 
					 | 
				
			||||||
using System.ComponentModel;
 | 
					 | 
				
			||||||
using System.Diagnostics;
 | 
					 | 
				
			||||||
using System.IO;
 | 
					 | 
				
			||||||
using System.Text;
 | 
					 | 
				
			||||||
using System.Threading.Tasks;
 | 
					 | 
				
			||||||
using System.Web;
 | 
					 | 
				
			||||||
using Avalonia.Controls;
 | 
					 | 
				
			||||||
using Avalonia.Platform.Storage;
 | 
					 | 
				
			||||||
using DHT.Desktop.Common;
 | 
					 | 
				
			||||||
using DHT.Desktop.Dialogs.File;
 | 
					 | 
				
			||||||
using DHT.Desktop.Dialogs.Message;
 | 
					 | 
				
			||||||
using DHT.Desktop.Main.Controls;
 | 
					 | 
				
			||||||
using DHT.Desktop.Server;
 | 
					 | 
				
			||||||
using DHT.Server.Data.Filters;
 | 
					 | 
				
			||||||
using DHT.Server.Database;
 | 
					 | 
				
			||||||
using DHT.Server.Database.Export;
 | 
					 | 
				
			||||||
using DHT.Server.Database.Export.Strategy;
 | 
					 | 
				
			||||||
using DHT.Utils.Models;
 | 
					 | 
				
			||||||
using static DHT.Desktop.Program;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace DHT.Desktop.Main.Pages;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
sealed class ViewerPageModel : BaseModel, IDisposable {
 | 
					 | 
				
			||||||
	public static readonly ConcurrentBag<string> TemporaryFiles = new ();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public bool DatabaseToolFilterModeKeep { get; set; } = true;
 | 
					 | 
				
			||||||
	public bool DatabaseToolFilterModeRemove { get; set; } = false;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private bool hasFilters = false;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public bool HasFilters {
 | 
					 | 
				
			||||||
		get => hasFilters;
 | 
					 | 
				
			||||||
		set => Change(ref hasFilters, value);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private MessageFilterPanelModel FilterModel { get; }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private readonly Window window;
 | 
					 | 
				
			||||||
	private readonly IDatabaseFile db;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	[Obsolete("Designer")]
 | 
					 | 
				
			||||||
	public ViewerPageModel() : this(null!, DummyDatabaseFile.Instance) {}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public ViewerPageModel(Window window, IDatabaseFile db) {
 | 
					 | 
				
			||||||
		this.window = window;
 | 
					 | 
				
			||||||
		this.db = db;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		FilterModel = new MessageFilterPanelModel(window, db, "Will export");
 | 
					 | 
				
			||||||
		FilterModel.FilterPropertyChanged += OnFilterPropertyChanged;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public void Dispose() {
 | 
					 | 
				
			||||||
		FilterModel.Dispose();
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private void OnFilterPropertyChanged(object? sender, PropertyChangedEventArgs e) {
 | 
					 | 
				
			||||||
		HasFilters = FilterModel.HasAnyFilters;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private async Task WriteViewerFile(string path, IViewerExportStrategy strategy) {
 | 
					 | 
				
			||||||
		const string ArchiveTag = "/*[ARCHIVE]*/";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		string indexFile = await Resources.ReadTextAsync("Viewer/index.html");
 | 
					 | 
				
			||||||
		string viewerTemplate = indexFile.Replace("/*[JS]*/", await Resources.ReadJoinedAsync("Viewer/scripts/", '\n'))
 | 
					 | 
				
			||||||
		                                 .Replace("/*[CSS]*/", await Resources.ReadJoinedAsync("Viewer/styles/", '\n'));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		int viewerArchiveTagStart = viewerTemplate.IndexOf(ArchiveTag);
 | 
					 | 
				
			||||||
		int viewerArchiveTagEnd = viewerArchiveTagStart + ArchiveTag.Length;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		string jsonTempFile = path + ".tmp";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		await using (var jsonStream = new FileStream(jsonTempFile, FileMode.Create, FileAccess.ReadWrite, FileShare.Read)) {
 | 
					 | 
				
			||||||
			await ViewerJsonExport.Generate(jsonStream, strategy, db, FilterModel.CreateFilter());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			char[] jsonBuffer = new char[Math.Min(32768, jsonStream.Position)];
 | 
					 | 
				
			||||||
			jsonStream.Position = 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			await using (var outputStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read))
 | 
					 | 
				
			||||||
			await using (var outputWriter = new StreamWriter(outputStream, Encoding.UTF8)) {
 | 
					 | 
				
			||||||
				await outputWriter.WriteAsync(viewerTemplate[..viewerArchiveTagStart]);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				using (var jsonReader = new StreamReader(jsonStream, Encoding.UTF8)) {
 | 
					 | 
				
			||||||
					int readBytes;
 | 
					 | 
				
			||||||
					while ((readBytes = await jsonReader.ReadAsync(jsonBuffer, 0, jsonBuffer.Length)) > 0) {
 | 
					 | 
				
			||||||
						string jsonChunk = new string(jsonBuffer, 0, readBytes);
 | 
					 | 
				
			||||||
						await outputWriter.WriteAsync(HttpUtility.JavaScriptStringEncode(jsonChunk));
 | 
					 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				await outputWriter.WriteAsync(viewerTemplate[viewerArchiveTagEnd..]);
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		File.Delete(jsonTempFile);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public async void OnClickOpenViewer() {
 | 
					 | 
				
			||||||
		string rootPath = Path.Combine(Path.GetTempPath(), "DiscordHistoryTracker");
 | 
					 | 
				
			||||||
		string filenameBase = Path.GetFileNameWithoutExtension(db.Path) + "-" + DateTime.Now.ToString("yyyy-MM-dd");
 | 
					 | 
				
			||||||
		string fullPath = Path.Combine(rootPath, filenameBase + ".html");
 | 
					 | 
				
			||||||
		int counter = 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		while (File.Exists(fullPath)) {
 | 
					 | 
				
			||||||
			++counter;
 | 
					 | 
				
			||||||
			fullPath = Path.Combine(rootPath, filenameBase + "-" + counter + ".html");
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		TemporaryFiles.Add(fullPath);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		Directory.CreateDirectory(rootPath);
 | 
					 | 
				
			||||||
		await WriteViewerFile(fullPath, new LiveViewerExportStrategy(ServerManager.Port, ServerManager.Token));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		Process.Start(new ProcessStartInfo(fullPath) { UseShellExecute = true });
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	private static readonly FilePickerFileType[] ViewerFileTypes = {
 | 
					 | 
				
			||||||
		FileDialogs.CreateFilter("Discord History Viewer", new string[] { "html" }),
 | 
					 | 
				
			||||||
	};
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public async void OnClickSaveViewer() {
 | 
					 | 
				
			||||||
		string? path = await window.StorageProvider.SaveFile(new FilePickerSaveOptions {
 | 
					 | 
				
			||||||
			Title = "Save Viewer",
 | 
					 | 
				
			||||||
			FileTypeChoices = ViewerFileTypes,
 | 
					 | 
				
			||||||
			SuggestedFileName = Path.GetFileNameWithoutExtension(db.Path) + ".html",
 | 
					 | 
				
			||||||
			SuggestedStartLocation = await FileDialogs.GetSuggestedStartLocation(window, Path.GetDirectoryName(db.Path)),
 | 
					 | 
				
			||||||
		});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if (path != null) {
 | 
					 | 
				
			||||||
			await WriteViewerFile(path, StandaloneViewerExportStrategy.Instance);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public async void OnClickApplyFiltersToDatabase() {
 | 
					 | 
				
			||||||
		var filter = FilterModel.CreateFilter();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if (DatabaseToolFilterModeKeep) {
 | 
					 | 
				
			||||||
			if (DialogResult.YesNo.Yes == await Dialog.ShowYesNo(window, "Keep Matching Messages in This Database", db.CountMessages(filter).Pluralize("message") + " will be kept, and the rest will be removed from this database. This action cannot be undone. Proceed?")) {
 | 
					 | 
				
			||||||
				db.RemoveMessages(filter, FilterRemovalMode.KeepMatching);
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		else if (DatabaseToolFilterModeRemove) {
 | 
					 | 
				
			||||||
			if (DialogResult.YesNo.Yes == await Dialog.ShowYesNo(window, "Remove Matching Messages in This Database", db.CountMessages(filter).Pluralize("message") + " will be removed from this database. This action cannot be undone. Proceed?")) {
 | 
					 | 
				
			||||||
				db.RemoveMessages(filter, FilterRemovalMode.RemoveMatching);
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,7 +1,7 @@
 | 
				
			|||||||
using System.Globalization;
 | 
					using System.Globalization;
 | 
				
			||||||
using System.Reflection;
 | 
					using System.Reflection;
 | 
				
			||||||
using Avalonia;
 | 
					using Avalonia;
 | 
				
			||||||
using DHT.Utils.Resources;
 | 
					using DHT.Desktop.Resources;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Desktop;
 | 
					namespace DHT.Desktop;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -32,7 +32,7 @@ static class Program {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private static AppBuilder BuildAvaloniaApp() {
 | 
						private static AppBuilder BuildAvaloniaApp() {
 | 
				
			||||||
		return AppBuilder.Configure<App>()
 | 
							return AppBuilder.Configure<App.App>()
 | 
				
			||||||
		                 .UsePlatformDetect()
 | 
							                 .UsePlatformDetect()
 | 
				
			||||||
		                 .WithInterFont()
 | 
							                 .WithInterFont()
 | 
				
			||||||
		                 .LogToTrace();
 | 
							                 .LogToTrace();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,7 +4,7 @@ using System.Reflection;
 | 
				
			|||||||
using System.Text;
 | 
					using System.Text;
 | 
				
			||||||
using System.Threading.Tasks;
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace DHT.Utils.Resources;
 | 
					namespace DHT.Desktop.Resources;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public sealed class ResourceLoader {
 | 
					public sealed class ResourceLoader {
 | 
				
			||||||
	private readonly Assembly assembly;
 | 
						private readonly Assembly assembly;
 | 
				
			||||||
@@ -1 +0,0 @@
 | 
				
			|||||||
fetch("{url}").then(r => r.ok ? (r.headers.get("X-DHT") === "1" ? r.text() : Promise.reject("Invalid response")) : Promise.reject(r.status + " " + r.statusText)).then(s => eval(s)).catch(e => alert("Could not load tracking script:\n" + e));
 | 
					 | 
				
			||||||
@@ -1,37 +0,0 @@
 | 
				
			|||||||
<Project>
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  <PropertyGroup>
 | 
					 | 
				
			||||||
    <TargetFramework>net8.0</TargetFramework>
 | 
					 | 
				
			||||||
    <LangVersion>11</LangVersion>
 | 
					 | 
				
			||||||
    <Nullable>enable</Nullable>
 | 
					 | 
				
			||||||
  </PropertyGroup>
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  <PropertyGroup>
 | 
					 | 
				
			||||||
    <Authors>chylex</Authors>
 | 
					 | 
				
			||||||
    <Company>DiscordHistoryTracker</Company>
 | 
					 | 
				
			||||||
    <Product>DiscordHistoryTracker</Product>
 | 
					 | 
				
			||||||
  </PropertyGroup>
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  <PropertyGroup>
 | 
					 | 
				
			||||||
    <GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
 | 
					 | 
				
			||||||
    <GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
 | 
					 | 
				
			||||||
    <GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
 | 
					 | 
				
			||||||
  </PropertyGroup>
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  <PropertyGroup>
 | 
					 | 
				
			||||||
    <PublishTrimmed>true</PublishTrimmed>
 | 
					 | 
				
			||||||
    <TrimMode>partial</TrimMode>
 | 
					 | 
				
			||||||
    <JsonSerializerIsReflectionEnabledByDefault>true</JsonSerializerIsReflectionEnabledByDefault>
 | 
					 | 
				
			||||||
  </PropertyGroup>
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
 | 
					 | 
				
			||||||
    <DebugSymbols>false</DebugSymbols>
 | 
					 | 
				
			||||||
    <DebugType>none</DebugType>
 | 
					 | 
				
			||||||
  </PropertyGroup>
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  <PropertyGroup>
 | 
					 | 
				
			||||||
    <UseArtifactsOutput>true</UseArtifactsOutput>
 | 
					 | 
				
			||||||
    <ArtifactsPath>$(MSBuildThisFileDirectory).artifacts</ArtifactsPath>
 | 
					 | 
				
			||||||
  </PropertyGroup>
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
</Project>
 | 
					 | 
				
			||||||
							
								
								
									
										8
									
								
								app/Directory.build.props
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								app/Directory.build.props
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
				
			|||||||
 | 
					<Project>
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  <PropertyGroup>
 | 
				
			||||||
 | 
					    <TargetFramework>net8.0</TargetFramework>
 | 
				
			||||||
 | 
					    <LangVersion>11</LangVersion>
 | 
				
			||||||
 | 
					  </PropertyGroup>
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					</Project>
 | 
				
			||||||
							
								
								
									
										5
									
								
								app/Resources/Tracker/bootstrap.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										5
									
								
								app/Resources/Tracker/bootstrap.js
									
									
									
									
										vendored
									
									
								
							@@ -64,11 +64,9 @@
 | 
				
			|||||||
			let action = null;
 | 
								let action = null;
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
			if (!DISCORD.hasMoreMessages()) {
 | 
								if (!DISCORD.hasMoreMessages()) {
 | 
				
			||||||
				console.debug("[DHT] Reached first message.");
 | 
					 | 
				
			||||||
				action = SETTINGS.afterFirstMsg;
 | 
									action = SETTINGS.afterFirstMsg;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if (isNoAction(action) && !anyNewMessages) {
 | 
								if (isNoAction(action) && !anyNewMessages) {
 | 
				
			||||||
				console.debug("[DHT] No new messages.");
 | 
					 | 
				
			||||||
				action = SETTINGS.afterSavedMsg;
 | 
									action = SETTINGS.afterSavedMsg;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
@@ -123,7 +121,7 @@
 | 
				
			|||||||
				onTrackingContinued(false);
 | 
									onTrackingContinued(false);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			else {
 | 
								else {
 | 
				
			||||||
				const anyNewMessages = await STATE.addDiscordMessages(messages);
 | 
									const anyNewMessages = await STATE.addDiscordMessages(info.id, messages);
 | 
				
			||||||
				onTrackingContinued(anyNewMessages);
 | 
									onTrackingContinued(anyNewMessages);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		} catch (e) {
 | 
							} catch (e) {
 | 
				
			||||||
@@ -158,4 +156,3 @@
 | 
				
			|||||||
		GUI.showSettings();
 | 
							GUI.showSettings();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
})();
 | 
					})();
 | 
				
			||||||
/*[DEBUGGER]*/
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,23 +1,5 @@
 | 
				
			|||||||
// noinspection JSUnresolvedVariable
 | 
					// noinspection JSUnresolvedVariable
 | 
				
			||||||
// noinspection LocalVariableNamingConventionJS
 | 
					 | 
				
			||||||
class DISCORD {
 | 
					class DISCORD {
 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	// https://discord.com/developers/docs/resources/channel#channel-object-channel-types
 | 
					 | 
				
			||||||
	static CHANNEL_TYPE = {
 | 
					 | 
				
			||||||
		DM: 1,
 | 
					 | 
				
			||||||
		GROUP_DM: 3,
 | 
					 | 
				
			||||||
		ANNOUNCEMENT_THREAD: 10,
 | 
					 | 
				
			||||||
		PUBLIC_THREAD: 11,
 | 
					 | 
				
			||||||
		PRIVATE_THREAD: 12
 | 
					 | 
				
			||||||
	};
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	// https://discord.com/developers/docs/resources/channel#message-object-message-types
 | 
					 | 
				
			||||||
	static MESSAGE_TYPE = {
 | 
					 | 
				
			||||||
		DEFAULT: 0,
 | 
					 | 
				
			||||||
		REPLY: 19,
 | 
					 | 
				
			||||||
		THREAD_STARTER: 21
 | 
					 | 
				
			||||||
	};
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	static getMessageOuterElement() {
 | 
						static getMessageOuterElement() {
 | 
				
			||||||
		return DOM.queryReactClass("messagesWrapper");
 | 
							return DOM.queryReactClass("messagesWrapper");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -27,7 +9,7 @@ class DISCORD {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	static getMessageElements() {
 | 
						static getMessageElements() {
 | 
				
			||||||
		return this.getMessageOuterElement().querySelectorAll("[class*='message_']");
 | 
							return this.getMessageOuterElement().querySelectorAll("[class*='message-']");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	static hasMoreMessages() {
 | 
						static hasMoreMessages() {
 | 
				
			||||||
@@ -46,11 +28,46 @@ class DISCORD {
 | 
				
			|||||||
	 * Calls the provided function with a list of messages whenever the currently loaded messages change.
 | 
						 * Calls the provided function with a list of messages whenever the currently loaded messages change.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	static setupMessageCallback(callback) {
 | 
						static setupMessageCallback(callback) {
 | 
				
			||||||
 | 
							let skipsLeft = 0;
 | 
				
			||||||
 | 
							let waitForCleanup = false;
 | 
				
			||||||
		const previousMessages = new Set();
 | 
							const previousMessages = new Set();
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		const onMessageElementsChanged = function() {
 | 
							const timer = window.setInterval(() => {
 | 
				
			||||||
			const messages = DISCORD.getMessages();
 | 
								if (skipsLeft > 0) {
 | 
				
			||||||
			const hasChanged = messages.some(message => !previousMessages.has(message.id)) || !DISCORD.hasMoreMessages();
 | 
									--skipsLeft;
 | 
				
			||||||
 | 
									return;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								const view = this.getMessageOuterElement();
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if (!view) {
 | 
				
			||||||
 | 
									skipsLeft = 2;
 | 
				
			||||||
 | 
									return;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								const anyMessage = DOM.queryReactClass("message", this.getMessageOuterElement());
 | 
				
			||||||
 | 
								const messageCount = anyMessage ? anyMessage.parentElement.children.length : 0;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if (messageCount > 300) {
 | 
				
			||||||
 | 
									if (waitForCleanup) {
 | 
				
			||||||
 | 
										return;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									skipsLeft = 3;
 | 
				
			||||||
 | 
									waitForCleanup = true;
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									window.setTimeout(() => {
 | 
				
			||||||
 | 
										const view = this.getMessageScrollerElement();
 | 
				
			||||||
 | 
										// noinspection JSUnusedGlobalSymbols
 | 
				
			||||||
 | 
										view.scrollTop = view.scrollHeight / 2;
 | 
				
			||||||
 | 
									}, 1);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								else {
 | 
				
			||||||
 | 
									waitForCleanup = false;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								const messages = this.getMessages();
 | 
				
			||||||
 | 
								const hasChanged = messages.some(message => !previousMessages.has(message.id)) || !this.hasMoreMessages();
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
			if (!hasChanged) {
 | 
								if (!hasChanged) {
 | 
				
			||||||
				return;
 | 
									return;
 | 
				
			||||||
@@ -62,74 +79,24 @@ class DISCORD {
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
			callback(messages);
 | 
								callback(messages);
 | 
				
			||||||
		};
 | 
							}, 200);
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		let debounceTimer;
 | 
							window.DHT_ON_UNLOAD.push(() => window.clearInterval(timer));
 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		/**
 | 
					 | 
				
			||||||
		 * Do not trigger the callback too often due to autoscrolling.
 | 
					 | 
				
			||||||
		 */
 | 
					 | 
				
			||||||
		const onMessageElementsChangedLater = function() {
 | 
					 | 
				
			||||||
			window.clearTimeout(debounceTimer);
 | 
					 | 
				
			||||||
			debounceTimer = window.setTimeout(onMessageElementsChanged, 100);
 | 
					 | 
				
			||||||
		};
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		const observer = new MutationObserver(function () {
 | 
					 | 
				
			||||||
			onMessageElementsChangedLater();
 | 
					 | 
				
			||||||
		});
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		let skipsLeft = 0;
 | 
					 | 
				
			||||||
		let observedElement = null;
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		const observerTimer = window.setInterval(() => {
 | 
					 | 
				
			||||||
			if (skipsLeft > 0) {
 | 
					 | 
				
			||||||
				--skipsLeft;
 | 
					 | 
				
			||||||
				return;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			
 | 
					 | 
				
			||||||
			const view = this.getMessageOuterElement();
 | 
					 | 
				
			||||||
			
 | 
					 | 
				
			||||||
			if (!view) {
 | 
					 | 
				
			||||||
				skipsLeft = 1;
 | 
					 | 
				
			||||||
				return;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			
 | 
					 | 
				
			||||||
			if (observedElement !== null && observedElement.isConnected) {
 | 
					 | 
				
			||||||
				return;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			
 | 
					 | 
				
			||||||
			observedElement = view.querySelector("[data-list-id='chat-messages']");
 | 
					 | 
				
			||||||
			
 | 
					 | 
				
			||||||
			if (observedElement) {
 | 
					 | 
				
			||||||
				console.debug("[DHT] Observed message container.");
 | 
					 | 
				
			||||||
				observer.observe(observedElement, { childList: true });
 | 
					 | 
				
			||||||
				onMessageElementsChangedLater();
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}, 400);
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		window.DHT_ON_UNLOAD.push(() => {
 | 
					 | 
				
			||||||
			observer.disconnect();
 | 
					 | 
				
			||||||
			observedElement = null;
 | 
					 | 
				
			||||||
			window.clearInterval(observerTimer);
 | 
					 | 
				
			||||||
		});
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Returns the message from a message element.
 | 
						 * Returns the property object of a message element.
 | 
				
			||||||
	 * @returns { null | DiscordMessage } }
 | 
						 * @returns { null | { message: DiscordMessage, channel: Object } }
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	static getMessageFromElement(ele) {
 | 
						static getMessageElementProps(ele) {
 | 
				
			||||||
		const props = DOM.getReactProps(ele);
 | 
							const props = DOM.getReactProps(ele);
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		if (props && Array.isArray(props.children)) {
 | 
							if (props.children && props.children.length) {
 | 
				
			||||||
			for (const child of props.children) {
 | 
								for (let i = 3; i < props.children.length; i++) {
 | 
				
			||||||
				if (!(child instanceof Object)) {
 | 
									const childProps = props.children[i].props;
 | 
				
			||||||
					continue;
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
				
 | 
									
 | 
				
			||||||
				const childProps = child.props;
 | 
									if (childProps && "message" in childProps && "channel" in childProps) {
 | 
				
			||||||
				if (childProps instanceof Object && "message" in childProps) {
 | 
										return childProps;
 | 
				
			||||||
					return childProps.message;
 | 
					 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -146,10 +113,10 @@ class DISCORD {
 | 
				
			|||||||
			
 | 
								
 | 
				
			||||||
			for (const ele of this.getMessageElements()) {
 | 
								for (const ele of this.getMessageElements()) {
 | 
				
			||||||
				try {
 | 
									try {
 | 
				
			||||||
					const message = this.getMessageFromElement(ele);
 | 
										const props = this.getMessageElementProps(ele);
 | 
				
			||||||
					
 | 
										
 | 
				
			||||||
					if (message != null) {
 | 
										if (props != null) {
 | 
				
			||||||
						messages.push(message);
 | 
											messages.push(props.message);
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				} catch (e) {
 | 
									} catch (e) {
 | 
				
			||||||
					console.error("[DHT] Error extracing message data, skipping it.", e, ele, DOM.tryGetReactProps(ele));
 | 
										console.error("[DHT] Error extracing message data, skipping it.", e, ele, DOM.tryGetReactProps(ele));
 | 
				
			||||||
@@ -170,7 +137,7 @@ class DISCORD {
 | 
				
			|||||||
	 */
 | 
						 */
 | 
				
			||||||
	static getSelectedChannel() {
 | 
						static getSelectedChannel() {
 | 
				
			||||||
		try {
 | 
							try {
 | 
				
			||||||
			let obj = null;
 | 
								let obj;
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
			try {
 | 
								try {
 | 
				
			||||||
				for (const child of DOM.getReactProps(DOM.queryReactClass("chatContent")).children) {
 | 
									for (const child of DOM.getReactProps(DOM.queryReactClass("chatContent")).children) {
 | 
				
			||||||
@@ -181,6 +148,15 @@ class DISCORD {
 | 
				
			|||||||
				}
 | 
									}
 | 
				
			||||||
			} catch (e) {
 | 
								} catch (e) {
 | 
				
			||||||
				console.error("[DHT] Error retrieving selected channel from 'chatContent' element.", e);
 | 
									console.error("[DHT] Error retrieving selected channel from 'chatContent' element.", e);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									for (const ele of this.getMessageElements()) {
 | 
				
			||||||
 | 
										const props = this.getMessageElementProps(ele);
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										if (props != null) {
 | 
				
			||||||
 | 
											obj = props.channel;
 | 
				
			||||||
 | 
											break;
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
			if (!obj || typeof obj.id !== "string") {
 | 
								if (!obj || typeof obj.id !== "string") {
 | 
				
			||||||
@@ -192,7 +168,7 @@ class DISCORD {
 | 
				
			|||||||
			if (dms) {
 | 
								if (dms) {
 | 
				
			||||||
				let name;
 | 
									let name;
 | 
				
			||||||
				
 | 
									
 | 
				
			||||||
				for (const ele of dms.querySelectorAll("[class*='channel_'] [class*='selected_'] [class^='name_'] *")) {
 | 
									for (const ele of dms.querySelectorAll("[class*='channel-'] [class*='selected-'] [class^='name-'] *, [class*='channel-'][class*='selected-'] [class^='name-'] *")) {
 | 
				
			||||||
					const node = Array.prototype.find.call(ele.childNodes, node => node.nodeType === Node.TEXT_NODE);
 | 
										const node = Array.prototype.find.call(ele.childNodes, node => node.nodeType === Node.TEXT_NODE);
 | 
				
			||||||
					
 | 
										
 | 
				
			||||||
					if (node) {
 | 
										if (node) {
 | 
				
			||||||
@@ -209,8 +185,8 @@ class DISCORD {
 | 
				
			|||||||
				
 | 
									
 | 
				
			||||||
				// https://discord.com/developers/docs/resources/channel#channel-object-channel-types
 | 
									// https://discord.com/developers/docs/resources/channel#channel-object-channel-types
 | 
				
			||||||
				switch (obj.type) {
 | 
									switch (obj.type) {
 | 
				
			||||||
					case DISCORD.CHANNEL_TYPE.DM: type = "DM"; break;
 | 
										case 1: type = "DM"; break;
 | 
				
			||||||
					case DISCORD.CHANNEL_TYPE.GROUP_DM: type = "GROUP"; break;
 | 
										case 3: type = "GROUP"; break;
 | 
				
			||||||
					default: return null;
 | 
										default: return null;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				
 | 
									
 | 
				
			||||||
@@ -223,7 +199,7 @@ class DISCORD {
 | 
				
			|||||||
			else if (obj.guild_id) {
 | 
								else if (obj.guild_id) {
 | 
				
			||||||
				let guild;
 | 
									let guild;
 | 
				
			||||||
				
 | 
									
 | 
				
			||||||
				for (const child of DOM.getReactProps(document.querySelector("nav header [class*='headerContent_']")).children) {
 | 
									for (const child of DOM.getReactProps(document.querySelector("nav header [class*='headerContent-']")).children) {
 | 
				
			||||||
					if (child && child.props && child.props.guild) {
 | 
										if (child && child.props && child.props.guild) {
 | 
				
			||||||
						guild = child.props.guild;
 | 
											guild = child.props.guild;
 | 
				
			||||||
						break;
 | 
											break;
 | 
				
			||||||
@@ -248,7 +224,7 @@ class DISCORD {
 | 
				
			|||||||
					}
 | 
										}
 | 
				
			||||||
				};
 | 
									};
 | 
				
			||||||
				
 | 
									
 | 
				
			||||||
				if (obj.type === DISCORD.CHANNEL_TYPE.ANNOUNCEMENT_THREAD || obj.type === DISCORD.CHANNEL_TYPE.PUBLIC_THREAD || obj.type === DISCORD.CHANNEL_TYPE.PRIVATE_THREAD) {
 | 
									if (obj.parent_id) {
 | 
				
			||||||
					channel["extra"]["parent"] = obj.parent_id;
 | 
										channel["extra"]["parent"] = obj.parent_id;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				else {
 | 
									else {
 | 
				
			||||||
@@ -275,10 +251,10 @@ class DISCORD {
 | 
				
			|||||||
		
 | 
							
 | 
				
			||||||
		if (dms) {
 | 
							if (dms) {
 | 
				
			||||||
			const currentChannel = DOM.queryReactClass("selected", dms);
 | 
								const currentChannel = DOM.queryReactClass("selected", dms);
 | 
				
			||||||
			const currentChannelContainer = currentChannel && currentChannel.closest("[class*='channel_']");
 | 
								const currentChannelContainer = currentChannel && currentChannel.closest("[class*='channel-']");
 | 
				
			||||||
			const nextChannel = currentChannelContainer && currentChannelContainer.nextElementSibling;
 | 
								const nextChannel = currentChannelContainer && currentChannelContainer.nextElementSibling;
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
			if (!nextChannel || !nextChannel.getAttribute("class").includes("channel_")) {
 | 
								if (!nextChannel || !nextChannel.getAttribute("class").includes("channel-")) {
 | 
				
			||||||
				return false;
 | 
									return false;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
@@ -305,7 +281,7 @@ class DISCORD {
 | 
				
			|||||||
			let nextChannel = null;
 | 
								let nextChannel = null;
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
			for (let index = 0; index < allTextChannels.length - 1; index++) {
 | 
								for (let index = 0; index < allTextChannels.length - 1; index++) {
 | 
				
			||||||
				if (allTextChannels[index].className.includes("selected_")) {
 | 
									if (allTextChannels[index].className.includes("selected-")) {
 | 
				
			||||||
					nextChannel = allTextChannels[index + 1];
 | 
										nextChannel = allTextChannels[index + 1];
 | 
				
			||||||
					break;
 | 
										break;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -11,7 +11,7 @@ class DOM {
 | 
				
			|||||||
	 * Returns the first child element containing the specified obfuscated class. Parent defaults to the entire document.
 | 
						 * Returns the first child element containing the specified obfuscated class. Parent defaults to the entire document.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	static queryReactClass(cls, parent) {
 | 
						static queryReactClass(cls, parent) {
 | 
				
			||||||
		return (parent || document).querySelector(`[class*="${cls}_"]`);
 | 
							return (parent || document).querySelector(`[class*="${cls}-"]`);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -86,12 +86,12 @@ const GUI = (function() {
 | 
				
			|||||||
<label><input id='dht-cfg-autoscroll' type='checkbox'> Autoscroll</label><br>
 | 
					<label><input id='dht-cfg-autoscroll' type='checkbox'> Autoscroll</label><br>
 | 
				
			||||||
<br>
 | 
					<br>
 | 
				
			||||||
<label>After reaching the first message in channel...</label><br>
 | 
					<label>After reaching the first message in channel...</label><br>
 | 
				
			||||||
${radio("afm", "nothing", "Continue Tracking")}
 | 
					${radio("afm", "nothing", "Do Nothing")}
 | 
				
			||||||
${radio("afm", "pause", "Pause Tracking")}
 | 
					${radio("afm", "pause", "Pause Tracking")}
 | 
				
			||||||
${radio("afm", "switch", "Switch to Next Channel")}
 | 
					${radio("afm", "switch", "Switch to Next Channel")}
 | 
				
			||||||
<br>
 | 
					<br>
 | 
				
			||||||
<label>After reaching a previously saved message...</label><br>
 | 
					<label>After reaching a previously saved message...</label><br>
 | 
				
			||||||
${radio("asm", "nothing", "Continue Tracking")}
 | 
					${radio("asm", "nothing", "Do Nothing")}
 | 
				
			||||||
${radio("asm", "pause", "Pause Tracking")}
 | 
					${radio("asm", "pause", "Pause Tracking")}
 | 
				
			||||||
${radio("asm", "switch", "Switch to Next Channel")}
 | 
					${radio("asm", "switch", "Switch to Next Channel")}
 | 
				
			||||||
<p id='dht-cfg-note'>It is recommended to disable link and image previews to avoid putting unnecessary strain on your browser.</p>`;
 | 
					<p id='dht-cfg-note'>It is recommended to disable link and image previews to avoid putting unnecessary strain on your browser.</p>`;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -174,142 +174,18 @@ const STATE = (function() {
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		/**
 | 
							/**
 | 
				
			||||||
 | 
							 * @param {String} channelId
 | 
				
			||||||
		 * @param {DiscordMessage[]} discordMessageArray
 | 
							 * @param {DiscordMessage[]} discordMessageArray
 | 
				
			||||||
		 */
 | 
							 */
 | 
				
			||||||
		async addDiscordMessages(discordMessageArray) {
 | 
							async addDiscordMessages(channelId, discordMessageArray) {
 | 
				
			||||||
			discordMessageArray = discordMessageArray.filter(msg => (msg.type === DISCORD.MESSAGE_TYPE.DEFAULT || msg.type === DISCORD.MESSAGE_TYPE.REPLY || msg.type === DISCORD.MESSAGE_TYPE.THREAD_STARTER) && msg.state === "SENT");
 | 
								// https://discord.com/developers/docs/resources/channel#message-object-message-types
 | 
				
			||||||
 | 
								discordMessageArray = discordMessageArray.filter(msg => msg.state === "SENT");
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
			if (discordMessageArray.length === 0) {
 | 
								if (discordMessageArray.length === 0) {
 | 
				
			||||||
				return false;
 | 
									return false;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
			const userInfo = {};
 | 
								const response = await post("/track-messages", JSON.stringify(discordMessageArray));
 | 
				
			||||||
			let hasNewUsers = false;
 | 
					 | 
				
			||||||
			
 | 
					 | 
				
			||||||
			for (const msg of discordMessageArray) {
 | 
					 | 
				
			||||||
				const user = msg.author;
 | 
					 | 
				
			||||||
				
 | 
					 | 
				
			||||||
				if (!addedUsers.has(user.id)) {
 | 
					 | 
				
			||||||
					const obj = {
 | 
					 | 
				
			||||||
						id: user.id,
 | 
					 | 
				
			||||||
						name: user.username
 | 
					 | 
				
			||||||
					};
 | 
					 | 
				
			||||||
					
 | 
					 | 
				
			||||||
					if (user.avatar) {
 | 
					 | 
				
			||||||
						obj.avatar = user.avatar;
 | 
					 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
					
 | 
					 | 
				
			||||||
					if (!user.bot) {
 | 
					 | 
				
			||||||
						// noinspection JSUnusedGlobalSymbols
 | 
					 | 
				
			||||||
						obj.discriminator = user.discriminator;
 | 
					 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
					
 | 
					 | 
				
			||||||
					userInfo[user.id] = obj;
 | 
					 | 
				
			||||||
					hasNewUsers = true;
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			
 | 
					 | 
				
			||||||
			if (hasNewUsers) {
 | 
					 | 
				
			||||||
				await post("/track-users", Object.values(userInfo));
 | 
					 | 
				
			||||||
				
 | 
					 | 
				
			||||||
				for (const id of Object.keys(userInfo)) {
 | 
					 | 
				
			||||||
					addedUsers.add(id);
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			
 | 
					 | 
				
			||||||
			const response = await post("/track-messages", discordMessageArray.map(msg => {
 | 
					 | 
				
			||||||
				const obj = {
 | 
					 | 
				
			||||||
					id: msg.id,
 | 
					 | 
				
			||||||
					sender: msg.author.id,
 | 
					 | 
				
			||||||
					channel: msg.channel_id,
 | 
					 | 
				
			||||||
					text: msg.content,
 | 
					 | 
				
			||||||
					timestamp: msg.timestamp.toDate().getTime()
 | 
					 | 
				
			||||||
				};
 | 
					 | 
				
			||||||
				
 | 
					 | 
				
			||||||
				if (msg.editedTimestamp !== null) {
 | 
					 | 
				
			||||||
					// noinspection JSUnusedGlobalSymbols
 | 
					 | 
				
			||||||
					obj.editTimestamp = msg.editedTimestamp.toDate().getTime();
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
				
 | 
					 | 
				
			||||||
				if (msg.messageReference !== null) {
 | 
					 | 
				
			||||||
					// noinspection JSUnusedGlobalSymbols
 | 
					 | 
				
			||||||
					obj.repliedToId = msg.messageReference.message_id;
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
				
 | 
					 | 
				
			||||||
				if (msg.attachments.length > 0) {
 | 
					 | 
				
			||||||
					obj.attachments = msg.attachments.map(attachment => {
 | 
					 | 
				
			||||||
						const mapped = {
 | 
					 | 
				
			||||||
							id: attachment.id,
 | 
					 | 
				
			||||||
							name: attachment.filename,
 | 
					 | 
				
			||||||
							size: attachment.size,
 | 
					 | 
				
			||||||
							url: attachment.url
 | 
					 | 
				
			||||||
						};
 | 
					 | 
				
			||||||
						
 | 
					 | 
				
			||||||
						if (attachment.content_type) {
 | 
					 | 
				
			||||||
							mapped.type = attachment.content_type;
 | 
					 | 
				
			||||||
						}
 | 
					 | 
				
			||||||
						
 | 
					 | 
				
			||||||
						if (attachment.width && attachment.height) {
 | 
					 | 
				
			||||||
							mapped.width = attachment.width;
 | 
					 | 
				
			||||||
							mapped.height = attachment.height;
 | 
					 | 
				
			||||||
						}
 | 
					 | 
				
			||||||
						
 | 
					 | 
				
			||||||
						return mapped;
 | 
					 | 
				
			||||||
					});
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
				
 | 
					 | 
				
			||||||
				if (msg.embeds.length > 0) {
 | 
					 | 
				
			||||||
					obj.embeds = msg.embeds.map(embed => {
 | 
					 | 
				
			||||||
						const mapped = {};
 | 
					 | 
				
			||||||
						
 | 
					 | 
				
			||||||
						for (const key of Object.keys(embed)) {
 | 
					 | 
				
			||||||
							if (key === "id") {
 | 
					 | 
				
			||||||
								continue;
 | 
					 | 
				
			||||||
							}
 | 
					 | 
				
			||||||
							
 | 
					 | 
				
			||||||
							if (key === "rawTitle") {
 | 
					 | 
				
			||||||
								mapped["title"] = embed[key];
 | 
					 | 
				
			||||||
							}
 | 
					 | 
				
			||||||
							else if (key === "rawDescription") {
 | 
					 | 
				
			||||||
								mapped["description"] = embed[key];
 | 
					 | 
				
			||||||
							}
 | 
					 | 
				
			||||||
							else {
 | 
					 | 
				
			||||||
								mapped[key] = embed[key];
 | 
					 | 
				
			||||||
							}
 | 
					 | 
				
			||||||
						}
 | 
					 | 
				
			||||||
						
 | 
					 | 
				
			||||||
						return JSON.stringify(mapped);
 | 
					 | 
				
			||||||
					});
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
				
 | 
					 | 
				
			||||||
				if (msg.reactions.length > 0) {
 | 
					 | 
				
			||||||
					obj.reactions = msg.reactions.map(reaction => {
 | 
					 | 
				
			||||||
						const emoji = reaction.emoji;
 | 
					 | 
				
			||||||
						
 | 
					 | 
				
			||||||
						const mapped = {
 | 
					 | 
				
			||||||
							count: reaction.count
 | 
					 | 
				
			||||||
						};
 | 
					 | 
				
			||||||
						
 | 
					 | 
				
			||||||
						if (emoji.id) {
 | 
					 | 
				
			||||||
							mapped.id = emoji.id;
 | 
					 | 
				
			||||||
						}
 | 
					 | 
				
			||||||
						
 | 
					 | 
				
			||||||
						if (emoji.name) {
 | 
					 | 
				
			||||||
							mapped.name = emoji.name;
 | 
					 | 
				
			||||||
						}
 | 
					 | 
				
			||||||
						
 | 
					 | 
				
			||||||
						if (emoji.animated) {
 | 
					 | 
				
			||||||
							// noinspection JSUnusedGlobalSymbols
 | 
					 | 
				
			||||||
							mapped.isAnimated = emoji.animated;
 | 
					 | 
				
			||||||
						}
 | 
					 | 
				
			||||||
						
 | 
					 | 
				
			||||||
						return mapped;
 | 
					 | 
				
			||||||
					});
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
				
 | 
					 | 
				
			||||||
				return obj;
 | 
					 | 
				
			||||||
			}));
 | 
					 | 
				
			||||||
			
 | 
					 | 
				
			||||||
			const anyNewMessages = await response.text();
 | 
								const anyNewMessages = await response.text();
 | 
				
			||||||
			return anyNewMessages === "1";
 | 
								return anyNewMessages === "1";
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,8 +1,7 @@
 | 
				
			|||||||
const DISCORD = (function() {
 | 
					const DISCORD = (function() {
 | 
				
			||||||
	const regex = {
 | 
						const regex = {
 | 
				
			||||||
		formatBold: /\*\*([\s\S]+?)\*\*(?!\*)/g,
 | 
							formatBold: /\*\*([\s\S]+?)\*\*(?!\*)/g,
 | 
				
			||||||
		formatItalic1: /\*([\s\S]+?)\*(?!\*)/g,
 | 
							formatItalic: /(.)?([_*])([\s\S]+?)\2(?!\2)/g,
 | 
				
			||||||
		formatItalic2: /_([\s\S]+?)_(?!_)\b/g,
 | 
					 | 
				
			||||||
		formatUnderline: /__([\s\S]+?)__(?!_)/g,
 | 
							formatUnderline: /__([\s\S]+?)__(?!_)/g,
 | 
				
			||||||
		formatStrike: /~~([\s\S]+?)~~(?!~)/g,
 | 
							formatStrike: /~~([\s\S]+?)~~(?!~)/g,
 | 
				
			||||||
		formatCodeInline: /(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/g,
 | 
							formatCodeInline: /(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/g,
 | 
				
			||||||
@@ -49,8 +48,7 @@ const DISCORD = (function() {
 | 
				
			|||||||
				.replace(regex.specialEscapedDouble, full => full.replace(/\\/g, "").replace(/(.)/g, escapeHtmlMatch))
 | 
									.replace(regex.specialEscapedDouble, full => full.replace(/\\/g, "").replace(/(.)/g, escapeHtmlMatch))
 | 
				
			||||||
				.replace(regex.formatBold, "<b>$1</b>")
 | 
									.replace(regex.formatBold, "<b>$1</b>")
 | 
				
			||||||
				.replace(regex.formatUnderline, "<u>$1</u>")
 | 
									.replace(regex.formatUnderline, "<u>$1</u>")
 | 
				
			||||||
				.replace(regex.formatItalic1, "<i>$1</i>")
 | 
									.replace(regex.formatItalic, (full, pre, char, match) => pre === "\\" ? full : (pre || "") + "<i>" + match + "</i>")
 | 
				
			||||||
				.replace(regex.formatItalic2, "<i>$1</i>")
 | 
					 | 
				
			||||||
				.replace(regex.formatStrike, "<s>$1</s>");
 | 
									.replace(regex.formatStrike, "<s>$1</s>");
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										27
									
								
								app/Resources/minify.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								app/Resources/minify.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,27 @@
 | 
				
			|||||||
 | 
					#!/usr/bin/env python3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import glob
 | 
				
			||||||
 | 
					import os
 | 
				
			||||||
 | 
					import shutil
 | 
				
			||||||
 | 
					import sys
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if os.name == "nt":
 | 
				
			||||||
 | 
					    uglifyjs = os.path.abspath("../../lib/uglifyjs.cmd")
 | 
				
			||||||
 | 
					else:
 | 
				
			||||||
 | 
					    uglifyjs = "uglifyjs"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if shutil.which(uglifyjs) is None:
 | 
				
			||||||
 | 
					    print("Cannot find executable: {0}".format(uglifyjs))
 | 
				
			||||||
 | 
					    sys.exit(1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					input_dir = os.path.abspath("./Tracker/scripts")
 | 
				
			||||||
 | 
					output_dir = os.path.abspath("../Desktop/bin/.res/scripts")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					os.makedirs(output_dir, exist_ok=True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					for file in glob.glob(input_dir + "/*.js"):
 | 
				
			||||||
 | 
					    name = os.path.basename(file)
 | 
				
			||||||
 | 
					    print("Minifying {0}...".format(name))
 | 
				
			||||||
 | 
					    os.system("{0} {1} -o {2}/{3}".format(uglifyjs, file, output_dir, name))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					print("Done!")
 | 
				
			||||||
@@ -1,15 +0,0 @@
 | 
				
			|||||||
namespace DHT.Server.Data.Aggregations;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public sealed class DownloadStatusStatistics {
 | 
					 | 
				
			||||||
	public int EnqueuedCount { get; internal set; }
 | 
					 | 
				
			||||||
	public ulong EnqueuedSize { get; internal set; }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public int SuccessfulCount { get; internal set; }
 | 
					 | 
				
			||||||
	public ulong SuccessfulSize { get; internal set; }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public int FailedCount { get; internal set; }
 | 
					 | 
				
			||||||
	public ulong FailedSize { get; internal set; }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public int SkippedCount { get; internal set; }
 | 
					 | 
				
			||||||
	public ulong SkippedSize { get; internal set; }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,12 +0,0 @@
 | 
				
			|||||||
namespace DHT.Server.Data;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public readonly struct Attachment {
 | 
					 | 
				
			||||||
	public ulong Id { get; internal init; }
 | 
					 | 
				
			||||||
	public string Name { get; internal init; }
 | 
					 | 
				
			||||||
	public string? Type { get; internal init; }
 | 
					 | 
				
			||||||
	public string NormalizedUrl { get; internal init; }
 | 
					 | 
				
			||||||
	public string DownloadUrl { get; internal init; }
 | 
					 | 
				
			||||||
	public ulong Size { get; internal init; }
 | 
					 | 
				
			||||||
	public int? Width { get; internal init; }
 | 
					 | 
				
			||||||
	public int? Height { get; internal init; }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,11 +0,0 @@
 | 
				
			|||||||
namespace DHT.Server.Data;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public readonly struct Channel {
 | 
					 | 
				
			||||||
	public ulong Id { get; init; }
 | 
					 | 
				
			||||||
	public ulong Server { get; init; }
 | 
					 | 
				
			||||||
	public string Name { get; init; }
 | 
					 | 
				
			||||||
	public ulong? ParentId { get; init; }
 | 
					 | 
				
			||||||
	public int? Position { get; init; }
 | 
					 | 
				
			||||||
	public string? Topic { get; init; }
 | 
					 | 
				
			||||||
	public bool? Nsfw { get; init; }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,33 +0,0 @@
 | 
				
			|||||||
using System;
 | 
					 | 
				
			||||||
using System.Net;
 | 
					 | 
				
			||||||
using DHT.Server.Download;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace DHT.Server.Data;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public readonly struct Download {
 | 
					 | 
				
			||||||
	internal static Download NewSuccess(DownloadItem item, byte[] data) {
 | 
					 | 
				
			||||||
		return new Download(item.NormalizedUrl, item.DownloadUrl, DownloadStatus.Success, (ulong) Math.Max(data.LongLength, 0), data);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	internal static Download NewFailure(DownloadItem item, HttpStatusCode? statusCode, ulong size) {
 | 
					 | 
				
			||||||
		return new Download(item.NormalizedUrl, item.DownloadUrl, statusCode.HasValue ? (DownloadStatus) (int) statusCode : DownloadStatus.GenericError, size);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public string NormalizedUrl { get; }
 | 
					 | 
				
			||||||
	public string DownloadUrl { get; }
 | 
					 | 
				
			||||||
	public DownloadStatus Status { get; }
 | 
					 | 
				
			||||||
	public ulong Size { get; }
 | 
					 | 
				
			||||||
	public byte[]? Data { get; }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	internal Download(string normalizedUrl, string downloadUrl, DownloadStatus status, ulong size, byte[]? data = null) {
 | 
					 | 
				
			||||||
		NormalizedUrl = normalizedUrl;
 | 
					 | 
				
			||||||
		DownloadUrl = downloadUrl;
 | 
					 | 
				
			||||||
		Status = status;
 | 
					 | 
				
			||||||
		Size = size;
 | 
					 | 
				
			||||||
		Data = data;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	internal Download WithData(byte[] data) {
 | 
					 | 
				
			||||||
		return new Download(NormalizedUrl, DownloadUrl, Status, Size, data);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,12 +0,0 @@
 | 
				
			|||||||
using System.Net;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace DHT.Server.Data;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/// <summary>
 | 
					 | 
				
			||||||
/// Extends <see cref="HttpStatusCode"/> with custom status codes in the range 0-99.
 | 
					 | 
				
			||||||
/// </summary>
 | 
					 | 
				
			||||||
public enum DownloadStatus {
 | 
					 | 
				
			||||||
	Enqueued = 0,
 | 
					 | 
				
			||||||
	GenericError = 1,
 | 
					 | 
				
			||||||
	Success = HttpStatusCode.OK
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,6 +0,0 @@
 | 
				
			|||||||
namespace DHT.Server.Data;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public readonly struct DownloadedAttachment {
 | 
					 | 
				
			||||||
	public string? Type { get; internal init; }
 | 
					 | 
				
			||||||
	public byte[] Data { get; internal init; }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,5 +0,0 @@
 | 
				
			|||||||
namespace DHT.Server.Data;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public readonly struct Embed {
 | 
					 | 
				
			||||||
	public string Json { get; internal init; }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,9 +0,0 @@
 | 
				
			|||||||
using System;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace DHT.Server.Data;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
[Flags]
 | 
					 | 
				
			||||||
public enum EmojiFlags : ushort {
 | 
					 | 
				
			||||||
	None = 0,
 | 
					 | 
				
			||||||
	Animated = 0b1
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,15 +0,0 @@
 | 
				
			|||||||
namespace DHT.Server.Data.Filters;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public sealed class AttachmentFilter {
 | 
					 | 
				
			||||||
	public ulong? MaxBytes { get; set; } = null;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public DownloadItemRules? DownloadItemRule { get; set; } = null;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public bool IsEmpty => MaxBytes == null &&
 | 
					 | 
				
			||||||
	                       DownloadItemRule == null;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public enum DownloadItemRules {
 | 
					 | 
				
			||||||
		OnlyNotPresent,
 | 
					 | 
				
			||||||
		OnlyPresent
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,10 +0,0 @@
 | 
				
			|||||||
using System.Collections.Generic;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace DHT.Server.Data.Filters;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public sealed class DownloadItemFilter {
 | 
					 | 
				
			||||||
	public HashSet<DownloadStatus>? IncludeStatuses { get; init; } = null;
 | 
					 | 
				
			||||||
	public HashSet<DownloadStatus>? ExcludeStatuses { get; init; } = null;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public bool IsEmpty => IncludeStatuses == null && ExcludeStatuses == null;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,6 +0,0 @@
 | 
				
			|||||||
namespace DHT.Server.Data.Filters;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public enum FilterRemovalMode {
 | 
					 | 
				
			||||||
	KeepMatching,
 | 
					 | 
				
			||||||
	RemoveMatching
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,19 +0,0 @@
 | 
				
			|||||||
using System;
 | 
					 | 
				
			||||||
using System.Collections.Generic;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace DHT.Server.Data.Filters;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public sealed class MessageFilter {
 | 
					 | 
				
			||||||
	public DateTime? StartDate { get; set; } = null;
 | 
					 | 
				
			||||||
	public DateTime? EndDate { get; set; } = null;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public HashSet<ulong>? ChannelIds { get; set; } = null;
 | 
					 | 
				
			||||||
	public HashSet<ulong>? UserIds { get; set; } = null;
 | 
					 | 
				
			||||||
	public HashSet<ulong>? MessageIds { get; set; } = null;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public bool IsEmpty => StartDate == null &&
 | 
					 | 
				
			||||||
	                       EndDate == null &&
 | 
					 | 
				
			||||||
	                       ChannelIds == null &&
 | 
					 | 
				
			||||||
	                       UserIds == null &&
 | 
					 | 
				
			||||||
	                       MessageIds == null;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,16 +0,0 @@
 | 
				
			|||||||
using System.Collections.Immutable;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace DHT.Server.Data;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public readonly struct Message {
 | 
					 | 
				
			||||||
	public ulong Id { get; init; }
 | 
					 | 
				
			||||||
	public ulong Sender { get; init; }
 | 
					 | 
				
			||||||
	public ulong Channel { get; init; }
 | 
					 | 
				
			||||||
	public string Text { get; init; }
 | 
					 | 
				
			||||||
	public long Timestamp { get; init; }
 | 
					 | 
				
			||||||
	public long? EditTimestamp { get; init; }
 | 
					 | 
				
			||||||
	public ulong? RepliedToId { get; init; }
 | 
					 | 
				
			||||||
	public ImmutableArray<Attachment> Attachments { get; init; }
 | 
					 | 
				
			||||||
	public ImmutableArray<Embed> Embeds { get; init; }
 | 
					 | 
				
			||||||
	public ImmutableArray<Reaction> Reactions { get; init; }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,8 +0,0 @@
 | 
				
			|||||||
namespace DHT.Server.Data;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public readonly struct Reaction {
 | 
					 | 
				
			||||||
	public ulong? EmojiId { get; internal init; }
 | 
					 | 
				
			||||||
	public string? EmojiName { get; internal init; }
 | 
					 | 
				
			||||||
	public EmojiFlags EmojiFlags { get; internal init; }
 | 
					 | 
				
			||||||
	public int Count { get; internal init; }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user