Author Topic: [Plugin WIP] SumatraPDF reader (only for windows)  (Read 14026 times)

qqplayer

  • Sr. Member
  • ****
  • Posts: 301
    • View Profile
[Plugin WIP] SumatraPDF reader (only for windows)
« 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.
I´ve tried but failed  :(

« Last Edit: October 16, 2017, 07:58:30 AM by qqplayer »

kent79

  • Hero Member
  • *****
  • Posts: 842
    • View Profile
Re: [Plugin WIP] SumatraPDF reader (only for windows)
« Reply #1 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.
I´ve tried but failed  :(

Not working. Is it missing any instruction ?

qqplayer

  • Sr. Member
  • ****
  • Posts: 301
    • View Profile
Re: [Plugin WIP] SumatraPDF reader (only for windows)
« Reply #2 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



Add custom 1 key to launch Sumatrapdf

« Last Edit: October 17, 2017, 04:38:00 AM by qqplayer »

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
Re: [Plugin WIP] SumatraPDF reader (only for windows)
« Reply #3 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.

qqplayer

  • Sr. Member
  • ****
  • Posts: 301
    • View Profile
Re: [Plugin WIP] SumatraPDF reader (only for windows)
« Reply #4 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 :)
I´ve just discover I could make something like this:

Code: [Select]
local slash = @"/"
I´m trying to "port" this idea to the rpi but can´t send paths with blanck spaces  :(
I´ll post the code , maybe you can help me with this too.

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
Re: [Plugin WIP] SumatraPDF reader (only for windows)
« Reply #5 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?

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
Re: [Plugin WIP] SumatraPDF reader (only for windows)
« Reply #6 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
« Last Edit: October 28, 2017, 02:40:30 PM by liquid8d »

qqplayer

  • Sr. Member
  • ****
  • Posts: 301
    • View Profile
Re: [Plugin WIP] SumatraPDF reader (only for windows)
« Reply #7 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!!! I´ll try tomorrow.

Talking about the rpi thing I have to convert the pdf into png files and keep into a folder.
I´ve 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
« Last Edit: October 28, 2017, 05:27:10 PM by qqplayer »

qqplayer

  • Sr. Member
  • ****
  • Posts: 301
    • View Profile
Re: [Plugin WIP] SumatraPDF reader (only for windows)
« Reply #8 on: October 28, 2017, 05:56:44 PM »
Update , I can´t 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 I´ll test on the pi :)

« Last Edit: October 28, 2017, 06:09:28 PM by qqplayer »

qqplayer

  • Sr. Member
  • ****
  • Posts: 301
    • View Profile
Re: [Plugin WIP] SumatraPDF reader (only for windows)
« Reply #9 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... :'(
« Last Edit: July 14, 2019, 05:36:53 AM by qqplayer »

qqplayer

  • Sr. Member
  • ****
  • Posts: 301
    • View Profile
Re: [Plugin WIP] SumatraPDF reader (only for windows)
« Reply #10 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

rand0m

  • Sr. Member
  • ****
  • Posts: 343
    • View Profile
Re: [Plugin WIP] SumatraPDF reader (only for windows)
« Reply #11 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?

jedione

  • Hero Member
  • *****
  • Posts: 1135
  • punktoe
    • View Profile
Re: [Plugin WIP] SumatraPDF reader (only for windows)
« Reply #12 on: May 12, 2020, 07:48:21 PM »
i know this is a bit old,  but could somone awnser this Q:

Put your pdfs in the plugins/SumatraPDF/list_title/Game Name.pdf

what is the list_title ?

what im doing is puting the pdf in the Game Manuals folder with same name as the game 
and just says no manule found
« Last Edit: May 12, 2020, 07:54:24 PM by jedione »
help a friend....

progets

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1271
    • View Profile
Re: [Plugin WIP] SumatraPDF reader (only for windows)
« Reply #13 on: May 12, 2020, 08:24:22 PM »
i know this is a bit old,  but could somone awnser this Q:

Put your pdfs in the plugins/SumatraPDF/list_title/Game Name.pdf

what is the list_title ?

what im doing is puting the pdf in the Game Manuals folder with same name as the game 
and just says no manule found

Default place to put your PDFs examples would be:
/attract/plugins/SumatraPDF/Game Manuals/Nintendo Entertainment System/<rom_name>.pdf
/attract/plugins/SumatraPDF/Game Manuals/NES/<rom_name>.pdf
/attract/plugins/SumatraPDF/Game Manuals/Nintendo NES/<rom_name>.pdf

list_title = the exact name of your emulator

The PDF names needs to exactly match your rom names.

Make sure you set the path in the plugin settings if you're not using the default. Example: /EmuMovies/[Emulator]/Manual

P.S. I recommend version 1.1 in this post http://forum.attractmode.org/index.php?topic=1927.msg13403#msg13403 over the OP version 1.0, which has no options.
« Last Edit: May 13, 2020, 12:31:39 AM by progets »

jedione

  • Hero Member
  • *****
  • Posts: 1135
  • punktoe
    • View Profile
Re: [Plugin WIP] SumatraPDF reader (only for windows)
« Reply #14 on: May 13, 2020, 06:49:16 AM »
ok that realy explaind it wel,  it now works for me thank you very mutch..
help a friend....