Attract-Mode Support Forum

Attract-Mode Support => Scripting => Topic started by: qqplayer on October 16, 2017, 07:56:53 AM

Title: [Plugin WIP] SumatraPDF reader (only for windows)
Post by: qqplayer on October 16, 2017, 07:56:53 AM
Just for testing , ONLY WORK ON WINDOWS BUILD.

Its really easy to use , just decompress in the main AM folder.
Download Sumatrapdf portable.

https://www.sumatrapdfreader.org/dl/SumatraPDF-3.1.2.zip

Put exe on "plugins\SumatraPDF\SumatraPDF.exe"

And pdf manuals like:

plugins\SumatraPDF\Game Manuals\Atari 2600\Basketball (USA).pdf

Changing "Atari 2600" for your emulator name.

*IMPORTANT* Decompress on the main AM instalation folder.


P.D. Maybe someone with more "squirrel skills" can improve the code and add the manual image found.
Ive tried but failed  :(

Title: Re: [Plugin WIP] SumatraPDF reader (only for windows)
Post by: kent79 on October 16, 2017, 08:57:39 PM
Just for testing , ONLY WORK ON WINDOWS BUILD.

Its really easy to use , just decompress in the main AM folder.
Download Sumatrapdf portable.

https://www.sumatrapdfreader.org/dl/SumatraPDF-3.1.2.zip

Put exe on "plugins\SumatraPDF\SumatraPDF.exe"

And pdf manuals like:

plugins\SumatraPDF\Game Manuals\Atari 2600\Basketball (USA).pdf

Changing "Atari 2600" for your emulator name.

*IMPORTANT* Decompress on the main AM instalation folder.


P.D. Maybe someone with more "squirrel skills" can improve the code and add the manual image found.
Ive tried but failed  :(

Not working. Is it missing any instruction ?
Title: Re: [Plugin WIP] SumatraPDF reader (only for windows)
Post by: qqplayer on October 17, 2017, 04:31:20 AM
Can you post some screen capture?
I mean you need the "SumatraPDF.bat" alongside the attract.exe
"SumatraPDF.exe" inside the module folder...

UPDATE: Working on a fresh install.

Im going to put two screenshots , maybe this can help.

Enable plugin

(https://i.imgur.com/cx6pPRf.png)

Add custom 1 key to launch Sumatrapdf

(https://i.imgur.com/PKbZqAL.png)
Title: Re: [Plugin WIP] SumatraPDF reader (only for windows)
Post by: liquid8d on October 28, 2017, 11:34:21 AM
oh,nice job!

Steps to use:

1. Extract plugin to AttractMode directory
2. Extract SumatraPDF.exe to plugins/SumatraPDF directory
3. Setup your custom1 key to the key you want to launch the PDF
4. Put your pdfs in the plugins/SumatraPDF/list_title/Game Name.pdf

I can improve the plugin, what would you like to do with it? I'd say for starters, a choice of which button [custom1, custom2, etc..] because some have custom1 already set for something else.

Is the reason for slash option based on OS? I think you can use / for cross-platform, I'd have to double check.
Title: Re: [Plugin WIP] SumatraPDF reader (only for windows)
Post by: qqplayer on October 28, 2017, 12:45:38 PM
oh,nice job!

Steps to use:

1. Extract plugin to AttractMode directory
2. Extract SumatraPDF.exe to plugins/SumatraPDF directory
3. Setup your custom1 key to the key you want to launch the PDF
4. Put your pdfs in the plugins/SumatraPDF/list_title/Game Name.pdf

I can improve the plugin, what would you like to do with it? I'd say for starters, a choice of which button [custom1, custom2, etc..] because some have custom1 already set for something else.

Is the reason for slash option based on OS? I think you can use / for cross-platform, I'd have to double check.

Maybe the "image-found" thing.
Just to be sure you have the pdf manual.
I put the slash on the config because I was having tons of problems setting a "literal" slash on the code :)
Ive just discover I could make something like this:

Code: [Select]
local slash = @"/"
Im trying to "port" this idea to the rpi but cant send paths with blanck spaces  :(
Ill post the code , maybe you can help me with this too.
Title: Re: [Plugin WIP] SumatraPDF reader (only for windows)
Post by: liquid8d on October 28, 2017, 01:13:52 PM
Yes, slashes are a pain.. but you can do \\ for backslash and it should take care of the rest. Also, I believe if you use forward slashes (/) it will work for Windows/Linux/Mac.

I'll have an updated version here in a bit.

So there is a Linux variant of Sumatra?
Title: Re: [Plugin WIP] SumatraPDF reader (only for windows)
Post by: liquid8d on October 28, 2017, 02:37:35 PM
OK here is v1.1:

Code: [Select]
For the batch file:
- moved the .bat file into the plugin folder (command will now run from the FeConfigDirectory  + "/plugins/SumatraPDF/" folder, so if you do a bash script for RPi, you can drop it in there and update your plugin command setting)
- updated the .bat file to remove cd'ing to the directory (plugin_command starts there)
- added %2 in batch file to accept custom missing image

For the plugin:
 - added option to choose view key
 - added options for extension to ones I believe Sumatra supports
 - added option to set missing image location
 - added functions so paths can use some magic_tokens such as [Emulator], [System], etc..
 - add quotes for command line

Let me know if you notice any issues or have any questions about what I changed.

Thanks for this! I had the manuals and had completely forgotten about it, now they are easily accessible in AM  ;D
Title: Re: [Plugin WIP] SumatraPDF reader (only for windows)
Post by: qqplayer on October 28, 2017, 05:19:53 PM
OK here is v1.1:

Code: [Select]
For the batch file:
- moved the .bat file into the plugin folder (command will now run from the FeConfigDirectory  + "/plugins/SumatraPDF/" folder, so if you do a bash script for RPi, you can drop it in there and update your plugin command setting)
- updated the .bat file to remove cd'ing to the directory (plugin_command starts there)
- added %2 in batch file to accept custom missing image

For the plugin:
 - added option to choose view key
 - added options for extension to ones I believe Sumatra supports
 - added option to set missing image location
 - added functions so paths can use some magic_tokens such as [Emulator], [System], etc..
 - add quotes for command line

Let me know if you notice any issues or have any questions about what I changed.

Thanks for this! I had the manuals and had completely forgotten about it, now they are easily accessible in AM  ;D

Thanks!!! Ill try tomorrow.

Talking about the rpi thing I have to convert the pdf into png files and keep into a folder.
Ive tried "fbi" but it doesnt launch with AM.
The only way I found to launch a "manual-reader" was with this awesome retroarch-libretro:

https://github.com/recalbox/libretro-imageviewer-legacy

So... maybe you can try to "convert" this plugin to be used with the imageviewer libretro :)
This could be awesome to add new features to the frontend because with a libretro it will work on each version of AM.

P.D. Can you add this feature?Show an image if an object doesnt exists.

http://forum.attractmode.org/index.php?topic=1925.0

I was thinking that could be awesome if we could know if we "really" have the manual for the game unless to have to press the key and see if appears the manual or the "not found" png
Title: Re: [Plugin WIP] SumatraPDF reader (only for windows)
Post by: qqplayer on October 28, 2017, 05:56:44 PM
Update , I cant wait and tried retroarch imageviewer on windows , I think is easy to get it working.
So liquid8d please try to add the "pdf image found" if you have some time.

I made some little adjustments and is launching the "png"

Code: [Select]
///////////////////////////////////////////////////
//
// Attract-Mode Frontend - SumatraPDF  WIP plugin (By Machiminax)
//
// For use with the SumatraPDF Reader
//
///////////////////////////////////////////////////

//
// The UserConfig class identifies plugin settings that can be configured
// from Attract-Mode's configuration menu
//
class UserConfig </ help="Read your Manuals with SumatraPDF" /> {

    </ label="Command", help="SumatraPDF launcher", order=1 />
    command="Retroarch.bat";
    </ label="Extension", help="File extension to use", options=".png, .pdf, .chm, .djvu, .djv, .epub, .fb2, .fb2.zip, .mobi, .prc, .oxps, .xps, .cb7, .cbr, .cbt, .cbz", order = 2 />
    extension=".pdf";
    </ label="Path", help="Path to manuals - can include [Name], [Emulator], [Year], [Manufacturer], [System], [DisplayName]", order = 3 />
    path="Game Manuals/[Emulator]";
    </ label="View Key", help="Key to use to view", options="custom1,custom2,custom3,custom4,custom5,custom6", order = 4 />
    key="custom1";
    </ label="Missing Image", help="Path to 'missing' image - can include [Name], [Emulator], [Year], [Manufacturer], [System], [DisplayName]", order = 5 />
    missing="png/Manual_not_found.png";
}

local config=fe.get_config(); // get user config settings corresponding to the UserConfig class above

//
// Copy the configured values from uconfig so we can use them
// whenever the transition callback function gets called
//

class PDFManualReader
{
    VERSION=1.1;
    game_name=null;

    constructor()
    {
        fe.add_signal_handler( this, "on_signal" )
    }


    function on_signal( signal )
    {
            if ( signal == config["key"] )
            {
                local path = get_magic_token_path(config["path"]);
                local game_name = fe.game_info(Info.Name);
                local firstpng = @"1.png"
                local slash = @"\"
                local filename = "\"" + path + game_name + slash + firstpng + "\"";
                local x = @"I'm a verbatim string\n"
                local missing_path = get_magic_token_path(config["missing"]);
                local missing = "\"" + missing_path.slice(0, missing_path.len() - 1) + "\"";
                local exe = FeConfigDirectory  + "plugins/RetroarchImageviewer/" + config["command"];
                print("Launching RetroarchImageviewer:\n");
                print(" " + exe + " " + filename + " " + missing + "\n");
                fe.plugin_command( exe, filename + " " + missing );
                return true;
            }
            return false;
    }
   
    //replace specified magic tokens in path
    function get_magic_token_path(path) {
        local tokens = {
            "Name": fe.game_info(Info.Name),
            "Emulator": fe.game_info(Info.Emulator),
            "Year": fe.game_info(Info.Year),
            "Manufacturer": fe.game_info(Info.Manufacturer),
            "Category": fe.game_info(Info.Category),
            "System": fe.game_info(Info.System),
            "DisplayName": fe.list.name
        }
        foreach( key, val in tokens)
            path = replace(path, "[" + key + "]", val);
           
        //replace slashes with backslashes
        path = replace(path, "\\", "/");
        //ensure trailing slash
        local trailing = path.slice(path.len() - 1, path.len());
        if ( trailing != "/") path += "/";
        return path;
    }
   
    //replace all instances of 'find' in 'str' with 'repl'
    function replace(str, find, repl) {
        local start = str.find(find);
        if ( start != null ) {
            local end = start + find.len();
            local before = str.slice(0, start);
            local after = str.slice(end, str.len());
            str = before + repl + after;
            str = replace(str, find, repl);
        }
        return str;
    }
}

PDFManualReader();

Tomorrow Ill test on the pi :)

Title: Re: [Plugin WIP] SumatraPDF reader (only for windows)
Post by: qqplayer on July 14, 2019, 05:33:16 AM
The plugin doesnt work with the new daily builds.
Freezes AM and I have to close it manually.

http://forum.attractmode.org/index.php?topic=2324.msg20822#new

Anyone can help me?
All my crashes and speed problems has been solved with the last daily updates.
Since attract-daily_06_17_2019
But now I cant read my manuals and guides... :'(
Title: Re: [Plugin WIP] SumatraPDF reader (only for windows)
Post by: qqplayer on July 15, 2019, 11:40:22 AM
Solved, thanks to Oomek.

Just change

Code: [Select]
fe.plugin_command
for

Code: [Select]
fe.plugin_command_bg
Title: Re: [Plugin WIP] SumatraPDF reader (only for windows)
Post by: rand0m on July 15, 2019, 04:05:25 PM
Solved, thanks to Oomek.

Just change

Code: [Select]
fe.plugin_command
for

Code: [Select]
fe.plugin_command_bg

Is it possible to give a path like [rompath]/ .. /docs/[name].pdf?