Changeset - 92490ac9c583
[Not reviewed]
0 1 0
Branko Majic (branko) - 4 years ago 2020-07-18 15:16:58
branko@majic.rs
Noticket: [factorio_manager.sh] Allow empty directory to be used as game installation directory.
1 file changed with 14 insertions and 7 deletions:
0 comments (0 inline, 0 general) First comment
games/factorio_manager.sh
Show inline comments
 
@@ -19,13 +19,13 @@
 
#
 

	
 
# Treat unset variables as errors.
 
set -u
 

	
 
program="factorio_manager.sh"
 
version="0.3.0"
 
version="0.3.1"
 

	
 
function synopsis() {
 
cat <<EOF
 
$program $version, helper tool for managing Factorio instances
 

	
 
Usage:
 
@@ -187,12 +187,15 @@ set-game-dir GAME_INSTALLATIONS_DIRECTORY
 
    after the version of Factorio it represents. For example:
 

	
 
        - ~/local/games/factorio/0.17.79/
 
        - ~/local/games/factorio/0.18.30/
 
        - ~/local/games/factorio/0.18.34/
 

	
 
    Directory must be either empty or it should contain at least one
 
    instance of Factorio installation already.
 

	
 
set-version INSTANCE
 

	
 
    Sets Factorio version for the specified instance. User is prompted
 
    to pick between locally available versions.
 

	
 
versions
 
@@ -1234,28 +1237,32 @@ if [[ $command == set-game-dir ]]; then
 

	
 
    if [[ -z $game_installations_directory_target ]]; then
 
        error "Missing argument: GAME_INSTALLATIONS_DIRECTORY"
 
        exit "$ERROR_ARGUMENTS"
 
    fi
 

	
 
    if [[ ! -e $game_installations_directory_target ]]; then
 
    if [[ ! -d $game_installations_directory_target ]]; then
 
        error "No such directory: $game_installations_directory"
 
        exit "$ERROR_GENERAL"
 
    fi
 

	
 
    # Verify that at least one Factorio instance can be found.
 
    # For directory to be usable, it must be either empty or contain
 
    # at least one Factorio installation.
 
    shopt -s nullglob
 
    candidates=("$game_installations_directory_target"/*)
 
    shopt -u nullglob
 

	
 
    factorio_versions_found=0
 
    for candidate in "$game_installations_directory_target"/*; do
 
    for candidate in "${candidates[@]}"; do
 
        if [[ -f $candidate/bin/x64/factorio ]]; then
 
            (( factorio_versions_found++ ))
 
        fi
 
    done
 

	
 
    if (( factorio_versions_found == 0 )); then
 
        error "Could not locate any Factorio installations under: $game_installations_directory_target"
 

	
 
    if [[ ${#candidates[@]} != 0 ]] && (( factorio_versions_found == 0 )); then
 
        error "Specified directory must be either empty or must contain at least one Factorio installation already."
 
        exit "$ERROR_GENERAL"
 
    fi
 

	
 
    # Update the link
 
    if [[ -L $game_installations_directory ]]; then
 
        rm "$game_installations_directory"
0 comments (0 inline, 0 general) First comment
You need to be logged in to comment. Login now