@@ -33,33 +33,39 @@ fn_mod_install_files(){
33
33
34
34
# Convert mod files to lowercase if needed.
35
35
fn_mod_lowercase (){
36
+ # Checking lowercase settings from mods array definition
36
37
if [ " ${modlowercase} " == " LowercaseOn" ]; then
37
-
38
38
echo -en " converting ${modprettyname} files to lowercase..."
39
39
fn_sleep_time
40
40
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)
43
48
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
48
60
local exitcode=$?
49
- (( renamedwc++ ))
61
+ if [ " ${exitcode} " != 0 ]; then
62
+ fn_print_fail_eol_nl
63
+ core_exit.sh
64
+ fi
50
65
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:]]*' )
60
67
fn_print_ok_eol_nl
61
- fi
62
- fi
68
+ fi
63
69
}
64
70
65
71
# Create ${modcommand}-files.txt containing the full extracted file/directory list.
0 commit comments