Files
valheim-dashboard/Valheim Dashboard/Views/LizenzView.axaml.cs
2025-08-01 23:28:27 +02:00

144 lines
4.3 KiB
C#

using System;
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Interactivity;
using KeyAuth;
using Valheim_Dashboard.ViewModels;
namespace Valheim_Dashboard.Views;
public partial class LizenzView : UserControl
{
public LizenzView()
{
InitializeComponent();
LizenzKeyTextBox.GotFocus += (sender, e) =>
{
if (LizenzKeyTextBox.Text == "Lizenzkey eingeben")
{
LizenzKeyTextBox.Text = "";
verifizieren_button.IsEnabled = true;
}else if (LizenzKeyTextBox.Text != "Lizenzkey eingeben" || LizenzKeyTextBox.Text != "")
{
verifizieren_button.IsEnabled = true;
verbindung_lizenz_server.IsVisible = false;
verbindung_erfolgreich_lizenz_server.IsVisible = false;
verbindung_fehler_lizenz_server.IsVisible = false;
lizenz_prüfung.IsVisible = false;
lizenz_fehler.IsVisible = false;
lizenz_erfolgreich.IsVisible = false;
}
};
}
public void SetAndCheckLizenz(string lizenzKey)
{
LizenzKeyTextBox.Text = lizenzKey;
VerifyKey();
}
private void Verifizieren_button_OnClick(object? sender, RoutedEventArgs e)
{
if (LizenzKeyTextBox.Text != "")
{
//Animationen.RunSlideAnimation(-60, ueberschrift);
//Animationen.RunSlideAnimation(-120, LizenzKeyTextBox);
//Animationen.FadeOutAnimation(verifizieren_button, 0.3D);
verifizieren_button.IsEnabled = false;
//Animationen.RunSlideAnimation(-100, StatusTextBlock);
VerifyKey();
}
}
public async void VerifyKey()
{
try
{
verbindung_lizenz_server.IsVisible = true;
await Task.Run(KeyAuthApp.init);
if (!KeyAuthApp.response.success)
{
verbindung_fehler_lizenz_server.IsVisible = true;
}
else
{
verbindung_erfolgreich_lizenz_server.IsVisible = true;
}
string key = LizenzKeyTextBox.Text;
lizenz_prüfung.IsVisible = true;
await Task.Run(() =>
{
KeyAuthApp.license(key);
return 0;
});
if (!KeyAuthApp.response.success)
{
lizenz_fehler.IsVisible = true;
Console.WriteLine(KeyAuthApp.response.message);
}
else
{
Settings.SettingsSave("LizenzKey", LizenzKeyTextBox.Text);
lizenz_erfolgreich.IsVisible = true;
weiter.IsVisible = true;
}
}catch (Exception ex)
{
Console.WriteLine("error" + ex);
}
}
public static api KeyAuthApp = new api(
name: "Valheim Dashboard", // App name - VaultCord.com FREE Discord backup bot for members & your entire server saved from terms and nukes!
ownerid: "sS0sZlXiY5", // Account ID
secret: "6e83db8b463d0a3822b002f8d06dbe51d07c8f0481bda05038291eac5d74eb0f",
version: "1.0" // Application version. Used for automatic downloads see video here https://www.youtube.com/watch?v=kW195PLCBKs
//path: @"Your_Path_Here" // (OPTIONAL) see tutorial here https://www.youtube.com/watch?v=I9rxt821gMk&t=1s
);
public static string[] lizenz_name;
private void Weiter_Click(object sender, RoutedEventArgs e)
{
Console.WriteLine("weiter geklickt");
if (this.Parent.Parent.Parent is MainWindow mainWindow)
{
if(mainWindow.DataContext is MainWindowViewModel mainWindowViewModel)
{
lizenz_name = LizenzKeyTextBox.Text.Split('-');
if (lizenz_name[2] == "A")
{
mainWindowViewModel.SwitchToServerSettings();
}
else
{
Console.WriteLine(KeyAuthApp.var(lizenz_name[1]));
mainWindowViewModel.SwitchToDashboard();
}
}
}
}
}