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
 
@@ -22,7 +22,7 @@
 
set -u
 

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

	
 
function synopsis() {
 
cat <<EOF
 
@@ -190,6 +190,9 @@ set-game-dir GAME_INSTALLATIONS_DIRECTORY
 
        - ~/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
 
@@ -1237,22 +1240,26 @@ if [[ $command == set-game-dir ]]; then
 
        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
 

	
0 comments (0 inline, 0 general) First comment
You need to be logged in to comment. Login now