public void InitializeWorldsList() { DirectoryInfo serverDir = new DirectoryInfo(Path.Combine(App.ServerPath, Server.Name)); if (!serverDir.Exists) { return; } Application.Current.Dispatcher?.Invoke(() => Worlds.Clear()); foreach (DirectoryInfo directory in serverDir.EnumerateDirectories()) { WorldValidationInfo worldVal = DirectoryValidator.ValidateWorldDirectory(directory); if (worldVal.IsValid) { World world = new World(worldVal.Name, this, directory); if (Server.ServerSettings.LevelName.Equals(world.Name)) { world.IsActive = true; } Application.Current.Dispatcher?.Invoke(() => Worlds.Add(world)); } } }
private void ServerDirPath_MouseDown(object sender, MouseButtonEventArgs e) { FolderBrowserDialog fbd = new FolderBrowserDialog(); if (lastPath != null) { fbd.SelectedPath = lastPath; } DialogResult result = fbd.ShowDialog(); if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath)) { worldFolderPathText.Text = fbd.SelectedPath; lastPath = fbd.SelectedPath; WorldValidationInfo valInfo = DirectoryValidator.ValidateWorldDirectory(new DirectoryInfo(fbd.SelectedPath)); if (!valInfo.IsValid) { serverPathBgr.Background = (Brush)Application.Current.FindResource("buttonBgrRed"); } else { serverPathBgr.Background = (Brush)Application.Current.FindResource("tabSelected"); } } }
private async void BtnApply_Click(object sender, RoutedEventArgs e) { if (isProxy) { string networkName = NetworkName.Text; if (networkName == null || networkName.Equals("")) { networkName = "Network"; } //TODO replace this with int value verifier int minRam, maxRam; if (!int.TryParse(NetworkMaxRam.Text, out maxRam)) { maxRam = 1024; } if (!int.TryParse(NetworkMinRam.Text, out minRam)) { minRam = 512; } JavaSettings javaSettings = new JavaSettings { MinRam = minRam, MaxRam = maxRam }; bool createNetworkSuccess = await ServerManager.Instance.CreateNetworkAsync(networkName, proxyType, javaSettings); } else { ServerVersion selectedVersion = (ServerVersion)versionComboBox.SelectedValue; //TODO check if inputs are valid / server not existing string serverName = ServerName.Text; if (serverName == null || serverName.Equals("")) { serverName = "Server"; } string worldPath = null; if (lastPath != null) { WorldValidationInfo valInfo = DirectoryValidator.ValidateWorldDirectory(new DirectoryInfo(lastPath)); if (valInfo.IsValid) { worldPath = lastPath; } } bool createServerSuccess = await ServerManager.Instance.CreateServerAsync(serverName, selectedVersion, viewModel.ServerSettings, new JavaSettings(), worldPath); } viewModel.GenerateNewSettings(); //TODO Do something if creating fails }
private async void BtnApply_Click(object sender, RoutedEventArgs e) { CreateBtn.IsEnabled = false; char[] illegalDirChars = Path.GetInvalidFileNameChars(); if (isProxy) { string networkName = NetworkName.Text; string refinedNetworkName = networkName; foreach (char c in networkName) { if (illegalDirChars.Contains(c)) { refinedNetworkName = refinedNetworkName.Replace(c + "", ""); } } if (refinedNetworkName.Equals("")) { refinedNetworkName = "Network"; } //TODO replace this with int value verifier int maxRam; if (!int.TryParse(NetworkMaxRam.Text, out maxRam)) { maxRam = 1024; } JavaSettings javaSettings = new JavaSettings { MaxRam = maxRam }; bool createNetworkSuccess = await ServerManager.Instance.CreateNetworkAsync(refinedNetworkName, proxyType, javaSettings); } else { ServerVersion selectedVersion = (ServerVersion)versionComboBox.SelectedValue; //TODO check if inputs are valid / server not existing string serverName = ServerName.Text; string refinedServerName = serverName; foreach (char c in serverName) { if (illegalDirChars.Contains(c)) { refinedServerName = refinedServerName.Replace(c + "", ""); } } if (refinedServerName.Equals("")) { refinedServerName = "Server"; } string worldPath = null; if (lastPath != null) { WorldValidationInfo valInfo = DirectoryValidator.ValidateWorldDirectory(new DirectoryInfo(lastPath)); if (valInfo.IsValid) { worldPath = lastPath; } } bool createServerSuccess = await ServerManager.Instance.CreateServerAsync(refinedServerName, selectedVersion, viewModel.ServerSettings, new JavaSettings(), worldPath); } viewModel.GenerateNewSettings(); CreateBtn.IsEnabled = true; //TODO Do something if creating fails }