From 38640368069014e216bad1234d9bfbceda1b604f Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Thu, 9 Oct 2025 23:58:40 -0400 Subject: [PATCH] A bit more work on the file organization. --- usr/local/bin/stormux_install_helper.sh | 45 ++++++++++++------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/usr/local/bin/stormux_install_helper.sh b/usr/local/bin/stormux_install_helper.sh index ef55267..fb3641d 100755 --- a/usr/local/bin/stormux_install_helper.sh +++ b/usr/local/bin/stormux_install_helper.sh @@ -95,33 +95,32 @@ setup_game_zip() { rm -rf "$game_dir" mkdir -p "$game_dir" - # Check if zip has a single top-level directory - mapfile -t topDirs < <(unzip -l "$zipfile" 2>> "$LOG_FILE" | awk 'NR>3 {print $4}' | grep '/$' | cut -d/ -f1 | sort -u | grep -v '^$') + # Extract to temp location first to handle any ZIP structure + local temp_extract="/tmp/stormux_install_$$" + mkdir -p "$temp_extract" - if [[ ${#topDirs[@]} -eq 1 ]]; then - # Zip has a single top-level dir - extract to temp location, then move - echo "Single top-level directory detected: ${topDirs[0]}" >> "$LOG_FILE" - local temp_extract="/tmp/stormux_install_$$" - mkdir -p "$temp_extract" - - if ! unzip -q "$zipfile" -d "$temp_extract" 2>> "$LOG_FILE"; then - echo "Extraction failed" >> "$LOG_FILE" - rm -rf "$temp_extract" - return 2 - fi - - # Move the extracted directory to final location - mv "$temp_extract/${topDirs[0]}" "$game_dir" 2>> "$LOG_FILE" + if ! unzip -q "$zipfile" -d "$temp_extract" 2>> "$LOG_FILE"; then + echo "Extraction failed" >> "$LOG_FILE" rm -rf "$temp_extract" - else - # Multiple top-level entries - extract directly to game_dir - echo "Multiple top-level entries detected" >> "$LOG_FILE" - if ! unzip -q "$zipfile" -d "$game_dir" 2>> "$LOG_FILE"; then - echo "Extraction failed" >> "$LOG_FILE" - return 2 - fi + return 2 fi + # Check if everything extracted into a single subdirectory + local extracted_items + extracted_items=("$temp_extract"/*) + + if [[ ${#extracted_items[@]} -eq 1 ]] && [[ -d "${extracted_items[0]}" ]]; then + # Single directory - move its contents to game_dir + echo "Single directory extracted, moving contents" >> "$LOG_FILE" + mv "${extracted_items[0]}"/* "$game_dir/" 2>> "$LOG_FILE" + else + # Multiple items or single file - move everything + echo "Multiple items extracted, moving all" >> "$LOG_FILE" + mv "$temp_extract"/* "$game_dir/" 2>> "$LOG_FILE" + fi + + rm -rf "$temp_extract" + # Replace NVDA DLLs replace_nvda_dlls "$game_dir"