Projektdateien hinzufügen.
This commit is contained in:
113
Valheim Mod Sync Desktop/Views/Setup.xaml.cs
Normal file
113
Valheim Mod Sync Desktop/Views/Setup.xaml.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
using System;
|
||||
using System.CodeDom.Compiler;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using Valheim_Mod_Sync_Desktop.Commands;
|
||||
using Valheim_Mod_Sync_Desktop.ViewModels;
|
||||
|
||||
namespace Valheim_Mod_Sync_Desktop.Views
|
||||
{
|
||||
public class LizenzIPReturn
|
||||
{
|
||||
public string admin { get; set; }
|
||||
public string IP_Alt { get; set; }
|
||||
public string IP { get; set; }
|
||||
}
|
||||
|
||||
public partial class Setup : UserControl
|
||||
{
|
||||
public Setup()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
}
|
||||
|
||||
private void SetupIPUebertragen(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (ServerIP.Text == null || !ServerIP.Text.Contains(":"))
|
||||
{
|
||||
output.Text += (string)Application.Current.FindResource("SetupIPFehler");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
var LizenzKey = Properties.Settings.Default.Lizenz;
|
||||
var ServerIPClean = ServerIP.Text.Replace(" ", "");
|
||||
|
||||
try
|
||||
{
|
||||
string html = string.Empty;
|
||||
string url = @"https://tbs-server.de//wp-json/lmfwc/v2/vms/check_server_ip/" + LizenzKey + "/" + ServerIPClean;
|
||||
string encoded = System.Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1")
|
||||
.GetBytes(Properties.Settings.Default.benutzername + ":" + Properties.Settings.Default.passwort));
|
||||
|
||||
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
||||
request.AutomaticDecompression = DecompressionMethods.GZip;
|
||||
request.Headers.Add("Authorization", "Basic " + encoded);
|
||||
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
|
||||
using (Stream stream = response.GetResponseStream())
|
||||
using (StreamReader reader = new StreamReader(stream))
|
||||
{
|
||||
html = reader.ReadToEnd();
|
||||
}
|
||||
|
||||
LizenzIPReturn lizenzip_return = JsonSerializer.Deserialize<LizenzIPReturn>(html);
|
||||
//Debug.WriteLine(lizenz_return.success);
|
||||
//Debug.WriteLine(lizenz_return.data.timesActivated);
|
||||
//Debug.WriteLine(lizenz_return.data.timesActivatedMax);
|
||||
//Debug.WriteLine(lizenz_return.data.remainingActivations);
|
||||
//Debug.WriteLine(lizenz_return.data.hwid);
|
||||
//Debug.WriteLine(html);
|
||||
|
||||
if (lizenzip_return.IP_Alt != lizenzip_return.IP)
|
||||
{
|
||||
|
||||
output.Text += (string)Application.Current.FindResource("ServerIPUebertragen");
|
||||
ServerIP.IsEnabled = false;
|
||||
SetupBeenden.Content = Application.Current.FindResource("SetupBeenden");
|
||||
SetupBeenden.Click -= new RoutedEventHandler(SetupIPUebertragen);
|
||||
SetupBeenden.Click += new RoutedEventHandler(SetupBeenden_);
|
||||
Properties.Settings.Default.Server = ServerIPClean;
|
||||
Properties.Settings.Default.ModVersion = 0;
|
||||
Properties.Settings.Default.Save();
|
||||
MainWindow mainWindow = (MainWindow)Application.Current.MainWindow;
|
||||
mainWindow.Server.Text = ServerIPClean;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
output.Text += (string)Application.Current.FindResource("ServerIPUebertragenFehler");
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Debug.WriteLine(ex);
|
||||
//output.Text = (string)Application.Current.FindResource("LizenzKeyFehler");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupBeenden_(object sender, RoutedEventArgs e)
|
||||
{
|
||||
MainViewModel mainViewModel = (MainViewModel)Application.Current.MainWindow.DataContext;
|
||||
mainViewModel.SelectedViewModel = new SyncViewModel();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user