Page 1 of 1
Favourites Menu
Posted: Thu Mar 03, 2022 11:27 am
by GreyAreaUK
Purely for gits and shiggles I thought I'd have a go at writing a 'Favourites' menu that would appear at the top and contain a subset of cores I prefer to use.
I'm using a directory called '/media/fat/_ Favourites' (note the space after the underscore) and it gets populated by this script:
Code: Select all
#!/bin/bash
input="/media/fat/favs.list"
rm -rf "/media/fat/_ Favourites"
mkdir "/media/fat/_ Favourites"
cd "/media/fat/_ Favourites"
while IFS= read -r line
do
for F in ${line}; do
ln -s "$F"
done
done < "$input"
I then create a text file called '/media/fat/favs.list' which looks like this:
Code: Select all
/media/fat/_Computer/BBCMicro*
/media/fat/_Computer/AtariST*
/media/fat/_Computer/TRS-80*
/media/fat/_Computer/Minim*
This creates symlinks inside the favourites folder to any core matching the wildcard. Seems to work nicely. I've put the shell script inside /media/fat/linux and made sure it's executable.
So, given that I just knocked this up for fun (LOT of copy/pasted code, bash shell-scripting isn't my thing) I'm wondering if there's an 'official' way of doing this?
Re: Favourites Menu
Posted: Thu Mar 03, 2022 12:41 pm
by held
Nice that you have the ambition to contribute, however using that "rm -rf" is ill advised.
Please don't use this.
If the '_' wasnt there, you would have emptied your entire /media/fat directory.
But keep at it, you'll get there (and make a backup just in case)
Re: Favourites Menu
Posted: Thu Mar 03, 2022 12:49 pm
by GreyAreaUK
I'm not in the least surprised to find there's horrible, horrible implications in the script - like I say, kind of a proof of concept from someone who knows just enough to be dangerous
Would a better way be to just iterate through the files in that folder and delete them individually? And have the script check to see if the folder exists to begin with, and if not create it?
Edit: Something like this perhaps?
Code: Select all
#!/bin/bash
input="/media/fat/favs.list"
mkdir -p "/media/fat/_ Favourites"
cd "/media/fat/_ Favourites"
# check to make sure we are actually in /media/fat/_ Favourites
if [ "$PWD" != "/media/fat/_ Favourites" ]; then
echo "Backing out"
exit 0
fi
# erase existing rbf files
for file in *.rbf
do
rm "$file"
done
# create the new symlinks
while IFS= read -r line
do
#echo "$line"
for F in ${line}; do
echo $F
ln -s "$F"
done
# ln -s "$line"
done < "$input" 34 1,1 All
Re: Favourites Menu
Posted: Thu Mar 03, 2022 2:51 pm
by Flandango
Much safer that way.
While the mkdir command won't harm anything if the folder exists, it will spew an error but still go on with script, so best to check if the folder doesn't exist first as such:
Code: Select all
if [ ! -d "/media/fat/_ Favourites" ]; then mkdir -p "/media/fat/_ Favourites"; fi
Re: Favourites Menu
Posted: Thu Mar 03, 2022 2:57 pm
by GreyAreaUK
Flandango wrote: ↑Thu Mar 03, 2022 2:51 pm
Much safer that way.
While the mkdir command won't harm anything if the folder exists, it will spew an error but still go on with script, so best to check if the folder doesn't exist first as such:
Code: Select all
if [ ! -d "/media/fat/_ Favourites" ]; then mkdir -p "/media/fat/_ Favourites"; fi
The '-p' is supposed to only create if it doesn't exist, and not throw an error if it does. I've tested it from the shell and that's certainly what it appears to do.
Re: Favourites Menu
Posted: Thu Mar 03, 2022 3:08 pm
by Flandango
Yes and no, the -p will create parent folders also if they don't exist instead of just failing.
But you are right as it doesn't complain if it does exist.
Re: Favourites Menu
Posted: Thu Mar 03, 2022 3:28 pm
by Akuma
Unfortunately ExFat does not support soft-links, so what you want to do is not possible.
Re: Favourites Menu
Posted: Thu Mar 03, 2022 4:22 pm
by GreyAreaUK
Akuma wrote: ↑Thu Mar 03, 2022 3:28 pm
Unfortunately ExFat does not support soft-links, so what you want to do is not possible.
Except it seems to be working?
- 9dsbGYV.jpg (4.34 MiB) Viewed 3122 times
- Tb8k21h.jpg (4.27 MiB) Viewed 3122 times
Re: Favourites Menu
Posted: Thu Mar 03, 2022 5:44 pm
by guyute74
Well done.
One of my favorite things about projects like the Mister is to tinker and learn new things from helpful members.
-in baltimore
Re: Favourites Menu
Posted: Thu Mar 03, 2022 6:51 pm
by GreyAreaUK
guyute74 wrote: ↑Thu Mar 03, 2022 5:44 pm
Well done.
One of my favorite things about projects like the Mister is to tinker and learn new things from helpful members.
-in baltimore
It remains to be seen if it survives an update, but it's a fun little script to tinker with (providing you have a backup!)
Re: Favourites Menu
Posted: Thu Mar 03, 2022 7:19 pm
by Flandango
GreyAreaUK wrote: ↑Thu Mar 03, 2022 6:51 pm
It remains to be seen if it survives an update, but it's a fun little script to tinker with (providing you have a backup!)
The update scripts won't delete your "_ Favourites" folder but what may happen is when one of your favorite cores is updated, the filename will change and render the link created invalid (i.e. file not found) so you may need to rerun your script to clear the folder of links and re-create them.
So make it a habit to run your script after each update and you are golden.
Also, you could move the script from /media/fat/linux to /media/fat/Scripts and then you can select and run it from the OSD.
Nice work by the way!
Re: Favourites Menu
Posted: Thu Mar 03, 2022 7:32 pm
by Akuma
GreyAreaUK wrote: ↑Thu Mar 03, 2022 4:22 pm
Akuma wrote: ↑Thu Mar 03, 2022 3:28 pm
Unfortunately ExFat does not support soft-links, so what you want to do is not possible.
Except it seems to be working?
How about that, everything I read says different, but it works. Good job!
Re: Favourites Menu
Posted: Thu Mar 03, 2022 7:44 pm
by GreyAreaUK
Flandango wrote: ↑Thu Mar 03, 2022 7:19 pm
GreyAreaUK wrote: ↑Thu Mar 03, 2022 6:51 pm
It remains to be seen if it survives an update, but it's a fun little script to tinker with (providing you have a backup!)
The update scripts won't delete your "_ Favourites" folder but what may happen is when one of your favorite cores is updated, the filename will change and render the link created invalid (i.e. file not found) so you may need to rerun your script to clear the folder of links and re-create them.
Ah, that's why I had it parse wildcards - if you just give it the first part of the core name it will symlink any that match, each time you boot. In theory that should catch it when the core number updates. I hope!
Flandango wrote: ↑Thu Mar 03, 2022 7:19 pm
Also, you could move the script from /media/fat/linux to /media/fat/Scripts and then you can select and run it from the OSD.
WHY THE HELL DIDN'T I THINK OF THAT?!
Nice catch, thank you!
Flandango wrote: ↑Thu Mar 03, 2022 7:19 pmNice work by the way!
You're welcome, and thank you as well.
Re: Favourites Menu
Posted: Thu Mar 03, 2022 11:16 pm
by LamerDeluxe
Really interesting idea. Would be great if it also worked for arcade .mra files. And the new MGL files, to directly load a favorite game into a core.
If you'd define /media/fat/ at the beginning of your script you wouldn't have to add it everywhere (including the config file). I don't use external media myself, but it might be handy for that as well.
Re: Favourites Menu
Posted: Fri Mar 04, 2022 6:18 am
by GreyAreaUK
Keep in mind the bulk of my shell-scripting knowledge was gained yesterday
Edit: Ah, I see what you mean about the Arcade cores. I guess they must get launched in a slightly different way. Would be interesting to know how, as there might be a way to accommodate them.
Re: Favourites Menu
Posted: Fri Mar 04, 2022 1:46 pm
by Flandango
For arcade cores, you want to link the mra/mgl instead of rbf, which will mean you will also need to clean mra files at the beginning.
You will also need to link the _Arcade/cores directory too.
Code: Select all
for file in *.rbf *.mra *.mgl
do
rm "$file"
done
And add this line right after
cd "/media/fat/_ Favourites":
Code: Select all
cd "/media/fat/_ Favourites"
if [ ! -d cores ]; then ln -s /media/fat/_Arcade/cores; fi
This will allow MRAs to launch.
MGL links will launch from the favourites folder without issue.
Re: Favourites Menu
Posted: Sun Apr 03, 2022 2:01 am
by wizzo
I liked this idea a lot and have expanded on it. You can try it out from my repo:
https://github.com/wizzomafizzo/MiSTer_Favorites
I've added a little GUI when you launch from the Scripts folder so you can add favourites a bit easier. It also inserts itself in the user startup script so broken links are recreated on boot (after core updates). Still a work in progress but I'll continue updating it. The script is very specific about what it deletes so should be no worries about losing any of your files.
It has the same limitation as the original script and currently only supports rbf cores but if there's some interest I should be able to add arcade cores pretty easily. Mostly needs some QOL changes to the selection menu. Eventually I'd like to add direct rom favorites but haven't investigate mgl files enough yet.
Re: Favourites Menu
Posted: Sun Apr 03, 2022 8:35 am
by GreyAreaUK
Time allowing I’ll give this a go later - thank you
Re: Favourites Menu
Posted: Mon Apr 04, 2022 3:14 am
by wizzo
I've made an update which adds a new file select dialog and supports choosing mra files so arcade cores can be linked but it's not quite working yet.
For some reason symlinks to rbf files are still working fine, but symlinks to mra files won't launch. I'm not quite sure what the problem is yet. I seem to be using the exact same method as the arcade organizer script, the symlinks from that script and my own script look identical. Not sure if anyone knows what's going on there.
EDIT: Nevermind I think I worked it out. Creating a shortcut in the _Arcade folder works from my script. Perhaps there is a hardcoded exception for mra files that only allow them to be launched from the _Arcade folder? Dunno how to work around that yet.
EDIT: Ok found a workaround. Arcade core favourites are now working.