Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 2
0
        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);
                }
            }
        }