diff --git a/Valheim Mod Sync Desktop.sln b/Valheim Mod Sync Desktop.sln new file mode 100644 index 0000000..2525624 --- /dev/null +++ b/Valheim Mod Sync Desktop.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.32106.194 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Valheim Mod Sync Desktop", "Valheim Mod Sync Desktop\Valheim Mod Sync Desktop.csproj", "{1DBE919B-67AE-4A8E-B127-F5F06AD57383}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1DBE919B-67AE-4A8E-B127-F5F06AD57383}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1DBE919B-67AE-4A8E-B127-F5F06AD57383}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1DBE919B-67AE-4A8E-B127-F5F06AD57383}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1DBE919B-67AE-4A8E-B127-F5F06AD57383}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {2B932E8B-267F-4AD8-85B7-2935D6E805FE} + EndGlobalSection +EndGlobal diff --git a/Valheim Mod Sync Desktop/App.config b/Valheim Mod Sync Desktop/App.config new file mode 100644 index 0000000..49cc43e --- /dev/null +++ b/Valheim Mod Sync Desktop/App.config @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/Valheim Mod Sync Desktop/App.xaml b/Valheim Mod Sync Desktop/App.xaml new file mode 100644 index 0000000..7c456df --- /dev/null +++ b/Valheim Mod Sync Desktop/App.xaml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Valheim Mod Sync Desktop/App.xaml.cs b/Valheim Mod Sync Desktop/App.xaml.cs new file mode 100644 index 0000000..a63b5a7 --- /dev/null +++ b/Valheim Mod Sync Desktop/App.xaml.cs @@ -0,0 +1,181 @@ +using System; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.Configuration; +using System.Data; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Text; +using System.Text.Json; +using System.Threading.Tasks; +using System.Web; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Threading; + + +namespace Valheim_Mod_Sync_Desktop +{ + + public partial class App : Application + { + protected override void OnStartup(StartupEventArgs e) + { + base.OnStartup(e); + DispatcherUnhandledException += App_DispatcherUnhandledException; + } + + private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) + { + // Erstellen Sie den Crash-Bericht. + var crashReport = CreateCrashReport(e.Exception); + + // Zeigen Sie eine Benutzeroberfläche an, um den Benutzer aufzufordern, den Bericht zu senden. + var result = ShowCrashReportDialog(crashReport); + + if (result == true) + { + // Senden Sie den Bericht an die URL. + SendCrashReport(crashReport, "https://vms.tbs-server.de/crashreport.php"); + } + + e.Handled = true; + } + + private void SendCrashReport(string crashReport, string url) + { + + try + { + using (WebClient client = new WebClient()) + { + NameValueCollection data = new NameValueCollection(); + data["crashReport"] = crashReport; + data["Lizenz"] = Valheim_Mod_Sync_Desktop.Properties.Settings.Default.Lizenz; + byte[] responseBytes = client.UploadValues(url, "POST", data); + NameValueCollection response = HttpUtility.ParseQueryString(Encoding.UTF8.GetString(responseBytes)); + if (response.ToString() == "true") + { + // Zeigen Sie eine Benachrichtigung an, dass der Crash-Bericht erfolgreich gesendet wurde. + MessageBox.Show((string)Application.Current.FindResource("CrashGesendet")); + } + else + { + // Zeigen Sie eine Benachrichtigung an, dass beim Senden des Crash-Berichts ein Fehler aufgetreten ist. + MessageBox.Show((string)Application.Current.FindResource("CrashFehler")); + } + } + } + catch (WebException ex) + { + // Zeigen Sie eine Benachrichtigung an, dass beim Senden des Crash-Berichts ein Fehler aufgetreten ist. + MessageBox.Show("Error sending crash report: " + ex.Message); + } + } + + + + private string CreateCrashReport(Exception exception) + { + + + var report = new StringBuilder(); + report.AppendLine("Crash report:"); + report.AppendLine(); + report.AppendLine("Lizenz: " + Valheim_Mod_Sync_Desktop.Properties.Settings.Default.Lizenz); + report.AppendLine(); + report.AppendLine("Exception type: " + exception.GetType().FullName); + report.AppendLine("Exception message: " + exception.Message); + report.AppendLine(); + report.AppendLine("Stack trace:"); + report.AppendLine(exception.StackTrace); + + + if (exception.InnerException != null) + { + report.AppendLine(); + report.AppendLine("Inner exception type: " + exception.InnerException.GetType().FullName); + report.AppendLine("Inner exception message: " + exception.InnerException.Message); + report.AppendLine(); + report.AppendLine("Inner stack trace:"); + report.AppendLine(exception.InnerException.StackTrace); + } + + string localAppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); + string configPath = Path.Combine(localAppDataPath, "tbS-server"); + File.WriteAllText(configPath + "/CrashReport.txt", report.ToString()); + + return report.ToString(); + } + + private bool ShowCrashReportDialog(string crashReport) + { + var window = new Crash(); + return window.ShowDialog() == true; + } + + + private void Application_Startup(object sender, StartupEventArgs e) + { + + if (e.Args.Length == 1 && e.Args[0] == "--config-reset") + { + if (File.Exists(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath)) + { + File.Delete(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath); + + } + + MessageBox.Show("Config deleted, please re-open VMS and Configure"); + + this.Shutdown(); + + + } else if (e.Args.Length == 1 && e.Args[0] == "--crashreport-send") + { + // Senden des Letzen CrashReports + + string localAppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); + string configPath = Path.Combine(localAppDataPath, "tbS-server"); + string crashReport = File.ReadAllText(configPath + "/CrashReport.txt"); + + SendCrashReport(crashReport, "https://vms.tbs-server.de/crashreport.php"); + this.Shutdown(); + + } else { + MainWindow wnd = new MainWindow(); + //wnd.Show(); + } + + } + + + + public ResourceDictionary ThemeDictionary + { + get { return Resources.MergedDictionaries[0]; } + } + + public void ChangeTheme(Uri uri) + { + ThemeDictionary.MergedDictionaries.Clear(); + ThemeDictionary.MergedDictionaries.Add(new ResourceDictionary() { Source = uri }); + } + + + public ResourceDictionary LanguageDictionary + { + get { return Resources.MergedDictionaries[1]; } + } + + public void ChangeLanguage(Uri uri) + { + + LanguageDictionary.MergedDictionaries.Clear(); + LanguageDictionary.MergedDictionaries.Add(new ResourceDictionary() { Source = uri }); + } + } +} diff --git a/Valheim Mod Sync Desktop/AssemblyInfo.cs b/Valheim Mod Sync Desktop/AssemblyInfo.cs new file mode 100644 index 0000000..8b5504e --- /dev/null +++ b/Valheim Mod Sync Desktop/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/Valheim Mod Sync Desktop/Benachrichtigung.xaml b/Valheim Mod Sync Desktop/Benachrichtigung.xaml new file mode 100644 index 0000000..6236c1d --- /dev/null +++ b/Valheim Mod Sync Desktop/Benachrichtigung.xaml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/Valheim Mod Sync Desktop/Benachrichtigung.xaml.cs b/Valheim Mod Sync Desktop/Benachrichtigung.xaml.cs new file mode 100644 index 0000000..b6a688a --- /dev/null +++ b/Valheim Mod Sync Desktop/Benachrichtigung.xaml.cs @@ -0,0 +1,113 @@ +using System.Diagnostics; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Input; + +namespace Valheim_Mod_Sync_Desktop +{ + /// + /// Interaktionslogik für Benachrichtigung.xaml + /// + public partial class Benachrichtigung : Window + { + public Benachrichtigung(bool Name, bool Email, bool Message, bool Send, bool KeinInternet, bool Error, bool StartKeinInternet, bool StartValheim) + { + InitializeComponent(); + + if (Name) + { + name.Visibility = Visibility.Visible; + } + + if (Email) + { + email.Visibility = Visibility.Visible; + } + + if(Message) + { + message.Visibility = Visibility.Visible; + } + + if (Send && !KeinInternet) + { + send.Visibility = Visibility.Visible; + } + + if (KeinInternet) + { + keininternet.Visibility = Visibility.Visible; + } + + if (Error) + { + error.Visibility = Visibility.Visible; + } + + if (StartKeinInternet) + { + startkeininternet.Visibility = Visibility.Visible; + MainWindow.LizenzReturn = "false"; + } + + if (StartValheim) + { + startvalheim.Visibility = Visibility.Visible; + BenachrichtigungsFenster.KeyDown += OnKeyDownHandler; + Keyboard.Focus(BenachrichtigungsFenster); + ValheimStart(); + } + + + } + + private bool abort = false; + + private async void ValheimStart() + { + await Task.Delay(5000); + if (abort == false) + { + var uri = "steam://rungameid/892970"; + var psi = new ProcessStartInfo(); + psi.UseShellExecute = true; + psi.FileName = uri; + Process.Start(psi); + this.Close(); + Application.Current.MainWindow.Close(); + }else + { + return; + } + } + + private async void OnKeyDownHandler(object sender, KeyEventArgs e) + { + if (e.Key == Key.Escape) + { + abort = true; + this.Close(); + return; + } + } + + //Close Button + private void exitBtn_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + this.Close(); + + } + + //Minimize Button + private void miniBtn_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + this.WindowState = WindowState.Minimized; + } + + //Header Move + private void header_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + this.DragMove(); + } + } +} diff --git a/Valheim Mod Sync Desktop/Commands/UpdateViewCommand.cs b/Valheim Mod Sync Desktop/Commands/UpdateViewCommand.cs new file mode 100644 index 0000000..111eb30 --- /dev/null +++ b/Valheim Mod Sync Desktop/Commands/UpdateViewCommand.cs @@ -0,0 +1,48 @@ +using Valheim_Mod_Sync_Desktop.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Input; + +namespace Valheim_Mod_Sync_Desktop.Commands +{ + class UpdateViewCommand : ICommand + { + private MainViewModel viewModel; + + public UpdateViewCommand(MainViewModel viewModel) + { + this.viewModel = viewModel; + } + + public event EventHandler CanExecuteChanged; + + public bool CanExecute(object parameter) + { + return true; + } + + public void Execute(object parameter) + { + + if (parameter.ToString() == "SyncView") + { + viewModel.SelectedViewModel = new SyncViewModel(); + } + else if (parameter.ToString() == "Kontakt") + { + viewModel.SelectedViewModel = new KontaktViewModel(); + } + else if (parameter.ToString() == "Setup") + { + viewModel.SelectedViewModel = new SetupViewModel(); + } + else if (parameter.ToString() == "FTP") + { + viewModel.SelectedViewModel = new FTPViewModel(); + } + } + } +} \ No newline at end of file diff --git a/Valheim Mod Sync Desktop/Crash.xaml b/Valheim Mod Sync Desktop/Crash.xaml new file mode 100644 index 0000000..79fe95e --- /dev/null +++ b/Valheim Mod Sync Desktop/Crash.xaml @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Valheim Mod Sync Desktop/MainWindow.xaml.cs b/Valheim Mod Sync Desktop/MainWindow.xaml.cs new file mode 100644 index 0000000..5318456 --- /dev/null +++ b/Valheim Mod Sync Desktop/MainWindow.xaml.cs @@ -0,0 +1,554 @@ +using System; +using System.Net; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; +using System.Text.Json; +using System.IO; +using Application = System.Windows.Application; +using Valheim_Mod_Sync_Desktop.ViewModels; +using Valheim_Mod_Sync_Desktop.Views; +using IWshRuntimeLibrary; +using System.Linq; +using System.Threading.Tasks; +using Valheim_Mod_Sync_Desktop.Properties; +using System.Diagnostics; +using System.Configuration; +using System.Security.Cryptography; +using System.Threading; +using System.Windows.Media; + +namespace Valheim_Mod_Sync_Desktop +{ + public class LizenzReturn + { + public bool success { get; set; } + public LizenzDetail data { get; set; } + } + + public class LizenzDetail + { + public int timesActivatedMax { get; set; } + public int remainingActivations { get; set; } + public int timesActivated { get; set; } + public string hwid { get; set; } + } + + public class LizenzReturnDeactivate + { + public bool success { get; set; } + public LizenzDetailDeactivate data { get; set; } + } + + public class LizenzDetailDeactivate + { + public int timesActivatedMax { get; set; } + public int remainingActivations { get; set; } + public int timesActivated { get; set; } + public string hwid { get; set; } + } + + + + public partial class MainWindow : Window + { + public static string LizenzReturn { get; set; } + private MainViewModel viewModel; + private Ladescreen _splashScreen; + + public MainWindow() + { + + InitializeComponent(); + + viewModel = new MainViewModel(); + DataContext = viewModel; + Loaded += Loadedfinish; + + // Erstelle den Splashscreen und zeige ihn an + _splashScreen = new Ladescreen(); + _splashScreen.Show(); + _splashScreen.SetProgress(0); + // Starte den Hintergrundprozess + Task.Run(async () => + { + // Führe die Aufgabe aus + await DoLongTaskAsync(); + + // Schließe den Splashscreen + Dispatcher.Invoke(() => + { + this.Show(); + _splashScreen.Close(); + Debug.WriteLine("show"); + + }); + }); + + } + + private async Task DoLongTaskAsync() + { + + await UpdateProgressAsync(10); + await UpdateProgressNameAsync("Prüfe Config"); + Debug.WriteLine("10"); + //Debug.WriteLine(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath); + //Übernehmem der alten Config beim ersten Start + if (Properties.Settings.Default.ErsterStart) + { + Properties.Settings.Default.Upgrade(); + Properties.Settings.Default.ErsterStart = false; + Properties.Settings.Default.Save(); + + } + + // Aktualisiere den Fortschritt + await UpdateProgressAsync(30); + await UpdateProgressNameAsync("Lade Config"); + Debug.WriteLine("30"); + //Read config + + Application.Current.Dispatcher.Invoke(() => + { + try + { + // Hier kommt Ihr Code rein + Theme.Text = Properties.Settings.Default.Theme; + Server.Text = Properties.Settings.Default.Server; + Sprache.Text = Properties.Settings.Default.Sprache; + Autostart.IsChecked = Properties.Settings.Default.Autostart; + StartmenueVerknuepfung.IsChecked = Properties.Settings.Default.Verknuepfung; + + } + catch (InvalidOperationException ex) + { + Debug.WriteLine("Fehler: " + ex.Message); + } + }); + + + + // Aktualisiere den Fortschritt + await UpdateProgressAsync(50); + await UpdateProgressNameAsync("Prüfe Internetzugang"); + Debug.WriteLine("50"); + //prüfe verbindung + if (SyncControl.IsConnectionAvailable()) + { + //prüfe lizenz + // Aktualisiere den Fortschritt + + await UpdateProgressAsync(60); + await UpdateProgressNameAsync("Prüfe Lizenz"); + Debug.WriteLine("60"); + await Prüfung(); + // Aktualisiere den Fortschritt + await UpdateProgressAsync(70); + await UpdateProgressNameAsync("Prüfe ob Server IP gesetzt"); + Debug.WriteLine("70"); + PrüfungServerIP(); + + + // Aktualisiere den Fortschritt + await UpdateProgressAsync(80); + Debug.WriteLine("80"); + + } + else + { + Benachrichtigung modalWindow = new Benachrichtigung(false, false, false, false, false, false, true, false); + modalWindow.ShowDialog(); + + if (LizenzReturn == "false") + { + this.Close(); + } + } + + // Aktualisiere den Fortschritt + await UpdateProgressAsync(90); + await UpdateProgressNameAsync("Prüfe Einstellungen"); + Debug.WriteLine("90"); + //check autostart + SyncControl.CheckUpdateAutostart(); + // Aktualisiere den Fortschritt + await UpdateProgressAsync(95); + await UpdateProgressNameAsync("Lade Anwendung"); + Debug.WriteLine("95"); + + await UpdateProgressAsync(100); + await UpdateProgressNameAsync("Fertig"); + Debug.WriteLine("100"); + + + } + + private async Task UpdateProgressAsync(int progress) + { + // Aktualisiere den Fortschritt + await Dispatcher.InvokeAsync(() => + { + _splashScreen.SetProgress(progress); + }); + + // Warte eine kurze Zeit, damit die Fortschrittsleiste aktualisiert wird + await Task.Delay(100); + } + + private async Task UpdateProgressNameAsync(string progressName) + { + // Aktualisiere den Fortschritt + await Dispatcher.InvokeAsync(() => + { + _splashScreen.SetProgressName(progressName); + }); + + // Warte eine kurze Zeit, damit die Fortschrittsleiste aktualisiert wird + await Task.Delay(100); + } + + //Wenn fertig geladen + + private void Loadedfinish(object sender, RoutedEventArgs e) + { + if (Properties.Settings.Default.Server == "..." && admin || !Properties.Settings.Default.Server.Contains(":") && admin) + { + contentControl.Content = new SetupViewModel(); + MenüGrid.Visibility = Visibility.Hidden; + } + + if (!admin) + { + Server.IsEnabled = false; + } + + } + + + //Prüfung + private async Task Prüfung() + { + + + if (Properties.Settings.Default.Lizenz == "") + { + + + Lizenz modalWindow = null; + await Application.Current.Dispatcher.InvokeAsync(() => + { + modalWindow = new Lizenz(); + modalWindow.ShowDialog(); + }); + + if (LizenzReturn == "false") + { + Application.Current.Dispatcher.Invoke(() => + { + // Schließen des Splashscreens + _splashScreen.Dispatcher.Invoke(() => + { + _splashScreen.Close(); + }); + ((MainWindow)Application.Current.MainWindow).Close(); + }); + + + } + }else + { + string html = string.Empty; + string url = @"https://tbs-server.de/wp-json/lmfwc/v2/licenses/validate/" + Properties.Settings.Default.Lizenz; + 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(); + } + + LizenzReturn lizenz_return = JsonSerializer.Deserialize(html); + + if (lizenz_return.data.hwid != Lizenz.HardwareID()) + { + Lizenz modalWindow = new Lizenz(); + modalWindow.ShowDialog(); + + if (LizenzReturn == "false") + { + this.Close(); + } + } + + } + } + + public class LizenzIPReturn_ + { + public string Admin { get; set; } + public string IP_Alt { get; set; } + public string IP { get; set; } + } + + private bool admin; + + //Prüfung ServerIP + private void PrüfungServerIP() + { + + string html = string.Empty; + string url = @"https://tbs-server.de//wp-json/lmfwc/v2/vms/check_server_ip/" + Properties.Settings.Default.Lizenz; + 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(html); + admin = (lizenzip_return_.Admin == "true") ? true : false; + + if (!lizenzip_return_.IP.Equals("0") | lizenzip_return_.IP.Contains(":")) + { + Properties.Settings.Default.Server = lizenzip_return_.IP; + Properties.Settings.Default.ModVersion = 0; + Properties.Settings.Default.Save(); + + Application.Current.Dispatcher.Invoke(() => + { + Server.Text = lizenzip_return_.IP; + }); + } + else + { + Properties.Settings.Default.Server = "..."; + Properties.Settings.Default.ModVersion = 0; + Properties.Settings.Default.Save(); + } + + } + + //Close Button + private void exitBtn_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + this.Close(); + } + + //Minimize Button + private void miniBtn_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + this.WindowState = WindowState.Minimized; + } + + //Header Move + private void header_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + this.DragMove(); + } + + //Save Theme Change to Config + private void theme_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + ComboBoxItem typeItem = (ComboBoxItem)Theme.SelectedItem; + string value = typeItem.Content.ToString(); + Properties.Settings.Default.Theme = value; + Properties.Settings.Default.Save(); + + var app = (App)Application.Current; app.ChangeTheme(new Uri("/Skins/" + value + ".xaml", UriKind.RelativeOrAbsolute)); + + } + + + //Save Sprache + private void Sprache_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + ComboBoxItem sprachItem = (ComboBoxItem)Sprache.SelectedItem; + string sprachvalue = sprachItem.Content.ToString(); + Properties.Settings.Default.Sprache = sprachvalue; + Properties.Settings.Default.Save(); + var app1 = (App)Application.Current; + app1.ChangeLanguage(new Uri("/Language/" + sprachvalue + ".xaml", UriKind.RelativeOrAbsolute)); + + } + + //Save Server + private void Server_TextChanged(object sender, TextChangedEventArgs e) + { + if (Server.Text != Properties.Settings.Default.Server) + { + //Debug.WriteLine("change"); + Properties.Settings.Default.ModVersion = 0; + Properties.Settings.Default.Server = Server.Text; + Properties.Settings.Default.Save(); + } + + } + + //Save state Autostart + private void Autostart_Click(object sender, RoutedEventArgs e) + { + Properties.Settings.Default.Autostart = (bool)Autostart.IsChecked; + Properties.Settings.Default.Save(); + } + + //Kontakt Button + private void KontaktButton_Click(object sender, RoutedEventArgs e) + { + contentControl.Content = new Kontakt(); + MenuToggleButton.Visibility = Visibility.Collapsed; + Back.Visibility = Visibility.Visible; + } + + //Zurück Button + private void Back_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + contentControl.Content = new SyncControl(); + Back.Visibility = Visibility.Collapsed; + MenuToggleButton.Visibility = Visibility.Visible; + } + + //Verknüpfung Hinzufügen / Löschen + private void StartmenueVerknuepfung_Click(object sender, RoutedEventArgs e) + { + Properties.Settings.Default.Verknuepfung = (bool)StartmenueVerknuepfung.IsChecked; + Properties.Settings.Default.Save(); + + string pathToExe = Directory.GetCurrentDirectory() + "/" + System.Diagnostics.Process.GetCurrentProcess().ProcessName + ".exe"; + string programs_path = Environment.GetFolderPath(Environment.SpecialFolder.Programs); + string appStartMenuOrdner = "tbs-server.de"; + string appStartMenuPath = Path.Combine(programs_path, appStartMenuOrdner, "Valheim Mod Sync"); + string settingsLink = Path.Combine(appStartMenuPath, "Valheim Mod Sync.lnk"); + + if (StartmenueVerknuepfung.IsChecked == true) + { + if (!Directory.Exists(appStartMenuPath)) + { + Directory.CreateDirectory(appStartMenuPath); + } + + new WebClient().DownloadFile("https://vms.tbs-server.de/vms.ico", appStartMenuPath+"/vms.ico"); + + WshShell shellClass = new WshShell(); + + IWshShortcut shortcut = (IWshShortcut)shellClass.CreateShortcut(settingsLink); + shortcut.TargetPath = pathToExe; + shortcut.WorkingDirectory = Directory.GetCurrentDirectory(); + shortcut.IconLocation = appStartMenuPath+"/vms.ico"; + shortcut.Description = "Valheim Mod Sync"; + shortcut.Save(); + }else + { + if (Directory.Exists(appStartMenuPath)) + { + System.IO.File.Delete(settingsLink); + System.IO.File.Delete(appStartMenuPath + "/vms.ico"); + Directory.Delete(appStartMenuPath); + if (!Directory.EnumerateFileSystemEntries(Path.Combine(programs_path, appStartMenuOrdner)).Any()) + { + Directory.Delete(Path.Combine(programs_path, appStartMenuOrdner)); + } + + } + } + + } + + private void Lizenz_Deaktivieren_Click(object sender, RoutedEventArgs e) + { + try + { + string html = string.Empty; + string url = @"https://tbs-server.de//wp-json/lmfwc/v2/licenses/deactivate/" + Properties.Settings.Default.Lizenz; + 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(); + } + + LizenzReturnDeactivate lizenz_return_deactivate = JsonSerializer.Deserialize(html); + + + if (lizenz_return_deactivate.data.timesActivated != lizenz_return_deactivate.data.timesActivatedMax && lizenz_return_deactivate.success == true) + { + + Properties.Settings.Default.Lizenz = ""; + Properties.Settings.Default.Save(); + + this.Close(); + } + else + { + + } + } + catch + { + //outputlizenz.Text = (string)Application.Current.FindResource("LizenzKeyFehler"); + } + } + + private void Sync_Menu_Click(object sender, RoutedEventArgs e) + { + contentControl.Content = new SyncControl(); + MenüAktivBorder(); + Sync_Menu.SetResourceReference(Button.BackgroundProperty, "BackgroundGrid"); + } + + private void Mods_View_Click(object sender, RoutedEventArgs e) + { + contentControl.Content = new FTP(); + MenüAktivBorder(); + Mods_View.SetResourceReference(Button.BackgroundProperty, "BackgroundGrid"); + } + + private void Lizenzen_View_Click(object sender, RoutedEventArgs e) + { + contentControl.Content = new Lizenzen(); + MenüAktivBorder(); + Mods_View.SetResourceReference(Button.BackgroundProperty, "BackgroundGrid"); + } + + private void Einstellungen_View_Click(object sender, RoutedEventArgs e) + { + contentControl.Content = new Kontakt(); + MenüAktivBorder(); + //Einstellungen_View.Background = Brushes.Red; + Einstellungen_View.SetResourceReference(Button.BackgroundProperty, "BackgroundGrid"); + + } + + private void MenüAktivBorder() + { + foreach (var child in MenüGrid.Children) + { + if (child is Button button) + { + button.Background = Brushes.Transparent; + } + } + } + } +} diff --git a/Valheim Mod Sync Desktop/Properties/.resx b/Valheim Mod Sync Desktop/Properties/.resx new file mode 100644 index 0000000..4fdb1b6 --- /dev/null +++ b/Valheim Mod Sync Desktop/Properties/.resx @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Valheim Mod Sync Desktop/Properties/Settings.Designer.cs b/Valheim Mod Sync Desktop/Properties/Settings.Designer.cs new file mode 100644 index 0000000..827b159 --- /dev/null +++ b/Valheim Mod Sync Desktop/Properties/Settings.Designer.cs @@ -0,0 +1,152 @@ +//------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +//------------------------------------------------------------------------------ + +namespace Valheim_Mod_Sync_Desktop.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.10.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("Light")] + public string Theme { + get { + return ((string)(this["Theme"])); + } + set { + this["Theme"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("...")] + public string Server { + get { + return ((string)(this["Server"])); + } + set { + this["Server"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool Autostart { + get { + return ((bool)(this["Autostart"])); + } + set { + this["Autostart"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("...")] + public string Pfad { + get { + return ((string)(this["Pfad"])); + } + set { + this["Pfad"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("0")] + public int ModVersion { + get { + return ((int)(this["ModVersion"])); + } + set { + this["ModVersion"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("German")] + public string Sprache { + get { + return ((string)(this["Sprache"])); + } + set { + this["Sprache"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool ErsterStart { + get { + return ((bool)(this["ErsterStart"])); + } + set { + this["ErsterStart"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string Lizenz { + get { + return ((string)(this["Lizenz"])); + } + set { + this["Lizenz"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool Verknuepfung { + get { + return ((bool)(this["Verknuepfung"])); + } + set { + this["Verknuepfung"] = value; + } + } + + [global::System.Configuration.ApplicationScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("ck_f225a03d33849d1ca1e9d0de7e680c2bb82acbcd")] + public string benutzername { + get { + return ((string)(this["benutzername"])); + } + } + + [global::System.Configuration.ApplicationScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("cs_02957c7f433035f4498ee991c69142f912a3ab0e")] + public string passwort { + get { + return ((string)(this["passwort"])); + } + } + } +} diff --git a/Valheim Mod Sync Desktop/Properties/Settings.settings b/Valheim Mod Sync Desktop/Properties/Settings.settings new file mode 100644 index 0000000..640aefc --- /dev/null +++ b/Valheim Mod Sync Desktop/Properties/Settings.settings @@ -0,0 +1,39 @@ + + + + + + Light + + + ... + + + False + + + ... + + + 0 + + + German + + + True + + + + + + False + + + ck_f225a03d33849d1ca1e9d0de7e680c2bb82acbcd + + + cs_02957c7f433035f4498ee991c69142f912a3ab0e + + + \ No newline at end of file diff --git a/Valheim Mod Sync Desktop/Properties/launchSettings.json b/Valheim Mod Sync Desktop/Properties/launchSettings.json new file mode 100644 index 0000000..b96d353 --- /dev/null +++ b/Valheim Mod Sync Desktop/Properties/launchSettings.json @@ -0,0 +1,7 @@ +{ + "profiles": { + "Valheim Mod Sync Desktop": { + "commandName": "Project" + } + } +} \ No newline at end of file diff --git a/Valheim Mod Sync Desktop/Skins/Dark.xaml b/Valheim Mod Sync Desktop/Skins/Dark.xaml new file mode 100644 index 0000000..8a2c5be --- /dev/null +++ b/Valheim Mod Sync Desktop/Skins/Dark.xaml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Valheim Mod Sync Desktop/Skins/Light.xaml b/Valheim Mod Sync Desktop/Skins/Light.xaml new file mode 100644 index 0000000..35cb634 --- /dev/null +++ b/Valheim Mod Sync Desktop/Skins/Light.xaml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Valheim Mod Sync Desktop/Skins/Overwrite_Styles.xaml b/Valheim Mod Sync Desktop/Skins/Overwrite_Styles.xaml new file mode 100644 index 0000000..a438c3d --- /dev/null +++ b/Valheim Mod Sync Desktop/Skins/Overwrite_Styles.xaml @@ -0,0 +1,118 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Valheim Mod Sync Desktop/Valheim Mod Sync Desktop.csproj b/Valheim Mod Sync Desktop/Valheim Mod Sync Desktop.csproj new file mode 100644 index 0000000..b41cb3d --- /dev/null +++ b/Valheim Mod Sync Desktop/Valheim Mod Sync Desktop.csproj @@ -0,0 +1,99 @@ + + + + WinExe + net7.0-windows + true + Valheim_Mod_Sync_Desktop + true + files\tbs.ico + 1.0.0.6 + Tobias Röhrich + tbS-Server + Valheim Mod Sync + false + Valheim_Mod_Sync_Desktop.App + Valheim-Mod-Sync + False + + False + tbS-server.de + https://tbs-server.de + Synchronsiere zwischen deinem Valheim Server und Client die Mods und Konfigs! + + Valheim Mod Sync + + + + + + + + + + + + + + tlbimp + 0 + 1 + f935dc20-1cf0-11d0-adb9-00c04fd58a0b + 0 + false + true + + + + + + + + + + + + + + + + + + Code + + + Code + + + Code + + + True + True + Settings.settings + + + Code + + + Code + + + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + + $(DefaultXamlRuntime) + + + $(DefaultXamlRuntime) + Designer + + + diff --git a/Valheim Mod Sync Desktop/ViewModels/BaseViewModel.cs b/Valheim Mod Sync Desktop/ViewModels/BaseViewModel.cs new file mode 100644 index 0000000..810e8d5 --- /dev/null +++ b/Valheim Mod Sync Desktop/ViewModels/BaseViewModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Valheim_Mod_Sync_Desktop.ViewModels +{ + class BaseViewModel : INotifyPropertyChanged + { + public event PropertyChangedEventHandler PropertyChanged; + + protected void onPopertyChanged(string propertyName) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + } +} diff --git a/Valheim Mod Sync Desktop/ViewModels/FTPViewModel.cs b/Valheim Mod Sync Desktop/ViewModels/FTPViewModel.cs new file mode 100644 index 0000000..ba905d2 --- /dev/null +++ b/Valheim Mod Sync Desktop/ViewModels/FTPViewModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Valheim_Mod_Sync_Desktop.ViewModels +{ + class FTPViewModel : BaseViewModel + { + } + +} diff --git a/Valheim Mod Sync Desktop/ViewModels/KontaktViewModel.cs b/Valheim Mod Sync Desktop/ViewModels/KontaktViewModel.cs new file mode 100644 index 0000000..e0a7c68 --- /dev/null +++ b/Valheim Mod Sync Desktop/ViewModels/KontaktViewModel.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Valheim_Mod_Sync_Desktop.ViewModels +{ + class KontaktViewModel : BaseViewModel + { + } +} diff --git a/Valheim Mod Sync Desktop/ViewModels/LizenzenViewModel.cs b/Valheim Mod Sync Desktop/ViewModels/LizenzenViewModel.cs new file mode 100644 index 0000000..dacfd38 --- /dev/null +++ b/Valheim Mod Sync Desktop/ViewModels/LizenzenViewModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Valheim_Mod_Sync_Desktop.ViewModels +{ + class LizenzenViewModel : BaseViewModel + { + } + +} diff --git a/Valheim Mod Sync Desktop/ViewModels/MainViewModel.cs b/Valheim Mod Sync Desktop/ViewModels/MainViewModel.cs new file mode 100644 index 0000000..37ca412 --- /dev/null +++ b/Valheim Mod Sync Desktop/ViewModels/MainViewModel.cs @@ -0,0 +1,39 @@ +using System; +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.Input; +using Valheim_Mod_Sync_Desktop.Commands; +using static Valheim_Mod_Sync_Desktop.MainWindow; + +namespace Valheim_Mod_Sync_Desktop.ViewModels +{ + class MainViewModel : BaseViewModel + { + + private BaseViewModel _selectedViewModel = new SyncViewModel(); + + public BaseViewModel SelectedViewModel + { + get { return _selectedViewModel; } + set { onPopertyChanged(nameof(SelectedViewModel)); } + } + + + + public ICommand UpdateViewCommand { get; set; } + + public MainViewModel() + { + UpdateViewCommand = new UpdateViewCommand(this); + + } + + + } +} diff --git a/Valheim Mod Sync Desktop/ViewModels/SetupViewModel.cs b/Valheim Mod Sync Desktop/ViewModels/SetupViewModel.cs new file mode 100644 index 0000000..89fdce0 --- /dev/null +++ b/Valheim Mod Sync Desktop/ViewModels/SetupViewModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Valheim_Mod_Sync_Desktop.ViewModels +{ + class SetupViewModel : BaseViewModel + { + + } + +} diff --git a/Valheim Mod Sync Desktop/ViewModels/SyncViewModel.cs b/Valheim Mod Sync Desktop/ViewModels/SyncViewModel.cs new file mode 100644 index 0000000..4ee63f3 --- /dev/null +++ b/Valheim Mod Sync Desktop/ViewModels/SyncViewModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Valheim_Mod_Sync_Desktop.ViewModels +{ + class SyncViewModel : BaseViewModel + { + } + +} diff --git a/Valheim Mod Sync Desktop/Views/FTP.xaml b/Valheim Mod Sync Desktop/Views/FTP.xaml new file mode 100644 index 0000000..bf247e2 --- /dev/null +++ b/Valheim Mod Sync Desktop/Views/FTP.xaml @@ -0,0 +1,40 @@ + + + + + + + + + +