warehouse aplpha test pass

This commit is contained in:
cuu 2021-10-24 19:29:20 +08:00
parent 94245a58e8
commit 5cb318cd56
12 changed files with 426 additions and 67 deletions

3
.gitignore vendored
View File

@ -24,3 +24,6 @@ screenshots/*
.pcsx/* .pcsx/*
*.log *.log
app-local.ini
*.db
app

View File

@ -72,9 +72,16 @@ func (self *ImageDownloadProcessPage) Init() {
self.LoadingLabel = LoadingLabel self.LoadingLabel = LoadingLabel
self.Downloader = grab.NewClient() self.Downloader = grab.NewClient()
self.Downloading = make(chan bool) self.Downloading = make(chan bool,1)
} }
func (self *ImageDownloadProcessPage) SetDownloading(v bool) {
for len(self.Downloading) > 0 {
<- self.Downloading
}
self.Downloading <- v
}
func (self *ImageDownloadProcessPage) OnLoadCb() { func (self *ImageDownloadProcessPage) OnLoadCb() {
@ -104,10 +111,8 @@ func (self *ImageDownloadProcessPage) OnLoadCb() {
self.req,_ = grab.NewRequest("/tmp",self.URL) self.req,_ = grab.NewRequest("/tmp",self.URL)
self.resp = self.Downloader.Do(self.req) self.resp = self.Downloader.Do(self.req)
for len(self.Downloading) > 0 {
<-self.Downloading self.SetDownloading(true)
}
self.Downloading <- true
go self.UpdateProcessInterval(400) go self.UpdateProcessInterval(400)
@ -116,10 +121,10 @@ func (self *ImageDownloadProcessPage) OnLoadCb() {
} }
func (self *ImageDownloadProcessPage) UpdateProcessInterval(ms int) { func (self *ImageDownloadProcessPage) UpdateProcessInterval(ms int) {
ms_total := 0
t := gotime.NewTicker(gotime.Duration(ms) * gotime.Millisecond) t := gotime.NewTicker(gotime.Duration(ms) * gotime.Millisecond)
defer t.Stop() defer t.Stop()
L:
for { for {
select { select {
case <-t.C: case <-t.C:
@ -127,14 +132,17 @@ func (self *ImageDownloadProcessPage) UpdateProcessInterval(ms int) {
self.resp.BytesComplete(), self.resp.BytesComplete(),
self.resp.Size, self.resp.Size,
100*self.resp.Progress()) 100*self.resp.Progress())
ms_total += ms
if(ms_total > 10000) {
fmt.Println("Get preview image timeout")
break L
}
case <-self.resp.Done: case <-self.resp.Done:
// download is complete // download is complete
break break L
case v:= <-self.Downloading: case v:= <-self.Downloading:
if v == false { if v == false {
t.Stop() break L
break
} }
} }
} }
@ -184,7 +192,7 @@ func (self *ImageDownloadProcessPage) KeyDown(ev *event.Event) {
if UI.IsKeyMenuOrB(ev.Data["Key"]) { if UI.IsKeyMenuOrB(ev.Data["Key"]) {
self.Downloading <- false self.SetDownloading(false)
self.ReturnToUpLevelPage() self.ReturnToUpLevelPage()
self.Screen.Draw() self.Screen.Draw()

View File

@ -8,6 +8,7 @@ import (
"strings" "strings"
"encoding/json" "encoding/json"
"path" "path"
"path/filepath"
"github.com/veandco/go-sdl2/ttf" "github.com/veandco/go-sdl2/ttf"
@ -15,6 +16,7 @@ import (
//"github.com/cuu/gogame/draw" //"github.com/cuu/gogame/draw"
"github.com/cuu/gogame/color" "github.com/cuu/gogame/color"
"github.com/cuu/gogame/event" "github.com/cuu/gogame/event"
"github.com/cuu/gogame/time"
"github.com/clockworkpi/LauncherGoDev/sysgo/UI" "github.com/clockworkpi/LauncherGoDev/sysgo/UI"
"github.com/cuu/grab" "github.com/cuu/grab"
) )
@ -60,10 +62,18 @@ func (self *LoadHousePage) Init() {
self.LoadingLabel.SetColor(self.TextColor) self.LoadingLabel.SetColor(self.TextColor)
self.Downloader = grab.NewClient() self.Downloader = grab.NewClient()
self.Downloading = make(chan bool) self.Downloading = make(chan bool,1)
} }
func (self *LoadHousePage) SetDownloading(v bool) {
for len(self.Downloading) > 0 {
<- self.Downloading
}
self.Downloading <- v
}
func (self *LoadHousePage) OnLoadCb() { func (self *LoadHousePage) OnLoadCb() {
if len(self.URL) < 10 { if len(self.URL) < 10 {
@ -77,7 +87,7 @@ func (self *LoadHousePage) OnLoadCb() {
//filename := strings.TrimSpace(parts[len(parts)-1]) //filename := strings.TrimSpace(parts[len(parts)-1])
local_dir := strings.Split(self.URL,"raw.githubusercontent.com") local_dir := strings.Split(self.URL,"raw.githubusercontent.com")
home_path, _ := os.UserHomeDir() home_path, _ := os.UserHomeDir()
fmt.Println("LoadHouse OnLoadCb")
if len(local_dir) > 1 { if len(local_dir) > 1 {
menu_file := local_dir[1] menu_file := local_dir[1]
local_menu_file := fmt.Sprintf("%s/aria2downloads%s", local_menu_file := fmt.Sprintf("%s/aria2downloads%s",
@ -93,21 +103,16 @@ func (self *LoadHousePage) OnLoadCb() {
defer jsonFile.Close() defer jsonFile.Close()
byteValue, _ := ioutil.ReadAll(jsonFile) byteValue, _ := ioutil.ReadAll(jsonFile)
json.Unmarshal(byteValue, &result) json.Unmarshal(byteValue, &result)
self.Parent.MyStack.Push(result.List)
for _, repo := range result.List {
self.Parent.MyStack.Push(repo)
}
self.Leave() self.Leave()
} else { } else {
self.req,_ = grab.NewRequest("/tmp",self.URL) self.req,_ = grab.NewRequest("/tmp",self.URL)
self.resp = self.Downloader.Do(self.req) self.resp = self.Downloader.Do(self.req)
for len(self.Downloading) > 0 { self.SetDownloading(true)
<-self.Downloading fmt.Println("Start Download index json to /tmp,grab")
}
self.Downloading <- true
go self.UpdateProcessInterval(400) go self.UpdateProcessInterval(400)
} }
@ -115,9 +120,10 @@ func (self *LoadHousePage) OnLoadCb() {
} }
func (self *LoadHousePage) UpdateProcessInterval(ms int) { func (self *LoadHousePage) UpdateProcessInterval(ms int) {
ms_total := 0
t := gotime.NewTicker(gotime.Duration(ms) * gotime.Millisecond) t := gotime.NewTicker(gotime.Duration(ms) * gotime.Millisecond)
defer t.Stop() defer t.Stop()
L:
for { for {
select { select {
case <-t.C: case <-t.C:
@ -125,19 +131,24 @@ func (self *LoadHousePage) UpdateProcessInterval(ms int) {
self.resp.BytesComplete(), self.resp.BytesComplete(),
self.resp.Size, self.resp.Size,
100*self.resp.Progress()) 100*self.resp.Progress())
ms_total += ms
if(ms_total > 5000) {
fmt.Println("LoadHouse Timeout")
break L
}
case <-self.resp.Done: case <-self.resp.Done:
// download is complete // download is complete
break fmt.Println("Grab Download House done")
break L
case v:= <- self.Downloading: case v:= <- self.Downloading:
if v == false { if v == false {
t.Stop() break L
break
} }
} }
} }
//dst_filename := self.resp.Filename dst_filename := self.resp.Filename
fmt.Println("dst_filename ",dst_filename)
if err := self.resp.Err(); err == nil {//download successfully if err := self.resp.Err(); err == nil {//download successfully
home_path, _ := os.UserHomeDir() home_path, _ := os.UserHomeDir()
@ -154,14 +165,21 @@ func (self *LoadHousePage) UpdateProcessInterval(ms int) {
home_path,menu_file) home_path,menu_file)
} }
dl_file := path.Join("/tmp",filename) dl_file := path.Join("/tmp",filename)
if UI.IsDirectory( path.Base(local_menu_file) ) == false { fmt.Println("dl_file: ",dl_file)
merr := os.MkdirAll( path.Base(local_menu_file), os.ModePerm) fmt.Println(local_menu_file)
if UI.IsDirectory( filepath.Dir(local_menu_file) ) == false {
merr := os.MkdirAll( filepath.Dir(local_menu_file), os.ModePerm)
if merr != nil { if merr != nil {
panic(merr) panic(merr)
} }
} }
UI.CopyFile(dl_file,local_menu_file) UI.CopyFile(dl_file,local_menu_file)
os.Remove(dl_file)
var result WareHouseIndex var result WareHouseIndex
jsonFile, err := os.Open(local_menu_file) jsonFile, err := os.Open(local_menu_file)
if err != nil { if err != nil {
@ -171,24 +189,22 @@ func (self *LoadHousePage) UpdateProcessInterval(ms int) {
defer jsonFile.Close() defer jsonFile.Close()
byteValue, _ := ioutil.ReadAll(jsonFile) byteValue, _ := ioutil.ReadAll(jsonFile)
json.Unmarshal(byteValue, &result) json.Unmarshal(byteValue, &result)
self.Parent.MyStack.Push(result.List)
for _, repo := range result.List {
self.Parent.MyStack.Push(repo)
}
self.Leave() self.Leave()
} else { } else {
fmt.Println(err)
self.Screen.MsgBox.SetText("Fetch house failed") self.Screen.MsgBox.SetText("Fetch house failed")
self.Screen.MsgBox.Draw() self.Screen.MsgBox.Draw()
self.Screen.SwapAndShow() self.Screen.SwapAndShow()
time.BlockDelay(500)
} }
} }
func (self *LoadHousePage) Leave() { func (self *LoadHousePage) Leave() {
self.Downloading <- false self.SetDownloading(false)
self.ReturnToUpLevelPage() self.ReturnToUpLevelPage()
self.Screen.Draw() self.Screen.Draw()

View File

@ -0,0 +1,5 @@
{
"SO_FILE":"",
"NAME":"Warehouse"
}

View File

@ -19,10 +19,12 @@ type WareHousePlugin struct {
MainPage *WareHouse MainPage *WareHouse
} }
var aria2dl_folder = "%s/aria2downloads%s"
func (self *WareHousePlugin) Init(main_screen *UI.MainScreen) { func (self *WareHousePlugin) Init(main_screen *UI.MainScreen) {
self.MainPage = NewWareHouse() self.MainPage = NewWareHouse()
self.MainPage.SetScreen(main_screen) self.MainPage.SetScreen(main_screen)
self.MainPage.SetName("Tiny cloud") self.MainPage.SetName("Warehouse")
self.MainPage.Init() self.MainPage.Init()
} }

View File

@ -13,7 +13,7 @@ type WareHouseListItem struct {
Type string Type string
Value map[string]string Value map[string]string
Parent *WareHouse
} }
@ -86,7 +86,7 @@ func (self *WareHouseListItem) Draw() {
if self.Type == "source" || self.Type == "dir" { if self.Type == "source" || self.Type == "dir" {
_,h := self.Icons["ware"].Size() _,h := self.Icons["ware"].Size()
self.Icons["ware"].NewCoord(4,(self.Height - h)/2) self.Icons["ware"].NewCoord(4,self.PosY + (self.Height - h)/2)
self.Icons["ware"].DrawTopLeft() self.Icons["ware"].DrawTopLeft()
} }
@ -96,13 +96,13 @@ func (self *WareHouseListItem) Draw() {
_icon = "appdling" _icon = "appdling"
} }
_,h := self.Icons[_icon].Size() _,h := self.Icons[_icon].Size()
self.Icons[_icon].NewCoord(4,(self.Height - h )/2) self.Icons[_icon].NewCoord(4,self.PosY + (self.Height - h )/2)
self.Icons[_icon].DrawTopLeft() self.Icons[_icon].DrawTopLeft()
} }
if self.Type == "add_house" { if self.Type == "add_house" {
_,h := self.Icons["add"].Size() _,h := self.Icons["add"].Size()
self.Icons["add"].NewCoord(4,(self.Height - h)/2) self.Icons["add"].NewCoord(4,self.PosY+(self.Height - h)/2)
self.Icons["add"].DrawTopLeft() self.Icons["add"].DrawTopLeft()
} }

View File

@ -11,6 +11,7 @@ import (
"io/ioutil" "io/ioutil"
"path/filepath" "path/filepath"
"encoding/json" "encoding/json"
"reflect"
"database/sql" "database/sql"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
@ -228,6 +229,12 @@ func (self *WareHouse) SyncTasks() []map[string]string {
return ret return ret
} }
func IsSlice(v interface{}) bool {
if reflect.TypeOf(v).Kind() == reflect.Slice || reflect.TypeOf(v).Kind() == reflect.Array {
return true
}
return false
}
func (self *WareHouse) SyncList() { func (self *WareHouse) SyncList() {
@ -240,10 +247,17 @@ func (self *WareHouse) SyncList() {
var repos []map[string]string var repos []map[string]string
fmt.Printf("SyncList: %+v\n", self.MyStack)
stk := self.MyStack.Last() stk := self.MyStack.Last()
stk_len := self.MyStack.Length() stk_len := self.MyStack.Length()
if IsSlice(stk) {
repos = append(repos, stk.([]map[string]string)...)
}else {
repos = append(repos, stk.(map[string]string)) repos = append(repos, stk.(map[string]string))
}
add_new_house := make(map[string]string) add_new_house := make(map[string]string)
add_new_house["title"] = "Add new warehouse..." add_new_house["title"] = "Add new warehouse..."
@ -266,7 +280,8 @@ func (self *WareHouse) SyncList() {
} }
for _, u := range repos { for _, u := range repos {
li := &WareHouseListItem{} fmt.Printf("%+v\n",u)
li := NewWareHouseListItem()
li.Parent = self li.Parent = self
li.PosX = start_x li.PosX = start_x
li.PosY = start_y + last_height li.PosY = start_y + last_height
@ -285,7 +300,8 @@ func (self *WareHouse) SyncList() {
if err != nil { if err != nil {
log.Fatal( err ) log.Fatal( err )
} }
local_menu_file := fmt.Sprintf("%s/aria2download%s",home_path,menu_file) local_menu_file := fmt.Sprintf(aria2dl_folder,home_path,menu_file)
fmt.Println("for loop ",local_menu_file)
if UI.FileExists(local_menu_file) { if UI.FileExists(local_menu_file) {
li.ReadOnly = false li.ReadOnly = false
}else { }else {
@ -350,11 +366,15 @@ func (self *WareHouse) Init() {
self.RemovePage.StartOrAEvent = self.RemoveGame self.RemovePage.StartOrAEvent = self.RemoveGame
self.RemovePage.Name = "Are you sure?" self.RemovePage.Name = "Are you sure?"
self.RemovePage.Init()
self.Keyboard = UI.NewKeyboard() self.Keyboard = UI.NewKeyboard()
self.Keyboard.Name = "Enter warehouse addr" self.Keyboard.Name = "Enter warehouse addr"
self.Keyboard.FootMsg = [5]string{"Nav.","Add","ABC","Backspace","Enter"} self.Keyboard.FootMsg = [5]string{"Nav.","Add","ABC","Backspace","Enter"}
self.Keyboard.Screen = self.Screen self.Keyboard.Screen = self.Screen
self.Keyboard.Init() self.Keyboard.Init()
self.Keyboard.SetPassword("github.com/cuu/warehouse")
self.Keyboard.Caller = self
self.PreviewPage = NewImageDownloadProcessPage() self.PreviewPage = NewImageDownloadProcessPage()
self.PreviewPage.Screen = self.Screen self.PreviewPage.Screen = self.Screen
@ -399,7 +419,7 @@ func (self *WareHouse) ResetHouse() {
remote_file_url := cur_li.Value["file"] remote_file_url := cur_li.Value["file"]
parts := strings.Split(remote_file_url,"raw.githubusercontent.com") parts := strings.Split(remote_file_url,"raw.githubusercontent.com")
menu_file := parts[1] menu_file := parts[1]
local_menu_file := fmt.Sprintf("%s/aria2download%s",home_path,menu_file) local_menu_file := fmt.Sprintf(aria2dl_folder,home_path,menu_file)
local_menu_file_path := filepath.Dir(local_menu_file) local_menu_file_path := filepath.Dir(local_menu_file)
fmt.Println(local_menu_file) fmt.Println(local_menu_file)
@ -467,11 +487,14 @@ func (self *WareHouse) UrlIsDownloading(url string) (string,bool) {
if uris,err := self.rpcc.GetURIs(v.Gid);err == nil { if uris,err := self.rpcc.GetURIs(v.Gid);err == nil {
for _,x := range uris { for _,x := range uris {
if x.URI == url { if x.URI == url {
fmt.Println(x.URI," ",url)
return v.Gid,true return v.Gid,true
} }
} }
} }
} }
}else {
log.Fatal(err)
} }
return "",false return "",false
} }
@ -480,6 +503,7 @@ func (self *WareHouse) RemoveGame() {
if self.PsIndex > len(self.MyList) -1 { if self.PsIndex > len(self.MyList) -1 {
return return
} }
fmt.Println("RemoveGame")
cur_li := self.MyList[self.PsIndex].(*WareHouseListItem) cur_li := self.MyList[self.PsIndex].(*WareHouseListItem)
fmt.Println("Remove cur_li._Value",cur_li.Value) fmt.Println("Remove cur_li._Value",cur_li.Value)
@ -505,7 +529,7 @@ func (self *WareHouse) RemoveGame() {
remote_file_url := cur_li.Value["file"] remote_file_url := cur_li.Value["file"]
parts := strings.Split(remote_file_url,"raw.githubusercontent.com") parts := strings.Split(remote_file_url,"raw.githubusercontent.com")
menu_file := parts[1] menu_file := parts[1]
local_menu_file := fmt.Sprintf("%s/aria2download%s",home_path,menu_file) local_menu_file := fmt.Sprintf(aria2dl_folder,home_path,menu_file)
local_menu_file_path := filepath.Dir(local_menu_file) local_menu_file_path := filepath.Dir(local_menu_file)
gid,ret := self.UrlIsDownloading(remote_file_url) gid,ret := self.UrlIsDownloading(remote_file_url)
@ -532,14 +556,14 @@ func (self *WareHouse) Click() {
} }
cur_li := self.MyList[self.PsIndex].(*WareHouseListItem) cur_li := self.MyList[self.PsIndex].(*WareHouseListItem)
home_path, _ := os.UserHomeDir() home_path, _ := os.UserHomeDir()
fmt.Println("cur_li._Value",cur_li.Value) fmt.Println("Click cur_li._Value",cur_li.Value)
if cur_li.Value["type"] == "source" || cur_li.Value["type"] == "dir" { if cur_li.Value["type"] == "source" || cur_li.Value["type"] == "dir" {
remote_file_url := cur_li.Value["file"] remote_file_url := cur_li.Value["file"]
parts := strings.Split(remote_file_url,"raw.githubusercontent.com")//assume master branch parts := strings.Split(remote_file_url,"raw.githubusercontent.com")//assume master branch
menu_file := parts[1] menu_file := parts[1]
local_menu_file := fmt.Sprintf("%s/aria2download%s",home_path,menu_file) local_menu_file := fmt.Sprintf(aria2dl_folder,home_path,menu_file)
fmt.Println(local_menu_file) fmt.Println("warehouse click: ",local_menu_file)
if UI.FileExists(local_menu_file) == false { if UI.FileExists(local_menu_file) == false {
self.LoadHouse() self.LoadHouse()
}else { }else {
@ -559,10 +583,7 @@ func (self *WareHouse) Click() {
byteValue, _ := ioutil.ReadAll(jsonFile) byteValue, _ := ioutil.ReadAll(jsonFile)
json.Unmarshal(byteValue, &result) json.Unmarshal(byteValue, &result)
self.MyStack.Push(result.List)
for _, repo := range result.List {
self.MyStack.Push(repo)
}
self.SyncList() self.SyncList()
self.Screen.Draw() self.Screen.Draw()
@ -581,17 +602,28 @@ func (self *WareHouse) Click() {
remote_file_url := cur_li.Value["file"] remote_file_url := cur_li.Value["file"]
parts := strings.Split(remote_file_url,"raw.githubusercontent.com")//assume master branch parts := strings.Split(remote_file_url,"raw.githubusercontent.com")//assume master branch
menu_file := parts[1] menu_file := parts[1]
local_menu_file := fmt.Sprintf("%s/aria2download%s",home_path,menu_file) local_menu_file := fmt.Sprintf(aria2dl_folder,home_path,menu_file)
fmt.Println("Click on game ", local_menu_file)
if UI.FileExists(local_menu_file) == false { if UI.FileExists(local_menu_file) == false {
gid,ret := self.UrlIsDownloading(remote_file_url) gid,ret := self.UrlIsDownloading(remote_file_url)
if ret == false { if ret == false {
gid,err := self.rpcc.AddURI([]string{remote_file_url},"out:"+menu_file)
outfile := struct {
Out string `json:"out"`
}{Out:menu_file}
gid,err := self.rpcc.AddURI([]string{remote_file_url},outfile)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
}else { }else {
fmt.Println("Warehouse Click game is downloading, ",gid)
fmt.Println(remote_file_url)
self.Aria2DownloadingGid = gid self.Aria2DownloadingGid = gid
} }
} else { } else {
fmt.Println(self.rpcc.TellStatus(gid,"status","totalLength","completedLength")) fmt.Println(self.rpcc.TellStatus(gid,"status","totalLength","completedLength"))
self.Screen.MsgBox.SetText("Getting the game now") self.Screen.MsgBox.SetText("Getting the game now")
@ -601,7 +633,7 @@ func (self *WareHouse) Click() {
self.Screen.TitleBar.Redraw() self.Screen.TitleBar.Redraw()
} }
}else { }else {
fmt.Println("file downloaded") //maybe check it if is installed fst,then execute it fmt.Println("file downloaded ", cur_li.Value) //maybe check it if is installed fst,then execute it
if cur_li.Value["type"] == "launcher" && cur_li.ReadOnly == false { if cur_li.Value["type"] == "launcher" && cur_li.ReadOnly == false {
local_menu_file_path := filepath.Dir(local_menu_file) local_menu_file_path := filepath.Dir(local_menu_file)
game_sh := filepath.Join(local_menu_file_path,cur_li.Value["title"],cur_li.Value["title"]+".sh") game_sh := filepath.Join(local_menu_file_path,cur_li.Value["title"],cur_li.Value["title"]+".sh")
@ -656,6 +688,7 @@ func (self *WareHouse) raw_github_com(url string) (bool,string) {
func (self *WareHouse) OnKbdReturnBackCb() { func (self *WareHouse) OnKbdReturnBackCb() {
inputed:= strings.Join(self.Keyboard.Textarea.MyWords,"") inputed:= strings.Join(self.Keyboard.Textarea.MyWords,"")
inputed = strings.Replace(inputed,"http://","",-1) inputed = strings.Replace(inputed,"http://","",-1)
inputed = strings.Replace(inputed,"https://","",-1) inputed = strings.Replace(inputed,"https://","",-1)
@ -904,6 +937,12 @@ func (self *WareHouse) KeyDown(ev *event.Event) {
func (self *WareHouse) Draw() { func (self *WareHouse) Draw() {
self.ClearCanvas() self.ClearCanvas()
if self.PsIndex > len(self.MyList) -1 {
self.PsIndex = len(self.MyList) -1
}
if self.PsIndex < 0 {
self.PsIndex = 0
}
if len(self.MyList) == 0 { if len(self.MyList) == 0 {
return return
} else { } else {
@ -913,7 +952,7 @@ func (self *WareHouse) Draw() {
self.Ps.Draw() self.Ps.Draw()
for _,v := range self.MyList { for _,v := range self.MyList {
_,y := v.Coord() _,y := v.Coord()
if y > self.Height + self.Height/2 { if y > (self.Height + self.Height/2) {
break break
} }
if y < 0 { if y < 0 {

View File

@ -0,0 +1,163 @@
package main
import (
"fmt"
"log"
"os"
"os/exec"
"strings"
"path/filepath"
"context"
"time"
"github.com/zyxar/argo/rpc"
//"database/sql"
//_"github.com/mattn/go-sqlite3"
)
// The RPC server might send notifications to the client.
// Notifications is unidirectional, therefore the client which receives the notification must not respond to it.
// The method signature of a notification is much like a normal method request but lacks the id key
func fileExists(filename string) bool {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
return false
}
return !info.IsDir()
}
func System(cmd string) string {
ret := ""
out, err := exec.Command("bash", "-c", cmd).Output()
if err != nil {
if _, ok := err.(*exec.ExitError); ok {
//exit code !=0 ,but it can be ignored
} else {
fmt.Println(err)
}
} else {
ret = string(out)
}
return ret
}
type AppNotifier struct{}
func (AppNotifier) OnDownloadStart(events []rpc.Event) { log.Printf("%s started.", events) }
func (AppNotifier) OnDownloadPause(events []rpc.Event) { log.Printf("%s paused.", events) }
func (AppNotifier) OnDownloadStop(events []rpc.Event) { log.Printf("%s stopped.", events) }
func (AppNotifier) OnDownloadComplete(events []rpc.Event) {
log.Printf("AppNotifier %s completed.", events)
rpcc_, err := rpc.New(context.Background(), rpcURI, rpcSecret, time.Second,nil)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
defer rpcc_.Close()
for _,v := range events {
gid := v.Gid
msg, err := rpcc_.TellStatus(gid)
if err == nil {
log.Printf("%+v\n",msg)
if msg.Status == "complete" {
go InstallGame(msg)
}else if msg.Status == "error" {
log.Println(msg.ErrorMessage)
for _,v := range msg.Files {
if fileExists(v.Path) {
e := os.Remove(v.Path)
if e != nil {
log.Fatal(e)
}
}
if fileExists( v.Path + ".aria2" ) {
e := os.Remove(v.Path + ".aria2")
if e != nil {
log.Fatal(e)
}
}
}
}
}else {
log.Println("TellStatus err: ",err)
}
}
}
func (AppNotifier) OnDownloadError(events []rpc.Event) {
log.Printf("%s error.", events)
}
func (AppNotifier) OnBtDownloadComplete(events []rpc.Event) {
log.Printf("bt %s completed.", events)
}
func InstallGame(msg rpc.StatusInfo) {
if len(msg.Files) <= 0 {
return
}
ret := msg.Files[0].URIs
home_path,_ := os.UserHomeDir()
remote_file_url := ret[0].URI
parts := strings.Split(remote_file_url,"raw.githubusercontent.com")
if len(parts) < 1 {
return
}
menu_file := parts[1]
local_menu_file := fmt.Sprintf("%s/aria2downloads%s",home_path,menu_file)
local_menu_file_path := filepath.Dir(local_menu_file)
if fileExists(local_menu_file) {
gametype := "launcher"
if strings.HasSuffix(local_menu_file,".tar.gz") {
gametype = "launcher"
}
if strings.HasSuffix(local_menu_file,".p8.png") {
gametype = "pico8"
}
if strings.HasSuffix(local_menu_file,".tic") {
gametype = "tic80"
}
if gametype == "launcher" {
_cmd := fmt.Sprintf( "tar zxvf '%s' -C %s",local_menu_file, local_menu_file_path)
fmt.Println(_cmd)
System(_cmd)
}
if gametype == "pico8" {
_cmd := fmt.Sprintf("cp -rf '%s' ~/.lexaloffle/pico-8/carts/", local_menu_file)
fmt.Println(_cmd)
System(_cmd)
}
if gametype == "tic80" {
_cmd := fmt.Sprintf("cp -rf '%s' ~/games/TIC-80/",local_menu_file)
fmt.Println(_cmd)
System(_cmd)
}
}else {
fmt.Println(local_menu_file, " not found")
}
}

View File

@ -0,0 +1,100 @@
package main
import (
"context"
"errors"
"flag"
"fmt"
"os"
//"os/exec"
"time"
"log"
"github.com/zyxar/argo/rpc"
"database/sql"
_"github.com/mattn/go-sqlite3"
)
var (
rpcc rpc.Client
rpcSecret string
rpcURI string
launchLocal bool
errParameter = errors.New("invalid parameter")
errNotSupportedCmd = errors.New("not supported command")
errInvalidCmd = errors.New("invalid command")
)
func init() {
flag.StringVar(&rpcSecret, "secret", "", "set --rpc-secret for aria2c")
flag.StringVar(&rpcURI, "uri", "ws://localhost:6800/jsonrpc", "set rpc address")
flag.BoolVar(&launchLocal, "launch", false, "launch local aria2c daemon")
}
func InitSql() {
db, err := sql.Open("sqlite3", "foo.db")
if err != nil {
log.Fatal(err)
}
defer db.Close()
sqlStmt := `
CREATE TABLE IF NOT EXISTS tasks (
id integer PRIMARY KEY,
gid text NOT NULL,
title text NOT NULL,
file text NOT NULL,
type text NOT NULL,
status text,
totalLength text,
completedLength text,
fav text
);
`
_, err = db.Exec(sqlStmt)
if err != nil {
log.Printf("%q: %s\n", err, sqlStmt)
return
}
sqlStmt = `
CREATE TABLE IF NOT EXISTS warehouse (
id integer PRIMARY KEY,
title text NOT NULL,
file text NOT NULL,
type text NOT NULL
);
`
_,err = db.Exec(sqlStmt)
if err != nil {
log.Printf("%q: %s\n",err,sqlStmt)
return
}
}
func main() {
flag.Parse()
if flag.NArg() == 0 {
fmt.Fprintf(os.Stderr, "usage: app start\n")
flag.PrintDefaults()
fmt.Fprintln(os.Stderr)
}
InitSql()
var err error
rpcc, err = rpc.New(context.Background(), rpcURI, rpcSecret, time.Second, AppNotifier{})
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(2)
}
defer rpcc.Close()
for {
}
}

19
local-build.sh Executable file
View File

@ -0,0 +1,19 @@
#!/bin/bash
set -x
go build -o app appinstaller/appinstaller.go appinstaller/app_notifier.go
if [ $? -eq 0 ]; then
cp app ~/github/clockworkpi/launchergo
fi
go build -o launchergo main.go mainscreen.go
#go build -ldflags="-s -w" -o main main.go mainscreen.go
if [ $? -eq 0 ]; then
cp launchergo ~/github/clockworkpi/launchergo
fi

View File

@ -67,7 +67,7 @@ type ConfirmPage struct {
func NewConfirmPage() *ConfirmPage { func NewConfirmPage() *ConfirmPage {
p := &ConfirmPage{} p := &ConfirmPage{}
p.ListFont = Fonts["veramono20"] p.ListFont = MyLangManager.TrFont("veramono20")
p.FootMsg = [5]string{"Nav", "", "", "Cancel", "Yes"} p.FootMsg = [5]string{"Nav", "", "", "Cancel", "Yes"}
p.ConfirmText = "Confirm?" p.ConfirmText = "Confirm?"

View File

@ -1,7 +1,7 @@
package UI package UI
import ( import (
//"fmt" "fmt"
//"os" //"os"
//"path/filepath" //"path/filepath"
//"strings" //"strings"
@ -24,6 +24,7 @@ func NewYesCancelConfirmPage() *YesCancelConfirmPage {
p := &YesCancelConfirmPage{} p := &YesCancelConfirmPage{}
p.FootMsg = [5]string{"Nav","","","Cancel","Yes"} p.FootMsg = [5]string{"Nav","","","Cancel","Yes"}
p.ConfirmText = MyLangManager.Tr("Awaiting Input") p.ConfirmText = MyLangManager.Tr("Awaiting Input")
p.ListFont = MyLangManager.TrFont("veramono20")
p.StartOrAEvent = nil p.StartOrAEvent = nil
p.KeyXEvent = nil p.KeyXEvent = nil
@ -42,8 +43,11 @@ func (self *YesCancelConfirmPage) KeyDown(ev *event.Event) {
if IsKeyStartOrA(ev.Data["Key"]) { if IsKeyStartOrA(ev.Data["Key"]) {
if self.StartOrAEvent != nil { if self.StartOrAEvent != nil {
fmt.Println("StartOrA yes or no")
self.StartOrAEvent() self.StartOrAEvent()
self.ReturnToUpLevelPage() self.ReturnToUpLevelPage()
}else {
fmt.Println("StartOrA nil")
} }
} }