Difference between revisions of "Mah!Cade:Plugins"
Line 3: | Line 3: | ||
== Plugin Types == | == Plugin Types == | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
=== Launcher === | === Launcher === | ||
Launcher plugins are tied to Mah!Cade by the lauched file extension. During the game launch process Mah!Cade looks for a plugin named '''launcher_<ext>.py''' (ext is loaded at runtime during launch). if a plugin is found Mah!Cade tries to executes the '''read_scexec()''' function; from this function Mah!Cade expects a returned set of values as per the table below. | Launcher plugins are tied to Mah!Cade by the lauched file extension. During the game launch process Mah!Cade looks for a plugin named '''launcher_<ext>.py''' (ext is loaded at runtime during launch). if a plugin is found Mah!Cade tries to executes the '''read_scexec()''' function; from this function Mah!Cade expects a returned set of values as per the table below. |
Revision as of 01:01, 26 December 2011
Plugins
The plugins system for Mah!Cade was initially created to add support for reading shortcut files under windows and linux; executing them directly instead of through a 3rd party launcher. They were built into plugins to allow for ease of changes in the future.
Plugin Types
Launcher
Launcher plugins are tied to Mah!Cade by the lauched file extension. During the game launch process Mah!Cade looks for a plugin named launcher_<ext>.py (ext is loaded at runtime during launch). if a plugin is found Mah!Cade tries to executes the read_scexec() function; from this function Mah!Cade expects a returned set of values as per the table below.
Mah!Cade Plugin Return Values
Pos | Name | Description | Value Type |
---|---|---|---|
1 | Message | A Return Message for log file | String |
2 | Executable | The commandline for the emulator (emulator_executable) | String |
3 | Arguments | The arguments for the emulator | String |
4 | Working Directory | No Longer used; chdir executed from base path of emulator_executable | Obsolete |
5 | Check Executable | Verify existance of executable before launch (default) | Booleen |
6 | Launch with Shell | Pass Shell=True to popen | Booleen |
Example Template
"""Plugin for Mah!Cade""" def read_scexec(String): return String, String, String, String, Booleen, Booleen
The example above illustrates the bare minimum requirement for a launcher plugin in Mah!Cade
Functional Example
#!/usr/bin/env python # -*- coding: UTF-8 -*- # ### # Application: sc_desktop # File: sc_desktop.py # Description: .desktop shortcut plugin # Copyright (c) 2005-2012 Wayne Moulden <http://www.mameau.com> ### # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Library General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # EXAMPLE FILE #============================================================ # [Desktop Entry] # Version=1.0 # Type=Application # Terminal=false # Icon[en_AU]=/usr/local/share/wahcade/pixmaps/wahcade.png # Name[en_AU]=Wah!Cade # Exec=/usr/bin/wahcade # Name=Wah!Cade # Icon=/usr/local/share/wahcade/pixmaps/wahcade-logo.png import sys """Plugin for Mah!Cade""" def read_scexec(scfile): """ read shortcut and return executable path """ if sys.platform != 'win32': f = open(scfile) for line in f: if line[:5] == "Exec=": cmd = line[5:] return "Executing " + cmd, cmd, "", "", False, True return "Ran into problems finding executable in .desktop shortcut" else: return "Only available for non-windows platforms! returning"
Standalone Example
Here is the full standalone script.
#!/usr/bin/env python # -*- coding: UTF-8 -*- # ### # Application: sc_desktop # File: sc_desktop.py # Description: .desktop shortcut plugin # Copyright (c) 2005-2012 Wayne Moulden <http://www.mameau.com> ### # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Library General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # EXAMPLE FILE #============================================================ # [Desktop Entry] # Version=1.0 # Type=Application # Terminal=false # Icon[en_AU]=/usr/local/share/wahcade/pixmaps/wahcade.png # Name[en_AU]=Wah!Cade # Exec=/usr/bin/wahcade # Name=Wah!Cade # Icon=/usr/local/share/wahcade/pixmaps/wahcade-logo.png import os, sys, subprocess from subprocess import Popen """Plugin for Mah!Cade""" def __init__(scfile=""): if (len(sys.argv) > 1): scfile = sys.argv[1] if (len(scfile) > 1): result = read_scexec(scfile) if (len(result[0]) > 1): run_scexec(result[0],result[1]) else: return result[3] else: return "No shortcut file passed" def read_scexec(scfile): """ read shortcut and return executable path """ if sys.platform != 'win32': f = open(scfile) for line in f: if line[:5] == "Exec=": cmd = line[5:] return "Executing " + cmd, cmd, "", "", False, True return "Ran into problems finding executable in .desktop shortcut" else: return "Only available for non-windows platforms! returning" def run_scexec(cmd, args, work_dir, message=""): if work_dir: os.chdir(os.path.join(os.path.abspath(sys.path[0]), work_dir)) else: os.chdir(os.path.split(cmd)[0]) if args: cmd = cmd + " " + args p = subprocess.Popen(cmd, shell=True) p.wait
The example above is a completely self contained launcher in its own right (written as such intentionally) to execute from a path stored in a *.desktop file under linux. It was built around the current Mah!Cade plugin implementation; you can see the function read_scexec() exists in the example above.