private static void RestartApplication() { if (ValheimServer.IsServerRunning()) { Process process = ValheimServer.GetServerProcess(); ValheimServer.Stop(); process.WaitForExit(); } System.Windows.Forms.Application.Restart(); Application.Current.Shutdown(); }
private async void Button_Click(object sender, RoutedEventArgs e) { #region Console/List Button Styling List <Button> toggleButtons = new List <Button>() { NetworkConsoleButton, DebugConsoleButton, WorldGenConsoleButton, PlayerListButton, AdminButton, PermittedButton, BannedButton }; if (toggleButtons.Contains(sender)) { var accentBrush = (Brush)FindResource("MahApps.Brushes.Accent"); var textBrush = (Brush)FindResource("MahApps.Brushes.Text"); foreach (Button button in toggleButtons) { if (sender == button) { button.Foreground = accentBrush; button.BorderBrush = accentBrush; button.BorderThickness = new Thickness(1); } else { button.Foreground = textBrush; button.BorderBrush = null; button.BorderThickness = new Thickness(0); } } } #endregion #region List Buttons if (sender == AdminButton) { LeTransit.Content = adminView; } if (sender == PermittedButton) { LeTransit.Content = permittedView; } if (sender == BannedButton) { LeTransit.Content = bannedView; } if (sender == PlayerListButton) { LeTransit.Content = playerView; } #endregion #region Console Buttons if (sender == NetworkConsoleButton) { LeTransit.Content = networkConsole; currentConsole = Enums.ConsoleType.Network; ClearBadgeForButton(NetworkConsoleButton); return; } if (sender == DebugConsoleButton) { LeTransit.Content = debugConsole; currentConsole = Enums.ConsoleType.Debug; ClearBadgeForButton(DebugConsoleButton); return; } if (sender == WorldGenConsoleButton) { LeTransit.Content = worldConsole; currentConsole = Enums.ConsoleType.WorldGen; ClearBadgeForButton(WorldGenConsoleButton); return; } #endregion #region Setting Tab Buttons if (sender == SteamButton) { if (SteamManager.SteamCMD.GetSteamCMDState() != SteamManager.SteamCMD.SteamCMDState.Installed) { SteamManager.SteamCMD.DownloadAndInstall(); } //else // TODO: Uninstall SteamCMD? } if (sender == SteamUpdate) { if (ValheimServer.ValidatePath(workingDirectory)) { var version = SteamManager.Server.GetVersion(workingDirectory); var latest = SteamManager.Server.GetLatestVersion(); if (version == latest) { MessageBox.Show("Latest version is already installed, not update necessary.", "Information", MessageBoxButton.OK, MessageBoxImage.Information); } else { MessageBoxResult mbr = MessageBox.Show("Update Available!", "Update?", MessageBoxButton.YesNo, MessageBoxImage.Question); if (mbr == MessageBoxResult.Yes) { await SteamManager.Server.UpdateValdiate(workingDirectory); } else { return; } } } } #endregion if (sender == ServerDirButton) { using (WinForms.FolderBrowserDialog fbd = new WinForms.FolderBrowserDialog()) { fbd.RootFolder = Environment.SpecialFolder.MyComputer; fbd.ShowNewFolderButton = true; fbd.Description = "Browse to the Valheim Dedicated Server directory"; if (fbd.ShowDialog() == WinForms.DialogResult.OK) { string path = fbd.SelectedPath; if (!String.IsNullOrWhiteSpace(path)) { // Make sure the directory exists if (Directory.Exists(path) && ValheimManager.IsValidServerDirectory(path)) { // Save the location ServerDirTextBox.Text = path; workingDirectory = path; Settings.Default.ServerPath = path; Settings.Default.Save(); UpdateWorlds(); } else { if (!ValheimManager.IsValidServerDirectory(path)) { MessageBox.Show("Specified directory does not seem to be a valid directory! Make sure you're choosing the folder containing the Valheim server files.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); } else { MessageBox.Show("Specified directory does not seem to Exist!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); } } } } else { // User cancelled } } } if (sender == SaveDirButton) { using (WinForms.FolderBrowserDialog fbd = new WinForms.FolderBrowserDialog()) { fbd.RootFolder = Environment.SpecialFolder.MyComputer; fbd.ShowNewFolderButton = true; fbd.Description = "Choose a Directory"; if (fbd.ShowDialog() == WinForms.DialogResult.OK) { string path = fbd.SelectedPath; if (Directory.Exists(path)) { SaveDirTextBox.Text = path; saveDirectory = path; Settings.Default.SavePath = path; Settings.Default.Save(); UpdateWorlds(); } } else { // User cancelled } } } if (sender == StartButton) { if (!String.IsNullOrWhiteSpace(workingDirectory) && File.Exists(Path.Combine(workingDirectory, "valheim_server.exe"))) { if (!ValheimServer.IsServerRunning()) { // Check all parameters before we start the serveroni await ValheimServer.StartAsync(new ValheimServer.ServerSettings { ServerPath = Path.Combine(workingDirectory, "valheim_server.exe"), ServerName = ServerNameTextBox.Text, ServerPassword = ServerPasswordTextBox.Password, ServerPort = (int)ServerPortNUD.Value, SaveDirectory = null, WorldName = WorldNameTextBox.Text }); } else { if (MessageBox.Show("Are you sure you wish to stop the server?", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) { ValheimServer.Stop(); } else { return; } } } else { MessageBox.Show("Error, unable to locate valheim_server.exe!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } if (sender == CreateTaskButton) { Scheduling.TaskWindow window = new Scheduling.TaskWindow(); window.Owner = this; bool dr = window.ShowDialog().GetValueOrDefault(); if (dr) { } } }