Changeset - 741d8e825ee6
[Not reviewed]
0 1 0
Branko Majic (branko) - 4 years ago 2020-07-05 14:29:02
branko@majic.rs
Noticket: Refactor all existing commands in Factorio Manager to use generic function for picking Factorio version.
1 file changed with 5 insertions and 95 deletions:
0 comments (0 inline, 0 general)
games/factorio_manager.sh
Show inline comments
 
@@ -1629,37 +1629,10 @@ elif [[ $command == set-version ]]; then
 
    source "$instance_config"
 

	
 
    # Display list of available Factorio versions.
 
    echo
 
    echo "The following versions of Factorio are locally available:"
 
    echo
 

	
 
    for candidate in "$game_installations_directory"/*; do
 
        if [[ -f $candidate/bin/x64/factorio ]]; then
 
            candidate_version=$(basename "$candidate")
 
            if [[ $candidate_version == $game_version ]]; then
 
                echo "  - $candidate_version $(colorecho -n green "[current]")"
 
            else
 
                echo "  - $candidate_version"
 
            fi
 

	
 
        fi
 
    done
 
    echo
 

	
 
    # Display current version.
 
    echo "Current version used for instance $(colorecho -n green "$instance") is $(colorecho -n green "$game_version")."
 
    echo
 
    read -p "Please specify what version you would like to use (enter to keep current): " game_version_selected
 

	
 
    if [[ -z $game_version_selected ]]; then
 
        game_version_selected="$game_version"
 
    fi
 

	
 
    # Validate user input.
 
    if [[ ! -f "$game_installations_directory/$game_version_selected/bin/x64/factorio" ]]; then
 
        error "Requested version not locally available: $game_version_selected"
 
        exit "$ERROR_ARGUMENTS"
 
    fi
 
    select_factorio_version "$game_installations_directory" "$game_version" "current" || exit "$ERROR_GENERAL"
 
    echo
 

	
 
    # Change instance game version.
 
    if [[ $game_version_selected == $game_version ]]; then
 
@@ -2016,36 +1989,10 @@ elif [[ $command == copy ]]; then
 
        echo
 
        echo "If you wish to, you can now change version of Factorio used for destination instance, or keep the same version as for source instance."
 
        echo
 
        echo "The following versions of Factorio are locally available:"
 
        echo
 

	
 
        for candidate in "$game_installations_directory"/*; do
 
            if [[ -f $candidate/bin/x64/factorio ]]; then
 
                candidate_version=$(basename "$candidate")
 
                if [[ $candidate_version == $game_version ]]; then
 
                    echo "  - $candidate_version $(colorecho -n green "[current]")"
 
                else
 
                    echo "  - $candidate_version"
 
                fi
 
            fi
 
        done
 
        select_factorio_version "$game_installations_directory" "$game_version" "current" | exit "$ERROR_GENERAL"
 
        echo
 

	
 
        # Display current version.
 
        echo "Current version used for instance $(colorecho -n green "$source_instance") is $(colorecho -n green "$game_version")."
 
        echo
 
        read -p "Please specify what version you would like to use for new instance (press enter to keep the current version): " game_version_selected
 

	
 
        if [[ -z $game_version_selected ]]; then
 
            game_version_selected="$game_version"
 
        fi
 

	
 
        # Validate user input.
 
        if [[ ! -f "$game_installations_directory/$game_version_selected/bin/x64/factorio" ]]; then
 
            error "Requested version not locally available: $game_version_selected"
 
            exit "$ERROR_ARGUMENTS"
 
        fi
 

	
 
        # Check if user wants to copy backup files as well.
 
        copy_backups=""
 

	
 
@@ -2150,25 +2097,7 @@ elif [[ $command == import ]]; then
 
    # Display list of available Factorio versions and let user pick one.
 
    echo "Factorio version must  be selected manually for imported instances."
 
    echo
 
    echo "The following versions of Factorio are locally available:"
 
    echo
 

	
 
    for candidate in "$game_installations_directory"/*; do
 
        if [[ -f $candidate/bin/x64/factorio ]]; then
 
            echo "  - $(basename "$candidate")"
 
        fi
 
    done
 

	
 
    echo
 

	
 
    echo -n "Please specify what version you would like to use: "
 
    read game_version_selected
 

	
 
    # Validate user input.
 
    if [[ ! -f "$game_installations_directory/$game_version_selected/bin/x64/factorio" ]]; then
 
        error "Requested version not locally available: $game_version_selected"
 
        exit "$ERROR_ARGUMENTS"
 
    fi
 
    select_factorio_version "$game_installations_directory" || exit "$ERROR_GENERAL"
 

	
 
    (
 

	
 
@@ -2277,26 +2206,7 @@ elif [[ $command == create-server ]]; then
 

	
 
    validate_path_or_terminate "instance_directory_new" "$instance_directory" "$ERROR_ARGUMENTS"
 

	
 
    # Display list of available Factorio versions and let user pick one.
 
    echo "The following versions of Factorio are locally available:"
 
    echo
 

	
 
    for candidate in "$game_installations_directory"/*; do
 
        if [[ -f $candidate/bin/x64/factorio ]]; then
 
            echo "  - $(basename "$candidate")"
 
        fi
 
    done
 

	
 
    echo
 

	
 
    echo -n "Please specify what version you would like to use: "
 
    read game_version_selected
 

	
 
    # Validate user input.
 
    if [[ ! -f "$game_installations_directory/$game_version_selected/bin/x64/factorio" ]]; then
 
        error "Requested version not locally available: $game_version_selected"
 
        exit "$ERROR_ARGUMENTS"
 
    fi
 
    select_factorio_version "$game_installations_directory" || exit "$ERROR_GENERAL"
 

	
 
    # Grab server settings from user.
 
    echo "You will now be prompted to provide settings for the server, with some pre-filled settings."
0 comments (0 inline, 0 general)