|
22 | 22 | fi |
23 | 23 |
|
24 | 24 | # Check mod description |
25 | | -#if [ -f "$3" ]; then |
26 | | -# description=$(sed -e ':a;N;$!ba' -e 's/\r//g' -e 's/\\/\\\\/g' -e 's/"/\\"/g' -e 's/\n/\\n/g' "$3") |
| 25 | +if [ -f "$3" ]; then |
| 26 | + description=$(sed -e ':a;N;$!ba' -e 's/\r//g' -e 's/\\/\\\\/g' -e 's/"/\\"/g' -e 's/\n/\\n/g' "$3") |
27 | 27 | # slurp entire file -e ':a;N;$!ba' |
28 | 28 | # remove any stray CR (^M) -e 's/\r//g' |
29 | 29 | # escape backslashes -e 's/\\/\\\\/g' |
30 | 30 | # escape double-quotes -e 's/"/\\"/g' |
31 | 31 | # escape newlines -e 's/\n/\\n/g' |
32 | 32 | # echo ">>> DEBUG: first 200 chars of desc:" >&2 |
33 | 33 | # printf '%s' "$description" | cut -c1-200 >&2 |
34 | | -#else |
35 | | -# printf 'Missing Steam description' |
36 | | -# printf '\n' |
37 | | -#fi |
38 | | -description="" |
| 34 | +else |
| 35 | + printf 'Missing Steam description' |
| 36 | + printf '\n' |
| 37 | +fi |
| 38 | +# If you need to test with a blank description: |
| 39 | +#description="" |
| 40 | + |
| 41 | +# After building $description (with all backslashes, quotes and newlines escaped): |
| 42 | +# 1) Measure its length in characters |
| 43 | +char_len=$(printf '%s' "$description" | wc -m) |
| 44 | +echo ">>> DEBUG: escaped description length = $char_len characters" >&2 |
| 45 | + |
| 46 | +# 2) Define your max in characters (e.g. 8000) |
| 47 | +MAX_CHARS=8000 |
| 48 | + |
| 49 | +# 3) If it’s too long, truncate to the first $MAX_CHARS characters |
| 50 | +if [ "$char_len" -gt "$MAX_CHARS" ]; then |
| 51 | + echo ">>> WARNING: description too long (${char_len} > ${MAX_CHARS}), truncating" >&2 |
| 52 | + # cut -c works on characters |
| 53 | + description=$(printf '%s' "$description" | cut -c1-"$MAX_CHARS") |
| 54 | + # (optionally append an ellipsis) |
| 55 | + # description="${description}…" |
| 56 | +fi |
| 57 | + |
| 58 | + |
39 | 59 |
|
40 | 60 | # Clean up old file |
41 | 61 | printf '' > workshop.vdf |
|
0 commit comments