Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - spud1

Pages: [1] 2 3
1
General / Echo or print name of romlist
« on: April 25, 2019, 06:01:29 AM »
In a Plugin I've created, I'm able to send the name of the Display to a file by using the command:

fe.plugin_command( "/usr/bin/printf9.sh", "\"" + fe.list.name + "\"" );

The above plugin command then invokes the printf9.sh bash script as follows;

#!/bin/bash
sudo /usr/bin/printf "$1" > "/home/pi/.attract/romlists/FAVOURITES/$1.temp"


However, instead of the name of the Display (ie fe.list.name), is there a way of sending the name of the Romlist to a file please?

2
I've got a Plugin that works for every Layout/Display.  However, I'd like it to work with every Layout/Display EXCEPT one.  Is it possible to do this with an if/else statement or some other way please?

Code: [Select]
// This plugin adds a newly "favourited" game to the "Favourites.txt" romlist
fe.add_transition_callback( "favourites" );
function favourites( ttype, var, ttime )
{
switch ( ttype )
{
case Transition.ChangedTag:
fe.plugin_command( "/usr/bin/printf5.sh", "\"" + fe.game_info(Info.Name) + "\"" );
fe.plugin_command( "/usr/bin/printf6.sh", "\"" + fe.game_info(Info.Name) + ";" + fe.game_info(Info.Title) + ";" + fe.game_info(Info.Emulator) + ";" + fe.game_info(Info.CloneOf) + ";" + fe.game_info(Info.Year) + ";" + fe.game_info(Info.Manufacturer) + ";" + fe.game_info(Info.Category) + ";" + fe.game_info(Info.Players) + ";" + fe.game_info(Info.Rotation) + ";" + fe.game_info(Info.Control) + ";" + fe.game_info(Info.Status) + ";" + fe.game_info(Info.DisplayCount) + ";" + fe.game_info(Info.DisplayType) + ";" + fe.game_info(Info.AltRomname) + ";" + fe.game_info(Info.AltTitle) + ";" + fe.game_info(Info.Extra) + ";" + fe.game_info(Info.Buttons) + "\"" );
system( "sudo /bin/bash /bin/addfavourite.sh" );
}
return false;
}
fe.add_transition_callback( "favourites" )

Thanks.

3
I managed to solve this problem I was having. I found "keeping it simple, stupid" and just having the plugin deal with one argument was the way to go.

I altered the plugin as follows:
Code: [Select]
// This module is just to be used for removing favourites from Favorites.txt
fe.add_transition_callback( "removefavourite" );
function removefavourite( ttype, var, ttime )
{
switch ( ttype )
{
case Transition.ChangedTag:
fe.plugin_command( "/usr/bin/printf1.sh", "\"" + fe.game_info(Info.Name) + "\"" );
system( "sudo /bin/bash /opt/retropie/configs/all/removefavourite.sh" ); // Starts the process of removing the game from Favourites.txt
}
return false;
}
fe.add_transition_callback( "removefavourite" )

This plugin sends the game's name to a new bash script I created called "printf1.sh".  The bash script goes in the same folder as the "printf" command which is in the "/usr/bin/" folder.  The bash script has to go into this folder, otherwise there is a "chdir" (change directory) error.

The contents of the bash script are:
Code: [Select]
#!/bin/bash
FILE1=$1
sudo /usr/bin/printf "$FILE1" > "/home/pi/.attract/romlists/REMOVEFAVOURITE.temp"

Basically, the game name is the "argument" and that is sent from the squirrel plugin to the bash script which then redirects the game name (the output) to the file "REMOVEFAVOURITE.temp".

The benefit of this approach is that no matter what form the game name takes eg with a single apostrophe or () or [] like "Sam's Journey (c64)" or "Sam's Journey [c64]", the script will capture it and pass it on.  Special characters make no difference.

From there, I can do whatever I like with the information recorded in "REMOVEFAVOURITE.temp".


4
That's no problem.  I guessed as much after looking at the Squirrel 3.1 documentation.  I tend to worry at these problems until I've defeated them.

I've now started having a look carefully at fe.plugin_command and have made a considerable amount of progress with only a "whitespace" problem now defeating me.

I've had a good look at this thread:  http://forum.attractmode.org/index.php?topic=1705.msg12673#msg12673 and adapted some of the code.  My code now looks like this:

Code: [Select]
fe.add_transition_callback( "removefavourite" );
function removefavourite( ttype, var, ttime )
{
 switch ( ttype )
 {
  case Transition.ChangedTag:
fe.plugin_command( "/bin/echo", "\"" + fe.game_info( Info.Name ) + "\"" + "1>/home/pi/.attract/romlists/REMOVEFAVOURITE.temp\"");
        return false;
}}

This code almost works.  It prints  "Sam's Journey (Easyflash)" to the console.  However, there is an error in trying to redirect that code to the REMOVEFAVOURITE.temp file.  It needs a "space" before the "1>/home/pi/.attract/romlists/REMOVEFAVOURITE.temp".  However, everything I've tried including just adding a space before the " 1>" (like so) has failed.  It is an identifiable problem with bash commands, but I can't figure out how to deal with it in this case given that it is part of a squirrel script.

The error is: "Parameter word expansion failed".

Would you know how to add a "space" that bash might recognise?

5
Scripting / Re: reset - reload layout
« on: January 05, 2019, 02:21:15 PM »
Thanks, giacomo82.  Unfortunately, I'm not using X-windows at all (ie I don't have the full installation of Raspbian) and xdotool only works in Raspbian.

6
Thanks, keilmillerjr and zpaolo11x.  I have manually checked both the favorites.tag and the c64.tag (where Sam's Journey should appear) and Sam's Journey remains listed in both of these. 

But I have made some progress using Attract Mode's internal print command, rather than echo or printf, as follows:

Code: [Select]
// This module is just to be used for removing favourites from Favorites.txt
fe.add_transition_callback( "removefavourite" );
function removefavourite( ttype, var, ttime )
{
switch ( ttype )
{
case Transition.ChangedTag:
print( fe.game_info( Info.Name ) + "\n" );
break;
}
return false;
}
fe.add_transition_callback( "removefavourite" )

I now need to be able to redirect the output from the console to a file.  I've tried replacing the print line with the following:

Code: [Select]
print( fe.game_info( Info.Name ) + "\n" ) > /home/pi/.attract/romlists/REMOVEFAVOURITE.temp;
But wind up with an error in console.  I get a "line 8 column 46" "expression expected" error.  It's clearly something to do with the redirection to the file.  Is there a way to redirect output from the console to a file?  Do I need to use quotation marks or something like that?  Thanks.

7
I have tried this (and various variations) but haven't got it to work as yet:

Code: [Select]
fe.add_transition_callback( "removefavourite" );
function removefavourite( ttype, var, ttime )
{
 switch ( ttype )
 {
  case Transition.ChangedTag:
                local romname = fe.game_info( Info.Name );
print( + romname + ) > /home/pi/.attract/romlists/REMOVEFAVOURITE.temp;
// system( "echo '" + fe.game_info( Info.Name ) + "' > /home/pi/.attract/romlists/REMOVEFAVOURITE.temp" ); // Takes the romname "unfavourited" by me in Favourites.txt and inserts it into REMOVEFAVOURITE.temp for further processing
system( "echo '" + fe.game_info( Info.Name ) + "' > /home/pi/.attract/romlists/ROMNAME.tmp" ); // Takes the romname "unfavourited" by me in Favourites.txt and inserts it into ROMNAME.tmp for further processing
system( "echo '" + fe.game_info( Info.Emulator ) + "' > /home/pi/.attract/romlists/EMULATORNAME.tmp" ); // Takes the emulator name "unfavourited" by me in Favourites.txt and inserts it into EMULATORNAME.tmp for further processing
// system( "sudo /bin/bash /opt/retropie/configs/all/removefavourite.sh" ); // Starts the process of removing the game from Favourites.txt
break;
}
        return false;
}

8
Sounds like a great idea.  Could I please ask how I use this command?  Thanks.

9
I have a module/plugin which generally works.  It's designed to take the name of the rom and dump it into a text file for further processing.  It works with most games but I can't get it to work with rom names that include a single apostrophe (eg Sam's Journey) or games with any kind of brackets (eg Sam's Journey (Easyflash) or Sam's Journey [Easyflash]).  I was hoping someone might be able to help please.

The module is as follows:

Code: [Select]
fe.add_transition_callback( "removefavourite" );
function removefavourite( ttype, var, ttime )
{
 switch ( ttype )
 {
  case Transition.ChangedTag:
                system( "echo '" + fe.game_info( Info.Name ) + "' > /home/pi/.attract/romlists/REMOVEFAVOURITE.temp" ); // Takes the romname "unfavourited" by me in Favourites.txt and inserts it into REMOVEFAVOURITE.temp for further processing
        return false;

Interestingly, I can get the code to work from the terminal eg
Code: [Select]
echo "Sam's Journey (Easyflash)" > /home/pi/.attract/romlists/REMOVEFAVOURITE.temp and
Code: [Select]
echo "Sam's Journey [Easyflash]" > /home/pi/.attract/romlists/REMOVEFAVOURITE.temp, but not if single quotations are used eg
Code: [Select]
echo '"Sam's Journey (Easyflash)"' > /home/pi/.attract/romlists/REMOVEFAVOURITE.temp
I don't think it's a problem with the fe.game-info part of the code.  It probably has something to do with the multiplicity of single and double quotations.  The use of the single quotations eg
Code: [Select]
echo '" + fe.game_info( Info.Name ) + "' in this code seems to mean it won't recognise the brackets, but it appears to need the single quotations in the module/plugin for it to work at all with other games that don't have brackets or apostrophes in their names. 

I've also tried printf instead of echo with the same result.

If anyone can help please, I would be grateful.  Thanks.


10
Scripting / Re: Creating a Delay before initiating another plugin script
« on: December 31, 2018, 10:05:18 PM »
Thanks for your help.  Hope the kids haven't driven you bananas.

I replaced the system call with
Code: [Select]
fe.plugin_command_bg( "/home/pi/.attract/plugins/AutoFavorites/update.sh" );
However, the same error appears. Not sure why line 50 would be so important.

I'm fine with how the bash scripts are operating at present.  There's no real transition delay as long as I've got them set up the way I've got them setup ie one bash script leading into another.

11
Scripting / Re: Creating a Delay before initiating another plugin script
« on: December 31, 2018, 04:29:50 PM »
The response I get is:

Code: [Select]
/home/pi/.attract/plugins/AutoFavorites/plugin.nut line = (50) column = (2) : error expression expected
Script Error in /home/pi/.attract/plugins/AutoFavorites/plugin.nut - expression expected

The whole script is:

Code: [Select]
// Plugin User Options
class UserConfig </ help="Plugin fades the screen when transitioning to and from a game." /> {
</ label="Wait time",
help="The amount of time in milliseconds to wait before switching to favorites display.",
order=1 />
wait="10000";
  </ label="Favorites Display Name",
    help="The name of your display name.",
    order=2 />
  displayName="Favourites";
}

// Auto Favorites
class AutoFavorites {
  user_config = null;
  wait = null;
  displayName = null;

  constructor() {
    user_config = fe.get_config();
    wait = user_config["wait"].tointeger();
    displayName = user_config["displayName"];

    fe.add_transition_callback(this, "transitions");
  }

  function transitions(ttype, var, ttime) {
    if ((ttype == Transition.ChangedTag) && (var == Info.Favourite)) {
      switch (OS) {
        case "Linux":
          system("sudo /bin/bash " + fe.module_dir + "update.sh");
          if (ttime >= wait) {
            loadDisplay(displayName);
            return false;
          }
          else {
            return true;
          }
          break;
      }
    }
    return false;
  }

  function loadDisplay(name) {
    foreach(idx, display in fe.displays)
      if ((name == fe.displays[idx].name) && (name != fe.displays[fe.list.display_index].name)) fe.set_display(idx);
    }
  }
}
fe.plugin["AutoFavorites"] <- AutoFavorites();

Line 50 is just the "}" on the second last line.

I was also wondering whether there might be a way to call the plugin from a bash script.  I've looked online but can't find anything.

12
Scripting / Re: Creating a Delay before initiating another plugin script
« on: December 31, 2018, 04:14:36 PM »
Hi.  Thanks for your patience.  I'm finally getting back to this. 

I did what you suggested - combined all of the bash scripts into one script.  However, although it works, now there is a pause in the front end.  When I press "Yes" to add a game to the favourites romlist, the front end pauses for about 10 seconds.  So it appears that the bash scripts don't work in the background, whereas if I string them together using the "nohup" (background) option, they work properly in the background.

My configuration is more or less silent so what I've done now is change the autostart.sh to "attract --loglevel debug".  That is now giving me enough information.  I'll report back in the next post what information I get.


13
Scripting / Re: Creating a Delay before initiating another plugin script
« on: December 28, 2018, 02:39:06 PM »
Thanks for this.  Sorry, I haven't been able to get back to this because of real life, but should be able to do so in the next day or so.  Thanks for all your help and patience.

14
Scripting / Re: Creating a Delay before initiating another plugin script
« on: December 26, 2018, 02:17:28 PM »
Hi.  Sorry, I'm not sure I understand.  I'm a bit obtuse!  Do you mean install Attract Mode on Windows and use the exe for console?  Or change the plugin so the case is "Windows" rather than "Linux", remove the line beginning system(" etc?

The "favourites.sh" calls a series of bash scripts that are in my /opt/retropie/configs/all folder.  I can confirm that these bash scripts all work to regenerate my Favourites romlist automatically in the background after being invoked by favourites.sh.

Here they are:

The plugin:
Code: [Select]
// This plugin regenerates the "Favourites.txt" romlist when a game is selected as a favourite or deselected as a favourite
fe.add_transition_callback( "favourites" );
function favourites( ttype, var, ttime )
{
 switch ( ttype )
 {
  case Transition.ChangedTag:
                system( "sudo /bin/bash /opt/retropie/configs/all/favourites.sh" ); // Starts the Favourites bash script to update the Favourites romlist whenever a game is tagged or untagged
        return false;
}}

"favourites.sh":
Code: [Select]
#!/bin/bash
sudo nohup /opt/retropie/configs/all/favourites1.sh &

"favourites1.sh":
Code: [Select]
#!/usr/bin/env bash
# Adds a semi-colon at the end of each line of a tag file, so that it decreases the possibility of every game called "1942" (for example) being added to Favourites (eg "1942;" is more limiting than "1942").
sleep 7
cd /home/pi/.attract/romlists
for i in "*.tag"; do
    sed -i 's/$/;/' $i
done
sudo nohup /opt/retropie/configs/all/favourites2.sh &

favourites2.sh:
Code: [Select]
#!/usr/bin/env bash
# The grep command is limited to Fixed Strings eg "1942;".
# The original command for grep was:   cat "${romlist}.txt"|grep -F -w "${gamename}" >> Favorites.txt
# But the "whole word" option -w would not pick up any game with a semi-colon at the end eg it would pick up "1942" but would not pick up "1942;"
# The next command I used was: cat "${romlist}.txt"|grep -F "${gamename}" >> Favorites.txt.  With the semi-colon added, this would ensure that the name of the game was treated as a Fixed String.  It would not capture every single 1942, only those ending with the semi-colon.  However, not only would it capture "mario", it would capture "drmario" ie words with other letters at the front.  In order to avoid this, I had to use the following:
# cat "${romlist}.txt"|grep "\<${gamename}" >> Favorites.txt.  Together with placing the semi-colon at the end, the \< meant that it would ignore games where there were letters at the beginning eg drmario.
# The Favorities.tag file is renamed so that it is not included in the creation of the new Favorites romlist.
cd /home/pi/.attract/romlists
# rm -f Favorites.tag
mv -f Favorites.tag Favorites.tag.backup
mv -f Favorites.txt Favorites.txt.backup
ls *.tag > tagfiles
while read filename
do
  while read gamename
  do
    romlist=`echo ${filename} |cut -f 1 -d '.'`
    cat "${romlist}.txt"|grep "\<${gamename}" >> Favorites.txt
  done < "${filename}"
done < tagfiles
rm -f tagfiles
sort Favorites.txt > Favorites1.txt
rm -f Favorites.txt
mv -f Favorites1.txt Favorites.txt
sort Favorites.txt | uniq >> Favorites1.txt
rm -f Favorites.txt
mv -f Favorites1.txt Favorites.txt
sudo nohup /opt/retropie/configs/all/favourites3.sh &

favourites3.sh:
Code: [Select]
#!/usr/bin/env bash
# Removes the trailing semi-colon at the end of all tag files so the tag files go back to "normal".
cd /home/pi/.attract/romlists
for i in "*.tag"; do
    sed -i 's/;*$//g' $i
done
sudo nohup /opt/retropie/configs/all/favourites4.sh &

favourites4.sh:
Code: [Select]
#!/usr/bin/env bash
# Changes ownership of Favorites.txt to pi and makes it read and write compatible by anyone.
sudo chown pi:pi /home/pi/attract/romlists/Favorites.txt
sudo chmod 0777 /home/pi/attract/romlists/Favorites.txt
sudo nohup /opt/retropie/configs/all/favourites5.sh &

favourites5.sh:
Code: [Select]
#!/usr/bin/env bash
# Copies the first field (ie the name of each game) from the new Favorites.txt and creates a Favorites.tag with it and ensures that only one copy of the game appears in the tags.
# Changes ownership of Favorites.tag to pi and makes it read and write compatible by anyone.
cd /home/pi/.attract/romlists
# cut -f 1 -d '.' Favorites.txt > Favorites.tag
sudo awk -F';' '{print $1}' Favorites.txt > Favorites.tag
sort Favorites.tag | uniq >> Favorites1.tag
rm -f Favorites.tag
mv -f Favorites1.tag Favorites.tag
sudo chown pi:pi /home/pi/attract/romlists/Favorites.tag
sudo chmod 0777 /home/pi/attract/romlists/Favorites.tag
# sudo nohup /opt/retropie/configs/all/favourites6.sh

Also, I'm just wondering whether your debug plugin could be used to send output to a file rather than to the console.  I'm using ssh from my Windows PC so it would pretty easy to check what the output error was if errors were redirected to a file.

15
Scripting / Re: Creating a Delay before initiating another plugin script
« on: December 26, 2018, 05:43:22 AM »
Thanks so much for your help on this.  I haven't been able to get the code to work so far.  Because I'm on a Raspberry Pi, I have a bit of trouble debugging scripts.

This is what I have done so far.  I created a sub-folder called AutoFavorites in the plugins folder.  In that subfolder, I've put a plugin.nut with all the code.  The only change I made was as follows: displayName="Favourites"; because I'm using the English spelling.

In the AutoFavorites subfolder, I've put an executable bash script called "update.sh", the contents of which are:
Code: [Select]
#!/bin/bash
sudo nohup /opt/retropie/configs/all/favourites1.sh &

ie the bash script calls another bash script in the background.

I just wanted to check with you that the AutoFavorites subfolder will be picked up by "fe.module_dir".

The only other thing I noted was that when I enabled the plugin there was only the name of the plugin and the line to enable/disable it.  Wasn't sure whether there should be anything else.

Thanks so much for your help on this.  It is really appreciated, especially over the Christmas break.

Pages: [1] 2 3