Favourites Menu

Kernel, Main, Utilities & Applications, Miscellaneous Devices.
User avatar
GreyAreaUK
Posts: 133
Joined: Wed Feb 02, 2022 12:58 pm
Has thanked: 62 times
Been thanked: 23 times

Favourites Menu

Unread post 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?

Orbiting inside the Roche Limit of sanity.
held
Posts: 209
Joined: Sun Sep 26, 2021 2:18 pm
Has thanked: 27 times
Been thanked: 32 times

Re: Favourites Menu

Unread post 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.:shock:

But keep at it, you'll get there (and make a backup just in case)
User avatar
GreyAreaUK
Posts: 133
Joined: Wed Feb 02, 2022 12:58 pm
Has thanked: 62 times
Been thanked: 23 times

Re: Favourites Menu

Unread post 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
Orbiting inside the Roche Limit of sanity.
Flandango
Core Developer
Posts: 459
Joined: Wed May 26, 2021 9:35 pm
Has thanked: 59 times
Been thanked: 383 times

Re: Favourites Menu

Unread post 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
User avatar
GreyAreaUK
Posts: 133
Joined: Wed Feb 02, 2022 12:58 pm
Has thanked: 62 times
Been thanked: 23 times

Re: Favourites Menu

Unread post 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.
Orbiting inside the Roche Limit of sanity.
Flandango
Core Developer
Posts: 459
Joined: Wed May 26, 2021 9:35 pm
Has thanked: 59 times
Been thanked: 383 times

Re: Favourites Menu

Unread post 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.
Akuma
Posts: 138
Joined: Sat Dec 11, 2021 9:50 pm
Has thanked: 24 times
Been thanked: 46 times

Re: Favourites Menu

Unread post by Akuma »

Unfortunately ExFat does not support soft-links, so what you want to do is not possible.
User avatar
GreyAreaUK
Posts: 133
Joined: Wed Feb 02, 2022 12:58 pm
Has thanked: 62 times
Been thanked: 23 times

Re: Favourites Menu

Unread post 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
9dsbGYV.jpg (4.34 MiB) Viewed 3126 times
Tb8k21h.jpg
Tb8k21h.jpg (4.27 MiB) Viewed 3126 times
Orbiting inside the Roche Limit of sanity.
guyute74
Posts: 1
Joined: Thu Feb 24, 2022 2:12 pm
Been thanked: 2 times

Re: Favourites Menu

Unread post 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
User avatar
GreyAreaUK
Posts: 133
Joined: Wed Feb 02, 2022 12:58 pm
Has thanked: 62 times
Been thanked: 23 times

Re: Favourites Menu

Unread post 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!)
Orbiting inside the Roche Limit of sanity.
Flandango
Core Developer
Posts: 459
Joined: Wed May 26, 2021 9:35 pm
Has thanked: 59 times
Been thanked: 383 times

Re: Favourites Menu

Unread post 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!
Akuma
Posts: 138
Joined: Sat Dec 11, 2021 9:50 pm
Has thanked: 24 times
Been thanked: 46 times

Re: Favourites Menu

Unread post 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!
User avatar
GreyAreaUK
Posts: 133
Joined: Wed Feb 02, 2022 12:58 pm
Has thanked: 62 times
Been thanked: 23 times

Re: Favourites Menu

Unread post 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.
Orbiting inside the Roche Limit of sanity.
User avatar
LamerDeluxe
Top Contributor
Posts: 1239
Joined: Sun May 24, 2020 10:25 pm
Has thanked: 887 times
Been thanked: 284 times

Re: Favourites Menu

Unread post 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.
User avatar
GreyAreaUK
Posts: 133
Joined: Wed Feb 02, 2022 12:58 pm
Has thanked: 62 times
Been thanked: 23 times

Re: Favourites Menu

Unread post 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.
Orbiting inside the Roche Limit of sanity.
Flandango
Core Developer
Posts: 459
Joined: Wed May 26, 2021 9:35 pm
Has thanked: 59 times
Been thanked: 383 times

Re: Favourites Menu

Unread post 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.
User avatar
wizzo
Scripting Wizard
Posts: 183
Joined: Sat Mar 12, 2022 11:32 am
Has thanked: 15 times
Been thanked: 243 times

Re: Favourites Menu

Unread post 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.
Attachments
IMG_5887.jpg
IMG_5887.jpg (75.7 KiB) Viewed 2548 times
User avatar
GreyAreaUK
Posts: 133
Joined: Wed Feb 02, 2022 12:58 pm
Has thanked: 62 times
Been thanked: 23 times

Re: Favourites Menu

Unread post by GreyAreaUK »

Time allowing I’ll give this a go later - thank you :)
Orbiting inside the Roche Limit of sanity.
User avatar
wizzo
Scripting Wizard
Posts: 183
Joined: Sat Mar 12, 2022 11:32 am
Has thanked: 15 times
Been thanked: 243 times

Re: Favourites Menu

Unread post 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.
Post Reply