Skip to content

Commit 420e4ab

Browse files
handle "basegame-organized" packaging style
For issue #27. If the zipfile already has things in a "copper" directory for example, we should assume copper basegame and then move all those contained files up a level.
1 parent 9b15612 commit 420e4ab

File tree

1 file changed

+97
-5
lines changed

1 file changed

+97
-5
lines changed

scripts/quakelaunch

Lines changed: 97 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,8 @@ then
429429
fi
430430
# Take our best shot at making this playable.
431431
cd "$destdir"
432+
inferred_basegame=
433+
basegamespat="id1\|hipnotic\|rogue\|quoth\|copper\|ad\|alkaline"
432434
# Try to get rid of any extra directories generated in archive-creation,
433435
# as well as other files we don't want.
434436
while true
@@ -444,23 +446,59 @@ then
444446
then
445447
break
446448
fi
449+
# If any directory looks like a "basegame", and it contains known Quake
450+
# content directories, move its contents up and infer the basegame. And
451+
# keep looping. (If "id1", don't infer basegame though.)
452+
did_move=false
453+
dirs_here=$(find -maxdepth 1 -type d | grep -v '^\.$' | grep -oP '^\./\K.+')
454+
basegames_here=$(echo "$dirs_here" | grep "^\($basegamespat\)$")
455+
for dir in $basegames_here
456+
do
457+
subdirs=$(find $dir -maxdepth 1 -type d | grep -v "^$dir$" | grep -oP "^$dir/\K.+")
458+
echo "$knowndirs" | grep -qwi "$subdirs"
459+
if [[ $? -eq 0 ]]
460+
then
461+
if [[ $dir != "id1" ]]
462+
then
463+
if [[ $inferred_basegame != "" && $inferred_basegame != $dir ]]
464+
then
465+
rm -rf "$destdir"
466+
message "archive seems to indicate both $inferred_basegame and $dir as basegame"
467+
exit 1
468+
fi
469+
inferred_basegame=$dir
470+
fi
471+
mv $dir/* .
472+
if [[ $? -ne 0 ]]
473+
then
474+
rm -rf "$destdir"
475+
message "failed in organizing the extracted archive contents"
476+
exit 1
477+
fi
478+
rm -rf $dir
479+
did_move=true
480+
fi
481+
done
482+
if [[ $did_move == "true" ]]
483+
then
484+
continue
485+
fi
447486
# If there is only one directory here, and it's not a known Quake
448487
# content directory, then it's packaging cruft. Move its contents up
449488
# and keep looping.
450-
dirshere=$(find -maxdepth 1 -type d | grep -v '^\.$')
451-
if [[ "$dirshere" != "" && $(echo "$dirshere" | wc -l) -eq 1 ]]
489+
if [[ "$dirs_here" != "" && $(echo "$dirs_here" | wc -l) -eq 1 ]]
452490
then
453-
echo "$knowndirs" | grep -qwi "$dirshere"
491+
echo "$knowndirs" | grep -qwi "$dirs_here"
454492
if [[ $? -ne 0 ]]
455493
then
456-
mv "$dirshere"/* .
494+
mv "$dirs_here"/* .
457495
if [[ $? -ne 0 ]]
458496
then
459497
rm -rf "$destdir"
460498
message "failed in organizing the extracted archive contents"
461499
exit 1
462500
fi
463-
rm -rf "$dirshere"
501+
rm -rf "$dirs_here"
464502
continue
465503
fi
466504
fi
@@ -704,6 +742,60 @@ then
704742
fi
705743
fi
706744
fi
745+
# If we didn't get basegame_args from a gamedir-specific conf, see if we can
746+
# infer it from the way the archive was organized.
747+
if [[ $calc_basegame_args == "true" && $inferred_basegame != "" ]]
748+
then
749+
if [[ $(is_standalone_gamedir "$mod") == "true" ]]
750+
then
751+
message "archive appears to depend on $inferred_basegame but also contains paks/progs"
752+
exit 1
753+
fi
754+
calc_basegame_args=false
755+
if [[ $inferred_basegame == "quoth" ]]
756+
then
757+
basegame_args=-quoth
758+
else
759+
if [[ $inferred_basegame == "hipnotic" ]]
760+
then
761+
basegame_args=-hipnotic
762+
else
763+
if [[ $inferred_basegame == "rogue" ]]
764+
then
765+
basegame_args=-rogue
766+
else
767+
if [[ $inferred_basegame == "ad" ]]
768+
if [[ -n "$ad_basegame_args" ]]
769+
then
770+
basegame_args=$ad_basegame_args
771+
else
772+
basegame_error="ad"
773+
fi
774+
then
775+
if [[ $inferred_basegame == "copper" ]]
776+
then
777+
if [[ -n "$copper_basegame_args" ]]
778+
then
779+
basegame_args=$copper_basegame_args
780+
else
781+
basegame_error="copper"
782+
fi
783+
else
784+
if [[ $inferred_basegame == "alkaline" ]]
785+
then
786+
if [[ -n "$alkaline_basegame_args" ]]
787+
then
788+
basegame_args=$alkaline_basegame_args
789+
else
790+
basegame_error="alkaline"
791+
fi
792+
fi
793+
fi
794+
fi
795+
fi
796+
fi
797+
fi
798+
fi
707799
# For a non-standalone mod where basegame_args was not explicitly set in a
708800
# gamedir-specific conf, see if we can figure out any required basegame from
709801
# grepping docs. Arcane Dimensions is somewhat different; we assume AD if

0 commit comments

Comments
 (0)