private void UpdateWorlds() { if (WorldsDropDown.Items.Count > 0) { WorldsDropDown.Items.Clear(); } if (String.IsNullOrWhiteSpace(saveDirectory)) { List <string> worldList = ValheimManager.GetWorldList(Path.Combine(ValheimManager.GetDefaultSaveDir(), "worlds")); if (worldList != null && worldList.Count > 0) { foreach (string world in worldList) { WorldsDropDown.Items.Add(world); } } } else { List <string> worldList = ValheimManager.GetWorldList(saveDirectory); if (worldList != null && worldList.Count > 0) { foreach (string world in worldList) { WorldsDropDown.Items.Add(world); } } else { WorldsDropDown.Items.Clear(); WorldsDropDown.SelectedIndex = -1; TextBoxHelper.SetWatermark(WorldsDropDown, "No worlds found..."); } } }
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) { } } }
private void MetroWindow_ContentRendered(object sender, EventArgs e) { #region Load Settings // Location if (Settings.Default.StartX != 0 && Settings.Default.StartY != 0) { this.Left = Settings.Default.StartX; this.Top = Settings.Default.StartY; } else { this.WindowStartupLocation = WindowStartupLocation.CenterScreen; } // Size if (Settings.Default.SizeX > 0 && Settings.Default.SizeY > 0) { this.SizeToContent = SizeToContent.Manual; this.Width = Settings.Default.SizeX; this.Height = Settings.Default.SizeY; } else { this.SizeToContent = SizeToContent.WidthAndHeight; this.Width = this.MinWidth; this.Height = this.MinHeight; } // Path to server string serverPath = Settings.Default.ServerPath; if (!String.IsNullOrWhiteSpace(serverPath) && Directory.Exists(serverPath) && ValheimManager.IsValidServerDirectory(serverPath)) { ServerDirTextBox.Text = serverPath; workingDirectory = serverPath; } // Save dir string savePath = Settings.Default.SavePath; if (!String.IsNullOrWhiteSpace(savePath) && Directory.Exists(savePath)) { SaveDirTextBox.Text = savePath; saveDirectory = savePath; } // Server name string serverName = Settings.Default.ServerName; if (!String.IsNullOrWhiteSpace(serverName)) { ServerNameTextBox.Text = serverName; } // Password string password = Settings.Default.ServerPassword; if (!String.IsNullOrWhiteSpace(password)) { ServerPasswordTextBox.Password = password; } // Port int serverPort = Settings.Default.ServerPort; if (serverPort != 0) { ServerPortNUD.Value = serverPort; } else { ServerPortNUD.Value = 2456; } #endregion #region Check Worlds UpdateWorlds(); if (WorldsDropDown.Items.Count > 0) { foreach (string world in WorldsDropDown.Items) { int i = 0; if (world == Settings.Default.PreviousWorld) { WorldsDropDown.SelectedIndex = i; break; } i++; } } #endregion syncContext = SynchronizationContext.Current; IsServerSetupValid(); // TODO: Verify path before doing this adminView.LoadEntriesFromFile(ValheimManager.GetListPath(Enums.ListType.Admin)); permittedView.LoadEntriesFromFile(ValheimManager.GetListPath(Enums.ListType.Permitted)); bannedView.LoadEntriesFromFile(ValheimManager.GetListPath(Enums.ListType.Banned)); ValheimServer.OnServerStarted += ValheimServer_OnServerStarted; ValheimServer.OnServerStopped += ValheimServer_OnServerStopped; ValheimServer.OnOutputReceived += ValheimServer_OnOutputReceived; ValheimServer.OnServerStateChanged += ValheimServer_OnServerStateChanged; Scheduling.ScheduledTask task1 = new Scheduling.ScheduledTask { Days = Scheduling.Days.All, Task = Scheduling.TaskKind.Restart, Time = DateTime.Now }; Scheduling.ScheduledTask task2 = new Scheduling.ScheduledTask { Days = Scheduling.Days.Weekdays, Task = Scheduling.TaskKind.Update, Time = DateTime.Now }; Scheduling.ScheduledTask task3 = new Scheduling.ScheduledTask { Days = Scheduling.Days.Weekends, Task = Scheduling.TaskKind.Restart, Time = DateTime.Now }; Scheduling.ScheduledTask task4 = new Scheduling.ScheduledTask { Days = Scheduling.Days.Wednesday, Task = Scheduling.TaskKind.UpdateAndRestart, Time = DateTime.Now }; foreach (var task in new Scheduling.ScheduledTask[] { task1, task2, task3, task4 }) { ScheduleGrid.Items.Add(task); } ScheduleGrid.Items.Refresh(); }