async void acceptClick(object sender, RoutedEventArgs e) { accept.IsEnabled = false; Result = new Server(name.Text, description.Text); var progress = new Progress <DownloadProgressChangedEventArgs>(); progress.ProgressChanged += (s, de) => Title = Res.GetStr("downloadingPercentage", de.ProgressPercentage); var result = await selectJarPage.GetSelectedJarToLocalFile(Result.ServerJar, progress, downloadCts); if (!result.HasValue) // operation cancelled { return; } if (result.Value) // success { if (!string.IsNullOrEmpty(worldPath)) { if (Directory.Exists(worldPath)) { new DirectoryInfo(worldPath).CopyDirectory( new DirectoryInfo(Path.Combine(Result.Location, ServerProperties.Empty["level-name"].Value))); } else if (File.Exists(worldPath) && worldPath.EndsWith(".zip")) { Result.UpdateServersProperty("level-name", MinecraftWorld.ExtractWorldZip(worldPath, Result.Location)); } } // set properties if (serverIcon.Source != null) { ((BitmapSource)serverIcon.Source).Save(Result.IconPath); } Result.UpdateServersProperty("difficulty", difficultyComboBox.SelectedIndex.ToString()); Result.UpdateServersProperty("gamemode", gameModeComboBox.SelectedIndex.ToString()); Result.UpdateServersProperty("max-players", maxPlayersTextBox.Text); Result.UpdateServersProperty("hardcore", hardcoreCheckBox.IsChecked.Value ? "true" : "false"); Result.UpdateServersProperty("online-mode", onlineModeCheckBox.IsChecked.Value ? "true" : "false"); Result.UpdateServersProperty("enable-command-block", enableCommandBlockCheckBox.IsChecked.Value ? "true" : "false"); Result.UpdateServersProperty("motd", motdBox.GeneratedCode); // finish DialogResult = true; Close(); } else // failed { selectJarPage.ShowNoVersionAvailable(); accept.IsEnabled = true; } }
async Task reloadWorldsList(string selectName) { worldsList.Items.Clear(); foreach (var world in await MinecraftWorld.ListWorlds(server.Location)) { worldsList.Items.Add(world); } if (worldsList.Items.Count == 0) { worldWillGenerate.Visibility = Visibility.Visible; deleteSelectedWorld.Visibility = Visibility.Collapsed; } worldsList.Text = selectName; }
// drag enter void dragEnter(object sender, DragEventArgs e) { Console.WriteLine("enter"); var paths = (string[])e.Data.GetData(DataFormats.FileDrop); if (paths != null && paths.Length == 1 && MinecraftWorld.IsValidWorld(paths[0])) { e.Effects = DragDropEffects.Copy; toggleDragDropGrid(true); } else { e.Effects = DragDropEffects.None; toggleDragDropGrid(false, true); } }
async void addWorldClick(object sender, RoutedEventArgs e) { var ofd = new OpenFileDialog { Title = Res.GetStr("selectZip"), Filter = Res.GetStr("zipFilter") }; if (ofd.ShowDialog() ?? false) { if (MinecraftWorld.IsValidWorld(ofd.FileName)) { await reloadWorldsList(MinecraftWorld.ExtractWorldZip(ofd.FileName, server.Location)); } else { MessageBox.Show(Res.GetStr("invalidZip"), Res.GetStr("invalidWorld"), MessageBoxButton.OK, MessageBoxImage.Error); } } }