mirror of
https://github.com/clockworkpi/LauncherGoDev.git
synced 2025-12-12 07:58:51 +01:00
PluginConfig
This commit is contained in:
parent
3c0884c2d7
commit
a1f49ad1d9
5
Menu/GameShell/HelloWorld/plugin.config
Normal file
5
Menu/GameShell/HelloWorld/plugin.config
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"SO_FILE":"HelloWorld.so",
|
||||
"NAME":"HelloWorld"
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import (
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"log"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
"github.com/veandco/go-sdl2/ttf"
|
||||
@ -27,6 +28,24 @@ var (
|
||||
plugin_flag = "plugin.config"
|
||||
)
|
||||
|
||||
type ActionConifg struct {
|
||||
ROM string `json:"ROM"`
|
||||
ROM_SO string `json:"ROM_SO"`
|
||||
EXT []string `json:"EXT"`
|
||||
EXCLUDE []string `json:"EXCLUDE"`
|
||||
FILETYPE string `json:"FILETYPE"` // defalut is file
|
||||
LAUNCHER string `json:"LAUNCHER"`
|
||||
TITLE string `json:"TITLE"` // defaut is Game
|
||||
SO_URL string `json:"SO_URL"`
|
||||
RETRO_CONFIG string `json:"RETRO_CONFIG"`
|
||||
}
|
||||
|
||||
type PluginConfig struct {
|
||||
NAME string `json:"NAME"` // plugin name,default could be the same as Plugin Folder's name
|
||||
SO_FILE string `json:"SO_FILE"`
|
||||
|
||||
}
|
||||
|
||||
type MessageBox struct {
|
||||
Label
|
||||
Parent *MainScreen
|
||||
@ -336,9 +355,27 @@ func (self *MainScreen) ReadTheDirIntoPages(_dir string, pglevel int, cur_page P
|
||||
}
|
||||
|
||||
if self.IsPluginPackage(_dir+"/"+f.Name()) {
|
||||
iconitem.MyType = ICON_TYPES["FUNC"]
|
||||
iconitem.CmdPath = f.Name()
|
||||
cur_page.AppendIcon(iconitem)
|
||||
p_c := PluginConfig{}
|
||||
|
||||
dat, err := ioutil.ReadFile(_dir+"/"+f.Name()+"/" +plugin_flag)
|
||||
ShowErr(err)
|
||||
|
||||
err = json.Unmarshal(dat, &p_c)
|
||||
if err == nil {
|
||||
if p_c.NAME == "" {
|
||||
p_c.NAME = f.Name()
|
||||
}
|
||||
|
||||
pi,err := LoadPlugin(_dir+"/"+f.Name()+"/"+p_c.SO_FILE)
|
||||
Assert(err)
|
||||
iconitem.CmdInvoke = InitPlugin(pi,self)
|
||||
if iconitem.CmdInvoke != nil {
|
||||
|
||||
iconitem.MyType = ICON_TYPES["FUNC"]
|
||||
iconitem.CmdPath = f.Name()
|
||||
cur_page.AppendIcon(iconitem)
|
||||
}
|
||||
}
|
||||
//Init it
|
||||
}else {
|
||||
iconitem.MyType = ICON_TYPES["DIR"]
|
||||
|
||||
@ -51,22 +51,26 @@ func LoadPlugin( pname string) (*goplugin.Plugin,error) {
|
||||
return goplugin.Open(pname)
|
||||
}
|
||||
|
||||
func InitPlugin(p *goplugin.Plugin, main_screen *MainScreen) {
|
||||
func InitPlugin(p *goplugin.Plugin, main_screen *MainScreen) PluginInterface {
|
||||
symAPI,err := p.Lookup("APIOBJ")
|
||||
|
||||
if err!= nil {
|
||||
log.Fatal( "init plugin failed")
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
var pi PluginInterface
|
||||
pi,ok := symAPI.(PluginInterface)
|
||||
if !ok {
|
||||
log.Fatal("unexpected type from module symbol")
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
//PluginPoolRegister(pi)
|
||||
|
||||
pi.Init(main_screen)
|
||||
|
||||
return pi
|
||||
}
|
||||
|
||||
func RunPlugin(p *goplugin.Plugin, main_screen *MainScreen) {
|
||||
|
||||
@ -5,12 +5,31 @@ import (
|
||||
"log"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"fmt"
|
||||
|
||||
"github.com/cuu/gogame/display"
|
||||
|
||||
"github.com/cuu/LauncherGo/sysgo"
|
||||
)
|
||||
|
||||
func ShowErr(e error) {
|
||||
if e != nil {
|
||||
fmt.Println(e)
|
||||
}
|
||||
}
|
||||
|
||||
func Assert(e error) {
|
||||
if e != nil {
|
||||
log.Fatal("Assert: " , e)
|
||||
}
|
||||
}
|
||||
|
||||
func CheckAndPanic(e error) {
|
||||
if e != nil {
|
||||
panic(e)
|
||||
}
|
||||
}
|
||||
|
||||
func Abs(n int) int {
|
||||
y := n >> 63
|
||||
return (n ^ y) - y
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user