From a1f49ad1d9321b2f8733fe3885e2aef3e40603d1 Mon Sep 17 00:00:00 2001 From: cuu Date: Mon, 10 Sep 2018 15:41:01 +0800 Subject: [PATCH] PluginConfig --- Menu/GameShell/HelloWorld/plugin.config | 5 +++ sysgo/UI/main_screen.go | 43 +++++++++++++++++++++++-- sysgo/UI/plugin.go | 10 ++++-- sysgo/UI/util_funcs.go | 19 +++++++++++ 4 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 Menu/GameShell/HelloWorld/plugin.config diff --git a/Menu/GameShell/HelloWorld/plugin.config b/Menu/GameShell/HelloWorld/plugin.config new file mode 100644 index 0000000..10eefe3 --- /dev/null +++ b/Menu/GameShell/HelloWorld/plugin.config @@ -0,0 +1,5 @@ +{ +"SO_FILE":"HelloWorld.so", +"NAME":"HelloWorld" +} + diff --git a/sysgo/UI/main_screen.go b/sysgo/UI/main_screen.go index 85f991f..907f6fe 100644 --- a/sysgo/UI/main_screen.go +++ b/sysgo/UI/main_screen.go @@ -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"] diff --git a/sysgo/UI/plugin.go b/sysgo/UI/plugin.go index c232ceb..28d0746 100644 --- a/sysgo/UI/plugin.go +++ b/sysgo/UI/plugin.go @@ -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) { diff --git a/sysgo/UI/util_funcs.go b/sysgo/UI/util_funcs.go index 7b5b398..2c6a2a1 100644 --- a/sysgo/UI/util_funcs.go +++ b/sysgo/UI/util_funcs.go @@ -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