Skip to content

Commit ec7325c

Browse files
authored
Add files via upload
1 parent dde79a4 commit ec7325c

1 file changed

Lines changed: 29 additions & 92 deletions

File tree

NonSteamLaunchers.sh

Lines changed: 29 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ fi
9393
exec > >(tee -a "$log_file") 2>&1
9494

9595
# Version number (major.minor)
96-
version=v4.2.85
96+
version=v4.2.86
9797
#NSL Decky Plugin Latest Github Version
9898
deckyversion=$(curl -s https://raw.githubusercontent.com/moraroy/NonSteamLaunchersDecky/refs/heads/main/package.json | grep -o '"version": "[^"]*' | sed 's/"version": "//')
9999

@@ -1250,6 +1250,7 @@ StartFreshFunction() {
12501250
delete_path "${logged_in_home}/.config/systemd/user/env_vars"
12511251
delete_path "${logged_in_home}/.config/systemd/user/NSLGameScanner.py"
12521252
delete_path "${logged_in_home}/.config/systemd/user/shortcuts"
1253+
delete_path "${logged_in_home}/.config/systemd/user/descriptions.json"
12531254
delete_path "${logged_in_home}/.local/share/applications/RemotePlayWhatever"
12541255
delete_path "${logged_in_home}/.local/share/applications/RemotePlayWhatever.desktop"
12551256
delete_path "${logged_in_home}/Downloads/NonSteamLaunchers-install.log"
@@ -2295,6 +2296,7 @@ function stop_service {
22952296

22962297
# Delete the NSLGameScanner.py
22972298
rm -rf ${logged_in_home}/.config/systemd/user/NSLGameScanner.py
2299+
rm -rf ${logged_in_home}/.config/systemd/user/descriptions.json
22982300

22992301
# Delete the service file
23002302
rm -rf ${logged_in_home}/.config/systemd/user/nslgamescanner.service
@@ -4026,12 +4028,12 @@ fi
40264028

40274029
#recieve noooooooooooootes
40284030
# Paths
4031+
# Paths
40294032
proton_dir=$(find -L "${logged_in_home}/.steam/root/compatibilitytools.d" -maxdepth 1 -type d -name "GE-Proton*" | sort -V | tail -n1)
40304033
CSV_FILE="$proton_dir/protonfixes/umu-database.csv"
40314034
echo "$CSV_FILE"
40324035
shortcuts_file="${logged_in_home}/.steam/root/userdata/${steamid3}/config/shortcuts.vdf"
40334036
output_dir="${logged_in_home}/.steam/root/userdata/${steamid3}/2371090/remote"
4034-
descriptions_file="${logged_in_home}/.config/systemd/user/descriptions.json"
40354037

40364038
# Function to get the current Unix timestamp
40374039
get_current_timestamp() {
@@ -4054,26 +4056,10 @@ urlencode() {
40544056
echo -n "$raw" | jq -sRr @uri
40554057
}
40564058

4057-
# Function to read descriptions from a file
4058-
read_descriptions() {
4059-
if [[ -f "$descriptions_file" ]]; then
4060-
if ! validate_json "$descriptions_file"; then
4061-
echo "Error: Invalid JSON in descriptions file $descriptions_file"
4062-
return 1
4063-
fi
4064-
cat "$descriptions_file"
4065-
else
4066-
echo "Descriptions file does not exist, creating a new one."
4067-
echo "[]" > "$descriptions_file" # Create an empty JSON array
4068-
fi
4069-
}
4070-
40714059
# Function to fetch all notes from the API at once
40724060
fetch_all_notes_from_api() {
4073-
# Get the JSON response from the API
40744061
response=$(curl -s "https://nslnotes.onrender.com/api/notes")
40754062

4076-
# Check if the response is valid JSON
40774063
if ! jq . <<< "$response" > /dev/null 2>&1; then
40784064
echo "Error: Invalid JSON response from the API"
40794065
return 1
@@ -4086,128 +4072,86 @@ fetch_all_notes_from_api() {
40864072
update_notes_in_file() {
40874073
local file_path="$1"
40884074
local game_name="$2"
4089-
local api_response="$3" # All notes are passed in at once
4075+
local api_response="$3"
40904076

4091-
# Sanitize the game name (replace spaces with underscores, etc.)
40924077
sanitized_game_name="$game_name"
40934078
sanitized_game_name="${sanitized_game_name// /_}"
40944079
sanitized_game_name="${sanitized_game_name//[^a-zA-Z0-9]/_}"
40954080

4096-
# URL encode the sanitized game name
40974081
encoded_game_name=$(urlencode "$sanitized_game_name")
40984082

4099-
# Filter the notes to only get the ones for the current game using `jq`
41004083
filtered_notes=$(echo "$api_response" | jq -r ".[] | select(.\"File Name\" == \"notes_shortcut_${encoded_game_name}\")")
41014084

4102-
# If no notes are found for this game, exit early
41034085
if [[ -z "$filtered_notes" ]]; then
41044086
echo "No notes found for game $game_name"
41054087
return
41064088
fi
41074089

4108-
# Start with an empty string to hold the formatted content for all notes
41094090
nsl_content=""
41104091

4111-
# Loop through the filtered notes for this game
4112-
# Loop through the filtered notes for this game
41134092
for note in $(echo "$filtered_notes" | jq -r '@base64'); do
4114-
# Decode the note
41154093
note_decoded=$(echo "$note" | base64 --decode)
41164094

4117-
# Extract the relevant information for each note
41184095
user=$(echo "$note_decoded" | jq -r '."user"')
41194096
content=$(echo "$note_decoded" | jq -r '."Content"')
41204097
time_created=$(echo "$note_decoded" | jq -r '."Time Created"')
41214098

4122-
# Sanitize content: remove any existing [p] tags
41234099
content_sanitized=$(echo "$content" | sed 's/\[\/\?p\]//g')
4124-
4125-
# Replace newlines with Steam-friendly line breaks (or leave as plain text)
41264100
content_sanitized=$(echo "$content_sanitized" | sed 's/\n/<br>/g')
41274101

4128-
# Construct the content block for this note using **only [p]…[/p]**
41294102
nsl_content+=$"[p][i]A note called \"$user\" says,[/i][/p]"
41304103
nsl_content+=$"[p]$content_sanitized[/p]"
41314104
nsl_content+=$"[p]$time_created[/p]"
41324105
done
41334106

4134-
4135-
4136-
# Generate the current timestamp
41374107
local current_time=$(get_current_timestamp)
41384108

4139-
# Get the game details from the CSV file
41404109
game_details=$(grep -i "$game_name" "$CSV_FILE")
41414110

4142-
# If no details are found, use default values for the game
41434111
if [[ -z "$game_details" ]]; then
41444112
game_details="N/A,N/A,N/A,N/A,N/A,N/A"
41454113
fi
41464114

4147-
# Loop through each matching result and print each field without colons
41484115
echo "$game_details" | while IFS=',' read -r title store codename umu_id common_acronym note; do
4149-
# Handle missing fields by replacing them with "N/A"
41504116
title=${title:-N/A}
41514117
store=${store:-N/A}
41524118
codename=${codename:-N/A}
41534119
umu_id=${umu_id:-N/A}
41544120
common_acronym=${common_acronym:-N/A}
41554121
note=${note:-N/A}
41564122

4157-
# Construct the Proton-GE note with the game details
41584123
proton_ge_content="[p]Title: $title[/p][p]Store: $store[/p][p]Codename: $codename[/p][p]UMU ID: $umu_id[/p][p]Common Acronym: $common_acronym[/p][p]Note: $note[/p]"
41594124

4160-
# Construct the notes using jq (dynamically including the new Proton-GE content)
41614125
local note_1=$(jq -n --arg shortcut_name "$game_name" --argjson time_created "$current_time" --arg proton_ge_content "$proton_ge_content" \
41624126
'{"id":"note1675","shortcut_name":$shortcut_name,"ordinal":0,"time_created":$time_created,"time_modified":$time_created,"title":"Proton-GE & UMU","content":$proton_ge_content}')
41634127

41644128
local note_2=$(jq -n --arg shortcut_name "$game_name" --argjson time_created "$current_time" --arg nsl_content "$nsl_content" \
41654129
'{"id":"note2675","shortcut_name":$shortcut_name,"ordinal":0,"time_created":$time_created,"time_modified":$time_created,"title":"NSL Community Notes","content":$nsl_content}')
41664130

4167-
# Read the descriptions from the JSON file
4168-
descriptions=$(read_descriptions)
4169-
4170-
# Find the description for the current game
4171-
game_description=$(echo "$descriptions" | jq -r ".[] | select(.game_name == \"$game_name\") | .about_the_game")
4172-
4173-
# Use a default description if none is found
4174-
if [[ -z "$game_description" ]]; then
4175-
game_description="No description found in the JSON file."
4176-
fi
4177-
4178-
#create a description note
4179-
local note_3=$(jq -n --arg shortcut_name "$game_name" --argjson time_created "$current_time" --arg game_description "$game_description" \
4180-
'{"id":"note3675","shortcut_name":$shortcut_name,"ordinal":0,"time_created":$time_created,"time_modified":$time_created,"title":"Game Description","content":$game_description}')
4181-
4182-
# Check if the file exists and is valid
4183-
if [[ -f "$file_path" ]]; then
4184-
# Validate if the file contains valid JSON
4185-
if validate_json "$file_path"; then
4186-
# Check if the file contains an array of notes
4187-
if jq -e '.notes | type == "array"' "$file_path" > /dev/null; then
4188-
# Replace the existing notes with the new ones on top
4189-
jq --argjson note1 "$note_1" --argjson note2 "$note_2" --argjson note3 "$note_3" \
4190-
'.notes = [$note1, $note2, $note3] + (.notes | map(select(.id != "note1675" and .id != "note2675" and .id != "note3675")))' \
4191-
"$file_path" > "$file_path.tmp" && mv "$file_path.tmp" "$file_path"
4192-
echo "Replaced Proton, NSL Community Notes, and Description Notes in $file_path"
4193-
else
4194-
echo "Error: The 'notes' field is not an array or is missing in $file_path."
4195-
return 1
4196-
fi
4131+
if [[ -f "$file_path" ]]; then
4132+
if validate_json "$file_path"; then
4133+
if jq -e '.notes | type == "array"' "$file_path" > /dev/null; then
4134+
jq --argjson note1 "$note_1" --argjson note2 "$note_2" \
4135+
'.notes = [$note1, $note2] + (.notes | map(select(.id != "note1675" and .id != "note2675")))' \
4136+
"$file_path" > "$file_path.tmp" && mv "$file_path.tmp" "$file_path"
4137+
echo "Replaced Proton and NSL Community Notes in $file_path"
41974138
else
4198-
echo "Invalid JSON. Skipping update."
4199-
return 1 # Exit if the JSON is invalid
4139+
echo "Error: The 'notes' field is not an array or is missing in $file_path."
4140+
return 1
42004141
fi
42014142
else
4202-
# Create a new file with the notes structure if the file does not exist
4203-
if jq -n --argjson note1 "$note_1" --argjson note2 "$note_2" --argjson note3 "$note_3" \
4204-
'{"notes":[$note1, $note2, $note3]}' > "$file_path"; then
4205-
echo "Created new file with notes: $file_path"
4206-
else
4207-
echo "Error creating file: $file_path"
4208-
return 1 # Exit if the file creation fails
4209-
fi
4143+
echo "Invalid JSON. Skipping update."
4144+
return 1
42104145
fi
4146+
else
4147+
if jq -n --argjson note1 "$note_1" --argjson note2 "$note_2" \
4148+
'{"notes":[$note1, $note2]}' > "$file_path"; then
4149+
echo "Created new file with notes: $file_path"
4150+
else
4151+
echo "Error creating file: $file_path"
4152+
return 1
4153+
fi
4154+
fi
42114155
done
42124156
}
42134157

@@ -4222,20 +4166,16 @@ list_game_names() {
42224166

42234167
echo "Reading game names from $shortcuts_file..."
42244168

4225-
# Reset games array
42264169
games=()
42274170

4228-
# Parse shortcuts.vdf for appname entries
42294171
mapfile -t lines < <(tr '\0\1\2' '\n\n\n' < "$shortcuts_file" | grep -v '^$')
42304172

42314173
for ((i=0; i < ${#lines[@]} - 1; i++)); do
42324174
if [[ "${lines[i],,}" == "appname" ]]; then
42334175
local appname="${lines[i+1]}"
4234-
# Trim whitespace
4235-
appname="${appname#"${appname%%[![:space:]]*}"}" # leading
4236-
appname="${appname%"${appname##*[![:space:]]}"}" # trailing
4176+
appname="${appname#"${appname%%[![:space:]]*}"}"
4177+
appname="${appname%"${appname##*[![:space:]]}"}"
42374178

4238-
# Skip if appname matches skip extensions (case-insensitive)
42394179
if [[ -n "$appname" && ! "${appname,,}" =~ $skip_ext ]]; then
42404180
games+=("$appname")
42414181
echo "Added game: $appname"
@@ -4248,21 +4188,17 @@ list_game_names() {
42484188
return 0
42494189
}
42504190

4251-
# Main process
42524191
echo "Starting script..."
42534192

4254-
# Fetch all notes from the API once
42554193
api_response=$(fetch_all_notes_from_api)
42564194
if [[ $? -ne 0 ]]; then
42574195
echo "Failed to fetch all notes from the API"
42584196
exit 1
42594197
fi
42604198

4261-
list_game_names # Get the list of game names
4199+
list_game_names
42624200

4263-
# Loop over each game name
42644201
for game_name in "${games[@]}"; do
4265-
# Create the file path for each game
42664202
sanitized_game_name="$game_name"
42674203
sanitized_game_name="${sanitized_game_name//\(/_}"
42684204
sanitized_game_name="${sanitized_game_name//\)/_}"
@@ -4275,6 +4211,7 @@ done
42754211

42764212
echo "Notes execution complete."
42774213
show_message "Notes have been recieved!"
4214+
42784215
#noooooooooooooooootes
42794216

42804217

0 commit comments

Comments
 (0)