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

qqplayer

  • Sr. Member
  • ****
  • Posts: 228
    • 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
« Last Edit: October 16, 2017, 07:58:30 AM by qqplayer »

kent79

  • Sr. Member
  • ****
  • Posts: 484
    • 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

Not working. Is it missing any instruction ?

qqplayer

  • Sr. Member
  • ****
  • Posts: 228
    • 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: 228
    • 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.
Code: [Select]
local slash = @"/"

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: 228
    • 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
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: 228
    • View Profile
Re: [Plugin WIP] SumatraPDF reader (only for windows)
« Reply #8 on: October 28, 2017, 05:56:44 PM »
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();
« Last Edit: October 28, 2017, 06:09:28 PM by qqplayer »