Skip to content

Commit de6240f

Browse files
authored
fix: #1868 mods lowercase conversion (#3717)
* Finally fixes #1868 mods lowercase conversion Sample output: Installing DarkRP ================================= creating mod download directory /home/ulti/lgsm/mods/tmp...OK #=#=- # # ################################################################################################################################################################################################################################################ 100.0% -#O=- # # # extracting darkrp-master.zip...OK converting DarkRP files to lowercase...Found 19 uppercase files out of 588, converting...OK building darkrp-files.txt...OK copying DarkRP to /home/ulti/serverfiles/garrysmod/gamemodes...OK tidy up darkrp-files.txt...OK clearing mod download directory /home/ulti/lgsm/mods/tmp...OK DarkRP installed * removed unused variable
1 parent 1c3e504 commit de6240f

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

lgsm/functions/mods_core.sh

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,33 +33,39 @@ fn_mod_install_files(){
3333

3434
# Convert mod files to lowercase if needed.
3535
fn_mod_lowercase(){
36+
# Checking lowercase settings from mods array definition
3637
if [ "${modlowercase}" == "LowercaseOn" ]; then
37-
3838
echo -en "converting ${modprettyname} files to lowercase..."
3939
fn_sleep_time
4040
fn_script_log_info "Converting ${modprettyname} files to lowercase"
41-
fileswc=$(find "${extractdir}" -depth | wc -l)
42-
echo -en "\r"
41+
# Total files and directories for the mod, to output to the user
42+
fileswc=$(find "${extractdir}" | wc -l)
43+
# Total uppercase files and directories for the mod, to output to the user
44+
filesupperwc=$(find "${extractdir}" -name '*[[:upper:]]*' | wc -l)
45+
fn_script_log_info "Found ${filesupperwc} uppercase files out of ${fileswc}, converting"
46+
echo -en "Found ${filesupperwc} uppercase files out of ${fileswc}, converting..."
47+
# Convert files and directories starting from the deepest to prevent issues (-depth argument)
4348
while read -r src; do
44-
dst=$(dirname "${src}$(/)basename" "${src}" | tr '[:upper:]' '[:lower:]')
45-
if [ "${src}" != "${dst}" ]
46-
then
47-
[ ! -e "${dst}" ] && mv -T "${src}" "${dst}" || echo -e "${src} was not renamed"
49+
# We have to convert only the last file from the path, otherwise we will fail to convert anything if a parent dir has any uppercase
50+
# therefore, we have to separate the end of the filename to only lowercase it rather than the whole line
51+
# Gather parent dir, filename lowercase filename, and set lowercase destination name
52+
latestparentdir=$(dirname "${src}")
53+
latestfilelc=$(basename "${src}" | tr '[:upper:]' '[:lower:]')
54+
dst="${latestparentdir}/${latestfilelc}"
55+
# Only convert if destination does not already exist for some reason
56+
if [ ! -e "${dst}" ]; then
57+
# Finally we can rename the file
58+
mv "${src}" "${dst}"
59+
# Exit if it fails for any reason
4860
local exitcode=$?
49-
((renamedwc++))
61+
if [ "${exitcode}" != 0 ]; then
62+
fn_print_fail_eol_nl
63+
core_exit.sh
64+
fi
5065
fi
51-
echo -en "${renamedwc} / ${totalfileswc} / ${fileswc} converting ${modprettyname} files to lowercase..." $'\r'
52-
((totalfileswc++))
53-
done < <(find "${extractdir}" -depth)
54-
echo -en "${renamedwc} / ${totalfileswc} / ${fileswc} converting ${modprettyname} files to lowercase..."
55-
56-
if [ "${exitcode}" != 0 ]; then
57-
fn_print_fail_eol_nl
58-
core_exit.sh
59-
else
66+
done < <(find "${extractdir}" -depth -name '*[[:upper:]]*')
6067
fn_print_ok_eol_nl
61-
fi
62-
fi
68+
fi
6369
}
6470

6571
# Create ${modcommand}-files.txt containing the full extracted file/directory list.

0 commit comments

Comments
 (0)