A bit more work on the file organization.

This commit is contained in:
Storm Dragon
2025-10-09 23:58:40 -04:00
parent 2e0abcc14b
commit 3864036806

View File

@@ -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"