warehouse alpha

This commit is contained in:
cuu 2019-12-18 13:07:47 +00:00
parent 31f117d65f
commit 46b67bc12f
3 changed files with 129 additions and 86 deletions

View File

@ -9,7 +9,7 @@ import gobject
import sqlite3 import sqlite3
#from beeprint import pp #from beeprint import pp
from libs.roundrects import aa_round_rect from libs.roundrects import aa_round_rect
from shutil import copyfile from shutil import copyfile,rmtree
## local UI import ## local UI import
from UI.constants import Width,Height,ICON_TYPES,RESTARTUI from UI.constants import Width,Height,ICON_TYPES,RESTARTUI
@ -372,7 +372,7 @@ class Aria2DownloadProcessPage(Page):
def CheckDownload(self,aria2_gid): def CheckDownload(self,aria2_gid):
self._GID = aria2_gid self._GID = aria2_gid
self._DownloaderTimer = gobject.timeout_add(123, self.GObjectUpdateProcessInterval) self._DownloaderTimer = gobject.timeout_add(234, self.GObjectUpdateProcessInterval)
def KeyDown(self,event): def KeyDown(self,event):
if IsKeyMenuOrB(event.key): if IsKeyMenuOrB(event.key):
@ -461,7 +461,7 @@ class GameStoreListItem(InfoPageListItem):
appdling_icon._ImgSurf = MyIconPool.GiveIconSurface("appdling") appdling_icon._ImgSurf = MyIconPool.GiveIconSurface("appdling")
appdling_icon._CanvasHWND = self._CanvasHWND appdling_icon._CanvasHWND = self._CanvasHWND
appdling_icon._Parent = self appdling_icon._Parent = self
app_icon.Init(0,0,MyIconPool.Width("appdling"),MyIconPool.Height("appdling"),0) appdling_icon.Init(0,0,MyIconPool.Width("appdling"),MyIconPool.Height("appdling"),0)
blackheart_icon = IconItem() blackheart_icon = IconItem()
blackheart_icon._ImgSurf = MyIconPool.GiveIconSurface("blackheart") blackheart_icon._ImgSurf = MyIconPool.GiveIconSurface("blackheart")
@ -518,7 +518,7 @@ class GameStoreListItem(InfoPageListItem):
self._Labels["Small"].Draw() self._Labels["Small"].Draw()
#pygame.draw.line(self._Parent._CanvasHWND,MySkinManager.GiveColor('Line'),(self._PosX,self._PosY+self._Height-1),(self._PosX+self._Width,self._PosY+self._Height-1),1) pygame.draw.line(self._Parent._CanvasHWND,MySkinManager.GiveColor('Line'),(self._PosX,self._PosY+self._Height-1),(self._PosX+self._Width,self._PosY+self._Height-1),1)
class GameStorePage(Page): class GameStorePage(Page):
@ -540,6 +540,8 @@ class GameStorePage(Page):
_Downloading = None _Downloading = None
_aria2_db = "aria2tasks.db" _aria2_db = "aria2tasks.db"
_warehouse_db = "warehouse.db" _warehouse_db = "warehouse.db"
_GobjTimer = -1
def __init__(self): def __init__(self):
Page.__init__(self) Page.__init__(self)
self._Icons = {} self._Icons = {}
@ -551,6 +553,23 @@ class GameStorePage(Page):
] ]
self._MyStack.Push(repos) self._MyStack.Push(repos)
def GObjectUpdateProcessInterval(self):
ret = True
dirty = False
for x in self._MyList:
if x._Type == "launcher" or x._Type == "pico8" or x._Type == "tic80":
percent = config.RPC.getPercent(x._Value["file"])
if percent is not None:
x.SetSmallText(str(percent)+"%")
dirty = True
else:
x.SetSmallText("")
if self._Screen.CurPage() == self and dirty == True:
self._Screen.Draw()
self._Screen.SwapAndShow()
return ret
def SyncWarehouse(self): def SyncWarehouse(self):
try: try:
@ -617,6 +636,7 @@ class GameStorePage(Page):
li._PosY = start_y + last_height li._PosY = start_y + last_height
li._Width = Width li._Width = Width
li._Fonts["normal"] = self._ListFont15 li._Fonts["normal"] = self._ListFont15
li._Fonts["small"] = self._ListFont12
li._Active = False li._Active = False
li._ReadOnly = True li._ReadOnly = True
li._Value = u li._Value = u
@ -624,7 +644,14 @@ class GameStorePage(Page):
li.Init( u["title"] ) li.Init( u["title"] )
if stk_lev >1: if stk_lev >1:
li._ReadOnly = False remote_file_url = u["file"]
menu_file = remote_file_url.split("raw.githubusercontent.com")[1]
local_menu_file = "%s/aria2download%s" % (os.path.expanduser('~'),menu_file )
if FileExists(local_menu_file):
li._ReadOnly = False
else:
li._ReadOnly = True
elif stk_lev == 1: elif stk_lev == 1:
if "status" in u: if "status" in u:
if u["status"] == "complete": if u["status"] == "complete":
@ -635,6 +662,9 @@ class GameStorePage(Page):
last_height += li._Height last_height += li._Height
if li._Type == "launcher" or li._Type == "pico8" or li._Type == "tic80":
li.SetSmallText("")
self._MyList.append(li) self._MyList.append(li)
@ -703,12 +733,18 @@ class GameStorePage(Page):
remote_file_url = cur_li._Value["file"] remote_file_url = cur_li._Value["file"]
menu_file = remote_file_url.split("raw.githubusercontent.com")[1] #assume master branch menu_file = remote_file_url.split("raw.githubusercontent.com")[1] #assume master branch
local_menu_file = "%s/aria2download%s" % (os.path.expanduser('~'),menu_file ) local_menu_file = "%s/aria2download%s" % (os.path.expanduser('~'),menu_file )
print(local_menu_file) local_menu_file_path = os.path.dirname(local_menu_file)
print(local_menu_file_path)
local_jsons = glob.glob(local_menu_file_path+"/**/*.json")
try: try:
if os.path.exists(local_menu_file): if os.path.exists(local_menu_file):
os.remove(local_menu_file) os.remove(local_menu_file)
if os.path.exists(local_menu_file+".aria2"): if os.path.exists(local_menu_file+".aria2"):
os.remove(local_menu_file+".aria2") os.remove(local_menu_file+".aria2")
for x in local_jsons:
os.remove(x)
except Exception as ex: except Exception as ex:
print(ex) print(ex)
@ -733,11 +769,12 @@ class GameStorePage(Page):
return return
cur_li = self._MyList[self._PsIndex] cur_li = self._MyList[self._PsIndex]
if cur_li._Value["type"] == "launcher" or cur_li._Value["type"] == "pico8" or cur_li._Value["type"] == "tic80": if cur_li._Value["type"] == "launcher" or cur_li._Value["type"] == "pico8" or cur_li._Value["type"] == "tic80":
print(cur_li._Value["shots"]) if "shots" in cur_li._Value:
self._PreviewPage._URL = cur_li._Value["shots"] print(cur_li._Value["shots"])
self._Screen.PushPage(self._PreviewPage) self._PreviewPage._URL = cur_li._Value["shots"]
self._Screen.Draw() self._Screen.PushPage(self._PreviewPage)
self._Screen.SwapAndShow() self._Screen.Draw()
self._Screen.SwapAndShow()
def RemoveGame(self): def RemoveGame(self):
@ -760,33 +797,27 @@ class GameStorePage(Page):
conn.close() conn.close()
except Exception as ex: except Exception as ex:
print(ex) print(ex)
elif "gid" in cur_li._Value: elif cur_li._Value["type"] == "launcher" or cur_li._Value["type"] == "pico8" or cur_li._Value["type"] == "tic80":
remote_file_url = cur_li._Value["file"]
menu_file = remote_file_url.split("raw.githubusercontent.com")[1]
local_menu_file = "%s/aria2download%s" % (os.path.expanduser('~'),menu_file )
local_menu_file_path = os.path.dirname(local_menu_file)
gid,ret = config.RPC.urlDownloading(remote_file_url)
if ret == True:
config.RPC.remove(gid)
try: try:
gid = cur_li._Value["gid"] if os.path.exists(local_menu_file):
conn = sqlite3.connect(self._aria2_db) os.remove(local_menu_file)
conn.row_factory = dict_factory if os.path.exists(local_menu_file+".aria2"):
c = conn.cursor() os.remove(local_menu_file+".aria2")
ret = c.execute("SELECT * FROM tasks WHERE gid='%s'" % gid ).fetchone() if os.path.exists( os.path.join(local_menu_file_path,cur_li._Value["title"])):
if ret != None: rmtree(os.path.join(local_menu_file_path,cur_li._Value["title"]) )
remote_file_url = ret["file"]
menu_file = remote_file_url.split("raw.githubusercontent.com")[1]
local_menu_file = "%s/aria2download%s" % (os.path.expanduser('~'),menu_file )
try:
if os.path.exists(local_menu_file):
os.remove(local_menu_file)
if os.path.exists(local_menu_file+".aria2"):
os.remove(local_menu_file+".aria2")
except Exception as ex:
print(ex)
c.execute("DELETE FROM tasks WHERE gid = '%s'" % gid )
conn.commit()
conn.close()
except Exception as ex: except Exception as ex:
print(ex) print(ex)
def Click(self): def Click(self):
if self._PsIndex > len(self._MyList) -1: if self._PsIndex > len(self._MyList) -1:
return return
@ -839,6 +870,7 @@ class GameStorePage(Page):
gid = config.RPC.addUri( remote_file_url, options={"out": menu_file}) gid = config.RPC.addUri( remote_file_url, options={"out": menu_file})
self._Downloading = gid self._Downloading = gid
print("stack length ",self._MyStack.Length()) print("stack length ",self._MyStack.Length())
"""
if self._MyStack.Length() > 1:## not on the top list page if self._MyStack.Length() > 1:## not on the top list page
try: try:
conn = sqlite3.connect(self._aria2_db) conn = sqlite3.connect(self._aria2_db)
@ -849,6 +881,7 @@ class GameStorePage(Page):
conn.close() conn.close()
except Exception as ex: except Exception as ex:
print("SQLITE3 ",ex) print("SQLITE3 ",ex)
"""
else: else:
print(config.RPC.tellStatus(gid,["status","totalLength","completedLength"])) print(config.RPC.tellStatus(gid,["status","totalLength","completedLength"]))
@ -863,7 +896,8 @@ class GameStorePage(Page):
else: else:
print("file downloaded")# maybe check it if is installed,then execute it print("file downloaded")# maybe check it if is installed,then execute it
if cur_li._Value["type"]=="launcher" and cur_li._ReadOnly == False: if cur_li._Value["type"]=="launcher" and cur_li._ReadOnly == False:
game_sh = os.path.join( "%s/apps/Menu/21_Indie Games/" % os.path.expanduser('~'),cur_li._Value["title"],cur_li._Value["title"]+".sh") local_menu_file_path = os.path.dirname(local_menu_file)
game_sh = os.path.join( local_menu_file_path, cur_li._Value["title"],cur_li._Value["title"]+".sh")
#game_sh = reconstruct_broken_string( game_sh) #game_sh = reconstruct_broken_string( game_sh)
print("run game: ",game_sh, os.path.exists( game_sh)) print("run game: ",game_sh, os.path.exists( game_sh))
self._Screen.RunEXE(game_sh) self._Screen.RunEXE(game_sh)
@ -928,6 +962,8 @@ class GameStorePage(Page):
c.execute(sql_insert) c.execute(sql_insert)
conn.commit() conn.commit()
self.SyncList() self.SyncList()
self._Screen.Draw()
self._Screen.SwapAndShow()
conn.close() conn.close()
except Exception as ex: except Exception as ex:
print(ex) print(ex)
@ -942,8 +978,10 @@ class GameStorePage(Page):
self._FootMsg[2] = "Remove" self._FootMsg[2] = "Remove"
self._FootMsg[1] = "UpdateWare" self._FootMsg[1] = "UpdateWare"
else: else:
self._FootMsg[2] = "Up" self._FootMsg[2] = "Remove"
self._FootMsg[1] = "" self._FootMsg[1] = "Preview"
self._GobjTimer = gobject.timeout_add(500, self.GObjectUpdateProcessInterval)
self.SyncList() self.SyncList()
@ -953,8 +991,8 @@ class GameStorePage(Page):
self._FootMsg[2] = "Remove" self._FootMsg[2] = "Remove"
self._FootMsg[1] = "UpdateWare" self._FootMsg[1] = "UpdateWare"
else: else:
self._FootMsg[2] = "" self._FootMsg[2] = "Remove"
self._FootMsg[1] = "" self._FootMsg[1] = "Preview"
self.SyncList() self.SyncList()
self._Screen.Draw() self._Screen.Draw()
@ -974,7 +1012,7 @@ class GameStorePage(Page):
self._FootMsg[2] = "Remove" self._FootMsg[2] = "Remove"
self._FootMsg[1] = "UpdateWare" self._FootMsg[1] = "UpdateWare"
else: else:
self._FootMsg[2] = "" self._FootMsg[2] = "Remove"
self._FootMsg[1] = "Preview" self._FootMsg[1] = "Preview"
self.SyncList() self.SyncList()
@ -985,6 +1023,7 @@ class GameStorePage(Page):
self.ReturnToUpLevelPage() self.ReturnToUpLevelPage()
self._Screen.Draw() self._Screen.Draw()
self._Screen.SwapAndShow() self._Screen.SwapAndShow()
gobject.source_remove(self._GobjTimer)
if IsKeyStartOrA(event.key): if IsKeyStartOrA(event.key):
self.Click() self.Click()
@ -993,7 +1032,7 @@ class GameStorePage(Page):
self._FootMsg[2] = "Remove" self._FootMsg[2] = "Remove"
self._FootMsg[1] = "UpdateWare" self._FootMsg[1] = "UpdateWare"
else: else:
self._FootMsg[2] = "" self._FootMsg[2] = "Remove"
self._FootMsg[1] = "Preview" self._FootMsg[1] = "Preview"
self._Screen.Draw() self._Screen.Draw()
@ -1002,24 +1041,19 @@ class GameStorePage(Page):
if event.key == CurKeys["X"]: if event.key == CurKeys["X"]:
#print(self._MyStack.Length() ) #print(self._MyStack.Length() )
if self._MyStack.Length() == 1 and self._PsIndex > 0: if self._PsIndex <= len(self._MyList) -1:
self._Screen.PushPage(self._remove_page) cur_li = self._MyList[self._PsIndex]
self._remove_page._StartOrA_Event = self.RemoveGame if cur_li._Type != "dir":
self._Screen.Draw() if self._MyStack.Length() == 1 and self._PsIndex == 0:
self._Screen.SwapAndShow() pass
#predefined source
else:
self._Screen.PushPage(self._remove_page)
self._remove_page._StartOrA_Event = self.RemoveGame
self._Screen.Draw()
self._Screen.SwapAndShow()
return return
"""
if self._MyStack.Length() > 1:
self._MyStack.Pop()
if self._MyStack.Length() == 1:
self._FootMsg[2] = "Remove"
self._FootMsg[1] = "UpdateWare"
else:
self._FootMsg[2] = "Up"
self._FootMsg[1] = "Preview"
"""
self.SyncList() self.SyncList()
self._Screen.Draw() self._Screen.Draw()
self._Screen.SwapAndShow() self._Screen.SwapAndShow()

View File

@ -21,29 +21,37 @@ def dict_factory(cursor, row):
return d return d
@misc.threaded @misc.threaded
def game_install_thread(gid): def game_install_thread(aria2_result):
try: try:
conn = sqlite3.connect(aria2_db) #print("game_install_thread ",aria2_result)
conn.row_factory = dict_factory if "files" in aria2_result:
c = conn.cursor() if len(aria2_result["files"]) <= 0:
ret = c.execute("SELECT * FROM tasks WHERE gid='%s'" % gid ).fetchone() return
if ret == None: if "arm" not in platform.machine():
conn.close()
return return
c.execute("UPDATE tasks SET status='complete' WHERE gid='%s'" % gid) ret = aria2_result["files"][0]['uris']
conn.commit()
conn.close()
remote_file_url = ret["file"] remote_file_url = ret[0]['uri']
menu_file = remote_file_url.split("raw.githubusercontent.com")[1] menu_file = remote_file_url.split("raw.githubusercontent.com")[1]
local_menu_file = "%s/aria2download%s" % (os.path.expanduser('~'),menu_file ) local_menu_file = "%s/aria2download%s" % (os.path.expanduser('~'),menu_file )
local_menu_file_path = os.path.dirname(local_menu_file)
if os.path.exists(local_menu_file) == True:
gametype = "launcher"
if local_menu_file.endswith(".tar.gz"):
gametype = "launcher"
if local_menu_file.endswith(".p8.png"):
gametype = "pico8"
if local_menu_file.endswith(".tic"):
gametype = "tic80"
if os.path.exists(local_menu_file) == True and "arm" in platform.machine():
gametype = ret["type"]
if gametype == "launcher": if gametype == "launcher":
#tar zxvf #tar zxvf
_cmd = "tar zxvf '%s' -C %s" % (local_menu_file, "~/apps/Menu/21_Indie\ Games/") _cmd = "tar zxvf '%s' -C %s" % (local_menu_file, local_menu_file_path)
print(_cmd) print(_cmd)
os.system(_cmd) os.system(_cmd)
if gametype == "pico8": if gametype == "pico8":
@ -57,9 +65,7 @@ def game_install_thread(gid):
except Exception as ex: except Exception as ex:
print("Sqlite3 error: ",ex) print("app install error: ",ex)
def on_message(ws, message): def on_message(ws, message):
@ -76,16 +82,17 @@ def on_message(ws, message):
if "method" in aria2_noti and aria2_noti["method"] == "aria2.onDownloadComplete": if "method" in aria2_noti and aria2_noti["method"] == "aria2.onDownloadComplete":
gid = aria2_noti["params"][0]["gid"] gid = aria2_noti["params"][0]["gid"]
#msg = rpc.tellStatus(gid) msg = rpc.tellStatus(gid)
#ws.send(msg) ws.send(msg)
game_install_thread(gid) #game_install_thread(gid)
if "method" not in aria2_noti and "result" in aria2_noti: if "method" not in aria2_noti and "result" in aria2_noti:
if "status" in aria2_noti: result = aria2_noti["result"]
if aria2_noti["status"] == "error": if "status" in result:
if result["status"] == "error":
try: try:
print(aria2_noti["errorMessage"]) print(result["errorMessage"])
for x in aria2_noti["files"]: for x in result["files"]:
if os.path.exists(x["path"]): if os.path.exists(x["path"]):
os.remove(x["path"]) os.remove(x["path"])
if os.path.exists(x["path"]+".aria2"): if os.path.exists(x["path"]+".aria2"):
@ -93,6 +100,8 @@ def on_message(ws, message):
except Exception as ex: except Exception as ex:
print(ex) print(ex)
if result["status"] == "complete":
game_install_thread(result)
def on_error(ws, error): def on_error(ws, error):

@ -1 +1 @@
Subproject commit 864bea5ca1252bc105cac47f640f47e95c81f6fa Subproject commit b554bce52720629420238c3813f72a4c6554917a