124 lines
3.5 KiB
Bash
Executable File
124 lines
3.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Define Colors
|
|
ORANGE="#FFA500"
|
|
GREY="#808080"
|
|
|
|
# 1. Check for required tools
|
|
if ! command -v gum &> /dev/null; then
|
|
echo "Error: 'gum' is not installed."
|
|
exit 1
|
|
fi
|
|
|
|
if ! command -v wit &> /dev/null; then
|
|
gum style --foreground "$ORANGE" "Error: 'wit' (Wiimms ISO Tools) is not installed."
|
|
exit 1
|
|
fi
|
|
|
|
# 2. Aesthetic Header
|
|
clear
|
|
gum style \
|
|
--border double \
|
|
--border-foreground "$ORANGE" \
|
|
--foreground "$ORANGE" \
|
|
--margin "1 2" \
|
|
--padding "1 4" \
|
|
--align center \
|
|
--width 50 \
|
|
"NINTENDO USB LOADER"
|
|
|
|
# 3. Mode Selection
|
|
gum style --foreground "$GREY" " > Select the console format:"
|
|
MODE=$(gum choose --cursor.foreground "$ORANGE" "Wii (WBFS)" "GameCube (ISO)")
|
|
[ -z "$MODE" ] && exit 1
|
|
|
|
# 4. Source Selection
|
|
gum style --foreground "$GREY" " > Select the directory containing your $MODE files"
|
|
ISO_DIR=$(gum file --directory)
|
|
[ -z "$ISO_DIR" ] && exit 1
|
|
|
|
# 5. USB Selection
|
|
USER_MEDIA="/run/media/$USER"
|
|
if [ ! -d "$USER_MEDIA" ] || [ -z "$(ls -A "$USER_MEDIA" 2>/dev/null)" ]; then
|
|
gum style --foreground 196 " No USB drives detected in $USER_MEDIA"
|
|
exit 1
|
|
fi
|
|
|
|
gum style --foreground "$GREY" " > Select your destination USB drive"
|
|
pushd "$USER_MEDIA" > /dev/null
|
|
SELECTED_DRIVE=$(gum choose --cursor.foreground "$ORANGE" *)
|
|
popd > /dev/null
|
|
[ -z "$SELECTED_DRIVE" ] && exit 1
|
|
|
|
USB_DIR="$USER_MEDIA/$SELECTED_DRIVE"
|
|
|
|
# 6. Final Summary and Confirmation
|
|
clear
|
|
gum style --foreground "$ORANGE" "Ready to Process $MODE"
|
|
echo -e " \033[90mSource: \033[0m $ISO_DIR"
|
|
echo -e " \033[90mTarget: \033[0m $USB_DIR"
|
|
echo ""
|
|
|
|
gum confirm --selected.background "$ORANGE" "Begin transfer?" || exit 0
|
|
|
|
# 7. Processing Loop
|
|
clear
|
|
gum style --foreground "$ORANGE" "Processing $MODE titles..."
|
|
echo ""
|
|
|
|
shopt -s nullglob
|
|
isos=("$ISO_DIR"/*.iso)
|
|
|
|
for iso_path in "${isos[@]}"; do
|
|
filename=$(basename "$iso_path")
|
|
|
|
if [ "$MODE" == "Wii (WBFS)" ]; then
|
|
# --- WII LOGIC ---
|
|
gum spin --spinner dot --title.foreground "$GREY" --title "Converting: $filename..." -- \
|
|
wit copy "$iso_path" --wbfs --split --dest "$USB_DIR/wbfs/%T [%I]/%I.wbfs"
|
|
|
|
if [ $? -eq 0 ]; then
|
|
gum style --foreground "$ORANGE" " ✔ $filename"
|
|
else
|
|
gum style --foreground 196 " ✘ Failed: $filename"
|
|
fi
|
|
|
|
else
|
|
# --- GAMECUBE LOGIC ---
|
|
# 1. Get Game ID (Using tail -n 1 to avoid header/color codes)
|
|
game_id=$(wit id "$iso_path" 2>/dev/null | tail -n 1 | awk '{print $1}')
|
|
|
|
# 2. Get Title from filename and sanitize for FAT32
|
|
game_title="${filename%.*}"
|
|
clean_title=$(echo "$game_title" | tr -d ':/\\*?<>|')
|
|
|
|
# 3. Create destination path
|
|
DEST_FOLDER="$USB_DIR/games/$clean_title [$game_id]"
|
|
|
|
# Validate ID before attempting
|
|
if [[ ! "$game_id" =~ ^[A-Z0-9]{6}$ ]]; then
|
|
gum style --foreground 196 " ✘ Failed: $filename (Invalid Game ID)"
|
|
continue
|
|
fi
|
|
|
|
# 4. Perform Folder Creation and Copy with Spinner
|
|
gum spin --spinner dot --title.foreground "$GREY" --title "Moving: $clean_title..." -- \
|
|
bash -c 'mkdir -p "$1" && cp "$2" "$1/game.iso"' _ "$DEST_FOLDER" "$iso_path"
|
|
|
|
if [ $? -eq 0 ]; then
|
|
gum style --foreground "$ORANGE" " ✔ $clean_title"
|
|
else
|
|
gum style --foreground 196 " ✘ Failed: $clean_title"
|
|
fi
|
|
fi
|
|
done
|
|
|
|
# 8. Finished
|
|
echo ""
|
|
gum style \
|
|
--border rounded \
|
|
--border-foreground "$GREY" \
|
|
--foreground "$ORANGE" \
|
|
--padding "1 2" \
|
|
"COMPLETE: Games synced to $SELECTED_DRIVE"
|