// Path: src/main/java/org/terasology/launcher/util/JavaHeapSize.java
// public enum JavaHeapSize {
// 
//     NOT_USED("", "heapsize_notUsed"),
//     MB_256("256m", "heapsize_mb_256"),
//     MB_512("512m", "heapsize_mb_512"),
//     MB_768("768m", "heapsize_mb_768"),
//     GB_1("1g", "heapsize_gb_1"),
//     GB_1_5("1536m", "heapsize_gb_1_5"),
//     GB_2("2g", "heapsize_gb_2"),
//     GB_2_5("2560m", "heapsize_gb_2_5"),
//     GB_3("3g", "heapsize_gb_3"),
//     GB_4("4g", "heapsize_gb_4"),
//     GB_5("5g", "heapsize_gb_5"),
//     GB_6("6g", "heapsize_gb_6"),
//     GB_7("7g", "heapsize_gb_7"),
//     GB_8("8g", "heapsize_gb_8"),
//     GB_9("9g", "heapsize_gb_9"),
//     GB_10("10g", "heapsize_gb_10"),
//     GB_11("11g", "heapsize_gb_11"),
//     GB_12("12g", "heapsize_gb_12"),
//     GB_13("13g", "heapsize_gb_13"),
//     GB_14("14g", "heapsize_gb_14"),
//     GB_15("15g", "heapsize_gb_15"),
//     GB_16("16g", "heapsize_gb_16");
// 
//     private final String sizeParameter;
//     private final String labelKey;
// 
//     JavaHeapSize(String sizeParameter, String labelKey) {
//         this.sizeParameter = sizeParameter;
//         this.labelKey = labelKey;
//     }
// 
//     public final boolean isUsed() {
//         return this != NOT_USED;
//     }
// 
//     public final String getSizeParameter() {
//         return sizeParameter;
//     }
// 
//     @Override
//     public final String toString() {
//         return BundleUtils.getLabel(labelKey);
//     }
// }
// 
// Path: src/main/java/org/terasology/launcher/util/Platform.java
// public final class Platform {
//     
//     private static final Platform PLATFORM = new Platform();
// 
//     private String os;
//     private String arch;
// 
//     /**
//      * Constructs platform information for the current host system.
//      * Simplifies operating system name to one of `linux`, `mac`, `windows` if applicable.
//      * Simplifies operating system architecture to one of `32` and `64` if applicable.
//      */
//     private Platform() {
//         final String platformOs = System.getProperty("os.name").toLowerCase();
//         // TODO: consider using regex
//         if (platformOs.startsWith("linux")) {
//             os = "linux";
//         } else if (platformOs.startsWith("mac os")) {
//             os = "mac";
//         } else if (platformOs.startsWith("windows")) {
//             os = "windows";
//         } else {
//             os = platformOs;
//         }
// 
//         final String platformArch = System.getProperty("os.arch");
//         if (platformArch.equals("x86_64") || platformArch.equals("amd64")) {
//             arch = "64";
//         } else if (platformArch.equals("x86") || platformArch.equals("i386")) {
//             arch = "32";
//         } else {
//             arch = platformArch;
//         }
//     }
// 
//     /**
//      * @return the simplified operating system name as platform os
//      */
//     public String getOs() {
//         return os;
//     }
// 
//     /**
//      * @return the simplified operating system architecture as platform arch
//      */
//     public String getArch() {
//         return arch;
//     }
// 
//     public boolean isLinux() {
//         return os.equals("linux");
//     }
// 
//     public boolean isMac() {
//         return os.equals("mac");
//     }
// 
//     public boolean isWindows() {
//         return os.equals("windows");
//     }
// 
//     public String toString() {
//         return "OS '" + os + "', arch '" + arch + "'";
//     }
// 
//     /**
//      * Get information on the host platform the launcher is currently running on.
//      *
//      * @return the platform
//      */
//     public static Platform getPlatform() {
//         return PLATFORM;
//     }
// }


import com.vdurmont.semver4j.Semver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.event.Level;
import org.terasology.launcher.util.JavaHeapSize;
import org.terasology.launcher.util.Platform;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

package org.terasology.launcher.game;



/**
 * Takes the game and runtime options, provides something that will launch a process.
 *
 * @see <a href="https://docs.oracle.com/en/java/javase/14/docs/specs/man/java.html#overview-of-java-options">java command manual</a>
 */
class GameStarter implements Callable<Process> {
    private static final Logger logger = LoggerFactory.getLogger(GameStarter.class);

    final ProcessBuilder processBuilder;
    private final Semver engineVersion;

    /**
     * @param installation          the directory under which we will find {@code libs/Terasology.jar}, also used as the process's
     *                          working directory
     * @param gameDataDirectory {@code -homedir}, the directory where Terasology's data files (saves & etc) are kept
     * @param heapMin           java's {@code -Xms}
     * @param heapMax           java's {@code -Xmx}
     * @param javaParams        additional arguments for the {@code java} command line
     * @param gameParams        additional arguments for the Terasology command line
     * @param logLevel          the minimum level of log events Terasology will include on its output stream to us
     */
// Path: src/main/java/org/terasology/launcher/util/JavaHeapSize.java
// public enum JavaHeapSize {
// 
//     NOT_USED("", "heapsize_notUsed"),
//     MB_256("256m", "heapsize_mb_256"),
//     MB_512("512m", "heapsize_mb_512"),
//     MB_768("768m", "heapsize_mb_768"),
//     GB_1("1g", "heapsize_gb_1"),
//     GB_1_5("1536m", "heapsize_gb_1_5"),
//     GB_2("2g", "heapsize_gb_2"),
//     GB_2_5("2560m", "heapsize_gb_2_5"),
//     GB_3("3g", "heapsize_gb_3"),
//     GB_4("4g", "heapsize_gb_4"),
//     GB_5("5g", "heapsize_gb_5"),
//     GB_6("6g", "heapsize_gb_6"),
//     GB_7("7g", "heapsize_gb_7"),
//     GB_8("8g", "heapsize_gb_8"),
//     GB_9("9g", "heapsize_gb_9"),
//     GB_10("10g", "heapsize_gb_10"),
//     GB_11("11g", "heapsize_gb_11"),
//     GB_12("12g", "heapsize_gb_12"),
//     GB_13("13g", "heapsize_gb_13"),
//     GB_14("14g", "heapsize_gb_14"),
//     GB_15("15g", "heapsize_gb_15"),
//     GB_16("16g", "heapsize_gb_16");
// 
//     private final String sizeParameter;
//     private final String labelKey;
// 
//     JavaHeapSize(String sizeParameter, String labelKey) {
//         this.sizeParameter = sizeParameter;
//         this.labelKey = labelKey;
//     }
// 
//     public final boolean isUsed() {
//         return this != NOT_USED;
//     }
// 
//     public final String getSizeParameter() {
//         return sizeParameter;
//     }
// 
//     @Override
//     public final String toString() {
//         return BundleUtils.getLabel(labelKey);
//     }
// }
// 
// Path: src/main/java/org/terasology/launcher/util/Platform.java
// public final class Platform {
//     
//     private static final Platform PLATFORM = new Platform();
// 
//     private String os;
//     private String arch;
// 
//     /**
//      * Constructs platform information for the current host system.
//      * Simplifies operating system name to one of `linux`, `mac`, `windows` if applicable.
//      * Simplifies operating system architecture to one of `32` and `64` if applicable.
//      */
//     private Platform() {
//         final String platformOs = System.getProperty("os.name").toLowerCase();
//         // TODO: consider using regex
//         if (platformOs.startsWith("linux")) {
//             os = "linux";
//         } else if (platformOs.startsWith("mac os")) {
//             os = "mac";
//         } else if (platformOs.startsWith("windows")) {
//             os = "windows";
//         } else {
//             os = platformOs;
//         }
// 
//         final String platformArch = System.getProperty("os.arch");
//         if (platformArch.equals("x86_64") || platformArch.equals("amd64")) {
//             arch = "64";
//         } else if (platformArch.equals("x86") || platformArch.equals("i386")) {
//             arch = "32";
//         } else {
//             arch = platformArch;
//         }
//     }
// 
//     /**
//      * @return the simplified operating system name as platform os
//      */
//     public String getOs() {
//         return os;
//     }
// 
//     /**
//      * @return the simplified operating system architecture as platform arch
//      */
//     public String getArch() {
//         return arch;
//     }
// 
//     public boolean isLinux() {
//         return os.equals("linux");
//     }
// 
//     public boolean isMac() {
//         return os.equals("mac");
//     }
// 
//     public boolean isWindows() {
//         return os.equals("windows");
//     }
// 
//     public String toString() {
//         return "OS '" + os + "', arch '" + arch + "'";
//     }
// 
//     /**
//      * Get information on the host platform the launcher is currently running on.
//      *
//      * @return the platform
//      */
//     public static Platform getPlatform() {
//         return PLATFORM;
//     }
// }


// Path: src/main/java/org/terasology/launcher/game/GameStarter.java
import com.vdurmont.semver4j.Semver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.event.Level;
import org.terasology.launcher.util.JavaHeapSize;
import org.terasology.launcher.util.Platform;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;

// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

package org.terasology.launcher.game;



/**
 * Takes the game and runtime options, provides something that will launch a process.
 *
 * @see <a href="https://docs.oracle.com/en/java/javase/14/docs/specs/man/java.html#overview-of-java-options">java command manual</a>
 */
class GameStarter implements Callable<Process> {
    private static final Logger logger = LoggerFactory.getLogger(GameStarter.class);

    final ProcessBuilder processBuilder;
    private final Semver engineVersion;

    /**
     * @param installation          the directory under which we will find {@code libs/Terasology.jar}, also used as the process's
     *                          working directory
     * @param gameDataDirectory {@code -homedir}, the directory where Terasology's data files (saves & etc) are kept
     * @param heapMin           java's {@code -Xms}
     * @param heapMax           java's {@code -Xmx}
     * @param javaParams        additional arguments for the {@code java} command line
     * @param gameParams        additional arguments for the Terasology command line
     * @param logLevel          the minimum level of log events Terasology will include on its output stream to us
     */
    GameStarter(Installation installation, Path gameDataDirectory, JavaHeapSize heapMin, JavaHeapSize heapMax,