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"); } } }
public void InitDirectoryControl(string path) { _imagePaths = new List <string>(); DirectoryValidator val = new DirectoryValidator(path); List <string> paths = val.GetAllValidPaths(); var sortedPaths = SortPaths(paths); _imagePaths.AddRange(sortedPaths); }
public void UsageTest() { _configuration.Setup(x => x.IgnoredDirectories).Returns(new[] {"ignored", @"a\b", "/b/d/"}); var validator = new DirectoryValidator(_configuration.Object); Assert.IsTrue(validator.IsDirectoryValid("my/valid/Directory")); Assert.IsFalse(validator.IsDirectoryValid("my/a/b/Directory")); Assert.IsFalse(validator.IsDirectoryValid(@"my/a\b/Directory")); Assert.IsFalse(validator.IsDirectoryValid(@"my/ignored/Directory")); Assert.IsFalse(validator.IsDirectoryValid(@"myignoredDirectory")); Assert.IsTrue(validator.IsDirectoryValid(@"myb/dDirectory")); }
public void Init() { _directoryValidator = new DirectoryValidator(); _directoryValidator.Initialize(new CachedValidationRegistry(), typeof(TestTarget).GetProperty("TargetField")); _filePathValidator = new FilePathValidator(); _filePathValidator.Initialize(new CachedValidationRegistry(), typeof(TestTarget).GetProperty("TargetField")); _target = new TestTarget(); }
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 }
/// <summary> /// Console program entry. /// </summary> /// <param name="args"> /// args[0]: BBKP bitmaps directory path /// </param> internal static void Main(string[] args) { ShowBanner(); var directoryPath = string.Empty; if (args.Length < 1) { Line.Write("Not enough arguments provided. Using manual input...", ConsoleColor.Yellow, "WARN"); Console.ForegroundColor = ConsoleColor.Cyan; while (DirectoryValidator.GetStatus(directoryPath) != DirectoryStatus.IsValid) { Line.Write("Please input a valid directory path:", ConsoleColor.Cyan, "STEP"); directoryPath = Console.ReadLine(); } } else { directoryPath = args[0]; if (DirectoryValidator.GetStatus(directoryPath) == DirectoryStatus.DoesNotExist) { Console.ForegroundColor = ConsoleColor.Red; Console.Error.WriteLine("Target folder does not exist."); Environment.Exit((int)ExitCodes.InvalidFilesFolderPath); } } var files = Directory.GetFiles(directoryPath, $"*.{Bbkpify.Main.Extension}*", SearchOption.AllDirectories); try { Bbkpify.Main.ResetBitmapFiles(files); } catch (Exception e) { Console.ForegroundColor = ConsoleColor.Red; Console.Error.WriteLine(e.Message); Environment.Exit((int)ExitCodes.ExceptionHasBeenThrown); } Line.Write($"\nRestored bitmaps in '{directoryPath}'!", ConsoleColor.Green, "DONE"); Console.ReadLine(); Environment.Exit((int)ExitCodes.Success); }
private async void BtnApply_Click(object sender, RoutedEventArgs e) { ServerVersion selectedVersion = (ServerVersion)versionComboBox.SelectedValue; //TODO check if inputs are valid / server not existing if (lastPath == null) { throw new Exception("Import Button should not be clickable, as path is not valid"); } DirectoryInfo oldDir = new DirectoryInfo(lastPath); string serverName = oldDir.Name; ServerValidationInfo validationInfo = DirectoryValidator.ValidateServerDirectory(oldDir); bool createServerSuccess = await ServerManager.Instance.ImportServerAsync(selectedVersion, validationInfo, oldDir.FullName, serverName); //TODO Do something if creating fails }
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)) { serverFolderPathText.Text = fbd.SelectedPath; lastPath = fbd.SelectedPath; ServerValidationInfo valInfo = null; try { valInfo = DirectoryValidator.ValidateServerDirectory(new DirectoryInfo(fbd.SelectedPath)); } catch (Exception ex) { ErrorLogger.Append(ex); } if (valInfo == null || !valInfo.IsValid) { serverPathBgr.Background = (Brush)Application.Current.FindResource("buttonBgrRed"); ImportConfirmButton.IsEnabled = false; } else { serverPathBgr.Background = (Brush)Application.Current.FindResource("tabSelected"); ImportConfirmButton.IsEnabled = true; } } }
/// <summary> /// Console program entry. /// </summary> /// <param name="args"> /// args[0]: Placeholder bitmap path /// args[1]: Target bitmaps directory path /// args[2]: Bitmaps search pattern /// </param> public static void Main(string[] args) { ShowBanner(); var bitmapPlaceholder = string.Empty; var bitmapsDirectory = string.Empty; var bitmapsPattern = string.Empty; if (args.Length < 3) { Line.Write("Not enough arguments provided. Using manual input...", ConsoleColor.Yellow, "WARN"); while (PlaceholderValidator.GetStatus(bitmapPlaceholder) != PlaceholderStatus.IsValid) { Line.Write("Please type a valid placeholder file under the size of 8MiB:", ConsoleColor.Cyan, "STEP"); bitmapPlaceholder = Console.ReadLine(); if (bitmapPlaceholder != null && File.Exists(bitmapPlaceholder)) { if (PlaceholderValidator.GetStatus(bitmapPlaceholder) == PlaceholderStatus.IsTooLarge) { Line.Write($"Placeholder file is larger than 8MiB!", ConsoleColor.Red, "STOP"); bitmapPlaceholder = string.Empty; } } } while (DirectoryValidator.GetStatus(bitmapsDirectory) != DirectoryStatus.IsValid) { Line.Write("Please type a valid target directory path:", ConsoleColor.Cyan, "STEP"); bitmapsDirectory = Console.ReadLine(); } while (PatternValidator.GetStatus(bitmapsPattern) != PatternStatus.IsValid) { Line.Write("Please type a valid file search pattern:", ConsoleColor.Cyan, "STEP"); bitmapsPattern = Console.ReadLine(); } } else { bitmapPlaceholder = args[0]; bitmapsDirectory = args[1]; bitmapsPattern = args[2]; var placeholderStatus = PlaceholderValidator.GetStatus(bitmapPlaceholder); var fileExists = placeholderStatus != PlaceholderStatus.DoesNotExist; var sizeIsUnder16MiB = placeholderStatus != PlaceholderStatus.IsTooLarge; var directoryExists = DirectoryValidator.GetStatus(bitmapsDirectory) != DirectoryStatus.DoesNotExist; var patternIsValid = PatternValidator.GetStatus(bitmapsPattern) != PatternStatus.IsInvalid; // prematurely exit if the following conditions aren't satisfied ExitIfFalse(fileExists, "Placeholder does not exist.", ExitCodes.InvalidPlaceholderPath); ExitIfFalse(sizeIsUnder16MiB, "Placeholder is larger than 8MiB.", ExitCodes.PlaceholderFileTooLong); ExitIfFalse(directoryExists, "Bitmaps directory does not exist.", ExitCodes.InvalidFilesFolderPath); ExitIfFalse(patternIsValid, "Searcg pattern is invalid.", ExitCodes.InvalidFileNamePattern); } // if everything is successful, get all files and back them up var files = Directory .GetFiles(bitmapsDirectory, $"*{bitmapsPattern}*.bitmap", SearchOption.AllDirectories) .Where(x => !x.Contains("multiplayer")) .ToArray(); Bbkpify.Main.ApplyPlaceholderAsync(files, bitmapPlaceholder).GetAwaiter().GetResult(); Line.Write($"\nApplied '{bitmapPlaceholder}' to '{bitmapsDirectory}'!", ConsoleColor.Green, "DONE"); Console.ReadLine(); Environment.Exit((int)ExitCodes.Success); }
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 }
public void CreateSurveyFolder() { _validator = DirectoryValidator.Create(_conf); }