Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autodetect RS2014 installation folder from steam vdf #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

xenein
Copy link

@xenein xenein commented Oct 8, 2023

this addresses #5

@@ -1,4 +1,7 @@
RS_PATH="/Users/$USER/Library/Application Support/Steam/steamapps/common/Rocksmith2014/Rocksmith2014.app/Contents/MacOS"
set -e
RS_PATH="$(/usr/bin/env python3 `dirname $0`/FindRSPath.py)/steamapps/common/Rocksmith2014/Rocksmith2014.app/Contents/MacOS"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather it would get back to previous approach in case of failure

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could change the python-script to return the old default path in case of error.

but: is still relevant with your second comment? if awk is used instead, awk could handle that case, too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It still should go back if it cannot find the file or awk fails for whatever reason

print("Error: Could not find libraryfolders.vdf.", file=sys.stderr)
exit(1)

with open(RS_LIB_PATH) as vdf:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice script, but in .command script it uses python3 explicitely, which can make it not usable for some users of old MacOS. It is a good idea to do it like that, but what do you think to stick to bash only? To make it more versatile?
awk '/221680/ {found=1} {a[i++]=$0} END {if(found) for(j=i-1;j>=0;j--) print a[j]}' "~/Library/Application Support/Steam/steamapps/libraryfolders.vdf" | awk '/path/ {print; exit}'

Explanation:

/221680/ {found=1}: When a line contains "221680", it sets the found flag to 1.
{a[i++]=$0}: This stores each line in an array a.
END {if(found) for(j=i-1;j>=0;j--) print a[j]}: After processing all lines, if found is set, it prints the lines in reverse order.
awk '/path/ {print; exit}': This looks for the first occurrence of "path" in the output and prints it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not firm in awk, but it sounds quite right.

alternatively: there is from __future__ import print_function and this is about the only thing not python2-compatible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with both approaches and don't want to push the awk, because it is harder to read.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants