Skip to content

Commit cbaf0af

Browse files
committed
Cleanup comments and add game check for mod name
1 parent b79a1bf commit cbaf0af

File tree

1 file changed

+29
-51
lines changed

1 file changed

+29
-51
lines changed

lgsm/functions/workshop_core.sh

Lines changed: 29 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,15 @@ fn_workshop_is_mod_copy_needed(){
155155

156156
fn_workshop_get_mod_name(){
157157
local modid="$1"
158-
if ! [ -d "${workshopmodsdir}/${modid}" ]; then
159-
echo "$(grep -Po '(?<=name = ").+?(?=")' ${workshopmodsdir}/${modid}/mod.cpp)"
160-
elif ! [ -d "${workshopmodsdldir}/steamapps/workshop/content/${gameappid}/${modid}" ]; then
161-
echo "$(grep -Po '(?<=name = ").+?(?=")' ${workshopmodsdldir}/steamapps/workshop/content/${gameappid}/${modid}/mod.cpp)"
158+
# Each game has different Steam Workshop structure, so mod id will be stored in a different place
159+
if [ "${engine}" == "realvirtuality" ]; then
160+
if ! [ -d "${workshopmodsdir}/${modid}" ]; then
161+
echo "$(grep -Po '(?<=name = ").+?(?=")' ${workshopmodsdir}/${modid}/mod.cpp)"
162+
elif ! [ -d "${workshopmodsdldir}/steamapps/workshop/content/${gameappid}/${modid}" ]; then
163+
echo "$(grep -Po '(?<=name = ").+?(?=")' ${workshopmodsdldir}/steamapps/workshop/content/${gameappid}/${modid}/mod.cpp)"
164+
else
165+
echo "$(fn_workshop_get_name_from_steam ${modid})"
166+
fi
162167
else
163168
echo "$(fn_workshop_get_name_from_steam ${modid})"
164169
fi
@@ -179,45 +184,29 @@ fn_workshop_lowercase() {
179184
filesupperwc=$(find "${workshopmodsdir}/" -name '*[[:upper:]]*' | wc -l)
180185
fn_script_log_info "Found ${filesupperwc} uppercase files out of ${fileswc}, converting"
181186
echo -en "Found ${filesupperwc} uppercase files out of ${fileswc}, converting..."
182-
# Works but not on folders
183-
# while IFS= read -r -d '' file; do
184-
# mv -b -- "$file" "${file,,}" 2>/dev/null
185-
# done < <(find ${workshopmodsdir} -depth -name '*[A-Z]*' -print0)
186-
# while IFS= read -r -d '' file; do
187-
# mv -b -- "$file" "${file,,}" 2>/dev/null
188-
# done < <(find ${workshopmodsdir}/ -depth -name '*[A-Z]*' -print0)
189-
190-
# Works bu not on WSL?
191-
# https://unix.stackexchange.com/questions/20222/change-entire-directory-tree-to-lower-case-names/20232#20232
192187
#
193-
find ${workshopmodsdir} -depth -exec sh -c '
194-
t=${0%/*}/$(printf %s "${0##*/}" | tr "[:upper:]" "[:lower:]");
195-
[ "$t" = "$0" ] || mv -i "$0" "$t"
196-
' {} \;
197-
198-
#
199-
# Coudln't get this to work.
188+
# Coudln't get this to work on WSL. Needs to be verified on an acutal linux server.
200189
#
201190
# Convert files and directories starting from the deepest to prevent issues (-depth argument)
202-
# while IFS= read -r -d '' src; do
203-
# # 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
204-
# # therefore, we have to separate the end of the filename to only lowercase it rather than the whole line
205-
# # Gather parent dir, filename lowercase filename, and set lowercase destination name
206-
# latestparentdir=$(dirname "${src}")
207-
# latestfilelc=$(basename "${src}" | tr '[:upper:]' '[:lower:]')
208-
# dst="${latestparentdir}/${latestfilelc}"
209-
# # Only convert if destination does not already exist for some reason
210-
# if [ ! -e "${dst}" ]; then
211-
# # Finally we can rename the file
212-
# mv "${src}" "${dst}"
213-
# # Exit if it fails for any reason
214-
# local exitcode=$?
215-
# if [ "${exitcode}" != 0 ]; then
216-
# fn_print_fail_eol_nl
217-
# core_exit.sh
218-
# fi
219-
# fi
220-
# done < <(find "${workshopmodsdir}" -depth -name '*[[:upper:]]*' -print0)
191+
while IFS= read -r -d '' src; do
192+
# 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
193+
# therefore, we have to separate the end of the filename to only lowercase it rather than the whole line
194+
# Gather parent dir, filename lowercase filename, and set lowercase destination name
195+
latestparentdir=$(dirname "${src}")
196+
latestfilelc=$(basename "${src}" | tr '[:upper:]' '[:lower:]')
197+
dst="${latestparentdir}/${latestfilelc}"
198+
# Only convert if destination does not already exist for some reason
199+
if [ ! -e "${dst}" ]; then
200+
# Finally we can rename the file
201+
mv "${src}" "${dst}"
202+
# Exit if it fails for any reason
203+
local exitcode=$?
204+
if [ "${exitcode}" != 0 ]; then
205+
fn_print_fail_eol_nl
206+
core_exit.sh
207+
fi
208+
fi
209+
done < <(find "${workshopmodsdir}" -depth -name '*[[:upper:]]*' -print0)
221210
fn_print_ok_eol_nl
222211
fi
223212
}
@@ -255,17 +244,6 @@ fn_workshop_copy_destination() {
255244
else
256245
echo "Mod ${modname} is already in mods folder."
257246
fi
258-
# echo -en "copying ${modprettyname} to ${modinstalldir}..."
259-
# fn_sleep_time
260-
# cp -Rf "${extractdir}/." "${modinstalldir}/"
261-
# local exitcode=$?
262-
# if [ "${exitcode}" != 0 ]; then
263-
# fn_print_fail_eol_nl
264-
# fn_script_log_fatal "Copying ${modprettyname} to ${modinstalldir}"
265-
# else
266-
# fn_print_ok_eol_nl
267-
# fn_script_log_pass "Copying ${modprettyname} to ${modinstalldir}"
268-
# fi
269247
}
270248

271249
# ## Directory management.

0 commit comments

Comments
 (0)